c300e3d4337f633197d2170c84d8d755fa8b36ed
[jalviewjs.git] / site / j2s / javax / swing / text / DefaultFormatter.js
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$ ();
13 }
14 if (!Clazz.isClassDefined ("javax.swing.text.DefaultFormatter.DefaultDocumentFilter")) {
15 javax.swing.text.DefaultFormatter.$DefaultFormatter$DefaultDocumentFilter$ ();
16 }
17 Clazz.instantialize (this, arguments);
18 }, javax.swing.text, "DefaultFormatter", javax.swing.JFormattedTextField.AbstractFormatter, Cloneable);
19 Clazz.makeConstructor (c$, 
20 function () {
21 Clazz.superConstructor (this, javax.swing.text.DefaultFormatter, []);
22 this.overwriteMode = true;
23 this.allowsInvalid = true;
24 });
25 Clazz.defineMethod (c$, "install", 
26 function (ftf) {
27 Clazz.superCall (this, javax.swing.text.DefaultFormatter, "install", [ftf]);
28 this.positionCursorAtInitialLocation ();
29 }, "javax.swing.JFormattedTextField");
30 Clazz.defineMethod (c$, "setCommitsOnValidEdit", 
31 function (commit) {
32 this.commitOnEdit = commit;
33 }, "~B");
34 Clazz.defineMethod (c$, "getCommitsOnValidEdit", 
35 function () {
36 return this.commitOnEdit;
37 });
38 Clazz.defineMethod (c$, "setOverwriteMode", 
39 function (overwriteMode) {
40 this.overwriteMode = overwriteMode;
41 }, "~B");
42 Clazz.defineMethod (c$, "getOverwriteMode", 
43 function () {
44 return this.overwriteMode;
45 });
46 Clazz.defineMethod (c$, "setAllowsInvalid", 
47 function (allowsInvalid) {
48 this.allowsInvalid = allowsInvalid;
49 }, "~B");
50 Clazz.defineMethod (c$, "getAllowsInvalid", 
51 function () {
52 return this.allowsInvalid;
53 });
54 Clazz.defineMethod (c$, "setValueClass", 
55 function (valueClass) {
56 this.valueClass = valueClass;
57 }, "Class");
58 Clazz.defineMethod (c$, "getValueClass", 
59 function () {
60 return this.valueClass;
61 });
62 Clazz.overrideMethod (c$, "stringToValue", 
63 function (string) {
64 var vc = this.getValueClass ();
65 var ftf = this.getFormattedTextField ();
66 if (vc == null && ftf != null) {
67 var value = ftf.getValue ();
68 if (value != null) {
69 vc = value.getClass ();
70 }}return string;
71 }, "~S");
72 Clazz.overrideMethod (c$, "valueToString", 
73 function (value) {
74 if (value == null) {
75 return "";
76 }return value.toString ();
77 }, "~O");
78 Clazz.overrideMethod (c$, "getDocumentFilter", 
79 function () {
80 if (this.documentFilter == null) {
81 this.documentFilter = Clazz.innerTypeInstance (javax.swing.text.DefaultFormatter.DefaultDocumentFilter, this, null);
82 }return this.documentFilter;
83 });
84 Clazz.overrideMethod (c$, "getNavigationFilter", 
85 function () {
86 if (this.navigationFilter == null) {
87 this.navigationFilter = Clazz.innerTypeInstance (javax.swing.text.DefaultFormatter.DefaultNavigationFilter, this, null);
88 }return this.navigationFilter;
89 });
90 Clazz.defineMethod (c$, "clone", 
91 function () {
92 var formatter = Clazz.superCall (this, javax.swing.text.DefaultFormatter, "clone", []);
93 formatter.navigationFilter = null;
94 formatter.documentFilter = null;
95 formatter.replaceHolder = null;
96 return formatter;
97 });
98 Clazz.defineMethod (c$, "positionCursorAtInitialLocation", 
99 function () {
100 var ftf = this.getFormattedTextField ();
101 if (ftf != null) {
102 ftf.setCaretPosition (this.getInitialVisualPosition ());
103 }});
104 Clazz.defineMethod (c$, "getInitialVisualPosition", 
105 function () {
106 return this.getNextNavigatableChar (0, 1);
107 });
108 Clazz.defineMethod (c$, "isNavigatable", 
109 function (offset) {
110 return true;
111 }, "~N");
112 Clazz.defineMethod (c$, "isLegalInsertText", 
113 function (text) {
114 return true;
115 }, "~S");
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)) {
121 return offset;
122 }offset += direction;
123 }
124 return offset;
125 }, "~N,~N");
126 Clazz.defineMethod (c$, "getReplaceString", 
127 function (offset, deleteLength, replaceString) {
128 var string = this.getFormattedTextField ().getText ();
129 var result;
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);
135 }return result;
136 }, "~N,~N,~S");
137 Clazz.defineMethod (c$, "isValidEdit", 
138 function (rh) {
139 if (!this.getAllowsInvalid ()) {
140 var newString = this.getReplaceString (rh.offset, rh.length, rh.text);
141 try {
142 rh.value = this.stringToValue (newString);
143 return true;
144 } catch (pe) {
145 if (Clazz.exceptionOf (pe, java.text.ParseException)) {
146 return false;
147 } else {
148 throw pe;
149 }
150 }
151 }return true;
152 }, "javax.swing.text.DefaultFormatter.ReplaceHolder");
153 Clazz.defineMethod (c$, "commitEdit", 
154 function () {
155 var ftf = this.getFormattedTextField ();
156 });
157 Clazz.defineMethod (c$, "updateValue", 
158 function () {
159 this.updateValue (null);
160 });
161 Clazz.defineMethod (c$, "updateValue", 
162 function (value) {
163 try {
164 if (value == null) {
165 var string = this.getFormattedTextField ().getText ();
166 value = this.stringToValue (string);
167 }if (this.getCommitsOnValidEdit ()) {
168 this.commitEdit ();
169 }this.setEditValid (true);
170 } catch (pe) {
171 if (Clazz.exceptionOf (pe, java.text.ParseException)) {
172 this.setEditValid (false);
173 } else {
174 throw pe;
175 }
176 }
177 }, "~O");
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) {
186 newOffset = offset;
187 }} else if (direction == 1 && newOffset >= max) {
188 newOffset = this.getNextNavigatableChar (max - 1, -1);
189 if (newOffset < max) {
190 newOffset++;
191 }}}return newOffset;
192 }, "~N,~N");
193 Clazz.defineMethod (c$, "repositionCursor", 
194 function (offset, direction) {
195 this.getFormattedTextField ().getCaret ().setDot (this.getNextCursorPosition (offset, direction));
196 }, "~N,~N");
197 Clazz.defineMethod (c$, "getNextVisualPositionFrom", 
198 function (text, pos, bias, direction, biasRet) {
199 var value = text.getUI ().getNextVisualPositionFrom (text, pos, bias, direction, biasRet);
200 if (value == -1) {
201 return -1;
202 }if (!this.getAllowsInvalid () && (direction == 3 || direction == 7)) {
203 var last = -1;
204 while (!this.isNavigatable (value) && value != last) {
205 last = value;
206 value = text.getUI ().getNextVisualPositionFrom (text, value, bias, direction, biasRet);
207 }
208 var max = this.getFormattedTextField ().getDocument ().getLength ();
209 if (last == value || value == max) {
210 if (value == 0) {
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;
216 }}}return value;
217 }, "javax.swing.text.JTextComponent,~N,javax.swing.text.Position.Bias,~N,~A");
218 Clazz.defineMethod (c$, "canReplace", 
219 function (rh) {
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);
225 this.replace (rh);
226 }, "javax.swing.text.DocumentFilter.FilterBypass,~N,~N,~S,javax.swing.text.AttributeSet");
227 Clazz.defineMethod (c$, "replace", 
228 function (rh) {
229 var valid = true;
230 var direction = 1;
231 if (rh.length > 0 && (rh.text == null || rh.text.length == 0) && (this.getFormattedTextField ().getSelectionStart () != rh.offset || rh.length > 1)) {
232 direction = -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))) {
236 valid = false;
237 }if (valid) {
238 var cursor = rh.cursorPosition;
239 rh.fb.replace (rh.offset, rh.length, rh.text, rh.attrs);
240 if (cursor == -1) {
241 cursor = rh.offset;
242 if (direction == 1 && rh.text != null) {
243 cursor = rh.offset + rh.text.length;
244 }}this.updateValue (rh.value);
245 this.repositionCursor (cursor, direction);
246 return true;
247 } else {
248 this.invalidEdit ();
249 }return false;
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 () {
267 Clazz.pu$h(self.c$);
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", 
273 function (a, b, c) {
274 var d = this.b$["javax.swing.text.DefaultFormatter"].getFormattedTextField ();
275 if (d.composedTextExists ()) {
276 a.setDot (b, c);
277 } else {
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", 
281 function (a, b, c) {
282 var d = this.b$["javax.swing.text.DefaultFormatter"].getFormattedTextField ();
283 if (d.composedTextExists ()) {
284 a.moveDot (b, c);
285 } else {
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);
292 } else {
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");
295 c$ = Clazz.p0p ();
296 };
297 c$.$DefaultFormatter$DefaultDocumentFilter$ = function () {
298 Clazz.pu$h(self.c$);
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", 
304 function (a, b, c) {
305 var d = this.b$["javax.swing.text.DefaultFormatter"].getFormattedTextField ();
306 if (d.composedTextExists ()) {
307 a.remove (b, c);
308 } else {
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);
316 } else {
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);
324 } else {
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");
327 c$ = Clazz.p0p ();
328 };
329 Clazz.pu$h(self.c$);
330 c$ = Clazz.decorateAsClass (function () {
331 this.fb = null;
332 this.offset = 0;
333 this.length = 0;
334 this.text = null;
335 this.attrs = null;
336 this.value = null;
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) {
342 this.fb = a;
343 this.offset = b;
344 this.length = c;
345 this.text = d;
346 this.attrs = e;
347 this.value = null;
348 this.cursorPosition = -1;
349 }, "javax.swing.text.DocumentFilter.FilterBypass,~N,~N,~S,javax.swing.text.AttributeSet");
350 c$ = Clazz.p0p ();
351 });