5 |
|
import javax.swing.JLabel; |
6 |
|
import java.awt.GridLayout; |
7 |
|
import javax.swing.JProgressBar; |
8 |
+ |
import javax.swing.SwingUtilities; |
9 |
|
|
10 |
|
/** |
11 |
|
* This is DataComponent specifically for |
16 |
|
* @author $Author$ |
17 |
|
* @version $Id$ |
18 |
|
*/ |
19 |
< |
public class CPUDataComponent extends VisibleDataComponent implements DataComponent { |
19 |
> |
public class CPUDataComponent extends VisibleDataComponent { |
20 |
|
|
21 |
|
//---FINAL ATTRIBUTES--- |
22 |
|
|
42 |
|
_label = new JLabel(_name + ": "); |
43 |
|
_label.setHorizontalAlignment(JLabel.RIGHT); |
44 |
|
setLayout(new GridLayout(1, 2)); |
45 |
+ |
_item.setString("-uninitialised-"); |
46 |
|
add(_label); |
47 |
|
add(_item); |
48 |
|
} |
50 |
|
//---PUBLIC METHODS--- |
51 |
|
|
52 |
|
/** |
53 |
+ |
* This run method updates any Swing components |
54 |
+ |
* The setValue() method adds this component |
55 |
+ |
* to the Swing Event Dispatching Queue to |
56 |
+ |
* run this method. |
57 |
+ |
*/ |
58 |
+ |
public void run() { |
59 |
+ |
_item.setString(_cache + "%"); |
60 |
+ |
_item.setValue(new Double(_cache).intValue()); |
61 |
+ |
} |
62 |
+ |
|
63 |
+ |
/** |
64 |
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
65 |
|
* method to provide clean logging (every class should have this). |
66 |
|
* |
77 |
|
/** |
78 |
|
* This takes the String value of the parameter that this component |
79 |
|
* is monitoring direct from the packet, it then performs all |
80 |
< |
* approriate conversions and displays the data. |
80 |
> |
* approriate conversions and adds this class to the Swing Event |
81 |
> |
* Dispatching queue. |
82 |
|
* |
83 |
|
* @param value the value for this data component |
84 |
|
* @throws DataFormatException if there was a problem converting the data for display |
87 |
|
try { |
88 |
|
if(!_cache.equals(value)) { |
89 |
|
_cache = value; |
90 |
< |
_item.setString(value + "%"); |
77 |
< |
_item.setValue(new Double(value).intValue()); |
90 |
> |
SwingUtilities.invokeLater(this); |
91 |
|
} |
92 |
|
} catch (Exception e) { |
93 |
|
throw new DataFormatException(value + " is an invalid data type for " + toString()); |
138 |
|
|
139 |
|
//---STATIC ATTRIBUTES--- |
140 |
|
|
141 |
< |
} |
141 |
> |
} |