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/StringDataComponent.java
(Generate patch)

Comparing projects/cms/source/conient/uk/org/iscream/cms/conient/datacomponents/StringDataComponent.java (file contents):
Revision 1.5 by ajm, Wed Jan 24 01:54:43 2001 UTC vs.
Revision 1.18 by tdb, Sat May 18 18:15:56 2002 UTC

# Line 1 | Line 1
1 + /*
2 + * i-scream central monitoring system
3 + * Copyright (C) 2000-2002 i-scream
4 + *
5 + * This program is free software; you can redistribute it and/or
6 + * modify it under the terms of the GNU General Public License
7 + * as published by the Free Software Foundation; either version 2
8 + * of the License, or (at your option) any later version.
9 + *
10 + * This program is distributed in the hope that it will be useful,
11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 + * GNU General Public License for more details.
14 + *
15 + * You should have received a copy of the GNU General Public License
16 + * along with this program; if not, write to the Free Software
17 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 + */
19 +
20   //---PACKAGE DECLARATION---
21 < uk.ac.ukc.iscream.conient.datacomponents;
21 > package uk.org.iscream.cms.conient.datacomponents;
22  
23   //---IMPORTS---
24   import javax.swing.JLabel;
25   import javax.swing.JTextField;
26   import java.awt.GridLayout;
27 + import javax.swing.SwingUtilities;
28 + import uk.org.iscream.cms.server.util.XMLPacket;
29  
30   /**
31   * This is the most basic of DataComponents.
# Line 15 | Line 36 | import java.awt.GridLayout;
36   * @author  $Author$
37   * @version $Id$
38   */
39 < public class StringDataComponent extends VisibleDataComponent implements DataComponent {
39 > public class StringDataComponent extends VisibleDataComponent {
40  
41   //---FINAL ATTRIBUTES---
42  
# Line 27 | Line 48 | public class StringDataComponent extends VisibleDataCo
48      /**
49       * The default length of the JTextField
50       */
51 <    private final int DEFAULT_DISPLAY_LENGTH = 20;
51 >    protected final int DEFAULT_TEXT_LENGTH = 20;
52  
53   //---STATIC METHODS---
54  
# Line 41 | Line 62 | public class StringDataComponent extends VisibleDataCo
62       * @param attribute the data attribute we look after
63       */
64      public StringDataComponent(String name, String attribute) {
44        this(name, attribute, DEFAULT_DISPLAY_LENGTH);
45    }
46
47    /**
48     * Creates the component with a friendly name to be
49     * used as label
50     *
51     * @param name the friendly name
52     * @param attribute the data attribute we look after
53     * @param displayLength the length of the JTextField
54     */
55    public StringDataComponent(String name, String attribute, int displayLength) {
65          _name = name;
66          _attribute = attribute;
67 <        _displayLength = displayLength;
59 <        _item = new JTextField("", _displayLength);
67 >        _item = new JTextField("", DEFAULT_TEXT_LENGTH);
68          _item.setEditable(false);
69          _label = new JLabel(_name + ": ");
70          _label.setHorizontalAlignment(JLabel.RIGHT);
71          setLayout(new GridLayout(1, 2));
72 +        _item.setText("-uninitialised-");
73          add(_label);
74          add(_item);
75 +        setVisible(false);
76      }
77  
78   //---PUBLIC METHODS---
79  
80      /**
81 +     * This run method updates any Swing components
82 +     * The setValue() method adds this component
83 +     * to the Swing Event Dispatching Queue to
84 +     * run this method.
85 +     */
86 +    public void run() {
87 +        if(!isVisible()) {
88 +            setVisible(true);
89 +        }
90 +        _item.setText(_cache);
91 +    }
92 +    
93 +    /**
94       * Overrides the {@link java.lang.Object#toString() Object.toString()}
95       * method to provide clean logging (every class should have this).
96       *
# Line 82 | Line 105 | public class StringDataComponent extends VisibleDataCo
105   //---ACCESSOR/MUTATOR METHODS---
106  
107      /**
108 <     * This takes the String value of the parameter that this component
109 <     * is monitoring direct from the packet, it then performs all
110 <     * approriate conversions and displays the data.
108 >     * This takes the packet to obtain the value from, it then performs all
109 >     * approriate conversions and adds this class to the Swing Event
110 >     * Dispatching queue.
111       *
112 <     * @param value the value for this data component
112 >     * @param packet the XMLPacket to get the data from
113       * @throws DataFormatException if there was a problem converting the data for display
114       */
115 <    public void setValue(String value) throws DataFormatException {
115 >    public void setValue(XMLPacket packet) throws DataFormatException {
116 >        String value = packet.getParam(_attribute);
117          try {
118              if(!_cache.equals(value)) {
119                  _cache = value;
120 <                _item.setText(value);
120 >                SwingUtilities.invokeLater(this);
121              }
122          } catch (Exception e) {
123              throw new DataFormatException(value + " is an invalid data type for " + toString());
124          }
125 <    }        
125 >    }
126 >    
127 >    /**
128 >     * Returns the string showing the packet
129 >     * attribute that the component is looking after
130 >     *
131 >     * @return the packet reference
132 >     */
133 >    public String getPacketAttribute() {
134 >        return _attribute;
135 >    }
136 >    
137 >    /**
138 >     * Returns the string showing the packet
139 >     * data that the component is looking after
140 >     *
141 >     * @return the packet reference
142 >     */
143 >    public String getValue() {
144 >        return _cache;
145 >    }
146  
147   //---ATTRIBUTES---
148  
149      /**
150       * The friendly name of this component
151       */
152 <    private String _name;
152 >    protected String _name;
153      
154      /**
155       * The attribute that this component is concerned with
156       */
157 <    private String _attribute;
157 >    protected String _attribute;
158  
159      /**
160       * The friendly label for this component
# Line 118 | Line 162 | public class StringDataComponent extends VisibleDataCo
162      protected JLabel _label;
163      
164      /**
165 <     * Remebers what the last value was, so we
165 >     * Remembers what the last value was, so we
166       * only update if we have to.
167       */    
168 <    String _cache = "";
168 >    protected String _cache = "";
169      
170      /**
171       * The length of the JTextField
# Line 135 | Line 179 | public class StringDataComponent extends VisibleDataCo
179  
180   //---STATIC ATTRIBUTES---
181  
182 < }
182 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines