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.21 by tdb, Sun Aug 1 10:40:10 2004 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines