1 |
|
//---PACKAGE DECLARATION--- |
2 |
< |
uk.ac.ukc.iscream.conient.datacomponents; |
2 |
> |
package uk.ac.ukc.iscream.conient.datacomponents; |
3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
|
import javax.swing.JLabel; |
8 |
|
import java.util.StringTokenizer; |
9 |
|
import javax.swing.JComboBox; |
10 |
|
import java.text.DateFormat; |
11 |
+ |
import javax.swing.SwingUtilities; |
12 |
|
|
13 |
|
/** |
14 |
|
* This component displays the users currently logged |
18 |
|
* @author $Author$ |
19 |
|
* @version $Id$ |
20 |
|
*/ |
21 |
< |
public class UsersDataComponent extends VisibleDataComponent implements DataComponent { |
21 |
> |
public class UsersDataComponent extends VisibleDataComponent { |
22 |
|
|
23 |
|
//---FINAL ATTRIBUTES--- |
24 |
|
|
41 |
|
_label = new JLabel(name + ": "); |
42 |
|
_label.setHorizontalAlignment(JLabel.RIGHT); |
43 |
|
setLayout(new GridLayout(1, 2)); |
44 |
+ |
_item.addItem("-uninitialised-"); |
45 |
|
add(_label); |
46 |
|
add(_item); |
47 |
|
} |
48 |
|
|
49 |
|
//---PUBLIC METHODS--- |
50 |
+ |
|
51 |
+ |
/** |
52 |
+ |
* This run method updates any Swing components |
53 |
+ |
* The setValue() method adds this component |
54 |
+ |
* to the Swing Event Dispatching Queue to |
55 |
+ |
* run this method. |
56 |
+ |
*/ |
57 |
+ |
public void run() { |
58 |
+ |
_item.removeAllItems(); |
59 |
+ |
if (_cache.equals(" ")) { |
60 |
+ |
_item.addItem("no users logged on"); |
61 |
+ |
} else { |
62 |
+ |
StringTokenizer st = new StringTokenizer(_cache); |
63 |
+ |
while(st.hasMoreTokens()) { |
64 |
+ |
_item.addItem(st.nextToken()); |
65 |
+ |
} |
66 |
+ |
} |
67 |
+ |
} |
68 |
|
|
69 |
|
/** |
70 |
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
83 |
|
/** |
84 |
|
* This takes the String value of the parameter that this component |
85 |
|
* is monitoring direct from the packet, it then performs all |
86 |
< |
* approriate conversions and displays the data. |
86 |
> |
* approriate conversions and adds this class to the Swing Event |
87 |
> |
* Dispatching queue. |
88 |
|
* |
89 |
|
* @param value the value for this data component |
90 |
|
* @throws DataFormatException if there was a problem converting the data for display |
93 |
|
try { |
94 |
|
if (!_cache.equals(value)) { |
95 |
|
_cache = value; |
96 |
< |
_item.removeAllItems(); |
76 |
< |
StringTokenizer st = new StringTokenizer(value); |
77 |
< |
while(st.hasMoreTokens()) { |
78 |
< |
_item.addItem(st.nextToken()); |
79 |
< |
} |
96 |
> |
SwingUtilities.invokeLater(this); |
97 |
|
} |
98 |
|
} catch (Exception e) { |
99 |
|
throw new DataFormatException(value + " is an invalid data type for " + toString()); |
100 |
|
} |
101 |
< |
} |
101 |
> |
} |
102 |
> |
|
103 |
> |
/** |
104 |
> |
* Returns the string showing the packet |
105 |
> |
* attribute that the component is looking after |
106 |
> |
* |
107 |
> |
* @return the packet reference |
108 |
> |
*/ |
109 |
> |
public String getPacketAttribute() { |
110 |
> |
return _attribute; |
111 |
> |
} |
112 |
|
|
113 |
|
//---ATTRIBUTES--- |
114 |
|
|
140 |
|
|
141 |
|
//---STATIC ATTRIBUTES--- |
142 |
|
|
143 |
< |
} |
143 |
> |
} |