1 |
//---PACKAGE DECLARATION--- |
2 |
|
3 |
//---IMPORTS--- |
4 |
import javax.swing.JLabel; |
5 |
import java.awt.GridLayout; |
6 |
import java.util.Date; |
7 |
import java.util.StringTokenizer; |
8 |
import javax.swing.JComboBox; |
9 |
import java.text.DateFormat; |
10 |
|
11 |
/** |
12 |
* This component displays the users currently logged |
13 |
* onto a syst |
14 |
* extend StringDataComponent, intercepting the value |
15 |
* to convert it. |
16 |
* |
17 |
* It uses the JProgressBar to display the value. |
18 |
* |
19 |
* @author $Author: tdb1 $ |
20 |
* @version $Id: UsersDataComponent.java,v 1.1 2001/01/22 19:35:36 tdb1 Exp $ |
21 |
*/ |
22 |
public class UsersDataComponent extends DataComponent { |
23 |
|
24 |
//---FINAL ATTRIBUTES--- |
25 |
|
26 |
//---STATIC METHODS--- |
27 |
|
28 |
//---CONSTRUCTORS--- |
29 |
|
30 |
/** |
31 |
* Creates the component with a friendly name to be |
32 |
* used as label, but as we're a very basic |
33 |
* extension of StringDataComponent, we just construct |
34 |
* that. |
35 |
* |
36 |
* @param name the friendly name |
37 |
*/ |
38 |
public UsersDataComponent(String name) { |
39 |
_label = new JLabel(name + ": "); |
40 |
_label.setHorizontalAlignment(JLabel.RIGHT); |
41 |
setLayout(new GridLayout(1, 2)); |
42 |
add(_label); |
43 |
add(_item); |
44 |
} |
45 |
|
46 |
//---PUBLIC METHODS--- |
47 |
|
48 |
//---PRIVATE METHODS--- |
49 |
|
50 |
//---ACCESSOR/MUTATOR METHODS--- |
51 |
|
52 |
/** |
53 |
* This takes the String value of the parameter that this component |
54 |
* is monitoring direct from the packet, it then performs all |
55 |
* approriate conversions and displays the data. |
56 |
* |
57 |
* In this case all we do is change string and pass it to our |
58 |
* super class for displaying. |
59 |
* |
60 |
* @param value the value for this data component |
61 |
* @throws DataFormatException if there was a problem converting the data for display |
62 |
*/ |
63 |
public void setValue(String value) throws DataFormatException { |
64 |
try { |
65 |
if (!_cache.equals(value)) { |
66 |
_cache = value; |
67 |
_item.removeAllItems(); |
68 |
StringTokenizer st = new StringTokenizer(value); |
69 |
while(st.hasMoreTokens()) { |
70 |
_item.addItem(st.nextToken()); |
71 |
} |
72 |
} |
73 |
} catch (Exception e) { |
74 |
throw new DataFormatException("invalid data type for component ( " + e + ")"); |
75 |
} |
76 |
} |
77 |
|
78 |
//---ATTRIBUTES--- |
79 |
|
80 |
String _cache = ""; |
81 |
|
82 |
/** |
83 |
* The friendly label for this component |
84 |
*/ |
85 |
protected JLabel _label; |
86 |
|
87 |
/** |
88 |
* Just a normal label to display our value as a String |
89 |
*/ |
90 |
protected JComboBox _item = new JComboBox(); |
91 |
|
92 |
//---STATIC ATTRIBUTES--- |
93 |
|
94 |
} |