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/ServiceDataComponent.java
Revision: 1.7
Committed: Tue May 29 17:41:32 2001 UTC (22 years, 11 months ago) by tdb
Branch: MAIN
Changes since 1.6: +4 -4 lines
Log Message:
The last of the central monitoring system packages to be changed to the newer
structure. It has changed from;

uk.org.iscream.conient.*

to;

uk.org.iscream.cms.conient.*

This is in keeping with the new style of packaging.

File Contents

# Content
1 //---PACKAGE DECLARATION---
2 package uk.org.iscream.cms.conient.datacomponents;
3
4 //---IMPORTS---
5 import javax.swing.JLabel;
6 import javax.swing.JTextField;
7 import java.awt.Color;
8 import java.awt.GridLayout;
9 import javax.swing.SwingUtilities;
10 import uk.org.iscream.cms.server.util.XMLPacket;
11
12 /**
13 * This is the most basic of DataComponents.
14 *
15 * It simply displays the value as a String
16 * in a JTextField.
17 *
18 * @author $Author: ajm4 $
19 * @version $Id: ServiceDataComponent.java,v 1.6 2001/03/19 13:56:22 ajm4 Exp $
20 */
21 public class ServiceDataComponent extends VisibleDataComponent {
22
23 //---FINAL ATTRIBUTES---
24
25 /**
26 * The current CVS revision of this class
27 */
28 public final String REVISION = "$Revision: 1.6 $";
29
30 /**
31 * The default length of the JTextField
32 */
33 protected final int DEFAULT_TEXT_LENGTH = 20;
34
35 //---STATIC METHODS---
36
37 //---CONSTRUCTORS---
38
39 /**
40 * Creates the component with a friendly name to be
41 * used as label
42 *
43 * @param name the friendly name
44 * @param attribute the data attribute we look after
45 */
46 public ServiceDataComponent(String name, String attribute, String statusAttribute) {
47 _name = name;
48 _statusAttribute = statusAttribute;
49 _attribute = attribute;
50 setLayout(new GridLayout(1,2));
51 _label = new JLabel(_name + ": ");
52 _label.setHorizontalAlignment(JLabel.RIGHT);
53 _item = new JTextField("", DEFAULT_TEXT_LENGTH);
54 _item.setHorizontalAlignment(JTextField.LEFT);
55 _item.setEditable(false);
56 _item.setText("-uninitialised-");
57 add(_label);
58 add(_item);
59 setVisible(false);
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 if(!isVisible()) {
72 setVisible(true);
73 }
74 if (_statusCache.equals("0")) {
75 _item.setForeground(Color.black);
76 _item.setText("[OK] : " + _cache);
77 } else {
78 _item.setForeground(Color.red);
79 _item.setText("[FAILED] : " + _cache);
80 }
81 _item.setCaretPosition(0);
82 }
83
84 /**
85 * Overrides the {@link java.lang.Object#toString() Object.toString()}
86 * method to provide clean logging (every class should have this).
87 *
88 * @return the name of this class and its CVS revision
89 */
90 public String toString() {
91 return _name + "(" + _attribute + ")";
92 }
93
94 //---PRIVATE METHODS---
95
96 //---ACCESSOR/MUTATOR METHODS---
97
98 /**
99 * This takes the packet to obtain the value from, it then performs all
100 * approriate conversions and adds this class to the Swing Event
101 * Dispatching queue.
102 *
103 * @param packet the XMLPacket to get the data from
104 * @throws DataFormatException if there was a problem converting the data for display
105 */
106 public void setValue(XMLPacket packet) throws DataFormatException {
107 String value = packet.getParam(_attribute);
108 String statusvalue = packet.getParam(_statusAttribute);
109 try {
110 if(!_cache.equals(value) || !_statusCache.equals(statusvalue)) {
111 _cache = value;
112 _statusCache = statusvalue;
113 SwingUtilities.invokeLater(this);
114 }
115 } catch (Exception e) {
116 throw new DataFormatException(value + " is an invalid data type for " + toString());
117 }
118 }
119
120 /**
121 * Returns the string showing the packet
122 * attribute that the component is looking after
123 *
124 * @return the packet reference
125 */
126 public String getPacketAttribute() {
127 return _attribute;
128 }
129
130 //---ATTRIBUTES---
131
132 /**
133 * The friendly name of this component
134 */
135 protected String _name;
136
137 /**
138 * The attribute that this component is concerned with
139 */
140 protected String _attribute;
141
142 /**
143 * The service status attribute that this component is concerned with
144 */
145 protected String _statusAttribute;
146
147 /**
148 * The friendly label for this component
149 */
150 protected JLabel _label;
151
152 /**
153 * Remembers what the last value was, so we
154 * only update if we have to.
155 */
156 protected String _cache = "";
157
158 /**
159 * Remembers what the last value was, so we
160 * only update if we have to.
161 */
162 protected String _statusCache = "";
163
164 /**
165 * The length of the JTextField
166 */
167 protected int _displayLength;
168
169 /**
170 * Just a normal label to display our value as a String
171 */
172 protected JTextField _item;
173
174 //---STATIC ATTRIBUTES---
175
176 }