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.3 |
* @version $Id: StringDataComponent.java,v 1.2 2001/01/22 12:32:14 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.3 |
public final String REVISION = "$Revision: 1.2 $"; |
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 |
|
|
_item.setText(value); |
61 |
|
|
} catch (Exception e) { |
62 |
|
|
throw new DataFormatException("invalid data type for component"); |
63 |
|
|
} |
64 |
|
|
} |
65 |
ajm |
1.2 |
|
66 |
|
|
//---ATTRIBUTES--- |
67 |
|
|
|
68 |
|
|
/** |
69 |
|
|
* The friendly label for this component |
70 |
|
|
*/ |
71 |
|
|
protected JLabel _label; |
72 |
ajm |
1.1 |
|
73 |
ajm |
1.3 |
protected int _displayLength = 20; |
74 |
|
|
|
75 |
ajm |
1.2 |
/** |
76 |
|
|
* Just a normal label to display our value as a String |
77 |
|
|
*/ |
78 |
ajm |
1.3 |
protected JTextField _item = new JTextField("", _displayLength); |
79 |
|
|
{ |
80 |
|
|
_item.setEditable(false); |
81 |
|
|
} |
82 |
ajm |
1.2 |
|
83 |
|
|
//---STATIC ATTRIBUTES--- |
84 |
|
|
|
85 |
ajm |
1.1 |
} |