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/UsersDataComponent.java
Revision: 1.11
Committed: Thu Mar 15 01:05:46 2001 UTC (23 years, 2 months ago) by ajm
Branch: MAIN
Changes since 1.10: +2 -2 lines
Log Message:
The whole bally lot now is under uk.org.iscream ;p

File Contents

# User Rev Content
1 tdb 1.1 //---PACKAGE DECLARATION---
2 ajm 1.11 package uk.org.iscream.conient.datacomponents;
3 tdb 1.1
4     //---IMPORTS---
5     import javax.swing.JLabel;
6     import java.awt.GridLayout;
7     import java.util.Date;
8 ajm 1.2 import java.util.StringTokenizer;
9     import javax.swing.JComboBox;
10 tdb 1.1 import java.text.DateFormat;
11 ajm 1.5 import javax.swing.SwingUtilities;
12 tdb 1.1
13     /**
14 ajm 1.2 * This component displays the users currently logged
15 ajm 1.3 * onto a system. Currently it does this simply by
16     * putting them all in a JCombobox.
17 tdb 1.1 *
18 ajm 1.10 * @author $Author: ajm4 $
19 ajm 1.11 * @version $Id: UsersDataComponent.java,v 1.10 2001/02/04 00:06:14 ajm4 Exp $
20 tdb 1.1 */
21 ajm 1.5 public class UsersDataComponent extends VisibleDataComponent {
22 tdb 1.1
23     //---FINAL ATTRIBUTES---
24    
25     //---STATIC METHODS---
26    
27     //---CONSTRUCTORS---
28    
29     /**
30     * Creates the component with a friendly name to be
31     * used as label, but as we're a very basic
32     * extension of StringDataComponent, we just construct
33     * that.
34     *
35     * @param name the friendly name
36 ajm 1.3 * @param attribute the data attribute we look after
37 tdb 1.1 */
38 ajm 1.3 public UsersDataComponent(String name, String attribute) {
39     _name = name;
40     _attribute = attribute;
41 ajm 1.2 _label = new JLabel(name + ": ");
42     _label.setHorizontalAlignment(JLabel.RIGHT);
43     setLayout(new GridLayout(1, 2));
44 ajm 1.7 _item.addItem("-uninitialised-");
45 ajm 1.2 add(_label);
46     add(_item);
47 tdb 1.1 }
48    
49     //---PUBLIC METHODS---
50 ajm 1.5
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 ajm 1.9 _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 ajm 1.5 }
67     }
68 tdb 1.1
69 ajm 1.3 /**
70     * Overrides the {@link java.lang.Object#toString() Object.toString()}
71     * method to provide clean logging (every class should have this).
72     *
73     * @return the name of this class and its CVS revision
74     */
75     public String toString() {
76     return _name + "(" + _attribute + ")";
77     }
78    
79 tdb 1.1 //---PRIVATE METHODS---
80    
81     //---ACCESSOR/MUTATOR METHODS---
82    
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 ajm 1.5 * approriate conversions and adds this class to the Swing Event
87     * Dispatching queue.
88 tdb 1.1 *
89     * @param value the value for this data component
90     * @throws DataFormatException if there was a problem converting the data for display
91     */
92     public void setValue(String value) throws DataFormatException {
93     try {
94 ajm 1.2 if (!_cache.equals(value)) {
95     _cache = value;
96 ajm 1.6 SwingUtilities.invokeLater(this);
97 tdb 1.1 }
98     } catch (Exception e) {
99 ajm 1.3 throw new DataFormatException(value + " is an invalid data type for " + toString());
100 tdb 1.1 }
101 ajm 1.10 }
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 tdb 1.1
113     //---ATTRIBUTES---
114 ajm 1.2
115 ajm 1.3 /**
116     * The friendly name of this component
117     */
118     private String _name;
119    
120     /**
121     * The attribute that this component is concerned with
122     */
123     private String _attribute;
124    
125     /**
126     * Remebers what the last value was, so we
127     * only update if we have to.
128     */
129 ajm 1.2 String _cache = "";
130    
131     /**
132     * The friendly label for this component
133     */
134     protected JLabel _label;
135    
136     /**
137 ajm 1.3 * Just a JComboBox to display the users in
138 ajm 1.2 */
139     protected JComboBox _item = new JComboBox();
140 tdb 1.1
141     //---STATIC ATTRIBUTES---
142    
143 ajm 1.5 }