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.9
Committed: Sun Aug 1 10:40:10 2004 UTC (19 years, 9 months ago) by tdb
Branch: MAIN
CVS Tags: HEAD
Changes since 1.8: +3 -3 lines
Error occurred while calculating annotation data.
Log Message:
Catch a lot of old URL's and update them. Also remove a couple of old files
that aren't used.

File Contents

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