c7f025051c95535288c79d13de15664645b550c5
[jalviewjs.git] / site / swingjs / j2s / javax / swing / text / MaskFormatter.js
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 () {
4 this.mask = null;
5 this.maskChars = null;
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$ ();
13 }
14 if (!Clazz.isClassDefined ("javax.swing.text.MaskFormatter.LiteralCharacter")) {
15 javax.swing.text.MaskFormatter.$MaskFormatter$LiteralCharacter$ ();
16 }
17 if (!Clazz.isClassDefined ("javax.swing.text.MaskFormatter.DigitMaskCharacter")) {
18 javax.swing.text.MaskFormatter.$MaskFormatter$DigitMaskCharacter$ ();
19 }
20 if (!Clazz.isClassDefined ("javax.swing.text.MaskFormatter.UpperCaseCharacter")) {
21 javax.swing.text.MaskFormatter.$MaskFormatter$UpperCaseCharacter$ ();
22 }
23 if (!Clazz.isClassDefined ("javax.swing.text.MaskFormatter.LowerCaseCharacter")) {
24 javax.swing.text.MaskFormatter.$MaskFormatter$LowerCaseCharacter$ ();
25 }
26 if (!Clazz.isClassDefined ("javax.swing.text.MaskFormatter.AlphaNumericCharacter")) {
27 javax.swing.text.MaskFormatter.$MaskFormatter$AlphaNumericCharacter$ ();
28 }
29 if (!Clazz.isClassDefined ("javax.swing.text.MaskFormatter.CharCharacter")) {
30 javax.swing.text.MaskFormatter.$MaskFormatter$CharCharacter$ ();
31 }
32 if (!Clazz.isClassDefined ("javax.swing.text.MaskFormatter.HexCharacter")) {
33 javax.swing.text.MaskFormatter.$MaskFormatter$HexCharacter$ ();
34 }
35 Clazz.instantialize (this, arguments);
36 }, javax.swing.text, "MaskFormatter", javax.swing.text.DefaultFormatter);
37 Clazz.makeConstructor (c$, 
38 function () {
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 = ' ';
44 });
45 Clazz.makeConstructor (c$, 
46 function (mask) {
47 this.construct ();
48 this.setMask (mask);
49 }, "~S");
50 Clazz.defineMethod (c$, "setMask", 
51 function (mask) {
52 this.mask = mask;
53 this.updateInternalMask ();
54 }, "~S");
55 Clazz.defineMethod (c$, "getMask", 
56 function () {
57 return this.mask;
58 });
59 Clazz.defineMethod (c$, "setValidCharacters", 
60 function (validCharacters) {
61 this.validCharacters = validCharacters;
62 }, "~S");
63 Clazz.defineMethod (c$, "getValidCharacters", 
64 function () {
65 return this.validCharacters;
66 });
67 Clazz.defineMethod (c$, "setInvalidCharacters", 
68 function (invalidCharacters) {
69 this.invalidCharacters = invalidCharacters;
70 }, "~S");
71 Clazz.defineMethod (c$, "getInvalidCharacters", 
72 function () {
73 return this.invalidCharacters;
74 });
75 Clazz.defineMethod (c$, "setPlaceholder", 
76 function (placeholder) {
77 this.placeholderString = placeholder;
78 }, "~S");
79 Clazz.defineMethod (c$, "getPlaceholder", 
80 function () {
81 return this.placeholderString;
82 });
83 Clazz.defineMethod (c$, "setPlaceholderCharacter", 
84 function (placeholder) {
85 this.placeholder = placeholder;
86 }, "~S");
87 Clazz.defineMethod (c$, "getPlaceholderCharacter", 
88 function () {
89 return this.placeholder;
90 });
91 Clazz.defineMethod (c$, "setValueContainsLiteralCharacters", 
92 function (containsLiteralChars) {
93 this.containsLiteralChars = containsLiteralChars;
94 }, "~B");
95 Clazz.defineMethod (c$, "getValueContainsLiteralCharacters", 
96 function () {
97 return this.containsLiteralChars;
98 });
99 Clazz.defineMethod (c$, "stringToValue", 
100 function (value) {
101 return this.stringToValue (value, true);
102 }, "~S");
103 Clazz.overrideMethod (c$, "valueToString", 
104 function (value) {
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 ();
111 }, "~O");
112 Clazz.defineMethod (c$, "install", 
113 function (ftf) {
114 Clazz.superCall (this, javax.swing.text.MaskFormatter, "install", [ftf]);
115 if (ftf != null) {
116 var value = ftf.getValue ();
117 try {
118 this.stringToValue (this.valueToString (value));
119 } catch (pe) {
120 if (Clazz.exceptionOf (pe, java.text.ParseException)) {
121 this.setEditValid (false);
122 } else {
123 throw pe;
124 }
125 }
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);
135 }, "~S,~B");
136 Clazz.defineMethod (c$, "getInvalidOffset", 
137  function (string, completeMatch) {
138 var iLength = string.length;
139 if (iLength != this.getMaxLength ()) {
140 return iLength;
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))) {
144 return counter;
145 }}
146 return -1;
147 }, "~S,~B");
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);
152 }
153 }, "StringBuffer,~S,~A,~S,~A");
154 Clazz.defineMethod (c$, "updateInternalMask", 
155  function () {
156 var mask = this.getMask ();
157 var fixed =  new java.util.ArrayList ();
158 var temp = fixed;
159 if (mask != null) {
160 for (var counter = 0, maxCounter = mask.length; counter < maxCounter; counter++) {
161 var maskChar = mask.charAt (counter);
162 switch (maskChar) {
163 case '#':
164 temp.add (Clazz.innerTypeInstance (javax.swing.text.MaskFormatter.DigitMaskCharacter, this, null));
165 break;
166 case '\'':
167 if (++counter < maxCounter) {
168 maskChar = mask.charAt (counter);
169 temp.add (Clazz.innerTypeInstance (javax.swing.text.MaskFormatter.LiteralCharacter, this, null, maskChar));
170 }break;
171 case 'U':
172 temp.add (Clazz.innerTypeInstance (javax.swing.text.MaskFormatter.UpperCaseCharacter, this, null));
173 break;
174 case 'L':
175 temp.add (Clazz.innerTypeInstance (javax.swing.text.MaskFormatter.LowerCaseCharacter, this, null));
176 break;
177 case 'A':
178 temp.add (Clazz.innerTypeInstance (javax.swing.text.MaskFormatter.AlphaNumericCharacter, this, null));
179 break;
180 case '?':
181 temp.add (Clazz.innerTypeInstance (javax.swing.text.MaskFormatter.CharCharacter, this, null));
182 break;
183 case '*':
184 temp.add (Clazz.innerTypeInstance (javax.swing.text.MaskFormatter.MaskCharacter, this, null));
185 break;
186 case 'H':
187 temp.add (Clazz.innerTypeInstance (javax.swing.text.MaskFormatter.HexCharacter, this, null));
188 break;
189 default:
190 temp.add (Clazz.innerTypeInstance (javax.swing.text.MaskFormatter.LiteralCharacter, this, null, maskChar));
191 break;
192 }
193 }
194 }if (fixed.size () == 0) {
195 this.maskChars = javax.swing.text.MaskFormatter.EmptyMaskChars;
196 } else {
197 this.maskChars =  new Array (fixed.size ());
198 fixed.toArray (this.maskChars);
199 }});
200 Clazz.defineMethod (c$, "getMaskCharacter", 
201  function (index) {
202 if (index >= this.maskChars.length) {
203 return null;
204 }return this.maskChars[index];
205 }, "~N");
206 Clazz.defineMethod (c$, "isPlaceholder", 
207  function (index, aChar) {
208 return (this.getPlaceholderCharacter () == aChar);
209 }, "~N,~S");
210 Clazz.defineMethod (c$, "isValidCharacter", 
211  function (index, aChar) {
212 return this.getMaskCharacter (index).isValidCharacter (aChar);
213 }, "~N,~S");
214 Clazz.defineMethod (c$, "isLiteral", 
215  function (index) {
216 return this.getMaskCharacter (index).isLiteral ();
217 }, "~N");
218 Clazz.defineMethod (c$, "getMaxLength", 
219  function () {
220 return this.maskChars.length;
221 });
222 Clazz.defineMethod (c$, "getLiteral", 
223  function (index) {
224 return this.getMaskCharacter (index).getChar (String.fromCharCode (0));
225 }, "~N");
226 Clazz.defineMethod (c$, "getCharacter", 
227  function (index, aChar) {
228 return this.getMaskCharacter (index).getChar (aChar);
229 }, "~N,~S");
230 Clazz.defineMethod (c$, "stripLiteralChars", 
231  function (string) {
232 var sb = null;
233 var last = 0;
234 for (var counter = 0, max = string.length; counter < max; counter++) {
235 if (this.isLiteral (counter)) {
236 if (sb == null) {
237 sb =  new StringBuffer ();
238 if (counter > 0) {
239 sb.append (string.substring (0, counter));
240 }last = counter + 1;
241 } else if (last != counter) {
242 sb.append (string.substring (last, counter));
243 }last = counter + 1;
244 }}
245 if (sb == null) {
246 return string;
247 } else if (last != string.length) {
248 sb.append (string.substring (last));
249 }return sb.toString ();
250 }, "~S");
251 Clazz.overrideMethod (c$, "isNavigatable", 
252 function (offset) {
253 if (!this.getAllowsInvalid ()) {
254 return (offset < this.getMaxLength () && !this.isLiteral (offset));
255 }return true;
256 }, "~N");
257 Clazz.overrideMethod (c$, "isValidEdit", 
258 function (rh) {
259 if (!this.getAllowsInvalid ()) {
260 var newString = this.getReplaceString (rh.offset, rh.length, rh.text);
261 try {
262 rh.value = this.stringToValue (newString, false);
263 return true;
264 } catch (pe) {
265 if (Clazz.exceptionOf (pe, java.text.ParseException)) {
266 return false;
267 } else {
268 throw pe;
269 }
270 }
271 }return true;
272 }, "javax.swing.text.DefaultFormatter.ReplaceHolder");
273 Clazz.defineMethod (c$, "canReplace", 
274 function (rh) {
275 if (!this.getAllowsInvalid ()) {
276 var replace = null;
277 var text = rh.text;
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)) {
281 rh.offset--;
282 }
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 ();
290 if (textIndex > 0) {
291 replace.append (text.substring (0, textIndex));
292 }}}if (replace != null) {
293 replace.append (this.getCharacter (rh.offset + counter, aChar));
294 }textIndex++;
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;
308 }} else {
309 rh.offset++;
310 rh.length--;
311 counter--;
312 max--;
313 }} else if (textIndex >= tl) {
314 if (replace == null) {
315 replace =  new StringBuffer ();
316 if (text != null) {
317 replace.append (text);
318 }}replace.append (this.getPlaceholderCharacter ());
319 if (tl > 0 && rh.cursorPosition == -1) {
320 rh.cursorPosition = rh.offset + counter;
321 }} else {
322 return false;
323 }}
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 () {
333 Clazz.pu$h(self.c$);
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", 
339 function () {
340 return false;
341 });
342 Clazz.defineMethod (c$, "isValidCharacter", 
343 function (a) {
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) {
349 return false;
350 }b = this.b$["javax.swing.text.MaskFormatter"].getInvalidCharacters ();
351 if (b != null && b.indexOf (a) != -1) {
352 return false;
353 }return true;
354 }, "~S");
355 Clazz.defineMethod (c$, "getChar", 
356 function (a) {
357 return a;
358 }, "~S");
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]);
368 }c[0] = c[0] + 1;
369 }} else if (c[0] >= b.length) {
370 if (d != null && c[0] < d.length) {
371 a.append (d.charAt (c[0]));
372 } else {
373 a.append (this.b$["javax.swing.text.MaskFormatter"].getPlaceholderCharacter ());
374 }c[0] = c[0] + 1;
375 } else if (this.isValidCharacter (f)) {
376 a.append (this.getChar (f));
377 c[0] = c[0] + 1;
378 } else {
379 throw  new java.text.ParseException ("Invalid character: " + f, c[0]);
380 }}, "StringBuffer,~S,~A,~S");
381 c$ = Clazz.p0p ();
382 };
383 c$.$MaskFormatter$LiteralCharacter$ = function () {
384 Clazz.pu$h(self.c$);
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$, 
391 function (a) {
392 Clazz.superConstructor (this, javax.swing.text.MaskFormatter.LiteralCharacter, []);
393 this.fixedChar = a;
394 }, "~S");
395 Clazz.overrideMethod (c$, "isLiteral", 
396 function () {
397 return true;
398 });
399 Clazz.overrideMethod (c$, "getChar", 
400 function (a) {
401 return this.fixedChar;
402 }, "~S");
403 c$ = Clazz.p0p ();
404 };
405 c$.$MaskFormatter$DigitMaskCharacter$ = function () {
406 Clazz.pu$h(self.c$);
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", 
412 function (a) {
413 return (Character.isDigit (a) && Clazz.superCall (this, javax.swing.text.MaskFormatter.DigitMaskCharacter, "isValidCharacter", [a]));
414 }, "~S");
415 c$ = Clazz.p0p ();
416 };
417 c$.$MaskFormatter$UpperCaseCharacter$ = function () {
418 Clazz.pu$h(self.c$);
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", 
424 function (a) {
425 return (Character.isLetter (a) && Clazz.superCall (this, javax.swing.text.MaskFormatter.UpperCaseCharacter, "isValidCharacter", [a]));
426 }, "~S");
427 Clazz.overrideMethod (c$, "getChar", 
428 function (a) {
429 return Character.toUpperCase (a);
430 }, "~S");
431 c$ = Clazz.p0p ();
432 };
433 c$.$MaskFormatter$LowerCaseCharacter$ = function () {
434 Clazz.pu$h(self.c$);
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", 
440 function (a) {
441 return (Character.isLetter (a) && Clazz.superCall (this, javax.swing.text.MaskFormatter.LowerCaseCharacter, "isValidCharacter", [a]));
442 }, "~S");
443 Clazz.overrideMethod (c$, "getChar", 
444 function (a) {
445 return Character.toLowerCase (a);
446 }, "~S");
447 c$ = Clazz.p0p ();
448 };
449 c$.$MaskFormatter$AlphaNumericCharacter$ = function () {
450 Clazz.pu$h(self.c$);
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", 
456 function (a) {
457 return (Character.isLetterOrDigit (a) && Clazz.superCall (this, javax.swing.text.MaskFormatter.AlphaNumericCharacter, "isValidCharacter", [a]));
458 }, "~S");
459 c$ = Clazz.p0p ();
460 };
461 c$.$MaskFormatter$CharCharacter$ = function () {
462 Clazz.pu$h(self.c$);
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", 
468 function (a) {
469 return (Character.isLetter (a) && Clazz.superCall (this, javax.swing.text.MaskFormatter.CharCharacter, "isValidCharacter", [a]));
470 }, "~S");
471 c$ = Clazz.p0p ();
472 };
473 c$.$MaskFormatter$HexCharacter$ = function () {
474 Clazz.pu$h(self.c$);
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", 
480 function (a) {
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]));
482 }, "~S");
483 Clazz.overrideMethod (c$, "getChar", 
484 function (a) {
485 if (Character.isDigit (a)) {
486 return a;
487 }return Character.toUpperCase (a);
488 }, "~S");
489 c$ = Clazz.p0p ();
490 };
491 Clazz.defineStatics (c$,
492 "DIGIT_KEY", '#',
493 "LITERAL_KEY", '\'',
494 "UPPERCASE_KEY", 'U',
495 "LOWERCASE_KEY", 'L',
496 "ALPHA_NUMERIC_KEY", 'A',
497 "CHARACTER_KEY", '?',
498 "ANYTHING_KEY", '*',
499 "HEX_KEY", 'H');
500 c$.EmptyMaskChars = c$.prototype.EmptyMaskChars =  new Array (0);
501 });