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/ProcessesDataComponent.java
Revision: 1.3
Committed: Sun Mar 18 14:43:39 2001 UTC (23 years, 2 months ago) by ajm
Branch: MAIN
Changes since 1.2: +11 -10 lines
Log Message:
Lots of changes to allow components to have multiple attributes.

This now means that data for memory/swap/disks/services are all correctly updated on the display the first time they get data.  Rather than before, when they had to have at least two packets to gain all the data and would be slightly wrong.

Now it is all fine and dandy...

File Contents

# User Rev Content
1 ajm 1.1 //---PACKAGE DECLARATION---
2 ajm 1.2 package uk.org.iscream.conient.datacomponents;
3 ajm 1.1
4     //---IMPORTS---
5     import javax.swing.JLabel;
6     import javax.swing.JTextField;
7     import java.awt.GridLayout;
8     import javax.swing.SwingUtilities;
9 ajm 1.3 import uk.org.iscream.util.XMLPacket;
10 ajm 1.1
11     /**
12     * Used to display some information about processes
13     *
14     * Used in combination with others of this type and displayed
15     * correctly, this will help display the number of processes
16     *
17     * It simply displays the value as a String
18     * in a JTextField.
19     *
20     * @author $Author: ajm4 $
21 ajm 1.3 * @version $Id: ProcessesDataComponent.java,v 1.2 2001/03/15 01:05:46 ajm4 Exp $
22 ajm 1.1 */
23     public class ProcessesDataComponent extends VisibleDataComponent {
24    
25     //---FINAL ATTRIBUTES---
26    
27     /**
28     * The current CVS revision of this class
29     */
30 ajm 1.3 public final String REVISION = "$Revision: 1.2 $";
31 ajm 1.1
32     /**
33     * The default length of the JTextField
34     */
35     protected final int DEFAULT_TEXT_LENGTH = 3;
36    
37     //---STATIC METHODS---
38    
39     //---CONSTRUCTORS---
40    
41     /**
42     * Creates the component with a friendly name to be
43     * used as label
44     *
45     * @param name the friendly name
46     * @param attribute the data attribute we look after
47     */
48     public ProcessesDataComponent(String name, String attribute) {
49     _name = name;
50     _attribute = attribute;
51     _item = new JTextField("", DEFAULT_TEXT_LENGTH);
52     _item.setEditable(false);
53     _label = new JLabel(_name);
54     _label.setHorizontalAlignment(JLabel.CENTER);
55     _item.setHorizontalAlignment(JTextField.CENTER);
56     setLayout(new GridLayout(2, 1));
57     _item.setText("-uninitialised-");
58     add(_label);
59     add(_item);
60     }
61    
62     //---PUBLIC METHODS---
63    
64     /**
65     * This run method updates any Swing components
66     * The setValue() method adds this component
67     * to the Swing Event Dispatching Queue to
68     * run this method.
69     */
70     public void run() {
71 ajm 1.3 _item.setText(_cache);
72 ajm 1.1 }
73    
74     /**
75     * Overrides the {@link java.lang.Object#toString() Object.toString()}
76     * method to provide clean logging (every class should have this).
77     *
78     * @return the name of this class and its CVS revision
79     */
80     public String toString() {
81     return _name + "(" + _attribute + ")";
82     }
83    
84     //---PRIVATE METHODS---
85    
86     //---ACCESSOR/MUTATOR METHODS---
87    
88     /**
89 ajm 1.3 * This takes the packet to obtain the value from, it then performs all
90 ajm 1.1 * approriate conversions and adds this class to the Swing Event
91     * Dispatching queue.
92     *
93 ajm 1.3 * @param packet the XMLPacket to get the data from
94 ajm 1.1 * @throws DataFormatException if there was a problem converting the data for display
95     */
96 ajm 1.3 public void setValue(XMLPacket packet) throws DataFormatException {
97     String value = packet.getParam(_attribute);
98 ajm 1.1 try {
99     if(!_cache.equals(value)) {
100     _cache = value;
101 ajm 1.3 SwingUtilities.invokeLater(this);
102 ajm 1.1 }
103     } catch (Exception e) {
104     throw new DataFormatException(value + " is an invalid data type for " + toString());
105     }
106     }
107    
108     /**
109     * Returns the string showing the packet
110     * attribute that the component is looking after
111     *
112     * @return the packet reference
113     */
114     public String getPacketAttribute() {
115     return _attribute;
116     }
117    
118     //---ATTRIBUTES---
119    
120     /**
121     * The friendly name of this component
122     */
123     protected String _name;
124    
125     /**
126     * The attribute that this component is concerned with
127     */
128     protected String _attribute;
129    
130     /**
131     * The friendly label for this component
132     */
133     protected JLabel _label;
134    
135     /**
136 ajm 1.3 * Remembers what the last value was, so we
137 ajm 1.1 * only update if we have to.
138     */
139 ajm 1.3 protected String _cache = "";
140 ajm 1.1
141     /**
142     * The length of the JTextField
143     */
144     protected int _displayLength;
145    
146     /**
147     * Just a normal label to display our value as a String
148     */
149     protected JTextField _item;
150    
151     //---STATIC ATTRIBUTES---
152    
153     }