1 Clazz.declarePackage ("javax.swing.text");
\r
2 Clazz.load (["javax.swing.JFormattedTextField", "javax.swing.text.DocumentFilter", "$.NavigationFilter"], "javax.swing.text.DefaultFormatter", ["javax.swing.text.Position", "$.Utilities"], function () {
\r
3 c$ = Clazz.decorateAsClass (function () {
\r
4 this.allowsInvalid = false;
\r
5 this.overwriteMode = false;
\r
6 this.commitOnEdit = false;
\r
7 this.valueClass = null;
\r
8 this.navigationFilter = null;
\r
9 this.documentFilter = null;
\r
10 this.replaceHolder = null;
\r
11 if (!Clazz.isClassDefined ("javax.swing.text.DefaultFormatter.DefaultNavigationFilter")) {
\r
12 javax.swing.text.DefaultFormatter.$DefaultFormatter$DefaultNavigationFilter$ ();
\r
14 if (!Clazz.isClassDefined ("javax.swing.text.DefaultFormatter.DefaultDocumentFilter")) {
\r
15 javax.swing.text.DefaultFormatter.$DefaultFormatter$DefaultDocumentFilter$ ();
\r
17 Clazz.instantialize (this, arguments);
\r
18 }, javax.swing.text, "DefaultFormatter", javax.swing.JFormattedTextField.AbstractFormatter, Cloneable);
\r
19 Clazz.makeConstructor (c$,
\r
21 Clazz.superConstructor (this, javax.swing.text.DefaultFormatter, []);
\r
22 this.overwriteMode = true;
\r
23 this.allowsInvalid = true;
\r
25 Clazz.defineMethod (c$, "install",
\r
27 Clazz.superCall (this, javax.swing.text.DefaultFormatter, "install", [ftf]);
\r
28 this.positionCursorAtInitialLocation ();
\r
29 }, "javax.swing.JFormattedTextField");
\r
30 Clazz.defineMethod (c$, "setCommitsOnValidEdit",
\r
32 this.commitOnEdit = commit;
\r
34 Clazz.defineMethod (c$, "getCommitsOnValidEdit",
\r
36 return this.commitOnEdit;
\r
38 Clazz.defineMethod (c$, "setOverwriteMode",
\r
39 function (overwriteMode) {
\r
40 this.overwriteMode = overwriteMode;
\r
42 Clazz.defineMethod (c$, "getOverwriteMode",
\r
44 return this.overwriteMode;
\r
46 Clazz.defineMethod (c$, "setAllowsInvalid",
\r
47 function (allowsInvalid) {
\r
48 this.allowsInvalid = allowsInvalid;
\r
50 Clazz.defineMethod (c$, "getAllowsInvalid",
\r
52 return this.allowsInvalid;
\r
54 Clazz.defineMethod (c$, "setValueClass",
\r
55 function (valueClass) {
\r
56 this.valueClass = valueClass;
\r
58 Clazz.defineMethod (c$, "getValueClass",
\r
60 return this.valueClass;
\r
62 Clazz.overrideMethod (c$, "stringToValue",
\r
64 var vc = this.getValueClass ();
\r
65 var ftf = this.getFormattedTextField ();
\r
66 if (vc == null && ftf != null) {
\r
67 var value = ftf.getValue ();
\r
68 if (value != null) {
\r
69 vc = value.getClass ();
\r
72 Clazz.overrideMethod (c$, "valueToString",
\r
74 if (value == null) {
\r
76 }return value.toString ();
\r
78 Clazz.overrideMethod (c$, "getDocumentFilter",
\r
80 if (this.documentFilter == null) {
\r
81 this.documentFilter = Clazz.innerTypeInstance (javax.swing.text.DefaultFormatter.DefaultDocumentFilter, this, null);
\r
82 }return this.documentFilter;
\r
84 Clazz.overrideMethod (c$, "getNavigationFilter",
\r
86 if (this.navigationFilter == null) {
\r
87 this.navigationFilter = Clazz.innerTypeInstance (javax.swing.text.DefaultFormatter.DefaultNavigationFilter, this, null);
\r
88 }return this.navigationFilter;
\r
90 Clazz.defineMethod (c$, "clone",
\r
92 var formatter = Clazz.superCall (this, javax.swing.text.DefaultFormatter, "clone", []);
\r
93 formatter.navigationFilter = null;
\r
94 formatter.documentFilter = null;
\r
95 formatter.replaceHolder = null;
\r
98 Clazz.defineMethod (c$, "positionCursorAtInitialLocation",
\r
100 var ftf = this.getFormattedTextField ();
\r
102 ftf.setCaretPosition (this.getInitialVisualPosition ());
\r
104 Clazz.defineMethod (c$, "getInitialVisualPosition",
\r
106 return this.getNextNavigatableChar (0, 1);
\r
108 Clazz.defineMethod (c$, "isNavigatable",
\r
109 function (offset) {
\r
112 Clazz.defineMethod (c$, "isLegalInsertText",
\r
116 Clazz.defineMethod (c$, "getNextNavigatableChar",
\r
117 function (offset, direction) {
\r
118 var max = this.getFormattedTextField ().getDocument ().getLength ();
\r
119 while (offset >= 0 && offset < max) {
\r
120 if (this.isNavigatable (offset)) {
\r
122 }offset += direction;
\r
126 Clazz.defineMethod (c$, "getReplaceString",
\r
127 function (offset, deleteLength, replaceString) {
\r
128 var string = this.getFormattedTextField ().getText ();
\r
130 result = string.substring (0, offset);
\r
131 if (replaceString != null) {
\r
132 result += replaceString;
\r
133 }if (offset + deleteLength < string.length) {
\r
134 result += string.substring (offset + deleteLength);
\r
137 Clazz.defineMethod (c$, "isValidEdit",
\r
139 if (!this.getAllowsInvalid ()) {
\r
140 var newString = this.getReplaceString (rh.offset, rh.length, rh.text);
\r
142 rh.value = this.stringToValue (newString);
\r
145 if (Clazz.exceptionOf (pe, java.text.ParseException)) {
\r
152 }, "javax.swing.text.DefaultFormatter.ReplaceHolder");
\r
153 Clazz.defineMethod (c$, "commitEdit",
\r
155 var ftf = this.getFormattedTextField ();
\r
157 Clazz.defineMethod (c$, "updateValue",
\r
159 this.updateValue (null);
\r
161 Clazz.defineMethod (c$, "updateValue",
\r
164 if (value == null) {
\r
165 var string = this.getFormattedTextField ().getText ();
\r
166 value = this.stringToValue (string);
\r
167 }if (this.getCommitsOnValidEdit ()) {
\r
168 this.commitEdit ();
\r
169 }this.setEditValid (true);
\r
171 if (Clazz.exceptionOf (pe, java.text.ParseException)) {
\r
172 this.setEditValid (false);
\r
178 Clazz.defineMethod (c$, "getNextCursorPosition",
\r
179 function (offset, direction) {
\r
180 var newOffset = this.getNextNavigatableChar (offset, direction);
\r
181 var max = this.getFormattedTextField ().getDocument ().getLength ();
\r
182 if (!this.getAllowsInvalid ()) {
\r
183 if (direction == -1 && offset == newOffset) {
\r
184 newOffset = this.getNextNavigatableChar (newOffset, 1);
\r
185 if (newOffset >= max) {
\r
186 newOffset = offset;
\r
187 }} else if (direction == 1 && newOffset >= max) {
\r
188 newOffset = this.getNextNavigatableChar (max - 1, -1);
\r
189 if (newOffset < max) {
\r
191 }}}return newOffset;
\r
193 Clazz.defineMethod (c$, "repositionCursor",
\r
194 function (offset, direction) {
\r
195 this.getFormattedTextField ().getCaret ().setDot (this.getNextCursorPosition (offset, direction));
\r
197 Clazz.defineMethod (c$, "getNextVisualPositionFrom",
\r
198 function (text, pos, bias, direction, biasRet) {
\r
199 var value = text.getUI ().getNextVisualPositionFrom (text, pos, bias, direction, biasRet);
\r
202 }if (!this.getAllowsInvalid () && (direction == 3 || direction == 7)) {
\r
204 while (!this.isNavigatable (value) && value != last) {
\r
206 value = text.getUI ().getNextVisualPositionFrom (text, value, bias, direction, biasRet);
\r
208 var max = this.getFormattedTextField ().getDocument ().getLength ();
\r
209 if (last == value || value == max) {
\r
211 biasRet[0] = javax.swing.text.Position.Bias.Forward;
\r
212 value = this.getInitialVisualPosition ();
\r
213 }if (value >= max && max > 0) {
\r
214 biasRet[0] = javax.swing.text.Position.Bias.Forward;
\r
215 value = this.getNextNavigatableChar (max - 1, -1) + 1;
\r
217 }, "javax.swing.text.JTextComponent,~N,javax.swing.text.Position.Bias,~N,~A");
\r
218 Clazz.defineMethod (c$, "canReplace",
\r
220 return this.isValidEdit (rh);
\r
221 }, "javax.swing.text.DefaultFormatter.ReplaceHolder");
\r
222 Clazz.defineMethod (c$, "replace",
\r
223 function (fb, offset, length, text, attrs) {
\r
224 var rh = this.getReplaceHolder (fb, offset, length, text, attrs);
\r
226 }, "javax.swing.text.DocumentFilter.FilterBypass,~N,~N,~S,javax.swing.text.AttributeSet");
\r
227 Clazz.defineMethod (c$, "replace",
\r
231 if (rh.length > 0 && (rh.text == null || rh.text.length == 0) && (this.getFormattedTextField ().getSelectionStart () != rh.offset || rh.length > 1)) {
\r
233 }if (this.getOverwriteMode () && rh.text != null) {
\r
234 rh.length = Math.min (Math.max (rh.length, rh.text.length), rh.fb.getDocument ().getLength () - rh.offset);
\r
235 }if ((rh.text != null && !this.isLegalInsertText (rh.text)) || !this.canReplace (rh) || (rh.length == 0 && (rh.text == null || rh.text.length == 0))) {
\r
238 var cursor = rh.cursorPosition;
\r
239 rh.fb.replace (rh.offset, rh.length, rh.text, rh.attrs);
\r
240 if (cursor == -1) {
\r
241 cursor = rh.offset;
\r
242 if (direction == 1 && rh.text != null) {
\r
243 cursor = rh.offset + rh.text.length;
\r
244 }}this.updateValue (rh.value);
\r
245 this.repositionCursor (cursor, direction);
\r
248 this.invalidEdit ();
\r
250 }, "javax.swing.text.DefaultFormatter.ReplaceHolder");
\r
251 Clazz.defineMethod (c$, "setDot",
\r
252 function (fb, dot, bias) {
\r
253 fb.setDot (dot, bias);
\r
254 }, "javax.swing.text.NavigationFilter.FilterBypass,~N,javax.swing.text.Position.Bias");
\r
255 Clazz.defineMethod (c$, "moveDot",
\r
256 function (fb, dot, bias) {
\r
257 fb.moveDot (dot, bias);
\r
258 }, "javax.swing.text.NavigationFilter.FilterBypass,~N,javax.swing.text.Position.Bias");
\r
259 Clazz.defineMethod (c$, "getReplaceHolder",
\r
260 function (fb, offset, length, text, attrs) {
\r
261 if (this.replaceHolder == null) {
\r
262 this.replaceHolder = new javax.swing.text.DefaultFormatter.ReplaceHolder ();
\r
263 }this.replaceHolder.reset (fb, offset, length, text, attrs);
\r
264 return this.replaceHolder;
\r
265 }, "javax.swing.text.DocumentFilter.FilterBypass,~N,~N,~S,javax.swing.text.AttributeSet");
\r
266 c$.$DefaultFormatter$DefaultNavigationFilter$ = function () {
\r
267 Clazz.pu$h(self.c$);
\r
268 c$ = Clazz.decorateAsClass (function () {
\r
269 Clazz.prepareCallback (this, arguments);
\r
270 Clazz.instantialize (this, arguments);
\r
271 }, javax.swing.text.DefaultFormatter, "DefaultNavigationFilter", javax.swing.text.NavigationFilter);
\r
272 Clazz.overrideMethod (c$, "setDot",
\r
273 function (a, b, c) {
\r
274 var d = this.b$["javax.swing.text.DefaultFormatter"].getFormattedTextField ();
\r
275 if (d.composedTextExists ()) {
\r
278 this.b$["javax.swing.text.DefaultFormatter"].setDot (a, b, c);
\r
279 }}, "javax.swing.text.NavigationFilter.FilterBypass,~N,javax.swing.text.Position.Bias");
\r
280 Clazz.overrideMethod (c$, "moveDot",
\r
281 function (a, b, c) {
\r
282 var d = this.b$["javax.swing.text.DefaultFormatter"].getFormattedTextField ();
\r
283 if (d.composedTextExists ()) {
\r
286 this.b$["javax.swing.text.DefaultFormatter"].moveDot (a, b, c);
\r
287 }}, "javax.swing.text.NavigationFilter.FilterBypass,~N,javax.swing.text.Position.Bias");
\r
288 Clazz.overrideMethod (c$, "getNextVisualPositionFrom",
\r
289 function (a, b, c, d, e) {
\r
290 if (a.composedTextExists ()) {
\r
291 return a.getUI ().getNextVisualPositionFrom (a, b, c, d, e);
\r
293 return this.b$["javax.swing.text.DefaultFormatter"].getNextVisualPositionFrom (a, b, c, d, e);
\r
294 }}, "javax.swing.text.JTextComponent,~N,javax.swing.text.Position.Bias,~N,~A");
\r
297 c$.$DefaultFormatter$DefaultDocumentFilter$ = function () {
\r
298 Clazz.pu$h(self.c$);
\r
299 c$ = Clazz.decorateAsClass (function () {
\r
300 Clazz.prepareCallback (this, arguments);
\r
301 Clazz.instantialize (this, arguments);
\r
302 }, javax.swing.text.DefaultFormatter, "DefaultDocumentFilter", javax.swing.text.DocumentFilter);
\r
303 Clazz.overrideMethod (c$, "remove",
\r
304 function (a, b, c) {
\r
305 var d = this.b$["javax.swing.text.DefaultFormatter"].getFormattedTextField ();
\r
306 if (d.composedTextExists ()) {
\r
309 this.b$["javax.swing.text.DefaultFormatter"].replace (a, b, c, null, null);
\r
310 }}, "javax.swing.text.DocumentFilter.FilterBypass,~N,~N");
\r
311 Clazz.overrideMethod (c$, "insertString",
\r
312 function (a, b, c, d) {
\r
313 var e = this.b$["javax.swing.text.DefaultFormatter"].getFormattedTextField ();
\r
314 if (e.composedTextExists () || javax.swing.text.Utilities.isComposedTextAttributeDefined (d)) {
\r
315 a.insertString (b, c, d);
\r
317 this.b$["javax.swing.text.DefaultFormatter"].replace (a, b, 0, c, d);
\r
318 }}, "javax.swing.text.DocumentFilter.FilterBypass,~N,~S,javax.swing.text.AttributeSet");
\r
319 Clazz.overrideMethod (c$, "replace",
\r
320 function (a, b, c, d, e) {
\r
321 var f = this.b$["javax.swing.text.DefaultFormatter"].getFormattedTextField ();
\r
322 if (f.composedTextExists () || javax.swing.text.Utilities.isComposedTextAttributeDefined (e)) {
\r
323 a.replace (b, c, d, e);
\r
325 this.b$["javax.swing.text.DefaultFormatter"].replace (a, b, c, d, e);
\r
326 }}, "javax.swing.text.DocumentFilter.FilterBypass,~N,~N,~S,javax.swing.text.AttributeSet");
\r
329 Clazz.pu$h(self.c$);
\r
330 c$ = Clazz.decorateAsClass (function () {
\r
337 this.cursorPosition = 0;
\r
338 Clazz.instantialize (this, arguments);
\r
339 }, javax.swing.text.DefaultFormatter, "ReplaceHolder");
\r
340 Clazz.defineMethod (c$, "reset",
\r
341 function (a, b, c, d, e) {
\r
348 this.cursorPosition = -1;
\r
349 }, "javax.swing.text.DocumentFilter.FilterBypass,~N,~N,~S,javax.swing.text.AttributeSet");
\r