1 Clazz.declarePackage ("javax.swing.text");
2 Clazz.load (["javax.swing.AbstractAction", "javax.swing.text.DefaultFormatter"], "javax.swing.text.InternationalFormatter", ["java.lang.StringBuffer", "java.util.ArrayList", "$.BitSet", "java.text.AttributedCharacterIterator.Attribute", "java.text.ParseException"], function () {
3 c$ = Clazz.decorateAsClass (function () {
7 this.literalMask = null;
9 this.validMask = false;
11 this.ignoreDocumentMutate = false;
12 if (!Clazz.isClassDefined ("javax.swing.text.InternationalFormatter.IncrementAction")) {
13 javax.swing.text.InternationalFormatter.$InternationalFormatter$IncrementAction$ ();
15 Clazz.instantialize (this, arguments);
16 }, javax.swing.text, "InternationalFormatter", javax.swing.text.DefaultFormatter);
17 Clazz.makeConstructor (c$,
19 Clazz.superConstructor (this, javax.swing.text.InternationalFormatter, []);
20 this.setOverwriteMode (false);
22 Clazz.makeConstructor (c$,
25 this.setFormat (format);
26 }, "java.text.Format");
27 Clazz.defineMethod (c$, "setFormat",
30 }, "java.text.Format");
31 Clazz.defineMethod (c$, "getFormat",
35 Clazz.defineMethod (c$, "setMinimum",
37 if (this.getValueClass () == null && minimum != null) {
38 this.setValueClass (minimum.getClass ());
41 Clazz.defineMethod (c$, "getMinimum",
45 Clazz.defineMethod (c$, "setMaximum",
47 if (this.getValueClass () == null && max != null) {
48 this.setValueClass (max.getClass ());
51 Clazz.defineMethod (c$, "getMaximum",
55 Clazz.defineMethod (c$, "install",
57 Clazz.superCall (this, javax.swing.text.InternationalFormatter, "install", [ftf]);
58 this.updateMaskIfNecessary ();
59 this.positionCursorAtInitialLocation ();
60 }, "javax.swing.JFormattedTextField");
61 Clazz.overrideMethod (c$, "valueToString",
65 }var f = this.getFormat ();
67 return value.toString ();
68 }return f.format (value);
70 Clazz.defineMethod (c$, "stringToValue",
72 var value = this.stringToValueParse (text, this.getFormat ());
73 if (value != null && this.getValueClass () != null && !this.getValueClass ().isInstance (value)) {
74 value = Clazz.superCall (this, javax.swing.text.InternationalFormatter, "stringToValue", [value.toString ()]);
76 if (!this.isValidValue (value, true)) {
77 throw new java.text.ParseException ("Value not within min/max range", 0);
79 if (Clazz.exceptionOf (cce, ClassCastException)) {
80 throw new java.text.ParseException ("Class cast exception comparing values: " + cce, 0);
87 Clazz.defineMethod (c$, "getFields",
89 if (this.getAllowsInvalid ()) {
91 }var attrs = this.getAttributes (offset);
92 if (attrs != null && attrs.size () > 0) {
93 var al = new java.util.ArrayList ();
94 al.addAll (attrs.keySet ());
95 return al.toArray (javax.swing.text.InternationalFormatter.EMPTY_FIELD_ARRAY);
96 }return javax.swing.text.InternationalFormatter.EMPTY_FIELD_ARRAY;
98 Clazz.defineMethod (c$, "clone",
100 var formatter = Clazz.superCall (this, javax.swing.text.InternationalFormatter, "clone", []);
101 formatter.literalMask = null;
102 formatter.iterator = null;
103 formatter.validMask = false;
104 formatter.string = null;
107 Clazz.overrideMethod (c$, "getActions",
109 if (this.getSupportsIncrement ()) {
110 return Clazz.newArray (-1, [Clazz.innerTypeInstance (javax.swing.text.InternationalFormatter.IncrementAction, this, null, "increment", 1), Clazz.innerTypeInstance (javax.swing.text.InternationalFormatter.IncrementAction, this, null, "decrement", -1)]);
113 Clazz.defineMethod (c$, "stringToValueParse",
117 }return f.parseObject (text);
118 }, "~S,java.text.Format");
119 Clazz.defineMethod (c$, "isValidValue",
120 function (value, wantsCCE) {
121 var min = this.getMinimum ();
123 if (min != null && min.compareTo (value) > 0) {
126 if (Clazz.exceptionOf (cce, ClassCastException)) {
134 var max = this.getMaximum ();
136 if (max != null && max.compareTo (value) < 0) {
139 if (Clazz.exceptionOf (cce, ClassCastException)) {
149 Clazz.defineMethod (c$, "getAttributes",
151 if (this.isValidMask ()) {
152 var iterator = this.getIterator ();
153 if (index >= 0 && index <= iterator.getEndIndex ()) {
154 iterator.setIndex (index);
155 return iterator.getAttributes ();
158 Clazz.defineMethod (c$, "getAttributeStart",
160 if (this.isValidMask ()) {
161 var iterator = this.getIterator ();
163 while (iterator.current () != '\uffff') {
164 if (iterator.getAttribute (id) != null) {
165 return iterator.getIndex ();
169 }, "java.text.AttributedCharacterIterator.Attribute");
170 Clazz.defineMethod (c$, "getIterator",
172 return this.iterator;
174 Clazz.defineMethod (c$, "updateMaskIfNecessary",
176 if (!this.getAllowsInvalid () && (this.getFormat () != null)) {
177 if (!this.isValidMask ()) {
180 var newString = this.getFormattedTextField ().getText ();
181 if (!newString.equals (this.string)) {
184 Clazz.defineMethod (c$, "updateMask",
186 if (this.getFormat () != null) {
187 var doc = this.getFormattedTextField ().getDocument ();
188 this.validMask = false;
191 this.string = doc.getText (0, doc.getLength ());
193 if (Clazz.exceptionOf (ble, javax.swing.text.BadLocationException)) {
199 if (this.string != null) {
201 var value = this.stringToValue (this.string);
202 var iterator = this.getFormat ().formatToCharacterIterator (value);
203 this.updateMask (iterator);
205 if (Clazz.exceptionOf (e$$, java.text.ParseException)) {
209 } else if (Clazz.exceptionOf (e$$, IllegalArgumentException)) {
213 } else if (Clazz.exceptionOf (e$$, NullPointerException)) {
222 Clazz.defineMethod (c$, "getLiteralCountTo",
225 for (var counter = 0; counter < index; counter++) {
226 if (this.isLiteral (counter)) {
231 Clazz.defineMethod (c$, "isLiteral",
233 if (this.isValidMask () && index < this.string.length) {
234 return this.literalMask.get (index);
237 Clazz.defineMethod (c$, "getLiteral",
239 if (this.isValidMask () && this.string != null && index < this.string.length) {
240 return this.string.charAt (index);
241 }return String.fromCharCode (0);
243 Clazz.overrideMethod (c$, "isNavigatable",
245 return !this.isLiteral (offset);
247 Clazz.defineMethod (c$, "updateValue",
249 Clazz.superCall (this, javax.swing.text.InternationalFormatter, "updateValue", [value]);
250 this.updateMaskIfNecessary ();
252 Clazz.defineMethod (c$, "replace",
253 function (fb, offset, length, text, attrs) {
254 if (this.ignoreDocumentMutate) {
255 fb.replace (offset, length, text, attrs);
257 }Clazz.superCall (this, javax.swing.text.InternationalFormatter, "replace", [fb, offset, length, text, attrs]);
258 }, "javax.swing.text.DocumentFilter.FilterBypass,~N,~N,~S,javax.swing.text.AttributeSet");
259 Clazz.defineMethod (c$, "getNextNonliteralIndex",
260 function (index, direction) {
261 var max = this.getFormattedTextField ().getDocument ().getLength ();
262 while (index >= 0 && index < max) {
263 if (this.isLiteral (index)) {
268 return (direction == -1) ? 0 : max;
270 Clazz.defineMethod (c$, "canReplace",
272 if (!this.getAllowsInvalid ()) {
274 var tl = (text != null) ? text.length : 0;
275 if (tl == 0 && rh.length == 1 && this.getFormattedTextField ().getSelectionStart () != rh.offset) {
276 rh.offset = this.getNextNonliteralIndex (rh.offset, -1);
277 }if (this.getOverwriteMode ()) {
279 for (var counter = 0, textIndex = 0, max = Math.max (tl, rh.length); counter < max; counter++) {
280 if (this.isLiteral (rh.offset + counter)) {
281 if (replace != null) {
282 replace.append (this.getLiteral (rh.offset + counter));
283 }if (textIndex < tl && text.charAt (textIndex) == this.getLiteral (rh.offset + counter)) {
285 } else if (textIndex == 0) {
290 } else if (replace == null) {
291 replace = new StringBuffer (max);
292 replace.append (text.substring (0, textIndex));
293 replace.append (this.getLiteral (rh.offset + counter));
294 }} else if (textIndex < tl) {
295 if (replace != null) {
296 replace.append (text.charAt (textIndex));
299 if (replace == null) {
300 replace = new StringBuffer (max);
302 replace.append (text.substring (0, textIndex));
303 }}if (replace != null) {
304 replace.append (' ');
306 if (replace != null) {
307 rh.text = replace.toString ();
308 }} else if (tl > 0) {
309 rh.offset = this.getNextNonliteralIndex (rh.offset, 1);
311 rh.offset = this.getNextNonliteralIndex (rh.offset, -1);
312 }(rh).endOffset = rh.offset;
313 (rh).endTextLength = (rh.text != null) ? rh.text.length : 0;
315 (rh).endOffset = rh.offset;
316 (rh).endTextLength = (rh.text != null) ? rh.text.length : 0;
317 }var can = Clazz.superCall (this, javax.swing.text.InternationalFormatter, "canReplace", [rh]);
318 if (can && !this.getAllowsInvalid ()) {
319 (rh).resetFromValue (this);
321 }, "javax.swing.text.DefaultFormatter.ReplaceHolder");
322 Clazz.defineMethod (c$, "replace",
326 var literalCount = -1;
327 if (rh.length > 0 && (rh.text == null || rh.text.length == 0) && (this.getFormattedTextField ().getSelectionStart () != rh.offset || rh.length > 1)) {
329 }if (!this.getAllowsInvalid ()) {
330 if ((rh.text == null || rh.text.length == 0) && rh.length > 0) {
331 start = this.getFormattedTextField ().getSelectionStart ();
334 }literalCount = this.getLiteralCountTo (start);
335 }if (Clazz.superCall (this, javax.swing.text.InternationalFormatter, "replace", [rh])) {
337 var end = (rh).endOffset;
338 end += (rh).endTextLength;
339 this.repositionCursor (literalCount, end, direction);
341 start = (rh).endOffset;
342 if (direction == 1) {
343 start += (rh).endTextLength;
344 }this.repositionCursor (start, direction);
347 }, "javax.swing.text.DefaultFormatter.ReplaceHolder");
348 Clazz.defineMethod (c$, "repositionCursor",
349 function (startLiteralCount, end, direction) {
350 var endLiteralCount = this.getLiteralCountTo (end);
351 if (endLiteralCount != end) {
352 end -= startLiteralCount;
353 for (var counter = 0; counter < end; counter++) {
354 if (this.isLiteral (counter)) {
357 }this.repositionCursor (end, 1);
359 Clazz.defineMethod (c$, "getBufferedChar",
361 if (this.isValidMask ()) {
362 if (this.string != null && index < this.string.length) {
363 return this.string.charAt (index);
364 }}return String.fromCharCode (0);
366 Clazz.defineMethod (c$, "isValidMask",
368 return this.validMask;
370 Clazz.defineMethod (c$, "isLiteral",
371 function (attributes) {
372 return ((attributes == null) || attributes.size () == 0);
374 Clazz.defineMethod (c$, "updateMask",
375 function (iterator) {
376 if (iterator != null) {
377 this.validMask = true;
378 this.iterator = iterator;
379 if (this.literalMask == null) {
380 this.literalMask = new java.util.BitSet ();
382 for (var counter = this.literalMask.length () - 1; counter >= 0; counter--) {
383 this.literalMask.clear (counter);
386 while (iterator.current () != '\uffff') {
387 var attributes = iterator.getAttributes ();
388 var set = this.isLiteral (attributes);
389 var start = iterator.getIndex ();
390 var end = iterator.getRunLimit ();
391 while (start < end) {
393 this.literalMask.set (start);
395 this.literalMask.clear (start);
398 iterator.setIndex (start);
400 }}, "java.text.AttributedCharacterIterator");
401 Clazz.defineMethod (c$, "canIncrement",
402 function (field, cursorPosition) {
403 return (field != null);
405 Clazz.defineMethod (c$, "selectField",
406 function (f, count) {
407 var iterator = this.getIterator ();
408 if (iterator != null && (Clazz.instanceOf (f, java.text.AttributedCharacterIterator.Attribute))) {
411 while (iterator.current () != '\uffff') {
412 while (iterator.getAttribute (field) == null && iterator.next () != '\uffff') ;
413 if (iterator.current () != '\uffff') {
414 var limit = iterator.getRunLimit (field);
416 this.getFormattedTextField ().select (iterator.getIndex (), limit);
418 }iterator.setIndex (limit);
422 Clazz.defineMethod (c$, "getAdjustField",
423 function (start, attributes) {
425 }, "~N,java.util.Map");
426 Clazz.defineMethod (c$, "getFieldTypeCountTo",
427 function (f, start) {
428 var iterator = this.getIterator ();
430 if (iterator != null && (Clazz.instanceOf (f, java.text.AttributedCharacterIterator.Attribute))) {
434 while (iterator.getIndex () < start) {
435 while (iterator.getAttribute (field) == null && iterator.next () != '\uffff') ;
436 if (iterator.current () != '\uffff') {
437 iterator.setIndex (iterator.getRunLimit (field));
445 Clazz.defineMethod (c$, "adjustValue",
446 function (value, attributes, field, direction) {
448 }, "~O,java.util.Map,~O,~N");
449 Clazz.defineMethod (c$, "getSupportsIncrement",
453 Clazz.defineMethod (c$, "resetValue",
455 var doc = this.getFormattedTextField ().getDocument ();
456 var string = this.valueToString (value);
458 this.ignoreDocumentMutate = true;
459 doc.remove (0, doc.getLength ());
460 doc.insertString (0, string, null);
462 this.ignoreDocumentMutate = false;
464 this.updateValue (value);
466 Clazz.defineMethod (c$, "getReplaceHolder",
467 function (fb, offset, length, text, attrs) {
468 if (this.replaceHolder == null) {
469 this.replaceHolder = new javax.swing.text.InternationalFormatter.ExtendedReplaceHolder ();
470 }return Clazz.superCall (this, javax.swing.text.InternationalFormatter, "getReplaceHolder", [fb, offset, length, text, attrs]);
471 }, "javax.swing.text.DocumentFilter.FilterBypass,~N,~N,~S,javax.swing.text.AttributeSet");
472 c$.$InternationalFormatter$IncrementAction$ = function () {
474 c$ = Clazz.decorateAsClass (function () {
475 Clazz.prepareCallback (this, arguments);
477 Clazz.instantialize (this, arguments);
478 }, javax.swing.text.InternationalFormatter, "IncrementAction", javax.swing.AbstractAction);
479 Clazz.makeConstructor (c$,
481 Clazz.superConstructor (this, javax.swing.text.InternationalFormatter.IncrementAction, [a]);
484 Clazz.overrideMethod (c$, "actionPerformed",
486 if (this.b$["javax.swing.text.InternationalFormatter"].getFormattedTextField ().isEditable ()) {
487 if (this.b$["javax.swing.text.InternationalFormatter"].getAllowsInvalid ()) {
488 this.b$["javax.swing.text.InternationalFormatter"].updateMask ();
490 if (this.b$["javax.swing.text.InternationalFormatter"].isValidMask ()) {
491 var c = this.b$["javax.swing.text.InternationalFormatter"].getFormattedTextField ().getSelectionStart ();
493 var d = this.b$["javax.swing.text.InternationalFormatter"].getIterator ();
495 var e = d.getAttributes ();
496 var f = this.b$["javax.swing.text.InternationalFormatter"].getAdjustField (c, e);
497 if (this.b$["javax.swing.text.InternationalFormatter"].canIncrement (f, c)) {
499 var g = this.b$["javax.swing.text.InternationalFormatter"].stringToValue (this.b$["javax.swing.text.InternationalFormatter"].getFormattedTextField ().getText ());
500 var h = this.b$["javax.swing.text.InternationalFormatter"].getFieldTypeCountTo (f, c);
501 g = this.b$["javax.swing.text.InternationalFormatter"].adjustValue (g, e, f, this.direction);
502 if (g != null && this.b$["javax.swing.text.InternationalFormatter"].isValidValue (g, false)) {
503 this.b$["javax.swing.text.InternationalFormatter"].resetValue (g);
504 this.b$["javax.swing.text.InternationalFormatter"].updateMask ();
505 if (this.b$["javax.swing.text.InternationalFormatter"].isValidMask ()) {
506 this.b$["javax.swing.text.InternationalFormatter"].selectField (f, h);
509 if (Clazz.exceptionOf (e$$, java.text.ParseException)) {
513 } else if (Clazz.exceptionOf (e$$, javax.swing.text.BadLocationException)) {
522 this.b$["javax.swing.text.InternationalFormatter"].invalidEdit ();
523 }}}, "java.awt.event.ActionEvent");
527 c$ = Clazz.decorateAsClass (function () {
529 this.endTextLength = 0;
530 Clazz.instantialize (this, arguments);
531 }, javax.swing.text.InternationalFormatter, "ExtendedReplaceHolder", javax.swing.text.DefaultFormatter.ReplaceHolder);
532 Clazz.defineMethod (c$, "resetFromValue",
536 this.text = a.valueToString (this.value);
538 if (Clazz.exceptionOf (pe, java.text.ParseException)) {
544 this.length = this.fb.getDocument ().getLength ();
545 }, "javax.swing.text.InternationalFormatter");
547 c$.EMPTY_FIELD_ARRAY = c$.prototype.EMPTY_FIELD_ARRAY = new Array (0);