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.15 by ajm, Sun Mar 18 14:43:39 2001 UTC

# Line 1 | Line 1
1   //---PACKAGE DECLARATION---
2 < uk.ac.ukc.iscream.conient.datacomponents;
2 > package uk.org.iscream.conient.datacomponents;
3  
4   //---IMPORTS---
5   import javax.swing.JLabel;
6   import javax.swing.JTextField;
7   import java.awt.GridLayout;
8 + import javax.swing.SwingUtilities;
9 + import uk.org.iscream.util.XMLPacket;
10  
11   /**
12   * This is the most basic of DataComponents.
# Line 15 | Line 17 | import java.awt.GridLayout;
17   * @author  $Author$
18   * @version $Id$
19   */
20 < public class StringDataComponent extends VisibleDataComponent implements DataComponent {
20 > public class StringDataComponent extends VisibleDataComponent {
21  
22   //---FINAL ATTRIBUTES---
23  
# Line 27 | Line 29 | public class StringDataComponent extends VisibleDataCo
29      /**
30       * The default length of the JTextField
31       */
32 <    private final int DEFAULT_DISPLAY_LENGTH = 20;
32 >    protected final int DEFAULT_TEXT_LENGTH = 20;
33  
34   //---STATIC METHODS---
35  
# Line 41 | Line 43 | public class StringDataComponent extends VisibleDataCo
43       * @param attribute the data attribute we look after
44       */
45      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) {
46          _name = name;
47          _attribute = attribute;
48 <        _displayLength = displayLength;
59 <        _item = new JTextField("", _displayLength);
48 >        _item = new JTextField("", DEFAULT_TEXT_LENGTH);
49          _item.setEditable(false);
50          _label = new JLabel(_name + ": ");
51          _label.setHorizontalAlignment(JLabel.RIGHT);
52          setLayout(new GridLayout(1, 2));
53 +        _item.setText("-uninitialised-");
54          add(_label);
55          add(_item);
56      }
# Line 68 | Line 58 | public class StringDataComponent extends VisibleDataCo
58   //---PUBLIC METHODS---
59  
60      /**
61 +     * This run method updates any Swing components
62 +     * The setValue() method adds this component
63 +     * to the Swing Event Dispatching Queue to
64 +     * run this method.
65 +     */
66 +    public void run() {
67 +        _item.setText(_cache);
68 +    }
69 +    
70 +    /**
71       * Overrides the {@link java.lang.Object#toString() Object.toString()}
72       * method to provide clean logging (every class should have this).
73       *
# Line 82 | Line 82 | public class StringDataComponent extends VisibleDataCo
82   //---ACCESSOR/MUTATOR METHODS---
83  
84      /**
85 <     * This takes the String value of the parameter that this component
86 <     * is monitoring direct from the packet, it then performs all
87 <     * approriate conversions and displays the data.
85 >     * This takes the packet to obtain the value from, it then performs all
86 >     * approriate conversions and adds this class to the Swing Event
87 >     * Dispatching queue.
88       *
89 <     * @param value the value for this data component
89 >     * @param packet the XMLPacket to get the data from
90       * @throws DataFormatException if there was a problem converting the data for display
91       */
92 <    public void setValue(String value) throws DataFormatException {
92 >    public void setValue(XMLPacket packet) throws DataFormatException {
93 >        String value = packet.getParam(_attribute);
94          try {
95              if(!_cache.equals(value)) {
96                  _cache = value;
97 <                _item.setText(value);
97 >                SwingUtilities.invokeLater(this);
98              }
99          } catch (Exception e) {
100              throw new DataFormatException(value + " is an invalid data type for " + toString());
101          }
102 <    }        
102 >    }
103 >    
104 >    /**
105 >     * Returns the string showing the packet
106 >     * attribute that the component is looking after
107 >     *
108 >     * @return the packet reference
109 >     */
110 >    public String getPacketAttribute() {
111 >        return _attribute;
112 >    }
113 >    
114 >    /**
115 >     * Returns the string showing the packet
116 >     * data that the component is looking after
117 >     *
118 >     * @return the packet reference
119 >     */
120 >    public String getValue() {
121 >        return _cache;
122 >    }
123  
124   //---ATTRIBUTES---
125  
126      /**
127       * The friendly name of this component
128       */
129 <    private String _name;
129 >    protected String _name;
130      
131      /**
132       * The attribute that this component is concerned with
133       */
134 <    private String _attribute;
134 >    protected String _attribute;
135  
136      /**
137       * The friendly label for this component
# Line 118 | Line 139 | public class StringDataComponent extends VisibleDataCo
139      protected JLabel _label;
140      
141      /**
142 <     * Remebers what the last value was, so we
142 >     * Remembers what the last value was, so we
143       * only update if we have to.
144       */    
145 <    String _cache = "";
145 >    protected String _cache = "";
146      
147      /**
148       * The length of the JTextField
# Line 135 | Line 156 | public class StringDataComponent extends VisibleDataCo
156  
157   //---STATIC ATTRIBUTES---
158  
159 < }
159 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines