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.2 by ajm, Mon Jan 22 12:32:14 2001 UTC vs.
Revision 1.9 by ajm, Mon Jan 29 12:27:52 2001 UTC

# Line 1 | Line 1
1   //---PACKAGE DECLARATION---
2 + package uk.ac.ukc.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  
10   /**
11   * This is the most basic of DataComponents.
12   *
13   * It simply displays the value as a String
14 < * in a JLabel.
14 > * in a JTextField.
15   *
16   * @author  $Author$
17   * @version $Id$
18   */
19 < public class StringDataComponent extends DataComponent {
19 > public class StringDataComponent extends VisibleDataComponent {
20  
21   //---FINAL ATTRIBUTES---
22  
# Line 21 | Line 24 | public class StringDataComponent extends DataComponent
24       * The current CVS revision of this class
25       */
26      public final String REVISION = "$Revision$";
27 +    
28 +    /**
29 +     * The default length of the JTextField
30 +     */
31 +    private final int DEFAULT_TEXT_LENGTH = 20;
32  
33   //---STATIC METHODS---
34  
# Line 31 | Line 39 | public class StringDataComponent extends DataComponent
39       * used as label
40       *
41       * @param name the friendly name
42 +     * @param attribute the data attribute we look after
43       */
44 <    public StringDataComponent(String name) {
45 <        _label = new JLabel(name + ": ");
44 >    public StringDataComponent(String name, String attribute) {
45 >        _name = name;
46 >        _attribute = attribute;
47 >        _item = new JTextField("", DEFAULT_TEXT_LENGTH);
48 >        _item.setEditable(false);
49 >        _label = new JLabel(_name + ": ");
50          _label.setHorizontalAlignment(JLabel.RIGHT);
51          setLayout(new GridLayout(1, 2));
52          add(_label);
# Line 42 | Line 55 | public class StringDataComponent extends DataComponent
55  
56   //---PUBLIC METHODS---
57  
58 +    /**
59 +     * This run method updates any Swing components
60 +     * The setValue() method adds this component
61 +     * to the Swing Event Dispatching Queue to
62 +     * run this method.
63 +     */
64 +    public void run() {
65 +        _item.setText(_cache);
66 +    }
67 +    
68 +    /**
69 +     * Overrides the {@link java.lang.Object#toString() Object.toString()}
70 +     * method to provide clean logging (every class should have this).
71 +     *
72 +     * @return the name of this class and its CVS revision
73 +     */
74 +    public String toString() {
75 +        return _name + "(" + _attribute + ")";
76 +    }
77 +
78   //---PRIVATE METHODS---
79  
80   //---ACCESSOR/MUTATOR METHODS---
# Line 49 | Line 82 | public class StringDataComponent extends DataComponent
82      /**
83       * This takes the String value of the parameter that this component
84       * is monitoring direct from the packet, it then performs all
85 <     * approriate conversions and displays the data.
85 >     * approriate conversions and adds this class to the Swing Event
86 >     * Dispatching queue.
87       *
88       * @param value the value for this data component
89       * @throws DataFormatException if there was a problem converting the data for display
90       */
91      public void setValue(String value) throws DataFormatException {
92          try {
93 <            _item.setText(value);
93 >            if(!_cache.equals(value)) {
94 >                _cache = value;
95 >                SwingUtilities.invokeLater(this);
96 >            }
97          } catch (Exception e) {
98 <            throw new DataFormatException("invalid data type for component");
98 >            throw new DataFormatException(value + " is an invalid data type for " + toString());
99          }
100      }        
101  
102   //---ATTRIBUTES---
103  
104      /**
105 +     * The friendly name of this component
106 +     */
107 +    private String _name;
108 +    
109 +    /**
110 +     * The attribute that this component is concerned with
111 +     */
112 +    private String _attribute;
113 +
114 +    /**
115       * The friendly label for this component
116       */
117      protected JLabel _label;
118      
119      /**
120 +     * Remebers what the last value was, so we
121 +     * only update if we have to.
122 +     */    
123 +    String _cache = "";
124 +    
125 +    /**
126 +     * The length of the JTextField
127 +     */
128 +    protected int _displayLength;
129 +    
130 +    /**
131       * Just a normal label to display our value as a String
132       */
133 <    protected JLabel _item = new JLabel();
133 >    protected JTextField _item;
134  
135   //---STATIC ATTRIBUTES---
136  
137 < }
137 > }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines