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.4 by ajm, Tue Jan 23 00:44:27 2001 UTC vs.
Revision 1.5 by ajm, Wed Jan 24 01:54:43 2001 UTC

# Line 1 | Line 1
1   //---PACKAGE DECLARATION---
2 + uk.ac.ukc.iscream.conient.datacomponents;
3  
4   //---IMPORTS---
5   import javax.swing.JLabel;
# Line 9 | Line 10 | import java.awt.GridLayout;
10   * This is the most basic of DataComponents.
11   *
12   * It simply displays the value as a String
13 < * in a JLabel.
13 > * in a JTextField.
14   *
15   * @author  $Author$
16   * @version $Id$
17   */
18 < public class StringDataComponent extends DataComponent {
18 > public class StringDataComponent extends VisibleDataComponent implements DataComponent {
19  
20   //---FINAL ATTRIBUTES---
21  
# Line 22 | Line 23 | public class StringDataComponent extends DataComponent
23       * The current CVS revision of this class
24       */
25      public final String REVISION = "$Revision$";
26 +    
27 +    /**
28 +     * The default length of the JTextField
29 +     */
30 +    private final int DEFAULT_DISPLAY_LENGTH = 20;
31  
32   //---STATIC METHODS---
33  
# Line 32 | Line 38 | public class StringDataComponent extends DataComponent
38       * used as label
39       *
40       * @param name the friendly name
41 +     * @param attribute the data attribute we look after
42       */
43 <    public StringDataComponent(String name) {
44 <        _label = new JLabel(name + ": ");
43 >    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) {
56 >        _name = name;
57 >        _attribute = attribute;
58 >        _displayLength = displayLength;
59 >        _item = new JTextField("", _displayLength);
60 >        _item.setEditable(false);
61 >        _label = new JLabel(_name + ": ");
62          _label.setHorizontalAlignment(JLabel.RIGHT);
63          setLayout(new GridLayout(1, 2));
64          add(_label);
# Line 43 | Line 67 | public class StringDataComponent extends DataComponent
67  
68   //---PUBLIC METHODS---
69  
70 +    /**
71 +     * Overrides the {@link java.lang.Object#toString() Object.toString()}
72 +     * method to provide clean logging (every class should have this).
73 +     *
74 +     * @return the name of this class and its CVS revision
75 +     */
76 +    public String toString() {
77 +        return _name + "(" + _attribute + ")";
78 +    }
79 +
80   //---PRIVATE METHODS---
81  
82   //---ACCESSOR/MUTATOR METHODS---
# Line 62 | Line 96 | public class StringDataComponent extends DataComponent
96                  _item.setText(value);
97              }
98          } catch (Exception e) {
99 <            throw new DataFormatException("invalid data type for component");
99 >            throw new DataFormatException(value + " is an invalid data type for " + toString());
100          }
101      }        
102  
103   //---ATTRIBUTES---
104  
105      /**
106 +     * The friendly name of this component
107 +     */
108 +    private String _name;
109 +    
110 +    /**
111 +     * The attribute that this component is concerned with
112 +     */
113 +    private String _attribute;
114 +
115 +    /**
116       * The friendly label for this component
117       */
118      protected JLabel _label;
119      
120 +    /**
121 +     * Remebers what the last value was, so we
122 +     * only update if we have to.
123 +     */    
124      String _cache = "";
125      
126 <    protected int _displayLength = 20;
126 >    /**
127 >     * The length of the JTextField
128 >     */
129 >    protected int _displayLength;
130      
131      /**
132       * Just a normal label to display our value as a String
133       */
134 <    protected JTextField _item = new JTextField("", _displayLength);
84 <    {
85 <        _item.setEditable(false);
86 <    }
134 >    protected JTextField _item;
135  
136   //---STATIC ATTRIBUTES---
137  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines