2dd4c1c1c71483fde1541e693c58e0f962cfce1a
[jalviewjs.git] / site / j2s / javax / swing / JTextField.js
1 Clazz.declarePackage ("javax.swing");
2 Clazz.load (["javax.swing.ActionPropertyChangeListener", "$.SwingConstants", "javax.swing.event.ChangeListener", "javax.swing.text.JTextComponent", "$.TextAction"], "javax.swing.JTextField", ["java.lang.Boolean", "$.IllegalArgumentException", "java.awt.EventQueue", "java.awt.event.ActionEvent", "$.ActionListener", "$.InputEvent", "javax.swing.AbstractAction", "$.JViewport", "swingjs.JSToolkit"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.$action = null;
5 this.actionPropertyChangeListener = null;
6 this.horizontalAlignment = 10;
7 this.columns = 0;
8 this.columnWidth = 0;
9 this.command = null;
10 if (!Clazz.isClassDefined ("javax.swing.JTextField.ScrollRepainter")) {
11 javax.swing.JTextField.$JTextField$ScrollRepainter$ ();
12 }
13 Clazz.instantialize (this, arguments);
14 }, javax.swing, "JTextField", javax.swing.text.JTextComponent, javax.swing.SwingConstants);
15 Clazz.makeConstructor (c$, 
16 function () {
17 this.construct (null, null, 0);
18 });
19 Clazz.makeConstructor (c$, 
20 function (text) {
21 this.construct (null, text, 0);
22 }, "~S");
23 Clazz.makeConstructor (c$, 
24 function (columns) {
25 this.construct (null, null, columns);
26 }, "~N");
27 Clazz.makeConstructor (c$, 
28 function (text, columns) {
29 this.construct (null, text, columns);
30 }, "~S,~N");
31 Clazz.makeConstructor (c$, 
32 function (doc, text, columns) {
33 Clazz.superConstructor (this, javax.swing.JTextField);
34 if (columns < 0) {
35 throw  new IllegalArgumentException ("columns less than zero.");
36 }this.columns = columns;
37 if (doc == null) {
38 doc = this.createDefaultModel ();
39 }this.setDocument (doc);
40 if (text != null) {
41 this.setText (text);
42 }}, "javax.swing.text.Document,~S,~N");
43 Clazz.overrideMethod (c$, "getUIClassID", 
44 function () {
45 return "TextFieldUI";
46 });
47 Clazz.defineMethod (c$, "setDocument", 
48 function (doc) {
49 if (doc != null) {
50 doc.putProperty ("filterNewlines", Boolean.TRUE);
51 }Clazz.superCall (this, javax.swing.JTextField, "setDocument", [doc]);
52 }, "javax.swing.text.Document");
53 Clazz.overrideMethod (c$, "isValidateRoot", 
54 function () {
55 var parent = this.getParent ();
56 if (Clazz.instanceOf (parent, javax.swing.JViewport)) {
57 return false;
58 }return true;
59 });
60 Clazz.defineMethod (c$, "getHorizontalAlignment", 
61 function () {
62 return this.horizontalAlignment;
63 });
64 Clazz.defineMethod (c$, "setHorizontalAlignment", 
65 function (alignment) {
66 if (alignment == this.horizontalAlignment) return;
67 var oldValue = this.horizontalAlignment;
68 if ((alignment == 2) || (alignment == 0) || (alignment == 4) || (alignment == 10) || (alignment == 11)) {
69 this.horizontalAlignment = alignment;
70 } else {
71 throw  new IllegalArgumentException ("horizontalAlignment");
72 }this.firePropertyChangeInt ("horizontalAlignment", oldValue, this.horizontalAlignment);
73 this.invalidate ();
74 this.repaint ();
75 }, "~N");
76 Clazz.defineMethod (c$, "createDefaultModel", 
77 function () {
78 return swingjs.JSToolkit.getPlainDocument (this);
79 });
80 Clazz.defineMethod (c$, "getColumns", 
81 function () {
82 return this.columns;
83 });
84 Clazz.defineMethod (c$, "setColumns", 
85 function (columns) {
86 var oldVal = this.columns;
87 if (columns < 0) {
88 throw  new IllegalArgumentException ("columns less than zero.");
89 }if (columns != oldVal) {
90 this.columns = columns;
91 this.invalidate ();
92 }}, "~N");
93 Clazz.defineMethod (c$, "getColumnWidth", 
94 function () {
95 if (this.columnWidth == 0) {
96 var metrics = this.getFontMetrics (this.getFont ());
97 this.columnWidth = metrics.charWidth ('m');
98 }return this.columnWidth;
99 });
100 Clazz.overrideMethod (c$, "getPreferredSize", 
101 function () {
102 return this.getPrefSizeJTF ();
103 });
104 Clazz.defineMethod (c$, "getPrefSizeJTF", 
105 function () {
106 var size = this.getPrefSizeJComp ();
107 if (this.columns != 0) {
108 var insets = this.getInsets ();
109 size.width = this.columns * this.getColumnWidth () + insets.left + insets.right;
110 }return size;
111 });
112 Clazz.defineMethod (c$, "setFont", 
113 function (f) {
114 Clazz.superCall (this, javax.swing.JTextField, "setFont", [f]);
115 this.columnWidth = 0;
116 }, "java.awt.Font");
117 Clazz.defineMethod (c$, "addActionListener", 
118 function (l) {
119 this.listenerList.add (java.awt.event.ActionListener, l);
120 }, "java.awt.event.ActionListener");
121 Clazz.defineMethod (c$, "removeActionListener", 
122 function (l) {
123 if ((l != null) && (this.getAction () === l)) {
124 this.setAction (null);
125 } else {
126 this.listenerList.remove (java.awt.event.ActionListener, l);
127 }}, "java.awt.event.ActionListener");
128 Clazz.defineMethod (c$, "getActionListeners", 
129 function () {
130 return this.listenerList.getListeners (java.awt.event.ActionListener);
131 });
132 Clazz.defineMethod (c$, "fireActionPerformed", 
133 function () {
134 var listeners = this.listenerList.getListenerList ();
135 var modifiers = 0;
136 var currentEvent = java.awt.EventQueue.getCurrentEvent ();
137 if (Clazz.instanceOf (currentEvent, java.awt.event.InputEvent)) {
138 modifiers = (currentEvent).getModifiers ();
139 } else if (Clazz.instanceOf (currentEvent, java.awt.event.ActionEvent)) {
140 modifiers = (currentEvent).getModifiers ();
141 }var e =  new java.awt.event.ActionEvent (this, 1001, (this.command != null) ? this.command : this.getText (), java.awt.EventQueue.getMostRecentEventTime (), modifiers);
142 for (var i = listeners.length - 2; i >= 0; i -= 2) {
143 if (listeners[i] === java.awt.event.ActionListener) {
144 (listeners[i + 1]).actionPerformed (e);
145 }}
146 });
147 Clazz.defineMethod (c$, "setActionCommand", 
148 function (command) {
149 this.command = command;
150 }, "~S");
151 Clazz.defineMethod (c$, "setAction", 
152 function (a) {
153 var oldValue = this.getAction ();
154 if (this.$action == null || !this.$action.equals (a)) {
155 this.$action = a;
156 if (oldValue != null) {
157 this.removeActionListener (oldValue);
158 oldValue.removePropertyChangeListener (this.actionPropertyChangeListener);
159 this.actionPropertyChangeListener = null;
160 }this.configurePropertiesFromAction (this.$action);
161 if (this.$action != null) {
162 if (!this.isListener (java.awt.event.ActionListener, this.$action)) {
163 this.addActionListener (this.$action);
164 }this.actionPropertyChangeListener = this.createActionPropertyChangeListener (this.$action);
165 this.$action.addPropertyChangeListener (this.actionPropertyChangeListener);
166 }this.firePropertyChangeObject ("action", oldValue, this.$action);
167 }}, "javax.swing.Action");
168 Clazz.defineMethod (c$, "isListener", 
169  function (c, a) {
170 var isListener = false;
171 var listeners = this.listenerList.getListenerList ();
172 for (var i = listeners.length - 2; i >= 0; i -= 2) {
173 if (listeners[i] === c && listeners[i + 1] === a) {
174 isListener = true;
175 }}
176 return isListener;
177 }, "Class,java.awt.event.ActionListener");
178 Clazz.defineMethod (c$, "getAction", 
179 function () {
180 return this.$action;
181 });
182 Clazz.defineMethod (c$, "configurePropertiesFromAction", 
183 function (a) {
184 javax.swing.AbstractAction.setEnabledFromAction (this, a);
185 javax.swing.AbstractAction.setToolTipTextFromAction (this, a);
186 this.setActionCommandFromAction (a);
187 }, "javax.swing.Action");
188 Clazz.defineMethod (c$, "actionPropertyChanged", 
189 function (action, propertyName) {
190 if (propertyName === "ActionCommandKey") {
191 this.setActionCommandFromAction (action);
192 } else if (propertyName === "enabled") {
193 javax.swing.AbstractAction.setEnabledFromAction (this, action);
194 } else if (propertyName === "ShortDescription") {
195 javax.swing.AbstractAction.setToolTipTextFromAction (this, action);
196 }}, "javax.swing.Action,~S");
197 Clazz.defineMethod (c$, "setActionCommandFromAction", 
198  function (action) {
199 this.setActionCommand ((action == null) ? null : action.getValue ("ActionCommandKey"));
200 }, "javax.swing.Action");
201 Clazz.defineMethod (c$, "createActionPropertyChangeListener", 
202 function (a) {
203 return  new javax.swing.JTextField.TextFieldActionPropertyChangeListener (this, a);
204 }, "javax.swing.Action");
205 Clazz.defineMethod (c$, "getActions", 
206 function () {
207 return javax.swing.text.TextAction.augmentList (Clazz.superCall (this, javax.swing.JTextField, "getActions", []), javax.swing.JTextField.defaultActions);
208 });
209 Clazz.defineMethod (c$, "postActionEvent", 
210 function () {
211 this.fireActionPerformed ();
212 });
213 Clazz.defineMethod (c$, "hasActionListener", 
214 function () {
215 var listeners = this.listenerList.getListenerList ();
216 for (var i = listeners.length - 2; i >= 0; i -= 2) {
217 if (listeners[i] === java.awt.event.ActionListener) {
218 return true;
219 }}
220 return false;
221 });
222 Clazz.defineMethod (c$, "paramString", 
223 function () {
224 var horizontalAlignmentString;
225 if (this.horizontalAlignment == 2) {
226 horizontalAlignmentString = "LEFT";
227 } else if (this.horizontalAlignment == 0) {
228 horizontalAlignmentString = "CENTER";
229 } else if (this.horizontalAlignment == 4) {
230 horizontalAlignmentString = "RIGHT";
231 } else if (this.horizontalAlignment == 10) {
232 horizontalAlignmentString = "LEADING";
233 } else if (this.horizontalAlignment == 11) {
234 horizontalAlignmentString = "TRAILING";
235 } else horizontalAlignmentString = "";
236 var commandString = (this.command != null ? this.command : "");
237 return Clazz.superCall (this, javax.swing.JTextField, "paramString", []) + ",columns=" + this.columns + ",columnWidth=" + this.columnWidth + ",command=" + commandString + ",horizontalAlignment=" + horizontalAlignmentString;
238 });
239 c$.$JTextField$ScrollRepainter$ = function () {
240 Clazz.pu$h(self.c$);
241 c$ = Clazz.decorateAsClass (function () {
242 Clazz.prepareCallback (this, arguments);
243 Clazz.instantialize (this, arguments);
244 }, javax.swing.JTextField, "ScrollRepainter", null, javax.swing.event.ChangeListener);
245 Clazz.overrideMethod (c$, "stateChanged", 
246 function (a) {
247 this.b$["javax.swing.JTextField"].repaint ();
248 }, "javax.swing.event.ChangeEvent");
249 c$ = Clazz.p0p ();
250 };
251 Clazz.pu$h(self.c$);
252 c$ = Clazz.declareType (javax.swing.JTextField, "TextFieldActionPropertyChangeListener", javax.swing.ActionPropertyChangeListener);
253 Clazz.overrideMethod (c$, "actionPropertyChanged", 
254 function (a, b, c) {
255 if (javax.swing.AbstractAction.shouldReconfigure (c)) {
256 a.configurePropertiesFromAction (b);
257 } else {
258 a.actionPropertyChanged (b, c.getPropertyName ());
259 }}, "javax.swing.JTextField,javax.swing.Action,java.beans.PropertyChangeEvent");
260 c$ = Clazz.p0p ();
261 Clazz.pu$h(self.c$);
262 c$ = Clazz.declareType (javax.swing.JTextField, "NotifyAction", javax.swing.text.TextAction);
263 Clazz.makeConstructor (c$, 
264 function () {
265 Clazz.superConstructor (this, javax.swing.JTextField.NotifyAction, ["notify-field-accept"]);
266 });
267 Clazz.overrideMethod (c$, "actionPerformed", 
268 function (a) {
269 var b = this.getFocusedComponent ();
270 if (Clazz.instanceOf (b, javax.swing.JTextField)) {
271 var c = b;
272 c.postActionEvent ();
273 }}, "java.awt.event.ActionEvent");
274 Clazz.overrideMethod (c$, "isEnabled", 
275 function () {
276 var a = this.getFocusedComponent ();
277 if (Clazz.instanceOf (a, javax.swing.JTextField)) {
278 return (a).hasActionListener ();
279 }return false;
280 });
281 c$ = Clazz.p0p ();
282 Clazz.defineStatics (c$,
283 "notifyAction", "notify-field-accept");
284 c$.defaultActions = c$.prototype.defaultActions =  Clazz.newArray (-1, [ new javax.swing.JTextField.NotifyAction ()]);
285 Clazz.defineStatics (c$,
286 "$uiClassID", "TextFieldUI");
287 });