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.3 by ajm, Wed Jan 24 01:54:43 2001 UTC vs.
Revision 1.10 by ajm, Sun Mar 18 16:28:53 2001 UTC

# Line 1 | Line 1
1   //---PACKAGE DECLARATION---
2 < uk.ac.ukc.iscream.conient.datacomponents;
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 15 | Line 17 | import javax.swing.JProgressBar;
17   * @author  $Author$
18   * @version $Id$
19   */
20 < public class CPUDataComponent extends VisibleDataComponent implements DataComponent {
20 > public class CPUDataComponent extends VisibleDataComponent {
21  
22   //---FINAL ATTRIBUTES---
23  
# Line 41 | Line 43 | public class CPUDataComponent extends VisibleDataCompo
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       *
# Line 62 | Line 80 | public class CPUDataComponent extends VisibleDataCompo
80   //---ACCESSOR/MUTATOR METHODS---
81  
82      /**
83 <     * This takes the String value of the parameter 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              if(!_cache.equals(value)) {
94                  _cache = value;
95 <                _item.setString(value + "%");
77 <                _item.setValue(new Double(value).intValue());
95 >                SwingUtilities.invokeLater(this);
96              }
97          } catch (Exception e) {
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  
# Line 94 | Line 122 | public class CPUDataComponent extends VisibleDataCompo
122      private String _attribute;
123      
124      /**
125 <     * Remebers what the last value was, so we
125 >     * Remembers what the last value was, so we
126       * only update if we have to.
127       */    
128 <    String _cache = "";
128 >    protected String _cache = "";
129      
130      /**
131       * The minimum value for the percentage
# Line 125 | Line 153 | public class CPUDataComponent extends VisibleDataCompo
153  
154   //---STATIC ATTRIBUTES---
155  
156 < }
156 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines