7c83965d15458a2b8c9899cb43ec040b8a6b1f82
[jalviewjs.git] / site / swingjs / j2s / javax / swing / JFormattedTextField.js
1 Clazz.declarePackage ("javax.swing");
2 Clazz.load (["javax.swing.JTextField", "javax.swing.event.DocumentListener", "javax.swing.text.TextAction"], "javax.swing.JFormattedTextField", ["java.lang.Boolean", "$.IllegalArgumentException", "$.Number", "java.util.Date", "java.text.DateFormat", "$.DecimalFormat", "$.Format", "$.NumberFormat", "javax.swing.ActionMap", "javax.swing.plaf.UIResource", "javax.swing.text.DateFormatter", "$.DefaultFormatter", "$.DefaultFormatterFactory", "$.DocumentFilter", "$.InternationalFormatter", "$.JSMinimalAbstractDocument", "$.NumberFormatter", "swingjs.JSToolkit"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.factory = null;
5 this.format = null;
6 this.value = null;
7 this.editValid = false;
8 this.focusLostBehavior = 0;
9 this.edited = false;
10 this.documentListener = null;
11 this.textFormatterActionMap = null;
12 this.focusLostHandler = null;
13 if (!Clazz.isClassDefined ("javax.swing.JFormattedTextField.FocusLostHandler")) {
14 javax.swing.JFormattedTextField.$JFormattedTextField$FocusLostHandler$ ();
15 }
16 if (!Clazz.isClassDefined ("javax.swing.JFormattedTextField.DocumentHandler")) {
17 javax.swing.JFormattedTextField.$JFormattedTextField$DocumentHandler$ ();
18 }
19 Clazz.instantialize (this, arguments);
20 }, javax.swing, "JFormattedTextField", javax.swing.JTextField);
21 Clazz.makeConstructor (c$, 
22 function () {
23 Clazz.superConstructor (this, javax.swing.JFormattedTextField);
24 this.enableEvents (4);
25 this.setFocusLostBehavior (1);
26 });
27 Clazz.makeConstructor (c$, 
28 function (value) {
29 this.construct ();
30 this.setValue (value);
31 }, "~O");
32 Clazz.makeConstructor (c$, 
33 function (format) {
34 this.construct ();
35 this.setFormatterFactory (this.getDefaultFormatterFactory (format));
36 }, "java.text.Format");
37 Clazz.makeConstructor (c$, 
38 function (formatter) {
39 this.construct ( new javax.swing.text.DefaultFormatterFactory (formatter));
40 }, "javax.swing.JFormattedTextField.AbstractFormatter");
41 Clazz.makeConstructor (c$, 
42 function (factory) {
43 this.construct ();
44 this.setFormatterFactory (factory);
45 }, "javax.swing.JFormattedTextField.AbstractFormatterFactory");
46 Clazz.makeConstructor (c$, 
47 function (factory, currentValue) {
48 this.construct (currentValue);
49 this.setFormatterFactory (factory);
50 }, "javax.swing.JFormattedTextField.AbstractFormatterFactory,~O");
51 Clazz.defineMethod (c$, "setFocusLostBehavior", 
52 function (behavior) {
53 if (behavior != 0 && behavior != 1 && behavior != 3 && behavior != 2) {
54 throw  new IllegalArgumentException ("setFocusLostBehavior must be one of: JFormattedTextField.COMMIT, JFormattedTextField.COMMIT_OR_REVERT, JFormattedTextField.PERSIST or JFormattedTextField.REVERT");
55 }this.focusLostBehavior = behavior;
56 }, "~N");
57 Clazz.defineMethod (c$, "getFocusLostBehavior", 
58 function () {
59 return this.focusLostBehavior;
60 });
61 Clazz.defineMethod (c$, "setFormatterFactory", 
62 function (tf) {
63 var oldFactory = this.factory = tf;
64 this.firePropertyChangeObject ("formatterFactory", oldFactory, tf);
65 this.setValue (this.getValue (), true, false);
66 }, "javax.swing.JFormattedTextField.AbstractFormatterFactory");
67 Clazz.defineMethod (c$, "getFormatterFactory", 
68 function () {
69 return this.factory;
70 });
71 Clazz.defineMethod (c$, "setFormatter", 
72 function (format) {
73 var oldFormat = this.format;
74 if (oldFormat != null) {
75 oldFormat.uninstall ();
76 }this.setEditValid (true);
77 this.format = format;
78 if (format != null) {
79 format.install (this);
80 }this.setEdited (false);
81 this.firePropertyChangeObject ("textFormatter", oldFormat, format);
82 }, "javax.swing.JFormattedTextField.AbstractFormatter");
83 Clazz.defineMethod (c$, "getFormatter", 
84 function () {
85 return this.format;
86 });
87 Clazz.defineMethod (c$, "setValue", 
88 function (value) {
89 if (value != null && this.getFormatterFactory () == null) {
90 this.setFormatterFactory (this.getDefaultFormatterFactory (value));
91 }this.setValue (value, true, true);
92 }, "~O");
93 Clazz.defineMethod (c$, "getValue", 
94 function () {
95 return this.value;
96 });
97 Clazz.defineMethod (c$, "commitEdit", 
98 function () {
99 var format = this.getFormatter ();
100 if (format != null) {
101 this.setValue (format.stringToValue (this.getText ()), false, true);
102 }});
103 Clazz.defineMethod (c$, "setEditValid", 
104  function (isValid) {
105 if (isValid != this.editValid) {
106 this.editValid = isValid;
107 this.firePropertyChangeObject ("editValid", Boolean.$valueOf (!isValid), Boolean.$valueOf (isValid));
108 }}, "~B");
109 Clazz.defineMethod (c$, "isEditValid", 
110 function () {
111 return this.editValid;
112 });
113 Clazz.defineMethod (c$, "invalidEdit", 
114 function () {
115 });
116 Clazz.defineMethod (c$, "processFocusEvent", 
117 function (e) {
118 Clazz.superCall (this, javax.swing.JFormattedTextField, "processFocusEvent", [e]);
119 if (e.isTemporary ()) {
120 return;
121 }if (this.isEdited () && e.getID () == 1005) {
122 if (this.focusLostHandler == null) {
123 this.focusLostHandler = Clazz.innerTypeInstance (javax.swing.JFormattedTextField.FocusLostHandler, this, null);
124 }this.focusLostHandler.run ();
125 } else if (!this.isEdited ()) {
126 this.setValue (this.getValue (), true, true);
127 }}, "java.awt.event.FocusEvent");
128 Clazz.defineMethod (c$, "getActions", 
129 function () {
130 return javax.swing.text.TextAction.augmentList (Clazz.superCall (this, javax.swing.JFormattedTextField, "getActions", []), javax.swing.JFormattedTextField.$defaultActions);
131 });
132 Clazz.overrideMethod (c$, "getUIClassID", 
133 function () {
134 return "FormattedTextFieldUI";
135 });
136 Clazz.defineMethod (c$, "setDocument", 
137 function (doc) {
138 if (this.documentListener != null && this.getDocument () != null) {
139 this.getDocument ().removeDocumentListener (this.documentListener);
140 }Clazz.superCall (this, javax.swing.JFormattedTextField, "setDocument", [doc]);
141 if (this.documentListener == null) {
142 this.documentListener = Clazz.innerTypeInstance (javax.swing.JFormattedTextField.DocumentHandler, this, null);
143 }doc.addDocumentListener (this.documentListener);
144 }, "javax.swing.text.Document");
145 Clazz.defineMethod (c$, "setFormatterActions", 
146  function (actions) {
147 if (actions == null) {
148 if (this.textFormatterActionMap != null) {
149 this.textFormatterActionMap.clear ();
150 }} else {
151 if (this.textFormatterActionMap == null) {
152 var map = this.getActionMap ();
153 this.textFormatterActionMap =  new javax.swing.ActionMap ();
154 while (map != null) {
155 var parent = map.getParent ();
156 if (Clazz.instanceOf (parent, javax.swing.plaf.UIResource) || parent == null) {
157 map.setParent (this.textFormatterActionMap);
158 this.textFormatterActionMap.setParent (parent);
159 break;
160 }map = parent;
161 }
162 }for (var counter = actions.length - 1; counter >= 0; counter--) {
163 var key = actions[counter].getValue ("Name");
164 if (key != null) {
165 this.textFormatterActionMap.put (key, actions[counter]);
166 }}
167 }}, "~A");
168 Clazz.defineMethod (c$, "setValue", 
169  function (value, createFormat, firePC) {
170 var oldValue = this.value;
171 this.value = value;
172 if (createFormat) {
173 var factory = this.getFormatterFactory ();
174 var atf;
175 if (factory != null) {
176 atf = factory.getFormatter (this);
177 } else {
178 atf = null;
179 }this.setFormatter (atf);
180 } else {
181 this.setEditValid (true);
182 }this.setEdited (false);
183 if (firePC) {
184 this.firePropertyChangeObject ("value", oldValue, value);
185 }}, "~O,~B,~B");
186 Clazz.defineMethod (c$, "setEdited", 
187  function (edited) {
188 this.edited = edited;
189 }, "~B");
190 Clazz.defineMethod (c$, "isEdited", 
191  function () {
192 return this.edited;
193 });
194 Clazz.defineMethod (c$, "getDefaultFormatterFactory", 
195  function (type) {
196 if (Clazz.instanceOf (type, java.text.DateFormat)) {
197 swingjs.JSToolkit.notImplemented (null);
198 return null;
199 }if (Clazz.instanceOf (type, java.text.NumberFormat)) {
200 return  new javax.swing.text.DefaultFormatterFactory ( new javax.swing.text.NumberFormatter (type));
201 }if (Clazz.instanceOf (type, java.text.Format)) {
202 return  new javax.swing.text.DefaultFormatterFactory ( new javax.swing.text.InternationalFormatter (type));
203 }if (Clazz.instanceOf (type, java.util.Date)) {
204 return  new javax.swing.text.DefaultFormatterFactory ( new javax.swing.text.DateFormatter ());
205 }if (Clazz.instanceOf (type, Number)) {
206 var displayFormatter =  new javax.swing.text.NumberFormatter ();
207 (displayFormatter).setValueClass (type.getClass ());
208 var editFormatter =  new javax.swing.text.NumberFormatter ( new java.text.DecimalFormat ("#.#"));
209 (editFormatter).setValueClass (type.getClass ());
210 return  new javax.swing.text.DefaultFormatterFactory (displayFormatter, displayFormatter, editFormatter);
211 }return  new javax.swing.text.DefaultFormatterFactory ( new javax.swing.text.DefaultFormatter ());
212 }, "~O");
213 c$.$JFormattedTextField$FocusLostHandler$ = function () {
214 Clazz.pu$h(self.c$);
215 c$ = Clazz.decorateAsClass (function () {
216 Clazz.prepareCallback (this, arguments);
217 Clazz.instantialize (this, arguments);
218 }, javax.swing.JFormattedTextField, "FocusLostHandler", null, Runnable);
219 Clazz.overrideMethod (c$, "run", 
220 function () {
221 var a = this.b$["javax.swing.JFormattedTextField"].getFocusLostBehavior ();
222 if (a == 0 || a == 1) {
223 try {
224 this.b$["javax.swing.JFormattedTextField"].commitEdit ();
225 this.b$["javax.swing.JFormattedTextField"].setValue (this.b$["javax.swing.JFormattedTextField"].getValue (), true, true);
226 } catch (pe) {
227 if (Clazz.exceptionOf (pe, java.text.ParseException)) {
228 if (a == 1) {
229 this.b$["javax.swing.JFormattedTextField"].setValue (this.b$["javax.swing.JFormattedTextField"].getValue (), true, true);
230 }} else {
231 throw pe;
232 }
233 }
234 } else if (a == 2) {
235 this.b$["javax.swing.JFormattedTextField"].setValue (this.b$["javax.swing.JFormattedTextField"].getValue (), true, true);
236 }});
237 c$ = Clazz.p0p ();
238 };
239 c$.$JFormattedTextField$DocumentHandler$ = 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.JFormattedTextField, "DocumentHandler", null, javax.swing.event.DocumentListener);
245 Clazz.overrideMethod (c$, "insertUpdate", 
246 function (a) {
247 this.b$["javax.swing.JFormattedTextField"].setEdited (true);
248 }, "javax.swing.event.DocumentEvent");
249 Clazz.overrideMethod (c$, "removeUpdate", 
250 function (a) {
251 this.b$["javax.swing.JFormattedTextField"].setEdited (true);
252 }, "javax.swing.event.DocumentEvent");
253 Clazz.overrideMethod (c$, "changedUpdate", 
254 function (a) {
255 }, "javax.swing.event.DocumentEvent");
256 c$ = Clazz.p0p ();
257 };
258 Clazz.pu$h(self.c$);
259 c$ = Clazz.declareType (javax.swing.JFormattedTextField, "AbstractFormatterFactory");
260 c$ = Clazz.p0p ();
261 Clazz.pu$h(self.c$);
262 c$ = Clazz.decorateAsClass (function () {
263 this.ftf = null;
264 Clazz.instantialize (this, arguments);
265 }, javax.swing.JFormattedTextField, "AbstractFormatter");
266 Clazz.defineMethod (c$, "install", 
267 function (a) {
268 if (this.ftf != null) {
269 this.uninstall ();
270 }this.ftf = a;
271 if (a != null) {
272 try {
273 a.setText (this.valueToString (a.getValue ()));
274 } catch (pe) {
275 if (Clazz.exceptionOf (pe, java.text.ParseException)) {
276 a.setText ("");
277 this.setEditValid (false);
278 } else {
279 throw pe;
280 }
281 }
282 this.installDocumentFilter (this.getDocumentFilter ());
283 a.setFormatterActions (this.getActions ());
284 }}, "javax.swing.JFormattedTextField");
285 Clazz.defineMethod (c$, "uninstall", 
286 function () {
287 if (this.ftf != null) {
288 this.installDocumentFilter (null);
289 this.ftf.setFormatterActions (null);
290 }});
291 Clazz.defineMethod (c$, "getFormattedTextField", 
292 function () {
293 return this.ftf;
294 });
295 Clazz.defineMethod (c$, "invalidEdit", 
296 function () {
297 var a = this.getFormattedTextField ();
298 if (a != null) {
299 a.invalidEdit ();
300 }});
301 Clazz.defineMethod (c$, "setEditValid", 
302 function (a) {
303 var b = this.getFormattedTextField ();
304 if (b != null) {
305 b.setEditValid (a);
306 }}, "~B");
307 Clazz.defineMethod (c$, "getActions", 
308 function () {
309 return null;
310 });
311 Clazz.defineMethod (c$, "getDocumentFilter", 
312 function () {
313 return null;
314 });
315 Clazz.defineMethod (c$, "getNavigationFilter", 
316 function () {
317 return null;
318 });
319 Clazz.defineMethod (c$, "clone", 
320 function () {
321 var a = Clazz.superCall (this, javax.swing.JFormattedTextField.AbstractFormatter, "clone", []);
322 a.ftf = null;
323 return a;
324 });
325 Clazz.defineMethod (c$, "installDocumentFilter", 
326  function (a) {
327 var b = this.getFormattedTextField ();
328 if (b != null) {
329 var c = b.getDocument ();
330 if (Clazz.instanceOf (c, javax.swing.text.JSMinimalAbstractDocument)) {
331 (c).setDocumentFilter (a);
332 }c.putProperty (javax.swing.text.DocumentFilter, null);
333 }}, "javax.swing.text.DocumentFilter");
334 c$ = Clazz.p0p ();
335 Clazz.pu$h(self.c$);
336 c$ = Clazz.declareType (javax.swing.JFormattedTextField, "CommitAction", javax.swing.JTextField.NotifyAction);
337 Clazz.defineMethod (c$, "actionPerformed", 
338 function (a) {
339 var b = this.getFocusedComponent ();
340 if (Clazz.instanceOf (b, javax.swing.JFormattedTextField)) {
341 try {
342 (b).commitEdit ();
343 } catch (pe) {
344 if (Clazz.exceptionOf (pe, java.text.ParseException)) {
345 (b).invalidEdit ();
346 return;
347 } else {
348 throw pe;
349 }
350 }
351 }Clazz.superCall (this, javax.swing.JFormattedTextField.CommitAction, "actionPerformed", [a]);
352 }, "java.awt.event.ActionEvent");
353 Clazz.defineMethod (c$, "isEnabled", 
354 function () {
355 var a = this.getFocusedComponent ();
356 if (Clazz.instanceOf (a, javax.swing.JFormattedTextField)) {
357 var b = a;
358 if (!b.isEdited ()) {
359 return false;
360 }return true;
361 }return Clazz.superCall (this, javax.swing.JFormattedTextField.CommitAction, "isEnabled", []);
362 });
363 c$ = Clazz.p0p ();
364 Clazz.pu$h(self.c$);
365 c$ = Clazz.declareType (javax.swing.JFormattedTextField, "CancelAction", javax.swing.text.TextAction);
366 Clazz.makeConstructor (c$, 
367 function () {
368 Clazz.superConstructor (this, javax.swing.JFormattedTextField.CancelAction, ["reset-field-edit"]);
369 });
370 Clazz.overrideMethod (c$, "actionPerformed", 
371 function (a) {
372 var b = this.getFocusedComponent ();
373 if (Clazz.instanceOf (b, javax.swing.JFormattedTextField)) {
374 var c = b;
375 c.setValue (c.getValue ());
376 }}, "java.awt.event.ActionEvent");
377 Clazz.defineMethod (c$, "isEnabled", 
378 function () {
379 var a = this.getFocusedComponent ();
380 if (Clazz.instanceOf (a, javax.swing.JFormattedTextField)) {
381 var b = a;
382 if (!b.isEdited ()) {
383 return false;
384 }return true;
385 }return Clazz.superCall (this, javax.swing.JFormattedTextField.CancelAction, "isEnabled", []);
386 });
387 c$ = Clazz.p0p ();
388 Clazz.defineStatics (c$,
389 "$$uiClassID", "FormattedTextFieldUI");
390 c$.$defaultActions = c$.prototype.$defaultActions =  Clazz.newArray (-1, [ new javax.swing.JFormattedTextField.CommitAction (),  new javax.swing.JFormattedTextField.CancelAction ()]);
391 Clazz.defineStatics (c$,
392 "COMMIT", 0,
393 "COMMIT_OR_REVERT", 1,
394 "REVERT", 2,
395 "PERSIST", 3);
396 });