| 1 |
//---PACKAGE DECLARATION--- |
| 2 |
|
| 3 |
//---IMPORTS--- |
| 4 |
|
| 5 |
import org.xml.sax.*; |
| 6 |
import javax.xml.parsers.SAXParserFactory; |
| 7 |
import javax.xml.parsers.ParserConfigurationException; |
| 8 |
import javax.xml.parsers.SAXParser; |
| 9 |
|
| 10 |
/** |
| 11 |
* DataLayout |
| 12 |
* |
| 13 |
* @author $Author: $ |
| 14 |
* @version $Id: $ |
| 15 |
*/ |
| 16 |
public class DataLayout { |
| 17 |
|
| 18 |
//---FINAL ATTRIBUTES--- |
| 19 |
|
| 20 |
/** |
| 21 |
* The current CVS revision of this class |
| 22 |
*/ |
| 23 |
public final String REVISION = "$Revision: $"; |
| 24 |
|
| 25 |
private final int topOffset = 4; |
| 26 |
private final int leftStart = 2; |
| 27 |
private final int rightStart = 41; |
| 28 |
private final int fieldLength = 17; |
| 29 |
|
| 30 |
//---STATIC METHODS--- |
| 31 |
|
| 32 |
//---CONSTRUCTORS--- |
| 33 |
|
| 34 |
// Constructor |
| 35 |
public DataLayout (TerminalScreen screen, String[][] showData) { |
| 36 |
_screen = screen; |
| 37 |
_showData = showData; |
| 38 |
} |
| 39 |
|
| 40 |
//---PUBLIC METHODS--- |
| 41 |
|
| 42 |
public void updateScreen(XMLPacket packet) { |
| 43 |
boolean onLeft = true; |
| 44 |
for (int i = 0; i < _showData.length; i++) { |
| 45 |
String friendlyName = _showData[i][1]; |
| 46 |
String value = packet.getParam(_showData[i][0]); |
| 47 |
|
| 48 |
friendlyName = this.StringSizer(friendlyName); |
| 49 |
value = this.StringSizer(value); |
| 50 |
|
| 51 |
if (onLeft) { |
| 52 |
onLeft = false; |
| 53 |
_screen.gotoxy(leftStart, (i/2)+topOffset); |
| 54 |
_screen.print(friendlyName+": "+value); |
| 55 |
|
| 56 |
} |
| 57 |
else { |
| 58 |
onLeft = true; |
| 59 |
_screen.gotoxy(rightStart, (i/2)+topOffset); |
| 60 |
_screen.print(friendlyName+": "+value); |
| 61 |
} |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
//---PRIVATE METHODS--- |
| 66 |
|
| 67 |
private String StringSizer(String value) { |
| 68 |
if (value == null) { |
| 69 |
value = ""; |
| 70 |
} |
| 71 |
|
| 72 |
int lengthDiff = fieldLength - value.length(); |
| 73 |
if (lengthDiff < 0) { |
| 74 |
value = value.substring(0, fieldLength - 3) + "..."; |
| 75 |
} |
| 76 |
else if (lengthDiff > 0) { |
| 77 |
char[] padding = new char[lengthDiff]; |
| 78 |
for (int i=0; i < lengthDiff; i++) { |
| 79 |
padding[i] = 32; |
| 80 |
} |
| 81 |
value = value + new String(padding); |
| 82 |
} |
| 83 |
return value; |
| 84 |
} |
| 85 |
|
| 86 |
//---ACCESSOR/MUTATOR METHODS--- |
| 87 |
|
| 88 |
//---ATTRIBUTES--- |
| 89 |
|
| 90 |
private TerminalScreen _screen; |
| 91 |
private String[][] _showData; |
| 92 |
|
| 93 |
//---STATIC ATTRIBUTES--- |
| 94 |
|
| 95 |
} |