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