1 |
ajm |
1.2 |
//---PACKAGE DECLARATION--- |
2 |
|
|
|
3 |
|
|
//---IMPORTS--- |
4 |
ajm |
1.1 |
import javax.swing.JLabel; |
5 |
ajm |
1.3 |
import javax.swing.JTextField; |
6 |
ajm |
1.1 |
import java.awt.GridLayout; |
7 |
|
|
|
8 |
ajm |
1.2 |
/** |
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 |
ajm |
1.4 |
* @version $Id: StringDataComponent.java,v 1.3 2001/01/23 00:38:24 ajm4 Exp $ |
16 |
ajm |
1.2 |
*/ |
17 |
ajm |
1.1 |
public class StringDataComponent extends DataComponent { |
18 |
ajm |
1.2 |
|
19 |
|
|
//---FINAL ATTRIBUTES--- |
20 |
|
|
|
21 |
|
|
/** |
22 |
|
|
* The current CVS revision of this class |
23 |
|
|
*/ |
24 |
ajm |
1.4 |
public final String REVISION = "$Revision: 1.3 $"; |
25 |
ajm |
1.2 |
|
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 |
ajm |
1.1 |
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 |
ajm |
1.2 |
//---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 |
ajm |
1.1 |
public void setValue(String value) throws DataFormatException { |
59 |
|
|
try { |
60 |
ajm |
1.4 |
if(!_cache.equals(value)) { |
61 |
|
|
_cache = value; |
62 |
|
|
_item.setText(value); |
63 |
|
|
} |
64 |
ajm |
1.1 |
} catch (Exception e) { |
65 |
|
|
throw new DataFormatException("invalid data type for component"); |
66 |
|
|
} |
67 |
|
|
} |
68 |
ajm |
1.2 |
|
69 |
|
|
//---ATTRIBUTES--- |
70 |
|
|
|
71 |
|
|
/** |
72 |
|
|
* The friendly label for this component |
73 |
|
|
*/ |
74 |
|
|
protected JLabel _label; |
75 |
ajm |
1.4 |
|
76 |
|
|
String _cache = ""; |
77 |
ajm |
1.1 |
|
78 |
ajm |
1.3 |
protected int _displayLength = 20; |
79 |
|
|
|
80 |
ajm |
1.2 |
/** |
81 |
|
|
* Just a normal label to display our value as a String |
82 |
|
|
*/ |
83 |
ajm |
1.3 |
protected JTextField _item = new JTextField("", _displayLength); |
84 |
|
|
{ |
85 |
|
|
_item.setEditable(false); |
86 |
|
|
} |
87 |
ajm |
1.2 |
|
88 |
|
|
//---STATIC ATTRIBUTES--- |
89 |
|
|
|
90 |
ajm |
1.1 |
} |