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