| 1 |
tdb |
1.1 |
//---PACKAGE DECLARATION--- |
| 2 |
ajm |
1.4 |
package uk.ac.ukc.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.3 |
* @author $Author: ajm4 $ |
| 19 |
ajm |
1.6 |
* @version $Id: UsersDataComponent.java,v 1.5 2001/01/29 12:23:25 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 |
|
|
add(_label); |
| 45 |
|
|
add(_item); |
| 46 |
tdb |
1.1 |
} |
| 47 |
|
|
|
| 48 |
|
|
//---PUBLIC METHODS--- |
| 49 |
ajm |
1.5 |
|
| 50 |
|
|
/** |
| 51 |
|
|
* This run method updates any Swing components |
| 52 |
|
|
* The setValue() method adds this component |
| 53 |
|
|
* to the Swing Event Dispatching Queue to |
| 54 |
|
|
* run this method. |
| 55 |
|
|
*/ |
| 56 |
|
|
public void run() { |
| 57 |
|
|
_item.removeAllItems(); |
| 58 |
|
|
StringTokenizer st = new StringTokenizer(_cache); |
| 59 |
|
|
while(st.hasMoreTokens()) { |
| 60 |
|
|
_item.addItem(st.nextToken()); |
| 61 |
|
|
} |
| 62 |
|
|
} |
| 63 |
tdb |
1.1 |
|
| 64 |
ajm |
1.3 |
/** |
| 65 |
|
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
| 66 |
|
|
* method to provide clean logging (every class should have this). |
| 67 |
|
|
* |
| 68 |
|
|
* @return the name of this class and its CVS revision |
| 69 |
|
|
*/ |
| 70 |
|
|
public String toString() { |
| 71 |
|
|
return _name + "(" + _attribute + ")"; |
| 72 |
|
|
} |
| 73 |
|
|
|
| 74 |
tdb |
1.1 |
//---PRIVATE METHODS--- |
| 75 |
|
|
|
| 76 |
|
|
//---ACCESSOR/MUTATOR METHODS--- |
| 77 |
|
|
|
| 78 |
|
|
/** |
| 79 |
|
|
* This takes the String value of the parameter that this component |
| 80 |
|
|
* is monitoring direct from the packet, it then performs all |
| 81 |
ajm |
1.5 |
* approriate conversions and adds this class to the Swing Event |
| 82 |
|
|
* Dispatching queue. |
| 83 |
tdb |
1.1 |
* |
| 84 |
|
|
* @param value the value for this data component |
| 85 |
|
|
* @throws DataFormatException if there was a problem converting the data for display |
| 86 |
|
|
*/ |
| 87 |
|
|
public void setValue(String value) throws DataFormatException { |
| 88 |
|
|
try { |
| 89 |
ajm |
1.2 |
if (!_cache.equals(value)) { |
| 90 |
|
|
_cache = value; |
| 91 |
ajm |
1.6 |
SwingUtilities.invokeLater(this); |
| 92 |
tdb |
1.1 |
} |
| 93 |
|
|
} catch (Exception e) { |
| 94 |
ajm |
1.3 |
throw new DataFormatException(value + " is an invalid data type for " + toString()); |
| 95 |
tdb |
1.1 |
} |
| 96 |
|
|
} |
| 97 |
|
|
|
| 98 |
|
|
//---ATTRIBUTES--- |
| 99 |
ajm |
1.2 |
|
| 100 |
ajm |
1.3 |
/** |
| 101 |
|
|
* The friendly name of this component |
| 102 |
|
|
*/ |
| 103 |
|
|
private String _name; |
| 104 |
|
|
|
| 105 |
|
|
/** |
| 106 |
|
|
* The attribute that this component is concerned with |
| 107 |
|
|
*/ |
| 108 |
|
|
private String _attribute; |
| 109 |
|
|
|
| 110 |
|
|
/** |
| 111 |
|
|
* Remebers what the last value was, so we |
| 112 |
|
|
* only update if we have to. |
| 113 |
|
|
*/ |
| 114 |
ajm |
1.2 |
String _cache = ""; |
| 115 |
|
|
|
| 116 |
|
|
/** |
| 117 |
|
|
* The friendly label for this component |
| 118 |
|
|
*/ |
| 119 |
|
|
protected JLabel _label; |
| 120 |
|
|
|
| 121 |
|
|
/** |
| 122 |
ajm |
1.3 |
* Just a JComboBox to display the users in |
| 123 |
ajm |
1.2 |
*/ |
| 124 |
|
|
protected JComboBox _item = new JComboBox(); |
| 125 |
tdb |
1.1 |
|
| 126 |
|
|
//---STATIC ATTRIBUTES--- |
| 127 |
|
|
|
| 128 |
ajm |
1.5 |
} |