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
(Generate patch)

Comparing projects/cms/source/conient/uk/org/iscream/cms/conient/datacomponents/UsersDataComponent.java (file contents):
Revision 1.12 by ajm, Sun Mar 18 14:43:39 2001 UTC vs.
Revision 1.17 by tdb, Thu Feb 14 17:17:00 2002 UTC

# Line 1 | Line 1
1   //---PACKAGE DECLARATION---
2 < package uk.org.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.util.XMLPacket;
11 > import uk.org.iscream.cms.server.util.XMLPacket;
12  
13   /**
14   * This component displays the users currently logged
# Line 45 | Line 44 | public class UsersDataComponent extends VisibleDataCom
44          _item.addItem("-uninitialised-");
45          add(_label);
46          add(_item);
47 +        setVisible(false);
48      }
49  
50   //---PUBLIC METHODS---
# Line 56 | Line 56 | public class UsersDataComponent extends VisibleDataCom
56       * run this method.
57       */
58      public void run() {
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);
66 >            StringTokenizer st = new StringTokenizer(_cache, ";");
67              while(st.hasMoreTokens()) {
68                  _item.addItem(st.nextToken());
69              }
# Line 91 | Line 94 | public class UsersDataComponent extends VisibleDataCom
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 +                    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      }
158      

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines