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.4
Committed: Tue Jan 23 00:44:27 2001 UTC (23 years, 4 months ago) by ajm
Branch: MAIN
Changes since 1.3: +8 -3 lines
Log Message:
now caches values

File Contents

# Content
1 //---PACKAGE DECLARATION---
2
3 //---IMPORTS---
4 import javax.swing.JLabel;
5 import javax.swing.JTextField;
6 import java.awt.GridLayout;
7
8 /**
9 * This is the most basic of DataComponents.
10 *
11 * It simply displays the value as a String
12 * in a JLabel.
13 *
14 * @author $Author: ajm4 $
15 * @version $Id: StringDataComponent.java,v 1.3 2001/01/23 00:38:24 ajm4 Exp $
16 */
17 public class StringDataComponent extends DataComponent {
18
19 //---FINAL ATTRIBUTES---
20
21 /**
22 * The current CVS revision of this class
23 */
24 public final String REVISION = "$Revision: 1.3 $";
25
26 //---STATIC METHODS---
27
28 //---CONSTRUCTORS---
29
30 /**
31 * Creates the component with a friendly name to be
32 * used as label
33 *
34 * @param name the friendly name
35 */
36 public StringDataComponent(String name) {
37 _label = new JLabel(name + ": ");
38 _label.setHorizontalAlignment(JLabel.RIGHT);
39 setLayout(new GridLayout(1, 2));
40 add(_label);
41 add(_item);
42 }
43
44 //---PUBLIC METHODS---
45
46 //---PRIVATE METHODS---
47
48 //---ACCESSOR/MUTATOR METHODS---
49
50 /**
51 * This takes the String value of the parameter that this component
52 * is monitoring direct from the packet, it then performs all
53 * approriate conversions and displays the data.
54 *
55 * @param value the value for this data component
56 * @throws DataFormatException if there was a problem converting the data for display
57 */
58 public void setValue(String value) throws DataFormatException {
59 try {
60 if(!_cache.equals(value)) {
61 _cache = value;
62 _item.setText(value);
63 }
64 } catch (Exception e) {
65 throw new DataFormatException("invalid data type for component");
66 }
67 }
68
69 //---ATTRIBUTES---
70
71 /**
72 * The friendly label for this component
73 */
74 protected JLabel _label;
75
76 String _cache = "";
77
78 protected int _displayLength = 20;
79
80 /**
81 * Just a normal label to display our value as a String
82 */
83 protected JTextField _item = new JTextField("", _displayLength);
84 {
85 _item.setEditable(false);
86 }
87
88 //---STATIC ATTRIBUTES---
89
90 }