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.10 by ajm, Sun Feb 4 00:06:14 2001 UTC vs.
Revision 1.15 by tdb, Thu Feb 14 16:32:52 2002 UTC

# Line 1 | Line 1
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
# Line 41 | Line 41 | public class UsersDataComponent extends VisibleDataCom
41          _label = new JLabel(name + ": ");
42          _label.setHorizontalAlignment(JLabel.RIGHT);
43          setLayout(new GridLayout(1, 2));
44 <        _item.addItem("-uninitialised-");
44 >        _item.addItem("-uninitialised-");
45          add(_label);
46          add(_item);
47 +        setVisible(false);
48      }
49  
50   //---PUBLIC METHODS---
# Line 55 | 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 80 | Line 84 | public class UsersDataComponent extends VisibleDataCom
84  
85   //---ACCESSOR/MUTATOR METHODS---
86      
87 <    /**
88 <     * This takes the String value of the parameter that this component
85 <     * 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 >                    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      

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines