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 () {
7 this.editValid = false;
8 this.focusLostBehavior = 0;
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$ ();
16 if (!Clazz.isClassDefined ("javax.swing.JFormattedTextField.DocumentHandler")) {
17 javax.swing.JFormattedTextField.$JFormattedTextField$DocumentHandler$ ();
19 Clazz.instantialize (this, arguments);
20 }, javax.swing, "JFormattedTextField", javax.swing.JTextField);
21 Clazz.makeConstructor (c$,
23 Clazz.superConstructor (this, javax.swing.JFormattedTextField);
24 this.enableEvents (4);
25 this.setFocusLostBehavior (1);
27 Clazz.makeConstructor (c$,
30 this.setValue (value);
32 Clazz.makeConstructor (c$,
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$,
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",
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;
57 Clazz.defineMethod (c$, "getFocusLostBehavior",
59 return this.focusLostBehavior;
61 Clazz.defineMethod (c$, "setFormatterFactory",
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",
71 Clazz.defineMethod (c$, "setFormatter",
73 var oldFormat = this.format;
74 if (oldFormat != null) {
75 oldFormat.uninstall ();
76 }this.setEditValid (true);
79 format.install (this);
80 }this.setEdited (false);
81 this.firePropertyChangeObject ("textFormatter", oldFormat, format);
82 }, "javax.swing.JFormattedTextField.AbstractFormatter");
83 Clazz.defineMethod (c$, "getFormatter",
87 Clazz.defineMethod (c$, "setValue",
89 if (value != null && this.getFormatterFactory () == null) {
90 this.setFormatterFactory (this.getDefaultFormatterFactory (value));
91 }this.setValue (value, true, true);
93 Clazz.defineMethod (c$, "getValue",
97 Clazz.defineMethod (c$, "commitEdit",
99 var format = this.getFormatter ();
100 if (format != null) {
101 this.setValue (format.stringToValue (this.getText ()), false, true);
103 Clazz.defineMethod (c$, "setEditValid",
105 if (isValid != this.editValid) {
106 this.editValid = isValid;
107 this.firePropertyChangeObject ("editValid", Boolean.$valueOf (!isValid), Boolean.$valueOf (isValid));
109 Clazz.defineMethod (c$, "isEditValid",
111 return this.editValid;
113 Clazz.defineMethod (c$, "invalidEdit",
116 Clazz.defineMethod (c$, "processFocusEvent",
118 Clazz.superCall (this, javax.swing.JFormattedTextField, "processFocusEvent", [e]);
119 if (e.isTemporary ()) {
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",
130 return javax.swing.text.TextAction.augmentList (Clazz.superCall (this, javax.swing.JFormattedTextField, "getActions", []), javax.swing.JFormattedTextField.$defaultActions);
132 Clazz.overrideMethod (c$, "getUIClassID",
134 return "FormattedTextFieldUI";
136 Clazz.defineMethod (c$, "setDocument",
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",
147 if (actions == null) {
148 if (this.textFormatterActionMap != null) {
149 this.textFormatterActionMap.clear ();
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);
162 }for (var counter = actions.length - 1; counter >= 0; counter--) {
163 var key = actions[counter].getValue ("Name");
165 this.textFormatterActionMap.put (key, actions[counter]);
168 Clazz.defineMethod (c$, "setValue",
169 function (value, createFormat, firePC) {
170 var oldValue = this.value;
173 var factory = this.getFormatterFactory ();
175 if (factory != null) {
176 atf = factory.getFormatter (this);
179 }this.setFormatter (atf);
181 this.setEditValid (true);
182 }this.setEdited (false);
184 this.firePropertyChangeObject ("value", oldValue, value);
186 Clazz.defineMethod (c$, "setEdited",
188 this.edited = edited;
190 Clazz.defineMethod (c$, "isEdited",
194 Clazz.defineMethod (c$, "getDefaultFormatterFactory",
196 if (Clazz.instanceOf (type, java.text.DateFormat)) {
197 swingjs.JSToolkit.notImplemented (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 ());
213 c$.$JFormattedTextField$FocusLostHandler$ = function () {
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",
221 var a = this.b$["javax.swing.JFormattedTextField"].getFocusLostBehavior ();
222 if (a == 0 || a == 1) {
224 this.b$["javax.swing.JFormattedTextField"].commitEdit ();
225 this.b$["javax.swing.JFormattedTextField"].setValue (this.b$["javax.swing.JFormattedTextField"].getValue (), true, true);
227 if (Clazz.exceptionOf (pe, java.text.ParseException)) {
229 this.b$["javax.swing.JFormattedTextField"].setValue (this.b$["javax.swing.JFormattedTextField"].getValue (), true, true);
235 this.b$["javax.swing.JFormattedTextField"].setValue (this.b$["javax.swing.JFormattedTextField"].getValue (), true, true);
239 c$.$JFormattedTextField$DocumentHandler$ = function () {
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",
247 this.b$["javax.swing.JFormattedTextField"].setEdited (true);
248 }, "javax.swing.event.DocumentEvent");
249 Clazz.overrideMethod (c$, "removeUpdate",
251 this.b$["javax.swing.JFormattedTextField"].setEdited (true);
252 }, "javax.swing.event.DocumentEvent");
253 Clazz.overrideMethod (c$, "changedUpdate",
255 }, "javax.swing.event.DocumentEvent");
259 c$ = Clazz.declareType (javax.swing.JFormattedTextField, "AbstractFormatterFactory");
262 c$ = Clazz.decorateAsClass (function () {
264 Clazz.instantialize (this, arguments);
265 }, javax.swing.JFormattedTextField, "AbstractFormatter");
266 Clazz.defineMethod (c$, "install",
268 if (this.ftf != null) {
273 a.setText (this.valueToString (a.getValue ()));
275 if (Clazz.exceptionOf (pe, java.text.ParseException)) {
277 this.setEditValid (false);
282 this.installDocumentFilter (this.getDocumentFilter ());
283 a.setFormatterActions (this.getActions ());
284 }}, "javax.swing.JFormattedTextField");
285 Clazz.defineMethod (c$, "uninstall",
287 if (this.ftf != null) {
288 this.installDocumentFilter (null);
289 this.ftf.setFormatterActions (null);
291 Clazz.defineMethod (c$, "getFormattedTextField",
295 Clazz.defineMethod (c$, "invalidEdit",
297 var a = this.getFormattedTextField ();
301 Clazz.defineMethod (c$, "setEditValid",
303 var b = this.getFormattedTextField ();
307 Clazz.defineMethod (c$, "getActions",
311 Clazz.defineMethod (c$, "getDocumentFilter",
315 Clazz.defineMethod (c$, "getNavigationFilter",
319 Clazz.defineMethod (c$, "clone",
321 var a = Clazz.superCall (this, javax.swing.JFormattedTextField.AbstractFormatter, "clone", []);
325 Clazz.defineMethod (c$, "installDocumentFilter",
327 var b = this.getFormattedTextField ();
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");
336 c$ = Clazz.declareType (javax.swing.JFormattedTextField, "CommitAction", javax.swing.JTextField.NotifyAction);
337 Clazz.defineMethod (c$, "actionPerformed",
339 var b = this.getFocusedComponent ();
340 if (Clazz.instanceOf (b, javax.swing.JFormattedTextField)) {
344 if (Clazz.exceptionOf (pe, java.text.ParseException)) {
351 }Clazz.superCall (this, javax.swing.JFormattedTextField.CommitAction, "actionPerformed", [a]);
352 }, "java.awt.event.ActionEvent");
353 Clazz.defineMethod (c$, "isEnabled",
355 var a = this.getFocusedComponent ();
356 if (Clazz.instanceOf (a, javax.swing.JFormattedTextField)) {
358 if (!b.isEdited ()) {
361 }return Clazz.superCall (this, javax.swing.JFormattedTextField.CommitAction, "isEnabled", []);
365 c$ = Clazz.declareType (javax.swing.JFormattedTextField, "CancelAction", javax.swing.text.TextAction);
366 Clazz.makeConstructor (c$,
368 Clazz.superConstructor (this, javax.swing.JFormattedTextField.CancelAction, ["reset-field-edit"]);
370 Clazz.overrideMethod (c$, "actionPerformed",
372 var b = this.getFocusedComponent ();
373 if (Clazz.instanceOf (b, javax.swing.JFormattedTextField)) {
375 c.setValue (c.getValue ());
376 }}, "java.awt.event.ActionEvent");
377 Clazz.defineMethod (c$, "isEnabled",
379 var a = this.getFocusedComponent ();
380 if (Clazz.instanceOf (a, javax.swing.JFormattedTextField)) {
382 if (!b.isEdited ()) {
385 }return Clazz.superCall (this, javax.swing.JFormattedTextField.CancelAction, "isEnabled", []);
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$,
393 "COMMIT_OR_REVERT", 1,