1 |
tdb |
1.2 |
/* |
2 |
|
|
* i-scream central monitoring system |
3 |
tdb |
1.3 |
* http://www.i-scream.org.uk |
4 |
tdb |
1.2 |
* Copyright (C) 2000-2002 i-scream |
5 |
|
|
* |
6 |
|
|
* This program is free software; you can redistribute it and/or |
7 |
|
|
* modify it under the terms of the GNU General Public License |
8 |
|
|
* as published by the Free Software Foundation; either version 2 |
9 |
|
|
* of the License, or (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* This program is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* GNU General Public License for more details. |
15 |
|
|
* |
16 |
|
|
* You should have received a copy of the GNU General Public License |
17 |
|
|
* along with this program; if not, write to the Free Software |
18 |
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 |
|
|
*/ |
20 |
|
|
|
21 |
pjm2 |
1.1 |
//---PACKAGE DECLARATION--- |
22 |
|
|
|
23 |
|
|
//---IMPORTS--- |
24 |
|
|
|
25 |
|
|
import org.xml.sax.*; |
26 |
|
|
import javax.xml.parsers.SAXParserFactory; |
27 |
|
|
import javax.xml.parsers.ParserConfigurationException; |
28 |
|
|
import javax.xml.parsers.SAXParser; |
29 |
|
|
|
30 |
|
|
/** |
31 |
|
|
* DataLayout |
32 |
|
|
* |
33 |
tdb |
1.3 |
* @author $Author: tdb $ |
34 |
tdb |
1.4 |
* @version $Id: DataLayout.java,v 1.3 2002/05/21 16:47:11 tdb Exp $ |
35 |
pjm2 |
1.1 |
*/ |
36 |
|
|
public class DataLayout { |
37 |
|
|
|
38 |
|
|
//---FINAL ATTRIBUTES--- |
39 |
|
|
|
40 |
|
|
/** |
41 |
|
|
* The current CVS revision of this class |
42 |
|
|
*/ |
43 |
tdb |
1.4 |
public final String REVISION = "$Revision: 1.3 $"; |
44 |
pjm2 |
1.1 |
|
45 |
|
|
private final int topOffset = 4; |
46 |
|
|
private final int leftStart = 2; |
47 |
|
|
private final int rightStart = 41; |
48 |
|
|
private final int fieldLength = 17; |
49 |
|
|
|
50 |
|
|
//---STATIC METHODS--- |
51 |
|
|
|
52 |
|
|
//---CONSTRUCTORS--- |
53 |
|
|
|
54 |
|
|
// Constructor |
55 |
|
|
public DataLayout (TerminalScreen screen, String[][] showData) { |
56 |
|
|
_screen = screen; |
57 |
|
|
_showData = showData; |
58 |
|
|
} |
59 |
|
|
|
60 |
|
|
//---PUBLIC METHODS--- |
61 |
|
|
|
62 |
|
|
public void updateScreen(XMLPacket packet) { |
63 |
|
|
boolean onLeft = true; |
64 |
|
|
for (int i = 0; i < _showData.length; i++) { |
65 |
|
|
String friendlyName = _showData[i][1]; |
66 |
|
|
String value = packet.getParam(_showData[i][0]); |
67 |
|
|
|
68 |
|
|
friendlyName = this.StringSizer(friendlyName); |
69 |
|
|
value = this.StringSizer(value); |
70 |
|
|
|
71 |
|
|
if (onLeft) { |
72 |
|
|
onLeft = false; |
73 |
|
|
_screen.gotoxy(leftStart, (i/2)+topOffset); |
74 |
|
|
_screen.print(friendlyName+": "+value); |
75 |
|
|
|
76 |
|
|
} |
77 |
|
|
else { |
78 |
|
|
onLeft = true; |
79 |
|
|
_screen.gotoxy(rightStart, (i/2)+topOffset); |
80 |
|
|
_screen.print(friendlyName+": "+value); |
81 |
|
|
} |
82 |
|
|
} |
83 |
|
|
} |
84 |
|
|
|
85 |
|
|
//---PRIVATE METHODS--- |
86 |
|
|
|
87 |
|
|
private String StringSizer(String value) { |
88 |
|
|
if (value == null) { |
89 |
|
|
value = ""; |
90 |
|
|
} |
91 |
|
|
|
92 |
|
|
int lengthDiff = fieldLength - value.length(); |
93 |
|
|
if (lengthDiff < 0) { |
94 |
|
|
value = value.substring(0, fieldLength - 3) + "..."; |
95 |
|
|
} |
96 |
|
|
else if (lengthDiff > 0) { |
97 |
|
|
char[] padding = new char[lengthDiff]; |
98 |
|
|
for (int i=0; i < lengthDiff; i++) { |
99 |
|
|
padding[i] = 32; |
100 |
|
|
} |
101 |
|
|
value = value + new String(padding); |
102 |
|
|
} |
103 |
|
|
return value; |
104 |
|
|
} |
105 |
|
|
|
106 |
|
|
//---ACCESSOR/MUTATOR METHODS--- |
107 |
|
|
|
108 |
|
|
//---ATTRIBUTES--- |
109 |
|
|
|
110 |
|
|
private TerminalScreen _screen; |
111 |
|
|
private String[][] _showData; |
112 |
|
|
|
113 |
|
|
//---STATIC ATTRIBUTES--- |
114 |
|
|
|
115 |
|
|
} |