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.2 by ajm, Mon Jan 22 12:32:14 2001 UTC vs.
Revision 1.15 by tdb, Sun Aug 1 10:40:10 2004 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines