1 |
+ |
/* |
2 |
+ |
* i-scream central monitoring system |
3 |
+ |
* Copyright (C) 2000-2002 i-scream |
4 |
+ |
* |
5 |
+ |
* This program is free software; you can redistribute it and/or |
6 |
+ |
* modify it under the terms of the GNU General Public License |
7 |
+ |
* as published by the Free Software Foundation; either version 2 |
8 |
+ |
* of the License, or (at your option) any later version. |
9 |
+ |
* |
10 |
+ |
* This program is distributed in the hope that it will be useful, |
11 |
+ |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
+ |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
+ |
* GNU General Public License for more details. |
14 |
+ |
* |
15 |
+ |
* You should have received a copy of the GNU General Public License |
16 |
+ |
* along with this program; if not, write to the Free Software |
17 |
+ |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 |
+ |
*/ |
19 |
+ |
|
20 |
|
//---PACKAGE DECLARATION--- |
21 |
< |
package uk.ac.ukc.iscream.conient.datacomponents; |
21 |
> |
package uk.org.iscream.cms.conient.datacomponents; |
22 |
|
|
23 |
|
//---IMPORTS--- |
24 |
|
import javax.swing.JLabel; |
25 |
|
import java.awt.GridLayout; |
26 |
|
import javax.swing.JProgressBar; |
27 |
+ |
import javax.swing.SwingUtilities; |
28 |
+ |
import uk.org.iscream.cms.server.util.XMLPacket; |
29 |
|
|
30 |
|
/** |
31 |
|
* This is DataComponent specifically for |
36 |
|
* @author $Author$ |
37 |
|
* @version $Id$ |
38 |
|
*/ |
39 |
< |
public class CPUDataComponent extends VisibleDataComponent implements DataComponent { |
39 |
> |
public class CPUDataComponent extends VisibleDataComponent { |
40 |
|
|
41 |
|
//---FINAL ATTRIBUTES--- |
42 |
|
|
62 |
|
_label = new JLabel(_name + ": "); |
63 |
|
_label.setHorizontalAlignment(JLabel.RIGHT); |
64 |
|
setLayout(new GridLayout(1, 2)); |
65 |
+ |
_item.setString("-uninitialised-"); |
66 |
|
add(_label); |
67 |
|
add(_item); |
68 |
+ |
setVisible(false); |
69 |
|
} |
70 |
|
|
71 |
|
//---PUBLIC METHODS--- |
72 |
|
|
73 |
|
/** |
74 |
+ |
* This run method updates any Swing components |
75 |
+ |
* The setValue() method adds this component |
76 |
+ |
* to the Swing Event Dispatching Queue to |
77 |
+ |
* run this method. |
78 |
+ |
*/ |
79 |
+ |
public void run() { |
80 |
+ |
if(!isVisible()) { |
81 |
+ |
setVisible(true); |
82 |
+ |
} |
83 |
+ |
_item.setString(_cache + "%"); |
84 |
+ |
_item.setValue(new Double(_cache).intValue()); |
85 |
+ |
} |
86 |
+ |
|
87 |
+ |
/** |
88 |
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
89 |
|
* method to provide clean logging (every class should have this). |
90 |
|
* |
99 |
|
//---ACCESSOR/MUTATOR METHODS--- |
100 |
|
|
101 |
|
/** |
102 |
< |
* This takes the String value of the parameter that this component |
103 |
< |
* is monitoring direct from the packet, it then performs all |
104 |
< |
* approriate conversions and displays the data. |
102 |
> |
* This takes the packet to obtain the value from, it then performs all |
103 |
> |
* approriate conversions and adds this class to the Swing Event |
104 |
> |
* Dispatching queue. |
105 |
|
* |
106 |
< |
* @param value the value for this data component |
106 |
> |
* @param packet the XMLPacket to get the data from |
107 |
|
* @throws DataFormatException if there was a problem converting the data for display |
108 |
|
*/ |
109 |
< |
public void setValue(String value) throws DataFormatException { |
109 |
> |
public void setValue(XMLPacket packet) throws DataFormatException { |
110 |
> |
String value = packet.getParam(_attribute); |
111 |
|
try { |
112 |
|
if(!_cache.equals(value)) { |
113 |
|
_cache = value; |
114 |
< |
_item.setString(value + "%"); |
77 |
< |
_item.setValue(new Double(value).intValue()); |
114 |
> |
SwingUtilities.invokeLater(this); |
115 |
|
} |
116 |
|
} catch (Exception e) { |
117 |
|
throw new DataFormatException(value + " is an invalid data type for " + toString()); |
118 |
|
} |
119 |
< |
} |
119 |
> |
} |
120 |
> |
|
121 |
> |
/** |
122 |
> |
* Returns the string showing the packet |
123 |
> |
* attribute that the component is looking after |
124 |
> |
* |
125 |
> |
* @return the packet reference |
126 |
> |
*/ |
127 |
> |
public String getPacketAttribute() { |
128 |
> |
return _attribute; |
129 |
> |
} |
130 |
|
|
131 |
|
//---ATTRIBUTES--- |
132 |
|
|
141 |
|
private String _attribute; |
142 |
|
|
143 |
|
/** |
144 |
< |
* Remebers what the last value was, so we |
144 |
> |
* Remembers what the last value was, so we |
145 |
|
* only update if we have to. |
146 |
|
*/ |
147 |
< |
String _cache = ""; |
147 |
> |
protected String _cache = ""; |
148 |
|
|
149 |
|
/** |
150 |
|
* The minimum value for the percentage |
172 |
|
|
173 |
|
//---STATIC ATTRIBUTES--- |
174 |
|
|
175 |
< |
} |
175 |
> |
} |