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/CPUDataComponent.java
Revision: 1.8
Committed: Thu Mar 15 01:05:46 2001 UTC (23 years, 2 months ago) by ajm
Branch: MAIN
Changes since 1.7: +3 -3 lines
Log Message:
The whole bally lot now is under uk.org.iscream ;p

File Contents

# Content
1 //---PACKAGE DECLARATION---
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
10 /**
11 * This is DataComponent specifically for
12 * displaying CPU percentages.
13 *
14 * It uses the JProgressBar to display the value.
15 *
16 * @author $Author: ajm4 $
17 * @version $Id: CPUDataComponent.java,v 1.7 2001/02/04 00:06:17 ajm4 Exp $
18 */
19 public class CPUDataComponent extends VisibleDataComponent {
20
21 //---FINAL ATTRIBUTES---
22
23 /**
24 * The current CVS revision of this class
25 */
26 public final String REVISION = "$Revision: 1.7 $";
27
28 //---STATIC METHODS---
29
30 //---CONSTRUCTORS---
31
32 /**
33 * Creates the component with a friendly name to be
34 * used as label
35 *
36 * @param name the friendly name
37 * @param attribute the data attribute we look after
38 */
39 public CPUDataComponent(String name, String attribute) {
40 _name = name;
41 _attribute = attribute;
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 }
49
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 *
67 * @return the name of this class and its CVS revision
68 */
69 public String toString() {
70 return _name + "(" + _attribute + ")";
71 }
72
73 //---PRIVATE METHODS---
74
75 //---ACCESSOR/MUTATOR METHODS---
76
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 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
85 */
86 public void setValue(String value) throws DataFormatException {
87 try {
88 if(!_cache.equals(value)) {
89 _cache = value;
90 SwingUtilities.invokeLater(this);
91 }
92 } catch (Exception e) {
93 throw new DataFormatException(value + " is an invalid data type for " + toString());
94 }
95 }
96
97 /**
98 * Returns the string showing the packet
99 * attribute that the component is looking after
100 *
101 * @return the packet reference
102 */
103 public String getPacketAttribute() {
104 return _attribute;
105 }
106
107 //---ATTRIBUTES---
108
109 /**
110 * The friendly name of this component
111 */
112 private String _name;
113
114 /**
115 * The attribute that this component is concerned with
116 */
117 private String _attribute;
118
119 /**
120 * Remebers what the last value was, so we
121 * only update if we have to.
122 */
123 String _cache = "";
124
125 /**
126 * The minimum value for the percentage
127 */
128 private final int _min = 0;
129
130 /**
131 * The maximum value for the percentage
132 */
133 private final int _max = 100;
134
135 /**
136 * The friendly label for this component
137 */
138 private JLabel _label;
139
140 /**
141 * The progress bar that we will display CPU
142 * percentage data in
143 */
144 private JProgressBar _item = new JProgressBar(JProgressBar.HORIZONTAL, _min, _max);
145 {
146 _item.setStringPainted(true);
147 }
148
149 //---STATIC ATTRIBUTES---
150
151 }