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