1 |
|
//---PACKAGE DECLARATION--- |
2 |
< |
package uk.ac.ukc.iscream.conient.datacomponents; |
2 |
> |
package uk.org.iscream.conient.datacomponents; |
3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
|
import javax.swing.JLabel; |
6 |
|
import java.awt.GridLayout; |
7 |
|
import javax.swing.JProgressBar; |
8 |
|
import javax.swing.SwingUtilities; |
9 |
+ |
import uk.org.iscream.util.XMLPacket; |
10 |
|
|
11 |
|
/** |
12 |
|
* This is DataComponent specifically for |
43 |
|
_label = new JLabel(_name + ": "); |
44 |
|
_label.setHorizontalAlignment(JLabel.RIGHT); |
45 |
|
setLayout(new GridLayout(1, 2)); |
46 |
+ |
_item.setString("-uninitialised-"); |
47 |
|
add(_label); |
48 |
|
add(_item); |
49 |
+ |
setVisible(false); |
50 |
|
} |
51 |
|
|
52 |
|
//---PUBLIC METHODS--- |
58 |
|
* run this method. |
59 |
|
*/ |
60 |
|
public void run() { |
61 |
+ |
if(!isVisible()) { |
62 |
+ |
setVisible(true); |
63 |
+ |
} |
64 |
|
_item.setString(_cache + "%"); |
65 |
|
_item.setValue(new Double(_cache).intValue()); |
66 |
|
} |
80 |
|
//---ACCESSOR/MUTATOR METHODS--- |
81 |
|
|
82 |
|
/** |
83 |
< |
* This takes the String value of the parameter that this component |
78 |
< |
* is monitoring direct from the packet, it then performs all |
83 |
> |
* This takes the packet to obtain the value from, it then performs all |
84 |
|
* approriate conversions and adds this class to the Swing Event |
85 |
|
* Dispatching queue. |
86 |
|
* |
87 |
< |
* @param value the value for this data component |
87 |
> |
* @param packet the XMLPacket to get the data from |
88 |
|
* @throws DataFormatException if there was a problem converting the data for display |
89 |
|
*/ |
90 |
< |
public void setValue(String value) throws DataFormatException { |
90 |
> |
public void setValue(XMLPacket packet) throws DataFormatException { |
91 |
> |
String value = packet.getParam(_attribute); |
92 |
|
try { |
93 |
|
if(!_cache.equals(value)) { |
94 |
|
_cache = value; |
97 |
|
} catch (Exception e) { |
98 |
|
throw new DataFormatException(value + " is an invalid data type for " + toString()); |
99 |
|
} |
100 |
< |
} |
100 |
> |
} |
101 |
> |
|
102 |
> |
/** |
103 |
> |
* Returns the string showing the packet |
104 |
> |
* attribute that the component is looking after |
105 |
> |
* |
106 |
> |
* @return the packet reference |
107 |
> |
*/ |
108 |
> |
public String getPacketAttribute() { |
109 |
> |
return _attribute; |
110 |
> |
} |
111 |
|
|
112 |
|
//---ATTRIBUTES--- |
113 |
|
|
122 |
|
private String _attribute; |
123 |
|
|
124 |
|
/** |
125 |
< |
* Remebers what the last value was, so we |
125 |
> |
* Remembers what the last value was, so we |
126 |
|
* only update if we have to. |
127 |
|
*/ |
128 |
< |
String _cache = ""; |
128 |
> |
protected String _cache = ""; |
129 |
|
|
130 |
|
/** |
131 |
|
* The minimum value for the percentage |