ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/conient/uk/org/iscream/cms/conient/datacomponents/StorageDataComponent.java
Revision: 1.8
Committed: Sun Aug 1 10:40:10 2004 UTC (19 years, 9 months ago) by tdb
Branch: MAIN
CVS Tags: HEAD
Changes since 1.7: +3 -3 lines
Error occurred while calculating annotation data.
Log Message:
Catch a lot of old URL's and update them. Also remove a couple of old files
that aren't used.

File Contents

# Content
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.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
33 * displaying storage, eg memory, disk and swap.
34 * It displays a value/total type display using a JProgessBar.
35 *
36 * @author $Author: tdb $
37 * @version $Id: StorageDataComponent.java,v 1.7 2003/02/05 19:35:04 tdb Exp $
38 */
39 public class StorageDataComponent extends VisibleDataComponent {
40
41 //---FINAL ATTRIBUTES---
42
43 /**
44 * The current CVS revision of this class
45 */
46 public final String REVISION = "$Revision: 1.7 $";
47
48 //---STATIC METHODS---
49
50 //---CONSTRUCTORS---
51
52 /**
53 * Creates the component with a friendly name to be
54 * used as label
55 *
56 * @param name the friendly name
57 * @param attribute the data attribute we look after
58 * @param maxAttribute the data attribute to obtain the maximum value from
59 * @param unit the string representation of the units eg, "Mb" or "Kb"
60 */
61 public StorageDataComponent(String name, String attribute, String maxAttribute, String unit) {
62 this(name, attribute, maxAttribute, unit, 1);
63 }
64
65 /**
66 * Creates the component with a friendly name to be
67 * used as label
68 *
69 * @param name the friendly name
70 * @param attribute the data attribute we look after
71 * @param maxAttribute the data attribute to obtain the maximum value from
72 * @param unit the string representation of the units eg, "Mb" or "Kb"
73 * @param divider the amount that the given value should be multiplied by to reach the given units
74 */
75 public StorageDataComponent(String name, String attribute, String maxAttribute, String unit, int divider) {
76 _name = name;
77 _attribute = attribute;
78 _unit = unit;
79 _divider = divider;
80 _maxAttribute = maxAttribute;
81 _label = new JLabel(name + ": ");
82 _label.setHorizontalAlignment(JLabel.RIGHT);
83 setLayout(new GridLayout(1, 2));
84 _item.setString("-uninitialised-");
85 add(_label);
86 add(_item);
87 setVisible(false);
88 }
89
90 //---PUBLIC METHODS---
91
92 /**
93 * This run method updates any Swing components
94 * The setValue() method adds this component
95 * to the Swing Event Dispatching Queue to
96 * run this method.
97 */
98 public void run() {
99 if(!isVisible()) {
100 setVisible(true);
101 }
102 int max = new Double(_maxvalue).intValue();
103 _item.setMaximum(max);
104 int value = new Double(_value).intValue();
105 _item.setValue(max - value);
106 _item.setString((max - value) + _unit + "/" + max + _unit + " (" + new Double(_item.getPercentComplete() * 100).intValue() + "%)");
107 }
108
109 /**
110 * Overrides the {@link java.lang.Object#toString() Object.toString()}
111 * method to provide clean logging (every class should have this).
112 *
113 * @return the name of this class and its CVS revision
114 */
115 public String toString() {
116 return _name + "(" + _attribute + ")";
117 }
118
119 //---PRIVATE METHODS---
120
121 //---ACCESSOR/MUTATOR METHODS---
122
123 /**
124 * This takes the packet to obtain the value from, it then performs all
125 * approriate conversions and adds this class to the Swing Event
126 * Dispatching queue.
127 *
128 * @param packet the XMLPacket to get the data from
129 * @throws DataFormatException if there was a problem converting the data for display
130 */
131 public void setValue(XMLPacket packet) throws DataFormatException {
132 String value = packet.getParam(_attribute);
133 String maxvalue = packet.getParam(_maxAttribute);
134 try {
135 if((!maxvalue.equals("0")) && (!_cache.equals(value) || !_maxcache.equals(maxvalue))) {
136 _cache = value;
137 _maxcache = maxvalue;
138 _value = Double.parseDouble(_cache) / _divider;
139 _maxvalue = Double.parseDouble(_maxcache) / _divider;
140 SwingUtilities.invokeLater(this);
141 }
142 } catch (Exception e) {
143 throw new DataFormatException(value + " is an invalid data type for " + toString());
144 }
145 }
146
147 /**
148 * Returns the string showing the packet
149 * attribute that the component is looking after
150 *
151 * @return the packet reference
152 */
153 public String getPacketAttribute() {
154 return _attribute;
155 }
156
157 //---ATTRIBUTES---
158
159 /**
160 * The friendly name of this component
161 */
162 protected String _name;
163
164 /**
165 * The attribute that this component is concerned with
166 */
167 protected String _attribute;
168
169 /**
170 * The max attribute that this component is concerned with
171 */
172 protected String _maxAttribute;
173
174 /**
175 * The string representation of the units the values
176 * are being measured in.
177 */
178 protected String _unit;
179
180 /**
181 * The divider to multiply the value to
182 * to reach the units.
183 */
184 protected int _divider;
185
186 /**
187 * Remebers what the last value was, so we
188 * only update if we have to.
189 */
190 protected String _cache = "";
191
192 /**
193 * Remebers what the last value was, so we
194 * only update if we have to.
195 */
196 protected String _maxcache = "";
197
198 /**
199 * Holds the integer value we are holding
200 */
201 protected double _value = 0;
202
203 /**
204 * Holds the integer value we are holding
205 */
206 protected double _maxvalue = 0;
207
208 /**
209 * The minimum value for the percentage
210 */
211 protected final int _min = 0;
212
213 /**
214 * The maximum value for the percentage
215 */
216 protected int _max = 0;
217
218 /**
219 * The friendly label for this component
220 */
221 protected JLabel _label;
222
223 /**
224 * The progress bar that we will display memory
225 * usage data in
226 */
227 protected JProgressBar _item = new JProgressBar(JProgressBar.HORIZONTAL, _min, _max);
228 {
229 _item.setStringPainted(true);
230 }
231
232 //---STATIC ATTRIBUTES---
233
234 }