7 |
|
import java.awt.Color; |
8 |
|
import java.awt.GridLayout; |
9 |
|
import javax.swing.SwingUtilities; |
10 |
+ |
import uk.org.iscream.util.XMLPacket; |
11 |
|
|
12 |
|
/** |
13 |
|
* This is the most basic of DataComponents. |
43 |
|
* @param name the friendly name |
44 |
|
* @param attribute the data attribute we look after |
45 |
|
*/ |
46 |
< |
public ServiceDataComponent(String name, String attribute, StringDataComponent serviceStatus) { |
46 |
> |
public ServiceDataComponent(String name, String attribute, String statusAttribute) { |
47 |
|
_name = name; |
48 |
< |
_serviceStatus = serviceStatus; |
48 |
> |
_statusAttribute = statusAttribute; |
49 |
|
_attribute = attribute; |
50 |
|
setLayout(new GridLayout(1,1)); |
51 |
|
_item = new JTextField("", DEFAULT_TEXT_LENGTH); |
52 |
< |
_item.setHorizontalAlignment(JTextField.CENTER); |
52 |
> |
_item.setHorizontalAlignment(JTextField.LEFT); |
53 |
|
_item.setEditable(false); |
54 |
|
_item.setText("-uninitialised-"); |
55 |
|
add(_item); |
56 |
+ |
setVisible(false); |
57 |
|
} |
58 |
|
|
59 |
|
//---PUBLIC METHODS--- |
65 |
|
* run this method. |
66 |
|
*/ |
67 |
|
public void run() { |
68 |
< |
if (_serviceStatusValue.equals("0")) { |
69 |
< |
_item.setBackground(Color.green); |
68 |
> |
if(!isVisible()) { |
69 |
> |
setVisible(true); |
70 |
> |
} |
71 |
> |
if (_statusCache.equals("0")) { |
72 |
> |
_item.setForeground(Color.black); |
73 |
|
_item.setText(_name + "[OK] : " + _cache); |
74 |
|
} else { |
75 |
< |
_item.setBackground(Color.red); |
75 |
> |
_item.setForeground(Color.red); |
76 |
|
_item.setText(_name + "[FAILED] : " + _cache); |
77 |
|
} |
78 |
+ |
_item.setCaretPosition(0); |
79 |
|
} |
80 |
|
|
81 |
|
/** |
93 |
|
//---ACCESSOR/MUTATOR METHODS--- |
94 |
|
|
95 |
|
/** |
96 |
< |
* This takes the String value of the parameter that this component |
91 |
< |
* is monitoring direct from the packet, it then performs all |
96 |
> |
* This takes the packet to obtain the value from, it then performs all |
97 |
|
* approriate conversions and adds this class to the Swing Event |
98 |
|
* Dispatching queue. |
99 |
|
* |
100 |
< |
* @param value the value for this data component |
100 |
> |
* @param packet the XMLPacket to get the data from |
101 |
|
* @throws DataFormatException if there was a problem converting the data for display |
102 |
|
*/ |
103 |
< |
public void setValue(String value) throws DataFormatException { |
103 |
> |
public void setValue(XMLPacket packet) throws DataFormatException { |
104 |
> |
String value = packet.getParam(_attribute); |
105 |
> |
String statusvalue = packet.getParam(_statusAttribute); |
106 |
|
try { |
107 |
< |
if((!_cache.equals(value) || !_serviceStatusValue.equals(_serviceStatus.getValue())) && !_serviceStatus.getValue().equals("")) { |
107 |
> |
if(!_cache.equals(value) || !_statusCache.equals(statusvalue)) { |
108 |
|
_cache = value; |
109 |
< |
_serviceStatusValue = _serviceStatus.getValue(); |
109 |
> |
_statusCache = statusvalue; |
110 |
|
SwingUtilities.invokeLater(this); |
111 |
|
} |
112 |
|
} catch (Exception e) { |
137 |
|
protected String _attribute; |
138 |
|
|
139 |
|
/** |
140 |
+ |
* The service status attribute that this component is concerned with |
141 |
+ |
*/ |
142 |
+ |
protected String _statusAttribute; |
143 |
+ |
|
144 |
+ |
/** |
145 |
|
* The friendly label for this component |
146 |
|
*/ |
147 |
|
protected JLabel _label; |
148 |
|
|
149 |
|
/** |
150 |
< |
* Remebers what the last value was, so we |
150 |
> |
* Remembers what the last value was, so we |
151 |
|
* only update if we have to. |
152 |
|
*/ |
153 |
< |
String _cache = ""; |
153 |
> |
protected String _cache = ""; |
154 |
|
|
155 |
+ |
/** |
156 |
+ |
* Remembers what the last value was, so we |
157 |
+ |
* only update if we have to. |
158 |
+ |
*/ |
159 |
+ |
protected String _statusCache = ""; |
160 |
+ |
|
161 |
|
/** |
162 |
|
* The length of the JTextField |
163 |
|
*/ |
167 |
|
* Just a normal label to display our value as a String |
168 |
|
*/ |
169 |
|
protected JTextField _item; |
152 |
– |
|
153 |
– |
private StringDataComponent _serviceStatus; |
154 |
– |
private String _serviceStatusValue = ""; |
155 |
– |
|
156 |
– |
|
170 |
|
|
171 |
|
//---STATIC ATTRIBUTES--- |
172 |
|
|