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.4 by ajm, Wed Jan 24 03:11:14 2001 UTC vs.
Revision 1.12 by tdb, Sat May 18 18:15:56 2002 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines