1 Clazz.declarePackage ("javax.swing.text");
2 Clazz.load (["javax.swing.text.DefaultFormatter"], "javax.swing.text.MaskFormatter", ["java.lang.Character", "$.StringBuffer", "java.util.ArrayList", "java.text.ParseException"], function () {
3 c$ = Clazz.decorateAsClass (function () {
6 this.validCharacters = null;
7 this.invalidCharacters = null;
8 this.placeholderString = null;
9 this.placeholder = '\0';
10 this.containsLiteralChars = false;
11 if (!Clazz.isClassDefined ("javax.swing.text.MaskFormatter.MaskCharacter")) {
12 javax.swing.text.MaskFormatter.$MaskFormatter$MaskCharacter$ ();
14 if (!Clazz.isClassDefined ("javax.swing.text.MaskFormatter.LiteralCharacter")) {
15 javax.swing.text.MaskFormatter.$MaskFormatter$LiteralCharacter$ ();
17 if (!Clazz.isClassDefined ("javax.swing.text.MaskFormatter.DigitMaskCharacter")) {
18 javax.swing.text.MaskFormatter.$MaskFormatter$DigitMaskCharacter$ ();
20 if (!Clazz.isClassDefined ("javax.swing.text.MaskFormatter.UpperCaseCharacter")) {
21 javax.swing.text.MaskFormatter.$MaskFormatter$UpperCaseCharacter$ ();
23 if (!Clazz.isClassDefined ("javax.swing.text.MaskFormatter.LowerCaseCharacter")) {
24 javax.swing.text.MaskFormatter.$MaskFormatter$LowerCaseCharacter$ ();
26 if (!Clazz.isClassDefined ("javax.swing.text.MaskFormatter.AlphaNumericCharacter")) {
27 javax.swing.text.MaskFormatter.$MaskFormatter$AlphaNumericCharacter$ ();
29 if (!Clazz.isClassDefined ("javax.swing.text.MaskFormatter.CharCharacter")) {
30 javax.swing.text.MaskFormatter.$MaskFormatter$CharCharacter$ ();
32 if (!Clazz.isClassDefined ("javax.swing.text.MaskFormatter.HexCharacter")) {
33 javax.swing.text.MaskFormatter.$MaskFormatter$HexCharacter$ ();
35 Clazz.instantialize (this, arguments);
36 }, javax.swing.text, "MaskFormatter", javax.swing.text.DefaultFormatter);
37 Clazz.makeConstructor (c$,
39 Clazz.superConstructor (this, javax.swing.text.MaskFormatter, []);
40 this.setAllowsInvalid (false);
41 this.containsLiteralChars = true;
42 this.maskChars = javax.swing.text.MaskFormatter.EmptyMaskChars;
43 this.placeholder = ' ';
45 Clazz.makeConstructor (c$,
50 Clazz.defineMethod (c$, "setMask",
53 this.updateInternalMask ();
55 Clazz.defineMethod (c$, "getMask",
59 Clazz.defineMethod (c$, "setValidCharacters",
60 function (validCharacters) {
61 this.validCharacters = validCharacters;
63 Clazz.defineMethod (c$, "getValidCharacters",
65 return this.validCharacters;
67 Clazz.defineMethod (c$, "setInvalidCharacters",
68 function (invalidCharacters) {
69 this.invalidCharacters = invalidCharacters;
71 Clazz.defineMethod (c$, "getInvalidCharacters",
73 return this.invalidCharacters;
75 Clazz.defineMethod (c$, "setPlaceholder",
76 function (placeholder) {
77 this.placeholderString = placeholder;
79 Clazz.defineMethod (c$, "getPlaceholder",
81 return this.placeholderString;
83 Clazz.defineMethod (c$, "setPlaceholderCharacter",
84 function (placeholder) {
85 this.placeholder = placeholder;
87 Clazz.defineMethod (c$, "getPlaceholderCharacter",
89 return this.placeholder;
91 Clazz.defineMethod (c$, "setValueContainsLiteralCharacters",
92 function (containsLiteralChars) {
93 this.containsLiteralChars = containsLiteralChars;
95 Clazz.defineMethod (c$, "getValueContainsLiteralCharacters",
97 return this.containsLiteralChars;
99 Clazz.defineMethod (c$, "stringToValue",
101 return this.stringToValue (value, true);
103 Clazz.overrideMethod (c$, "valueToString",
105 var sValue = (value == null) ? "" : value.toString ();
106 var result = new StringBuffer ();
107 var placeholder = this.getPlaceholder ();
108 var valueCounter = Clazz.newIntArray (-1, [0]);
109 this.append (result, sValue, valueCounter, placeholder, this.maskChars);
110 return result.toString ();
112 Clazz.defineMethod (c$, "install",
114 Clazz.superCall (this, javax.swing.text.MaskFormatter, "install", [ftf]);
116 var value = ftf.getValue ();
118 this.stringToValue (this.valueToString (value));
120 if (Clazz.exceptionOf (pe, java.text.ParseException)) {
121 this.setEditValid (false);
126 }}, "javax.swing.JFormattedTextField");
127 Clazz.defineMethod (c$, "stringToValue",
128 function (value, completeMatch) {
129 var errorOffset = -1;
130 if ((errorOffset = this.getInvalidOffset (value, completeMatch)) == -1) {
131 if (!this.getValueContainsLiteralCharacters ()) {
132 value = this.stripLiteralChars (value);
133 }return Clazz.superCall (this, javax.swing.text.MaskFormatter, "stringToValue", [value]);
134 }throw new java.text.ParseException ("stringToValue passed invalid value", errorOffset);
136 Clazz.defineMethod (c$, "getInvalidOffset",
137 function (string, completeMatch) {
138 var iLength = string.length;
139 if (iLength != this.getMaxLength ()) {
141 }for (var counter = 0, max = string.length; counter < max; counter++) {
142 var aChar = string.charAt (counter);
143 if (!this.isValidCharacter (counter, aChar) && (completeMatch || !this.isPlaceholder (counter, aChar))) {
148 Clazz.defineMethod (c$, "append",
149 function (result, value, index, placeholder, mask) {
150 for (var counter = 0, maxCounter = mask.length; counter < maxCounter; counter++) {
151 mask[counter].append (result, value, index, placeholder);
153 }, "StringBuffer,~S,~A,~S,~A");
154 Clazz.defineMethod (c$, "updateInternalMask",
156 var mask = this.getMask ();
157 var fixed = new java.util.ArrayList ();
160 for (var counter = 0, maxCounter = mask.length; counter < maxCounter; counter++) {
161 var maskChar = mask.charAt (counter);
164 temp.add (Clazz.innerTypeInstance (javax.swing.text.MaskFormatter.DigitMaskCharacter, this, null));
167 if (++counter < maxCounter) {
168 maskChar = mask.charAt (counter);
169 temp.add (Clazz.innerTypeInstance (javax.swing.text.MaskFormatter.LiteralCharacter, this, null, maskChar));
172 temp.add (Clazz.innerTypeInstance (javax.swing.text.MaskFormatter.UpperCaseCharacter, this, null));
175 temp.add (Clazz.innerTypeInstance (javax.swing.text.MaskFormatter.LowerCaseCharacter, this, null));
178 temp.add (Clazz.innerTypeInstance (javax.swing.text.MaskFormatter.AlphaNumericCharacter, this, null));
181 temp.add (Clazz.innerTypeInstance (javax.swing.text.MaskFormatter.CharCharacter, this, null));
184 temp.add (Clazz.innerTypeInstance (javax.swing.text.MaskFormatter.MaskCharacter, this, null));
187 temp.add (Clazz.innerTypeInstance (javax.swing.text.MaskFormatter.HexCharacter, this, null));
190 temp.add (Clazz.innerTypeInstance (javax.swing.text.MaskFormatter.LiteralCharacter, this, null, maskChar));
194 }if (fixed.size () == 0) {
195 this.maskChars = javax.swing.text.MaskFormatter.EmptyMaskChars;
197 this.maskChars = new Array (fixed.size ());
198 fixed.toArray (this.maskChars);
200 Clazz.defineMethod (c$, "getMaskCharacter",
202 if (index >= this.maskChars.length) {
204 }return this.maskChars[index];
206 Clazz.defineMethod (c$, "isPlaceholder",
207 function (index, aChar) {
208 return (this.getPlaceholderCharacter () == aChar);
210 Clazz.defineMethod (c$, "isValidCharacter",
211 function (index, aChar) {
212 return this.getMaskCharacter (index).isValidCharacter (aChar);
214 Clazz.defineMethod (c$, "isLiteral",
216 return this.getMaskCharacter (index).isLiteral ();
218 Clazz.defineMethod (c$, "getMaxLength",
220 return this.maskChars.length;
222 Clazz.defineMethod (c$, "getLiteral",
224 return this.getMaskCharacter (index).getChar (String.fromCharCode (0));
226 Clazz.defineMethod (c$, "getCharacter",
227 function (index, aChar) {
228 return this.getMaskCharacter (index).getChar (aChar);
230 Clazz.defineMethod (c$, "stripLiteralChars",
234 for (var counter = 0, max = string.length; counter < max; counter++) {
235 if (this.isLiteral (counter)) {
237 sb = new StringBuffer ();
239 sb.append (string.substring (0, counter));
241 } else if (last != counter) {
242 sb.append (string.substring (last, counter));
247 } else if (last != string.length) {
248 sb.append (string.substring (last));
249 }return sb.toString ();
251 Clazz.overrideMethod (c$, "isNavigatable",
253 if (!this.getAllowsInvalid ()) {
254 return (offset < this.getMaxLength () && !this.isLiteral (offset));
257 Clazz.overrideMethod (c$, "isValidEdit",
259 if (!this.getAllowsInvalid ()) {
260 var newString = this.getReplaceString (rh.offset, rh.length, rh.text);
262 rh.value = this.stringToValue (newString, false);
265 if (Clazz.exceptionOf (pe, java.text.ParseException)) {
272 }, "javax.swing.text.DefaultFormatter.ReplaceHolder");
273 Clazz.defineMethod (c$, "canReplace",
275 if (!this.getAllowsInvalid ()) {
278 var tl = (text != null) ? text.length : 0;
279 if (tl == 0 && rh.length == 1 && this.getFormattedTextField ().getSelectionStart () != rh.offset) {
280 while (rh.offset > 0 && this.isLiteral (rh.offset)) {
283 }var max = Math.min (this.getMaxLength () - rh.offset, Math.max (tl, rh.length));
284 for (var counter = 0, textIndex = 0; counter < max; counter++) {
285 if (textIndex < tl && this.isValidCharacter (rh.offset + counter, text.charAt (textIndex))) {
286 var aChar = text.charAt (textIndex);
287 if (aChar != this.getCharacter (rh.offset + counter, aChar)) {
288 if (replace == null) {
289 replace = new StringBuffer ();
291 replace.append (text.substring (0, textIndex));
292 }}}if (replace != null) {
293 replace.append (this.getCharacter (rh.offset + counter, aChar));
295 } else if (this.isLiteral (rh.offset + counter)) {
296 if (replace != null) {
297 replace.append (this.getLiteral (rh.offset + counter));
298 if (textIndex < tl) {
299 max = Math.min (max + 1, this.getMaxLength () - rh.offset);
300 }} else if (textIndex > 0) {
301 replace = new StringBuffer (max);
302 replace.append (text.substring (0, textIndex));
303 replace.append (this.getLiteral (rh.offset + counter));
304 if (textIndex < tl) {
305 max = Math.min (max + 1, this.getMaxLength () - rh.offset);
306 } else if (rh.cursorPosition == -1) {
307 rh.cursorPosition = rh.offset + counter;
313 }} else if (textIndex >= tl) {
314 if (replace == null) {
315 replace = new StringBuffer ();
317 replace.append (text);
318 }}replace.append (this.getPlaceholderCharacter ());
319 if (tl > 0 && rh.cursorPosition == -1) {
320 rh.cursorPosition = rh.offset + counter;
324 if (replace != null) {
325 rh.text = replace.toString ();
326 } else if (text != null && rh.offset + tl > this.getMaxLength ()) {
327 rh.text = text.substring (0, this.getMaxLength () - rh.offset);
328 }if (this.getOverwriteMode () && rh.text != null) {
329 rh.length = rh.text.length;
330 }}return Clazz.superCall (this, javax.swing.text.MaskFormatter, "canReplace", [rh]);
331 }, "javax.swing.text.DefaultFormatter.ReplaceHolder");
332 c$.$MaskFormatter$MaskCharacter$ = function () {
334 c$ = Clazz.decorateAsClass (function () {
335 Clazz.prepareCallback (this, arguments);
336 Clazz.instantialize (this, arguments);
337 }, javax.swing.text.MaskFormatter, "MaskCharacter");
338 Clazz.defineMethod (c$, "isLiteral",
342 Clazz.defineMethod (c$, "isValidCharacter",
344 if (this.isLiteral ()) {
345 return (this.getChar (a) == a);
346 }a = this.getChar (a);
347 var b = this.b$["javax.swing.text.MaskFormatter"].getValidCharacters ();
348 if (b != null && b.indexOf (a) == -1) {
350 }b = this.b$["javax.swing.text.MaskFormatter"].getInvalidCharacters ();
351 if (b != null && b.indexOf (a) != -1) {
355 Clazz.defineMethod (c$, "getChar",
359 Clazz.defineMethod (c$, "append",
360 function (a, b, c, d) {
361 var e = c[0] < b.length;
362 var f = e ? b.charAt (c[0]) : 0;
363 if (this.isLiteral ()) {
364 a.append (this.getChar (f));
365 if (this.b$["javax.swing.text.MaskFormatter"].getValueContainsLiteralCharacters ()) {
366 if (e && f != this.getChar (f)) {
367 throw new java.text.ParseException ("Invalid character: " + f, c[0]);
369 }} else if (c[0] >= b.length) {
370 if (d != null && c[0] < d.length) {
371 a.append (d.charAt (c[0]));
373 a.append (this.b$["javax.swing.text.MaskFormatter"].getPlaceholderCharacter ());
375 } else if (this.isValidCharacter (f)) {
376 a.append (this.getChar (f));
379 throw new java.text.ParseException ("Invalid character: " + f, c[0]);
380 }}, "StringBuffer,~S,~A,~S");
383 c$.$MaskFormatter$LiteralCharacter$ = function () {
385 c$ = Clazz.decorateAsClass (function () {
386 Clazz.prepareCallback (this, arguments);
387 this.fixedChar = '\0';
388 Clazz.instantialize (this, arguments);
389 }, javax.swing.text.MaskFormatter, "LiteralCharacter", javax.swing.text.MaskFormatter.MaskCharacter, null, Clazz.innerTypeInstance (javax.swing.text.MaskFormatter.MaskCharacter, this, null, Clazz.inheritArgs));
390 Clazz.makeConstructor (c$,
392 Clazz.superConstructor (this, javax.swing.text.MaskFormatter.LiteralCharacter, []);
395 Clazz.overrideMethod (c$, "isLiteral",
399 Clazz.overrideMethod (c$, "getChar",
401 return this.fixedChar;
405 c$.$MaskFormatter$DigitMaskCharacter$ = function () {
407 c$ = Clazz.decorateAsClass (function () {
408 Clazz.prepareCallback (this, arguments);
409 Clazz.instantialize (this, arguments);
410 }, javax.swing.text.MaskFormatter, "DigitMaskCharacter", javax.swing.text.MaskFormatter.MaskCharacter, null, Clazz.innerTypeInstance (javax.swing.text.MaskFormatter.MaskCharacter, this, null, Clazz.inheritArgs));
411 Clazz.defineMethod (c$, "isValidCharacter",
413 return (Character.isDigit (a) && Clazz.superCall (this, javax.swing.text.MaskFormatter.DigitMaskCharacter, "isValidCharacter", [a]));
417 c$.$MaskFormatter$UpperCaseCharacter$ = function () {
419 c$ = Clazz.decorateAsClass (function () {
420 Clazz.prepareCallback (this, arguments);
421 Clazz.instantialize (this, arguments);
422 }, javax.swing.text.MaskFormatter, "UpperCaseCharacter", javax.swing.text.MaskFormatter.MaskCharacter, null, Clazz.innerTypeInstance (javax.swing.text.MaskFormatter.MaskCharacter, this, null, Clazz.inheritArgs));
423 Clazz.defineMethod (c$, "isValidCharacter",
425 return (Character.isLetter (a) && Clazz.superCall (this, javax.swing.text.MaskFormatter.UpperCaseCharacter, "isValidCharacter", [a]));
427 Clazz.overrideMethod (c$, "getChar",
429 return Character.toUpperCase (a);
433 c$.$MaskFormatter$LowerCaseCharacter$ = function () {
435 c$ = Clazz.decorateAsClass (function () {
436 Clazz.prepareCallback (this, arguments);
437 Clazz.instantialize (this, arguments);
438 }, javax.swing.text.MaskFormatter, "LowerCaseCharacter", javax.swing.text.MaskFormatter.MaskCharacter, null, Clazz.innerTypeInstance (javax.swing.text.MaskFormatter.MaskCharacter, this, null, Clazz.inheritArgs));
439 Clazz.defineMethod (c$, "isValidCharacter",
441 return (Character.isLetter (a) && Clazz.superCall (this, javax.swing.text.MaskFormatter.LowerCaseCharacter, "isValidCharacter", [a]));
443 Clazz.overrideMethod (c$, "getChar",
445 return Character.toLowerCase (a);
449 c$.$MaskFormatter$AlphaNumericCharacter$ = function () {
451 c$ = Clazz.decorateAsClass (function () {
452 Clazz.prepareCallback (this, arguments);
453 Clazz.instantialize (this, arguments);
454 }, javax.swing.text.MaskFormatter, "AlphaNumericCharacter", javax.swing.text.MaskFormatter.MaskCharacter, null, Clazz.innerTypeInstance (javax.swing.text.MaskFormatter.MaskCharacter, this, null, Clazz.inheritArgs));
455 Clazz.defineMethod (c$, "isValidCharacter",
457 return (Character.isLetterOrDigit (a) && Clazz.superCall (this, javax.swing.text.MaskFormatter.AlphaNumericCharacter, "isValidCharacter", [a]));
461 c$.$MaskFormatter$CharCharacter$ = function () {
463 c$ = Clazz.decorateAsClass (function () {
464 Clazz.prepareCallback (this, arguments);
465 Clazz.instantialize (this, arguments);
466 }, javax.swing.text.MaskFormatter, "CharCharacter", javax.swing.text.MaskFormatter.MaskCharacter, null, Clazz.innerTypeInstance (javax.swing.text.MaskFormatter.MaskCharacter, this, null, Clazz.inheritArgs));
467 Clazz.defineMethod (c$, "isValidCharacter",
469 return (Character.isLetter (a) && Clazz.superCall (this, javax.swing.text.MaskFormatter.CharCharacter, "isValidCharacter", [a]));
473 c$.$MaskFormatter$HexCharacter$ = function () {
475 c$ = Clazz.decorateAsClass (function () {
476 Clazz.prepareCallback (this, arguments);
477 Clazz.instantialize (this, arguments);
478 }, javax.swing.text.MaskFormatter, "HexCharacter", javax.swing.text.MaskFormatter.MaskCharacter, null, Clazz.innerTypeInstance (javax.swing.text.MaskFormatter.MaskCharacter, this, null, Clazz.inheritArgs));
479 Clazz.defineMethod (c$, "isValidCharacter",
481 return ((a == '0' || a == '1' || a == '2' || a == '3' || a == '4' || a == '5' || a == '6' || a == '7' || a == '8' || a == '9' || a == 'a' || a == 'A' || a == 'b' || a == 'B' || a == 'c' || a == 'C' || a == 'd' || a == 'D' || a == 'e' || a == 'E' || a == 'f' || a == 'F') && Clazz.superCall (this, javax.swing.text.MaskFormatter.HexCharacter, "isValidCharacter", [a]));
483 Clazz.overrideMethod (c$, "getChar",
485 if (Character.isDigit (a)) {
487 }return Character.toUpperCase (a);
491 Clazz.defineStatics (c$,
494 "UPPERCASE_KEY", 'U',
495 "LOWERCASE_KEY", 'L',
496 "ALPHA_NUMERIC_KEY", 'A',
497 "CHARACTER_KEY", '?',
500 c$.EmptyMaskChars = c$.prototype.EmptyMaskChars = new Array (0);