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
Revision: 1.14
Committed: Thu Mar 15 01:05:46 2001 UTC (23 years, 2 months ago) by ajm
Branch: MAIN
Changes since 1.13: +3 -3 lines
Log Message:
The whole bally lot now is under uk.org.iscream ;p

File Contents

# User Rev Content
1 ajm 1.2 //---PACKAGE DECLARATION---
2 ajm 1.14 package uk.org.iscream.conient.datacomponents;
3 ajm 1.2
4     //---IMPORTS---
5 ajm 1.1 import javax.swing.JLabel;
6 ajm 1.3 import javax.swing.JTextField;
7 ajm 1.1 import java.awt.GridLayout;
8 ajm 1.8 import javax.swing.SwingUtilities;
9 ajm 1.1
10 ajm 1.2 /**
11     * This is the most basic of DataComponents.
12     *
13     * It simply displays the value as a String
14 ajm 1.5 * in a JTextField.
15 ajm 1.2 *
16     * @author $Author: ajm4 $
17 ajm 1.14 * @version $Id: StringDataComponent.java,v 1.13 2001/03/05 16:13:40 ajm4 Exp $
18 ajm 1.2 */
19 ajm 1.8 public class StringDataComponent extends VisibleDataComponent {
20 ajm 1.2
21     //---FINAL ATTRIBUTES---
22    
23     /**
24     * The current CVS revision of this class
25     */
26 ajm 1.14 public final String REVISION = "$Revision: 1.13 $";
27 ajm 1.5
28     /**
29     * The default length of the JTextField
30     */
31 ajm 1.11 protected final int DEFAULT_TEXT_LENGTH = 20;
32 ajm 1.2
33     //---STATIC METHODS---
34    
35     //---CONSTRUCTORS---
36    
37     /**
38     * Creates the component with a friendly name to be
39     * used as label
40     *
41     * @param name the friendly name
42 ajm 1.5 * @param attribute the data attribute we look after
43     */
44     public StringDataComponent(String name, String attribute) {
45     _name = name;
46     _attribute = attribute;
47 ajm 1.7 _item = new JTextField("", DEFAULT_TEXT_LENGTH);
48 ajm 1.5 _item.setEditable(false);
49     _label = new JLabel(_name + ": ");
50 ajm 1.1 _label.setHorizontalAlignment(JLabel.RIGHT);
51     setLayout(new GridLayout(1, 2));
52 ajm 1.11 _item.setText("-uninitialised-");
53 ajm 1.1 add(_label);
54     add(_item);
55     }
56    
57 ajm 1.2 //---PUBLIC METHODS---
58    
59 ajm 1.5 /**
60 ajm 1.8 * This run method updates any Swing components
61     * The setValue() method adds this component
62     * to the Swing Event Dispatching Queue to
63     * run this method.
64     */
65     public void run() {
66     _item.setText(_cache);
67     }
68    
69     /**
70 ajm 1.5 * Overrides the {@link java.lang.Object#toString() Object.toString()}
71     * method to provide clean logging (every class should have this).
72     *
73     * @return the name of this class and its CVS revision
74     */
75     public String toString() {
76     return _name + "(" + _attribute + ")";
77     }
78    
79 ajm 1.2 //---PRIVATE METHODS---
80    
81     //---ACCESSOR/MUTATOR METHODS---
82    
83     /**
84     * This takes the String value of the parameter that this component
85     * is monitoring direct from the packet, it then performs all
86 ajm 1.8 * approriate conversions and adds this class to the Swing Event
87     * Dispatching queue.
88 ajm 1.2 *
89     * @param value the value for this data component
90     * @throws DataFormatException if there was a problem converting the data for display
91     */
92 ajm 1.1 public void setValue(String value) throws DataFormatException {
93     try {
94 ajm 1.4 if(!_cache.equals(value)) {
95     _cache = value;
96 ajm 1.12 SwingUtilities.invokeLater(this);
97 ajm 1.4 }
98 ajm 1.1 } catch (Exception e) {
99 ajm 1.5 throw new DataFormatException(value + " is an invalid data type for " + toString());
100 ajm 1.1 }
101 ajm 1.11 }
102    
103     /**
104     * Returns the string showing the packet
105     * attribute that the component is looking after
106     *
107     * @return the packet reference
108     */
109     public String getPacketAttribute() {
110     return _attribute;
111 ajm 1.13 }
112    
113     /**
114     * Returns the string showing the packet
115     * data that the component is looking after
116     *
117     * @return the packet reference
118     */
119     public String getValue() {
120     return _cache;
121 ajm 1.11 }
122 ajm 1.2
123     //---ATTRIBUTES---
124    
125     /**
126 ajm 1.5 * The friendly name of this component
127     */
128 ajm 1.11 protected String _name;
129 ajm 1.5
130     /**
131     * The attribute that this component is concerned with
132     */
133 ajm 1.11 protected String _attribute;
134 ajm 1.5
135     /**
136 ajm 1.2 * The friendly label for this component
137     */
138     protected JLabel _label;
139 ajm 1.4
140 ajm 1.5 /**
141     * Remebers what the last value was, so we
142     * only update if we have to.
143     */
144 ajm 1.4 String _cache = "";
145 ajm 1.1
146 ajm 1.5 /**
147     * The length of the JTextField
148     */
149     protected int _displayLength;
150 ajm 1.3
151 ajm 1.2 /**
152     * Just a normal label to display our value as a String
153     */
154 ajm 1.5 protected JTextField _item;
155 ajm 1.2
156     //---STATIC ATTRIBUTES---
157    
158 ajm 1.8 }