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); |
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")) { |
68 |
> |
if(!isVisible()) { |
69 |
> |
setVisible(true); |
70 |
> |
} |
71 |
> |
if (_statusCache.equals("0")) { |
72 |
|
_item.setBackground(Color.green); |
73 |
|
_item.setText(_name + "[OK] : " + _cache); |
74 |
|
} else { |
92 |
|
//---ACCESSOR/MUTATOR METHODS--- |
93 |
|
|
94 |
|
/** |
95 |
< |
* This takes the String value of the parameter that this component |
91 |
< |
* is monitoring direct from the packet, it then performs all |
95 |
> |
* This takes the packet to obtain the value from, it then performs all |
96 |
|
* approriate conversions and adds this class to the Swing Event |
97 |
|
* Dispatching queue. |
98 |
|
* |
99 |
< |
* @param value the value for this data component |
99 |
> |
* @param packet the XMLPacket to get the data from |
100 |
|
* @throws DataFormatException if there was a problem converting the data for display |
101 |
|
*/ |
102 |
< |
public void setValue(String value) throws DataFormatException { |
102 |
> |
public void setValue(XMLPacket packet) throws DataFormatException { |
103 |
> |
String value = packet.getParam(_attribute); |
104 |
> |
String statusvalue = packet.getParam(_statusAttribute); |
105 |
|
try { |
106 |
< |
if((!_cache.equals(value) || !_serviceStatusValue.equals(_serviceStatus.getValue())) && !_serviceStatus.getValue().equals("")) { |
106 |
> |
if(!_cache.equals(value) || !_statusCache.equals(statusvalue)) { |
107 |
|
_cache = value; |
108 |
< |
_serviceStatusValue = _serviceStatus.getValue(); |
108 |
> |
_statusCache = statusvalue; |
109 |
|
SwingUtilities.invokeLater(this); |
110 |
|
} |
111 |
|
} catch (Exception e) { |
136 |
|
protected String _attribute; |
137 |
|
|
138 |
|
/** |
139 |
+ |
* The service status attribute that this component is concerned with |
140 |
+ |
*/ |
141 |
+ |
protected String _statusAttribute; |
142 |
+ |
|
143 |
+ |
/** |
144 |
|
* The friendly label for this component |
145 |
|
*/ |
146 |
|
protected JLabel _label; |
147 |
|
|
148 |
|
/** |
149 |
< |
* Remebers what the last value was, so we |
149 |
> |
* Remembers what the last value was, so we |
150 |
|
* only update if we have to. |
151 |
|
*/ |
152 |
< |
String _cache = ""; |
152 |
> |
protected String _cache = ""; |
153 |
|
|
154 |
+ |
/** |
155 |
+ |
* Remembers what the last value was, so we |
156 |
+ |
* only update if we have to. |
157 |
+ |
*/ |
158 |
+ |
protected String _statusCache = ""; |
159 |
+ |
|
160 |
|
/** |
161 |
|
* The length of the JTextField |
162 |
|
*/ |
166 |
|
* Just a normal label to display our value as a String |
167 |
|
*/ |
168 |
|
protected JTextField _item; |
152 |
– |
|
153 |
– |
private StringDataComponent _serviceStatus; |
154 |
– |
private String _serviceStatusValue = ""; |
155 |
– |
|
156 |
– |
|
169 |
|
|
170 |
|
//---STATIC ATTRIBUTES--- |
171 |
|
|