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.4 |
* @version $Id: ProcessesDataComponent.java,v 1.3 2001/03/18 14:43:39 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.4 |
public final String REVISION = "$Revision: 1.3 $"; |
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 |
ajm |
1.4 |
setVisible(false); |
61 |
ajm |
1.1 |
} |
62 |
|
|
|
63 |
|
|
//---PUBLIC METHODS--- |
64 |
|
|
|
65 |
|
|
/** |
66 |
|
|
* This run method updates any Swing components |
67 |
|
|
* The setValue() method adds this component |
68 |
|
|
* to the Swing Event Dispatching Queue to |
69 |
|
|
* run this method. |
70 |
|
|
*/ |
71 |
|
|
public void run() { |
72 |
ajm |
1.4 |
if(!isVisible()) { |
73 |
|
|
setVisible(true); |
74 |
|
|
} |
75 |
ajm |
1.3 |
_item.setText(_cache); |
76 |
ajm |
1.1 |
} |
77 |
|
|
|
78 |
|
|
/** |
79 |
|
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
80 |
|
|
* method to provide clean logging (every class should have this). |
81 |
|
|
* |
82 |
|
|
* @return the name of this class and its CVS revision |
83 |
|
|
*/ |
84 |
|
|
public String toString() { |
85 |
|
|
return _name + "(" + _attribute + ")"; |
86 |
|
|
} |
87 |
|
|
|
88 |
|
|
//---PRIVATE METHODS--- |
89 |
|
|
|
90 |
|
|
//---ACCESSOR/MUTATOR METHODS--- |
91 |
|
|
|
92 |
|
|
/** |
93 |
ajm |
1.3 |
* This takes the packet to obtain the value from, it then performs all |
94 |
ajm |
1.1 |
* approriate conversions and adds this class to the Swing Event |
95 |
|
|
* Dispatching queue. |
96 |
|
|
* |
97 |
ajm |
1.3 |
* @param packet the XMLPacket to get the data from |
98 |
ajm |
1.1 |
* @throws DataFormatException if there was a problem converting the data for display |
99 |
|
|
*/ |
100 |
ajm |
1.3 |
public void setValue(XMLPacket packet) throws DataFormatException { |
101 |
|
|
String value = packet.getParam(_attribute); |
102 |
ajm |
1.1 |
try { |
103 |
|
|
if(!_cache.equals(value)) { |
104 |
|
|
_cache = value; |
105 |
ajm |
1.3 |
SwingUtilities.invokeLater(this); |
106 |
ajm |
1.1 |
} |
107 |
|
|
} catch (Exception e) { |
108 |
|
|
throw new DataFormatException(value + " is an invalid data type for " + toString()); |
109 |
|
|
} |
110 |
|
|
} |
111 |
|
|
|
112 |
|
|
/** |
113 |
|
|
* Returns the string showing the packet |
114 |
|
|
* attribute that the component is looking after |
115 |
|
|
* |
116 |
|
|
* @return the packet reference |
117 |
|
|
*/ |
118 |
|
|
public String getPacketAttribute() { |
119 |
|
|
return _attribute; |
120 |
|
|
} |
121 |
|
|
|
122 |
|
|
//---ATTRIBUTES--- |
123 |
|
|
|
124 |
|
|
/** |
125 |
|
|
* The friendly name of this component |
126 |
|
|
*/ |
127 |
|
|
protected String _name; |
128 |
|
|
|
129 |
|
|
/** |
130 |
|
|
* The attribute that this component is concerned with |
131 |
|
|
*/ |
132 |
|
|
protected String _attribute; |
133 |
|
|
|
134 |
|
|
/** |
135 |
|
|
* The friendly label for this component |
136 |
|
|
*/ |
137 |
|
|
protected JLabel _label; |
138 |
|
|
|
139 |
|
|
/** |
140 |
ajm |
1.3 |
* Remembers what the last value was, so we |
141 |
ajm |
1.1 |
* only update if we have to. |
142 |
|
|
*/ |
143 |
ajm |
1.3 |
protected String _cache = ""; |
144 |
ajm |
1.1 |
|
145 |
|
|
/** |
146 |
|
|
* The length of the JTextField |
147 |
|
|
*/ |
148 |
|
|
protected int _displayLength; |
149 |
|
|
|
150 |
|
|
/** |
151 |
|
|
* Just a normal label to display our value as a String |
152 |
|
|
*/ |
153 |
|
|
protected JTextField _item; |
154 |
|
|
|
155 |
|
|
//---STATIC ATTRIBUTES--- |
156 |
|
|
|
157 |
|
|
} |