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.7
Committed: Wed Jan 24 03:22:24 2001 UTC (23 years, 4 months ago) by ajm
Branch: MAIN
Changes since 1.6: +3 -17 lines
Log Message:
removed code with super constructor error

File Contents

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