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 |
|
|
63 |
|
if (_cache.equals(" ")) { |
64 |
|
_item.addItem("no users logged on"); |
65 |
|
} else { |
66 |
< |
StringTokenizer st = new StringTokenizer(_cache); |
66 |
> |
StringTokenizer st = new StringTokenizer(_cache, ";"); |
67 |
|
while(st.hasMoreTokens()) { |
68 |
|
_item.addItem(st.nextToken()); |
69 |
|
} |
94 |
|
*/ |
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 |
+ |
valueBuffer.append(" ("); |
123 |
+ |
valueBuffer.append(count); |
124 |
+ |
valueBuffer.append(");"); |
125 |
+ |
} |
126 |
+ |
// starting a new token, so reset the |
127 |
+ |
// the last one and the count |
128 |
+ |
lastToken = tokens[i]; |
129 |
+ |
count = 1; |
130 |
+ |
} |
131 |
+ |
// if not, we'll increment our count of the |
132 |
+ |
// current one |
133 |
+ |
else { |
134 |
+ |
count++; |
135 |
+ |
} |
136 |
+ |
} |
137 |
+ |
// if the last two (or more) tokens are the |
138 |
+ |
// same we won't have added it, so we'll do |
139 |
+ |
// that now :) |
140 |
+ |
if(count > 1) { |
141 |
+ |
valueBuffer.append(lastToken); |
142 |
+ |
valueBuffer.append(" ("); |
143 |
+ |
valueBuffer.append(count); |
144 |
+ |
valueBuffer.append(");"); |
145 |
+ |
} |
146 |
+ |
String sortedValue = valueBuffer.toString(); |
147 |
|
try { |
148 |
< |
if (!_cache.equals(value)) { |
149 |
< |
_cache = value; |
148 |
> |
if (!_cache.equals(sortedValue)) { |
149 |
> |
_cache = sortedValue; |
150 |
|
SwingUtilities.invokeLater(this); |
151 |
|
} |
152 |
|
} catch (Exception e) { |
153 |
< |
throw new DataFormatException(value + " is an invalid data type for " + toString()); |
153 |
> |
throw new DataFormatException(sortedValue + " is an invalid data type for " + toString()); |
154 |
|
} |
155 |
|
} |
156 |
|
|