1 Clazz.declarePackage ("javax.swing.text");
2 Clazz.load (["javax.swing.text.InternationalFormatter", "java.text.NumberFormat"], "javax.swing.text.NumberFormatter", ["java.lang.Byte", "$.Character", "$.Double", "$.Float", "$.Long", "$.Number", "$.Short", "$.StringBuffer", "java.text.DecimalFormat"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.specialChars = null;
5 Clazz.instantialize (this, arguments);
6 }, javax.swing.text, "NumberFormatter", javax.swing.text.InternationalFormatter);
7 Clazz.makeConstructor (c$,
9 Clazz.superConstructor (this, javax.swing.text.NumberFormatter, []);
10 this.setN (java.text.NumberFormat.getNumberInstance ());
12 Clazz.makeConstructor (c$,
14 Clazz.superConstructor (this, javax.swing.text.NumberFormatter, []);
16 }, "java.text.NumberFormat");
17 Clazz.defineMethod (c$, "setN",
19 this.setFormat (format);
20 this.setAllowsInvalid (true);
21 this.setCommitsOnValidEdit (false);
22 this.setOverwriteMode (false);
23 }, "java.text.NumberFormat");
24 Clazz.defineMethod (c$, "setFormat",
26 Clazz.superCall (this, javax.swing.text.NumberFormatter, "setFormat", [format]);
27 var dfs = this.getDecimalFormatSymbols ();
29 var sb = new StringBuffer ();
30 sb.append (dfs.getCurrencySymbol ());
31 sb.append (dfs.getDecimalSeparator ());
32 sb.append (dfs.getGroupingSeparator ());
33 sb.append (dfs.getInfinity ());
34 sb.append (dfs.getInternationalCurrencySymbol ());
35 sb.append (dfs.getMinusSign ());
36 sb.append (dfs.getMonetaryDecimalSeparator ());
37 sb.append (dfs.getNaN ());
38 sb.append (dfs.getPercent ());
40 this.specialChars = sb.toString ();
42 this.specialChars = "";
43 }}, "java.text.Format");
44 Clazz.overrideMethod (c$, "stringToValueParse",
48 }var value = f.parseObject (text);
49 return this.convertValueToValueClass (value, this.getValueClass ());
50 }, "~S,java.text.Format");
51 Clazz.defineMethod (c$, "convertValueToValueClass",
52 function (value, valueClass) {
53 if (valueClass != null && (Clazz.instanceOf (value, Number))) {
54 if (valueClass === Integer) {
55 return new Integer ((value).intValue ());
56 } else if (valueClass === Long) {
57 return new Long ((value).longValue ());
58 } else if (valueClass === Float) {
59 return new Float ((value).floatValue ());
60 } else if (valueClass === Double) {
61 return new Double ((value).doubleValue ());
62 } else if (valueClass === Byte) {
63 return new Byte ((value).byteValue ());
64 } else if (valueClass === Short) {
65 return new Short ((value).shortValue ());
68 Clazz.defineMethod (c$, "getPositiveSign",
72 Clazz.defineMethod (c$, "getMinusSign",
74 var dfs = this.getDecimalFormatSymbols ();
76 return dfs.getMinusSign ();
79 Clazz.defineMethod (c$, "getDecimalSeparator",
81 var dfs = this.getDecimalFormatSymbols ();
83 return dfs.getDecimalSeparator ();
86 Clazz.defineMethod (c$, "getDecimalFormatSymbols",
88 var f = this.getFormat ();
89 if (Clazz.instanceOf (f, java.text.DecimalFormat)) {
90 return (f).getDecimalFormatSymbols ();
93 Clazz.overrideMethod (c$, "isLegalInsertText",
95 if (this.getAllowsInvalid ()) {
97 }for (var counter = text.length - 1; counter >= 0; counter--) {
98 var aChar = text.charAt (counter);
99 if (!Character.isDigit (aChar) && this.specialChars.indexOf (aChar) == -1) {
104 Clazz.defineMethod (c$, "isLiteral",
106 if (!Clazz.superCall (this, javax.swing.text.NumberFormatter, "isLiteral", [attrs])) {
109 }var size = attrs.size ();
110 if (attrs.get (java.text.NumberFormat.Field.GROUPING_SEPARATOR) != null) {
112 if (attrs.get (java.text.NumberFormat.Field.INTEGER) != null) {
114 }}if (attrs.get (java.text.NumberFormat.Field.EXPONENT_SYMBOL) != null) {
116 }if (attrs.get (java.text.NumberFormat.Field.PERCENT) != null) {
118 }if (attrs.get (java.text.NumberFormat.Field.PERMILLE) != null) {
120 }if (attrs.get (java.text.NumberFormat.Field.CURRENCY) != null) {
122 }if (attrs.get (java.text.NumberFormat.Field.SIGN) != null) {
129 Clazz.defineMethod (c$, "isNavigatable",
131 if (!Clazz.superCall (this, javax.swing.text.NumberFormatter, "isNavigatable", [index])) {
132 if (this.getBufferedChar (index) == this.getDecimalSeparator ()) {
137 Clazz.defineMethod (c$, "getFieldFrom",
138 function (index, direction) {
139 if (this.isValidMask ()) {
140 var max = this.getFormattedTextField ().getDocument ().getLength ();
141 var iterator = this.getIterator ();
144 }while (index >= 0 && index < max) {
145 iterator.setIndex (index);
146 var attrs = iterator.getAttributes ();
147 if (attrs != null && attrs.size () > 0) {
148 var keys = attrs.keySet ().iterator ();
149 while (keys.hasNext ()) {
150 var key = keys.next ();
151 if (Clazz.instanceOf (key, java.text.NumberFormat.Field)) {
158 Clazz.defineMethod (c$, "replace",
159 function (fb, offset, length, string, attr) {
160 if (!this.getAllowsInvalid () && length == 0 && string != null && string.length == 1 && this.toggleSignIfNecessary (fb, offset, string.charAt (0))) {
162 }Clazz.superCall (this, javax.swing.text.NumberFormatter, "replace", [fb, offset, length, string, attr]);
163 }, "javax.swing.text.DocumentFilter.FilterBypass,~N,~N,~S,javax.swing.text.AttributeSet");
164 Clazz.defineMethod (c$, "toggleSignIfNecessary",
165 function (fb, offset, aChar) {
166 if (aChar == this.getMinusSign () || aChar == this.getPositiveSign ()) {
167 var field = this.getFieldFrom (offset, -1);
170 if (field == null || (field !== java.text.NumberFormat.Field.EXPONENT && field !== java.text.NumberFormat.Field.EXPONENT_SYMBOL && field !== java.text.NumberFormat.Field.EXPONENT_SIGN)) {
171 newValue = this.toggleSign ((aChar == this.getPositiveSign ()));
173 newValue = this.toggleExponentSign (offset, aChar);
174 }if (newValue != null && this.isValidValue (newValue, false)) {
175 var lc = this.getLiteralCountTo (offset);
176 var string = this.valueToString (newValue);
177 fb.remove (0, fb.getDocument ().getLength ());
178 fb.insertString (0, string, null);
179 this.updateValue (newValue);
180 this.repositionCursor (this.getLiteralCountTo (offset) - lc + offset, 1);
183 if (Clazz.exceptionOf (pe, java.text.ParseException)) {
190 }, "javax.swing.text.DocumentFilter.FilterBypass,~N,~S");
191 Clazz.defineMethod (c$, "toggleSign",
192 function (positive) {
193 var value = this.stringToValue (this.getFormattedTextField ().getText ());
195 var string = value.toString ();
196 if (string != null && string.length > 0) {
198 if (string.charAt (0) == '-') {
199 string = string.substring (1);
201 if (string.charAt (0) == '+') {
202 string = string.substring (1);
203 }if (string.length > 0 && string.charAt (0) != '-') {
204 string = "-" + string;
205 }}if (string != null) {
206 var valueClass = this.getValueClass ();
207 if (valueClass == null) {
208 valueClass = value.getClass ();
210 var cons = valueClass.getConstructor ( Clazz.newArray (-1, [String]));
212 return cons.newInstance ( Clazz.newArray (-1, [string]));
217 Clazz.defineMethod (c$, "toggleExponentSign",
218 function (offset, aChar) {
219 var string = this.getFormattedTextField ().getText ();
220 var replaceLength = 0;
221 var loc = this.getAttributeStart (java.text.NumberFormat.Field.EXPONENT_SIGN);
225 }if (aChar == this.getPositiveSign ()) {
226 string = this.getReplaceString (offset, replaceLength, null);
228 string = this.getReplaceString (offset, replaceLength, String.instantialize ( Clazz.newCharArray (-1, [aChar])));
229 }return this.stringToValue (string);