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
(Generate patch)

Comparing projects/cms/source/conient/uk/org/iscream/cms/conient/datacomponents/CPUDataComponent.java (file contents):
Revision 1.1 by ajm, Mon Jan 22 03:03:39 2001 UTC vs.
Revision 1.10 by ajm, Sun Mar 18 16:28:53 2001 UTC

# Line 1 | Line 1
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 + import uk.org.iscream.util.XMLPacket;
10  
11   /**
12   * This is DataComponent specifically for
# Line 14 | Line 17 | import javax.swing.JProgressBar;
17   * @author  $Author$
18   * @version $Id$
19   */
20 < public class CPUDataComponent extends DataComponent {
20 > public class CPUDataComponent extends VisibleDataComponent {
21  
22   //---FINAL ATTRIBUTES---
23  
# Line 32 | Line 35 | public class CPUDataComponent extends DataComponent {
35       * used as label
36       *
37       * @param name the friendly name
38 +     * @param attribute the data attribute we look after
39       */
40 <    public CPUDataComponent(String name) {
41 <        _label = new JLabel(name + ": ");
40 >    public CPUDataComponent(String name, String attribute) {
41 >        _name = name;
42 >        _attribute = attribute;
43 >        _label = new JLabel(_name + ": ");
44          _label.setHorizontalAlignment(JLabel.RIGHT);
45          setLayout(new GridLayout(1, 2));
46 +            _item.setString("-uninitialised-");
47          add(_label);
48          add(_item);
49 +        setVisible(false);
50      }
51  
52   //---PUBLIC METHODS---
53  
54 +    /**
55 +     * This run method updates any Swing components
56 +     * The setValue() method adds this component
57 +     * to the Swing Event Dispatching Queue to
58 +     * run this method.
59 +     */
60 +    public void run() {
61 +        if(!isVisible()) {
62 +            setVisible(true);
63 +        }
64 +        _item.setString(_cache + "%");
65 +        _item.setValue(new Double(_cache).intValue());
66 +    }
67 +
68 +    /**
69 +     * Overrides the {@link java.lang.Object#toString() Object.toString()}
70 +     * method to provide clean logging (every class should have this).
71 +     *
72 +     * @return the name of this class and its CVS revision
73 +     */
74 +    public String toString() {
75 +        return _name + "(" + _attribute + ")";
76 +    }
77 +
78   //---PRIVATE METHODS---
79  
80   //---ACCESSOR/MUTATOR METHODS---
81  
82      /**
83 <     * This takes the String value of the parammeter that this component
84 <     * is monitoring direct from the packet, it then performs all
85 <     * approriate conversions and displays the data.
83 >     * This takes the packet to obtain the value from, it then performs all
84 >     * approriate conversions and adds this class to the Swing Event
85 >     * Dispatching queue.
86       *
87 <     * @param value the value for this data component
87 >     * @param packet the XMLPacket to get the data from
88 >     * @throws DataFormatException if there was a problem converting the data for display
89       */
90 <    public void setValue(String value) throws DataFormatException {
90 >    public void setValue(XMLPacket packet) throws DataFormatException {
91 >        String value = packet.getParam(_attribute);
92          try {
93 <            _item.setString(value + "%");
94 <            _item.setValue(new Double(value).intValue());
93 >            if(!_cache.equals(value)) {
94 >                _cache = value;
95 >                SwingUtilities.invokeLater(this);
96 >            }
97          } catch (Exception e) {
98 <            throw new DataFormatException("invalid data type for component");
98 >            throw new DataFormatException(value + " is an invalid data type for " + toString());
99          }
100 <    }        
100 >    }
101 >    
102 >    /**
103 >     * Returns the string showing the packet
104 >     * attribute that the component is looking after
105 >     *
106 >     * @return the packet reference
107 >     */
108 >    public String getPacketAttribute() {
109 >        return _attribute;
110 >    }
111  
112   //---ATTRIBUTES---
113  
114 +    /**
115 +     * The friendly name of this component
116 +     */
117 +    private String _name;
118 +    
119 +    /**
120 +     * The attribute that this component is concerned with
121 +     */
122 +    private String _attribute;
123 +    
124 +    /**
125 +     * Remembers what the last value was, so we
126 +     * only update if we have to.
127 +     */    
128 +    protected String _cache = "";
129 +    
130 +    /**
131 +     * The minimum value for the percentage
132 +     */
133      private final int _min = 0;
134 +    
135 +    /**
136 +     * The maximum value for the percentage
137 +     */
138      private final int _max = 100;
139 +    
140 +    /**
141 +     * The friendly label for this component
142 +     */
143      private JLabel _label;
144 +    
145 +    /**
146 +     * The progress bar that we will display CPU
147 +     * percentage data in
148 +     */
149      private JProgressBar _item = new JProgressBar(JProgressBar.HORIZONTAL, _min, _max);
150      {
151          _item.setStringPainted(true);
152      }
153 < }
153 >
154 > //---STATIC ATTRIBUTES---
155 >
156 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines