| 1 |
|
//---PACKAGE DECLARATION--- |
| 2 |
< |
package uk.ac.ukc.iscream.conient.datacomponents; |
| 2 |
> |
package uk.org.iscream.cms.conient.datacomponents; |
| 3 |
|
|
| 4 |
|
//---IMPORTS--- |
| 5 |
|
import javax.swing.JLabel; |
| 6 |
|
import java.awt.GridLayout; |
| 7 |
– |
import java.util.Date; |
| 7 |
|
import java.util.StringTokenizer; |
| 8 |
+ |
import java.util.Arrays; |
| 9 |
|
import javax.swing.JComboBox; |
| 10 |
– |
import java.text.DateFormat; |
| 10 |
|
import javax.swing.SwingUtilities; |
| 11 |
+ |
import uk.org.iscream.cms.server.util.XMLPacket; |
| 12 |
|
|
| 13 |
|
/** |
| 14 |
|
* This component displays the users currently logged |
| 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 |
+ |
setVisible(false); |
| 48 |
|
} |
| 49 |
|
|
| 50 |
|
//---PUBLIC METHODS--- |
| 56 |
|
* run this method. |
| 57 |
|
*/ |
| 58 |
|
public void run() { |
| 59 |
< |
_item.removeAllItems(); |
| 60 |
< |
StringTokenizer st = new StringTokenizer(_cache); |
| 59 |
< |
while(st.hasMoreTokens()) { |
| 60 |
< |
_item.addItem(st.nextToken()); |
| 59 |
> |
if(!isVisible()) { |
| 60 |
> |
setVisible(true); |
| 61 |
|
} |
| 62 |
+ |
_item.removeAllItems(); |
| 63 |
+ |
if (_cache.equals(" ")) { |
| 64 |
+ |
_item.addItem("no users logged on"); |
| 65 |
+ |
} else { |
| 66 |
+ |
StringTokenizer st = new StringTokenizer(_cache, ";"); |
| 67 |
+ |
while(st.hasMoreTokens()) { |
| 68 |
+ |
_item.addItem(st.nextToken()); |
| 69 |
+ |
} |
| 70 |
+ |
} |
| 71 |
|
} |
| 72 |
|
|
| 73 |
|
/** |
| 84 |
|
|
| 85 |
|
//---ACCESSOR/MUTATOR METHODS--- |
| 86 |
|
|
| 87 |
< |
/** |
| 88 |
< |
* This takes the String value of the parameter that this component |
| 80 |
< |
* is monitoring direct from the packet, it then performs all |
| 87 |
> |
/** |
| 88 |
> |
* This takes the packet to obtain the value from, it then performs all |
| 89 |
|
* approriate conversions and adds this class to the Swing Event |
| 90 |
|
* Dispatching queue. |
| 91 |
|
* |
| 92 |
< |
* @param value the value for this data component |
| 92 |
> |
* @param packet the XMLPacket to get the data from |
| 93 |
|
* @throws DataFormatException if there was a problem converting the data for display |
| 94 |
|
*/ |
| 95 |
< |
public void setValue(String value) throws DataFormatException { |
| 95 |
> |
public void setValue(XMLPacket packet) throws DataFormatException { |
| 96 |
> |
String value = packet.getParam(_attribute); |
| 97 |
> |
// tokenize the input |
| 98 |
> |
StringTokenizer st = new StringTokenizer(value); |
| 99 |
> |
// create an array to store the tokens in |
| 100 |
> |
int tokenCount = st.countTokens(); |
| 101 |
> |
String[] tokens = new String[tokenCount]; |
| 102 |
> |
int i=0; |
| 103 |
> |
while(st.hasMoreTokens()) { |
| 104 |
> |
tokens[i] = st.nextToken(); |
| 105 |
> |
i++; |
| 106 |
> |
} |
| 107 |
> |
// sort the array |
| 108 |
> |
Arrays.sort(tokens); |
| 109 |
> |
// put the array back into a String, sorted |
| 110 |
> |
StringBuffer valueBuffer = new StringBuffer(); |
| 111 |
> |
// we only add the token when we've gone past all |
| 112 |
> |
// the duplicates - this allows us to keep count. |
| 113 |
> |
String lastToken = ""; |
| 114 |
> |
int count = 0; |
| 115 |
> |
for(i=0; i < tokenCount; i++) { |
| 116 |
> |
// if the token is different, we'll add the |
| 117 |
> |
// last one |
| 118 |
> |
if(!tokens[i].equals(lastToken)) { |
| 119 |
> |
// just a check for the "first case" |
| 120 |
> |
if(!lastToken.equals("")) { |
| 121 |
> |
valueBuffer.append(lastToken); |
| 122 |
> |
if(count > 1) { |
| 123 |
> |
valueBuffer.append(" ("); |
| 124 |
> |
valueBuffer.append(count); |
| 125 |
> |
valueBuffer.append(")"); |
| 126 |
> |
} |
| 127 |
> |
valueBuffer.append(";"); |
| 128 |
> |
} |
| 129 |
> |
// starting a new token, so reset the |
| 130 |
> |
// the last one and the count |
| 131 |
> |
lastToken = tokens[i]; |
| 132 |
> |
count = 1; |
| 133 |
> |
} |
| 134 |
> |
// if not, we'll increment our count of the |
| 135 |
> |
// current one |
| 136 |
> |
else { |
| 137 |
> |
count++; |
| 138 |
> |
} |
| 139 |
> |
} |
| 140 |
> |
// we have to add the last one... |
| 141 |
> |
valueBuffer.append(lastToken); |
| 142 |
> |
if(count > 1) { |
| 143 |
> |
valueBuffer.append(" ("); |
| 144 |
> |
valueBuffer.append(count); |
| 145 |
> |
valueBuffer.append(");"); |
| 146 |
> |
} |
| 147 |
> |
valueBuffer.append(";"); |
| 148 |
> |
String sortedValue = valueBuffer.toString(); |
| 149 |
|
try { |
| 150 |
< |
if (!_cache.equals(value)) { |
| 151 |
< |
_cache = value; |
| 150 |
> |
if (!_cache.equals(sortedValue)) { |
| 151 |
> |
_cache = sortedValue; |
| 152 |
|
SwingUtilities.invokeLater(this); |
| 153 |
|
} |
| 154 |
|
} catch (Exception e) { |
| 155 |
< |
throw new DataFormatException(value + " is an invalid data type for " + toString()); |
| 155 |
> |
throw new DataFormatException(sortedValue + " is an invalid data type for " + toString()); |
| 156 |
|
} |
| 157 |
< |
} |
| 157 |
> |
} |
| 158 |
> |
|
| 159 |
> |
/** |
| 160 |
> |
* Returns the string showing the packet |
| 161 |
> |
* attribute that the component is looking after |
| 162 |
> |
* |
| 163 |
> |
* @return the packet reference |
| 164 |
> |
*/ |
| 165 |
> |
public String getPacketAttribute() { |
| 166 |
> |
return _attribute; |
| 167 |
> |
} |
| 168 |
|
|
| 169 |
|
//---ATTRIBUTES--- |
| 170 |
|
|