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