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.8
Committed: Wed Feb 5 19:35:04 2003 UTC (21 years, 3 months ago) by tdb
Branch: MAIN
Changes since 1.7: +3 -3 lines
Log Message:
Conient now uses the new seperate i-scream util package.

File Contents

# User Rev Content
1 tdb 1.6 /*
2     * i-scream central monitoring system
3 tdb 1.7 * http://www.i-scream.org.uk
4 tdb 1.6 * 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 ajm 1.1 //---PACKAGE DECLARATION---
22 tdb 1.5 package uk.org.iscream.cms.conient.datacomponents;
23 ajm 1.1
24     //---IMPORTS---
25     import javax.swing.JLabel;
26     import javax.swing.JTextField;
27     import java.awt.GridLayout;
28     import javax.swing.SwingUtilities;
29 tdb 1.8 import uk.org.iscream.cms.util.XMLPacket;
30 ajm 1.1
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 tdb 1.6 * @author $Author: tdb $
41 tdb 1.8 * @version $Id: ProcessesDataComponent.java,v 1.7 2002/05/21 16:47:10 tdb Exp $
42 ajm 1.1 */
43     public class ProcessesDataComponent extends VisibleDataComponent {
44    
45     //---FINAL ATTRIBUTES---
46    
47     /**
48     * The current CVS revision of this class
49     */
50 tdb 1.8 public final String REVISION = "$Revision: 1.7 $";
51 ajm 1.1
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 ajm 1.4 setVisible(false);
81 ajm 1.1 }
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 ajm 1.4 if(!isVisible()) {
93     setVisible(true);
94     }
95 ajm 1.3 _item.setText(_cache);
96 ajm 1.1 }
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 ajm 1.3 * This takes the packet to obtain the value from, it then performs all
114 ajm 1.1 * approriate conversions and adds this class to the Swing Event
115     * Dispatching queue.
116     *
117 ajm 1.3 * @param packet the XMLPacket to get the data from
118 ajm 1.1 * @throws DataFormatException if there was a problem converting the data for display
119     */
120 ajm 1.3 public void setValue(XMLPacket packet) throws DataFormatException {
121     String value = packet.getParam(_attribute);
122 ajm 1.1 try {
123     if(!_cache.equals(value)) {
124     _cache = value;
125 ajm 1.3 SwingUtilities.invokeLater(this);
126 ajm 1.1 }
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 ajm 1.3 * Remembers what the last value was, so we
161 ajm 1.1 * only update if we have to.
162     */
163 ajm 1.3 protected String _cache = "";
164 ajm 1.1
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     }