1 package org.catacomb.druid.gui.edit;
2
3
4 import org.catacomb.druid.event.TextActor;
5 import org.catacomb.druid.swing.DTextField;
6 import org.catacomb.interlish.content.StringValue;
7 import org.catacomb.interlish.structure.Ablable;
8 import org.catacomb.interlish.structure.TextField;
9 import org.catacomb.interlish.structure.Value;
10 import org.catacomb.interlish.structure.ValueWatcher;
11 import org.catacomb.report.E;
12
13
14
15
16 public class DruTextField extends DruGCPanel
17 implements TextActor, Ablable, TextField, ValueWatcher {
18
19 static final long serialVersionUID = 1001;
20
21 DTextField dTextField;
22
23 StringValue stringValue;
24
25
26 public DruTextField() {
27 this(null, 20);
28 }
29
30
31 public DruTextField(String s) {
32 this(s, s.length());
33 }
34
35
36 public DruTextField(String mn, int width) {
37 super();
38
39 dTextField = new DTextField("", width);
40 setActionMethod(mn);
41
42 addSingleDComponent(dTextField);
43 dTextField.setTextActor(this);
44
45 setLineBorder(0xc0c0c0);
46 }
47
48
49
50
51 public void valueChangedBy(Value pv, Object src) {
52 if (src == this) {
53
54 } else {
55 if (stringValue == pv) {
56 if (stringValue == null) {
57 dTextField.setText("");
58 able(false);
59 } else {
60 dTextField.setText(stringValue.getString());
61
62 able(stringValue.isAble());
63 }
64 } else {
65 E.error("value changed by called with mismatched value");
66 }
67
68 }
69 }
70
71
72
73 public void setEditable(boolean b) {
74 dTextField.setEditable(b);
75 dTextField.setEnabled(b);
76 }
77
78
79 public void able(boolean b) {
80 dTextField.setEnabled(b);
81 }
82
83
84
85 public void setStringValue(StringValue sv) {
86 if (stringValue != null) {
87 stringValue.removeValueWatcher(this);
88 }
89 stringValue = sv;
90 if (stringValue == null) {
91 able(false);
92
93 } else {
94 dTextField.setText(stringValue.getString());
95 stringValue.addValueWatcher(this);
96 able(stringValue.isAble());
97 }
98 }
99
100
101
102 public void setLineBorder(int icol) {
103 dTextField.setLineBorder(icol);
104 }
105
106
107
108 public void textChanged(String s) {
109 stringValue.reportableSetString(dTextField.getText(), this);
110 }
111
112 public void textEntered(String s) {
113 if (hasAction()) {
114 action();
115 }
116 }
117
118 public void textEdited(String s) {
119 stringValue.editCompleted();
120 }
121
122
123
124
125 public void setReturnAction(String action) {
126 setAction(action);
127 dTextField.enableReturnEvents();
128 }
129
130
131 public void focusGained() {
132
133
134 }
135
136
137 public void focusLost() {
138
139
140 }
141
142
143
144 }