Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / site / j2s / javax / swing / text / NumberFormatter.js
index c6361d6..c1d3b36 100644 (file)
-Clazz.declarePackage ("javax.swing.text");\r
-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 () {\r
-c$ = Clazz.decorateAsClass (function () {\r
-this.specialChars = null;\r
-Clazz.instantialize (this, arguments);\r
-}, javax.swing.text, "NumberFormatter", javax.swing.text.InternationalFormatter);\r
-Clazz.makeConstructor (c$, \r
-function () {\r
-Clazz.superConstructor (this, javax.swing.text.NumberFormatter, []);\r
-this.setN (java.text.NumberFormat.getNumberInstance ());\r
-});\r
-Clazz.makeConstructor (c$, \r
-function (format) {\r
-Clazz.superConstructor (this, javax.swing.text.NumberFormatter, []);\r
-this.setN (format);\r
-}, "java.text.NumberFormat");\r
-Clazz.defineMethod (c$, "setN", \r
- function (format) {\r
-this.setFormat (format);\r
-this.setAllowsInvalid (true);\r
-this.setCommitsOnValidEdit (false);\r
-this.setOverwriteMode (false);\r
-}, "java.text.NumberFormat");\r
-Clazz.defineMethod (c$, "setFormat", \r
-function (format) {\r
-Clazz.superCall (this, javax.swing.text.NumberFormatter, "setFormat", [format]);\r
-var dfs = this.getDecimalFormatSymbols ();\r
-if (dfs != null) {\r
-var sb =  new StringBuffer ();\r
-sb.append (dfs.getCurrencySymbol ());\r
-sb.append (dfs.getDecimalSeparator ());\r
-sb.append (dfs.getGroupingSeparator ());\r
-sb.append (dfs.getInfinity ());\r
-sb.append (dfs.getInternationalCurrencySymbol ());\r
-sb.append (dfs.getMinusSign ());\r
-sb.append (dfs.getMonetaryDecimalSeparator ());\r
-sb.append (dfs.getNaN ());\r
-sb.append (dfs.getPercent ());\r
-sb.append ('+');\r
-this.specialChars = sb.toString ();\r
-} else {\r
-this.specialChars = "";\r
-}}, "java.text.Format");\r
-Clazz.overrideMethod (c$, "stringToValueParse", \r
-function (text, f) {\r
-if (f == null) {\r
-return text;\r
-}var value = f.parseObject (text);\r
-return this.convertValueToValueClass (value, this.getValueClass ());\r
-}, "~S,java.text.Format");\r
-Clazz.defineMethod (c$, "convertValueToValueClass", \r
- function (value, valueClass) {\r
-if (valueClass != null && (Clazz.instanceOf (value, Number))) {\r
-if (valueClass === Integer) {\r
-return  new Integer ((value).intValue ());\r
-} else if (valueClass === Long) {\r
-return  new Long ((value).longValue ());\r
-} else if (valueClass === Float) {\r
-return  new Float ((value).floatValue ());\r
-} else if (valueClass === Double) {\r
-return  new Double ((value).doubleValue ());\r
-} else if (valueClass === Byte) {\r
-return  new Byte ((value).byteValue ());\r
-} else if (valueClass === Short) {\r
-return  new Short ((value).shortValue ());\r
-}}return value;\r
-}, "~O,Class");\r
-Clazz.defineMethod (c$, "getPositiveSign", \r
- function () {\r
-return '+';\r
-});\r
-Clazz.defineMethod (c$, "getMinusSign", \r
- function () {\r
-var dfs = this.getDecimalFormatSymbols ();\r
-if (dfs != null) {\r
-return dfs.getMinusSign ();\r
-}return '-';\r
-});\r
-Clazz.defineMethod (c$, "getDecimalSeparator", \r
- function () {\r
-var dfs = this.getDecimalFormatSymbols ();\r
-if (dfs != null) {\r
-return dfs.getDecimalSeparator ();\r
-}return '.';\r
-});\r
-Clazz.defineMethod (c$, "getDecimalFormatSymbols", \r
- function () {\r
-var f = this.getFormat ();\r
-if (Clazz.instanceOf (f, java.text.DecimalFormat)) {\r
-return (f).getDecimalFormatSymbols ();\r
-}return null;\r
-});\r
-Clazz.overrideMethod (c$, "isLegalInsertText", \r
-function (text) {\r
-if (this.getAllowsInvalid ()) {\r
-return true;\r
-}for (var counter = text.length - 1; counter >= 0; counter--) {\r
-var aChar = text.charAt (counter);\r
-if (!Character.isDigit (aChar) && this.specialChars.indexOf (aChar) == -1) {\r
-return false;\r
-}}\r
-return true;\r
-}, "~S");\r
-Clazz.defineMethod (c$, "isLiteral", \r
-function (attrs) {\r
-if (!Clazz.superCall (this, javax.swing.text.NumberFormatter, "isLiteral", [attrs])) {\r
-if (attrs == null) {\r
-return false;\r
-}var size = attrs.size ();\r
-if (attrs.get (java.text.NumberFormat.Field.GROUPING_SEPARATOR) != null) {\r
-size--;\r
-if (attrs.get (java.text.NumberFormat.Field.INTEGER) != null) {\r
-size--;\r
-}}if (attrs.get (java.text.NumberFormat.Field.EXPONENT_SYMBOL) != null) {\r
-size--;\r
-}if (attrs.get (java.text.NumberFormat.Field.PERCENT) != null) {\r
-size--;\r
-}if (attrs.get (java.text.NumberFormat.Field.PERMILLE) != null) {\r
-size--;\r
-}if (attrs.get (java.text.NumberFormat.Field.CURRENCY) != null) {\r
-size--;\r
-}if (attrs.get (java.text.NumberFormat.Field.SIGN) != null) {\r
-size--;\r
-}if (size == 0) {\r
-return true;\r
-}return false;\r
-}return true;\r
-}, "java.util.Map");\r
-Clazz.defineMethod (c$, "isNavigatable", \r
-function (index) {\r
-if (!Clazz.superCall (this, javax.swing.text.NumberFormatter, "isNavigatable", [index])) {\r
-if (this.getBufferedChar (index) == this.getDecimalSeparator ()) {\r
-return true;\r
-}return false;\r
-}return true;\r
-}, "~N");\r
-Clazz.defineMethod (c$, "getFieldFrom", \r
- function (index, direction) {\r
-if (this.isValidMask ()) {\r
-var max = this.getFormattedTextField ().getDocument ().getLength ();\r
-var iterator = this.getIterator ();\r
-if (index >= max) {\r
-index += direction;\r
-}while (index >= 0 && index < max) {\r
-iterator.setIndex (index);\r
-var attrs = iterator.getAttributes ();\r
-if (attrs != null && attrs.size () > 0) {\r
-var keys = attrs.keySet ().iterator ();\r
-while (keys.hasNext ()) {\r
-var key = keys.next ();\r
-if (Clazz.instanceOf (key, java.text.NumberFormat.Field)) {\r
-return key;\r
-}}\r
-}index += direction;\r
-}\r
-}return null;\r
-}, "~N,~N");\r
-Clazz.defineMethod (c$, "replace", \r
-function (fb, offset, length, string, attr) {\r
-if (!this.getAllowsInvalid () && length == 0 && string != null && string.length == 1 && this.toggleSignIfNecessary (fb, offset, string.charAt (0))) {\r
-return;\r
-}Clazz.superCall (this, javax.swing.text.NumberFormatter, "replace", [fb, offset, length, string, attr]);\r
-}, "javax.swing.text.DocumentFilter.FilterBypass,~N,~N,~S,javax.swing.text.AttributeSet");\r
-Clazz.defineMethod (c$, "toggleSignIfNecessary", \r
- function (fb, offset, aChar) {\r
-if (aChar == this.getMinusSign () || aChar == this.getPositiveSign ()) {\r
-var field = this.getFieldFrom (offset, -1);\r
-var newValue;\r
-try {\r
-if (field == null || (field !== java.text.NumberFormat.Field.EXPONENT && field !== java.text.NumberFormat.Field.EXPONENT_SYMBOL && field !== java.text.NumberFormat.Field.EXPONENT_SIGN)) {\r
-newValue = this.toggleSign ((aChar == this.getPositiveSign ()));\r
-} else {\r
-newValue = this.toggleExponentSign (offset, aChar);\r
-}if (newValue != null && this.isValidValue (newValue, false)) {\r
-var lc = this.getLiteralCountTo (offset);\r
-var string = this.valueToString (newValue);\r
-fb.remove (0, fb.getDocument ().getLength ());\r
-fb.insertString (0, string, null);\r
-this.updateValue (newValue);\r
-this.repositionCursor (this.getLiteralCountTo (offset) - lc + offset, 1);\r
-return true;\r
-}} catch (pe) {\r
-if (Clazz.exceptionOf (pe, java.text.ParseException)) {\r
-this.invalidEdit ();\r
-} else {\r
-throw pe;\r
-}\r
-}\r
-}return false;\r
-}, "javax.swing.text.DocumentFilter.FilterBypass,~N,~S");\r
-Clazz.defineMethod (c$, "toggleSign", \r
- function (positive) {\r
-var value = this.stringToValue (this.getFormattedTextField ().getText ());\r
-if (value != null) {\r
-var string = value.toString ();\r
-if (string != null && string.length > 0) {\r
-if (positive) {\r
-if (string.charAt (0) == '-') {\r
-string = string.substring (1);\r
-}} else {\r
-if (string.charAt (0) == '+') {\r
-string = string.substring (1);\r
-}if (string.length > 0 && string.charAt (0) != '-') {\r
-string = "-" + string;\r
-}}if (string != null) {\r
-var valueClass = this.getValueClass ();\r
-if (valueClass == null) {\r
-valueClass = value.getClass ();\r
-}try {\r
-var cons = valueClass.getConstructor ( Clazz.newArray (-1, [String]));\r
-if (cons != null) {\r
-return cons.newInstance ( Clazz.newArray (-1, [string]));\r
-}} catch (ex) {\r
-}\r
-}}}return null;\r
-}, "~B");\r
-Clazz.defineMethod (c$, "toggleExponentSign", \r
- function (offset, aChar) {\r
-var string = this.getFormattedTextField ().getText ();\r
-var replaceLength = 0;\r
-var loc = this.getAttributeStart (java.text.NumberFormat.Field.EXPONENT_SIGN);\r
-if (loc >= 0) {\r
-replaceLength = 1;\r
-offset = loc;\r
-}if (aChar == this.getPositiveSign ()) {\r
-string = this.getReplaceString (offset, replaceLength, null);\r
-} else {\r
-string = this.getReplaceString (offset, replaceLength,  String.instantialize ( Clazz.newCharArray (-1, [aChar])));\r
-}return this.stringToValue (string);\r
-}, "~N,~S");\r
-});\r
+Clazz.declarePackage ("javax.swing.text");
+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 () {
+c$ = Clazz.decorateAsClass (function () {
+this.specialChars = null;
+Clazz.instantialize (this, arguments);
+}, javax.swing.text, "NumberFormatter", javax.swing.text.InternationalFormatter);
+Clazz.makeConstructor (c$, 
+function () {
+Clazz.superConstructor (this, javax.swing.text.NumberFormatter, []);
+this.setN (java.text.NumberFormat.getNumberInstance ());
+});
+Clazz.makeConstructor (c$, 
+function (format) {
+Clazz.superConstructor (this, javax.swing.text.NumberFormatter, []);
+this.setN (format);
+}, "java.text.NumberFormat");
+Clazz.defineMethod (c$, "setN", 
+ function (format) {
+this.setFormat (format);
+this.setAllowsInvalid (true);
+this.setCommitsOnValidEdit (false);
+this.setOverwriteMode (false);
+}, "java.text.NumberFormat");
+Clazz.defineMethod (c$, "setFormat", 
+function (format) {
+Clazz.superCall (this, javax.swing.text.NumberFormatter, "setFormat", [format]);
+var dfs = this.getDecimalFormatSymbols ();
+if (dfs != null) {
+var sb =  new StringBuffer ();
+sb.append (dfs.getCurrencySymbol ());
+sb.append (dfs.getDecimalSeparator ());
+sb.append (dfs.getGroupingSeparator ());
+sb.append (dfs.getInfinity ());
+sb.append (dfs.getInternationalCurrencySymbol ());
+sb.append (dfs.getMinusSign ());
+sb.append (dfs.getMonetaryDecimalSeparator ());
+sb.append (dfs.getNaN ());
+sb.append (dfs.getPercent ());
+sb.append ('+');
+this.specialChars = sb.toString ();
+} else {
+this.specialChars = "";
+}}, "java.text.Format");
+Clazz.overrideMethod (c$, "stringToValueParse", 
+function (text, f) {
+if (f == null) {
+return text;
+}var value = f.parseObject (text);
+return this.convertValueToValueClass (value, this.getValueClass ());
+}, "~S,java.text.Format");
+Clazz.defineMethod (c$, "convertValueToValueClass", 
+ function (value, valueClass) {
+if (valueClass != null && (Clazz.instanceOf (value, Number))) {
+if (valueClass === Integer) {
+return  new Integer ((value).intValue ());
+} else if (valueClass === Long) {
+return  new Long ((value).longValue ());
+} else if (valueClass === Float) {
+return  new Float ((value).floatValue ());
+} else if (valueClass === Double) {
+return  new Double ((value).doubleValue ());
+} else if (valueClass === Byte) {
+return  new Byte ((value).byteValue ());
+} else if (valueClass === Short) {
+return  new Short ((value).shortValue ());
+}}return value;
+}, "~O,Class");
+Clazz.defineMethod (c$, "getPositiveSign", 
+ function () {
+return '+';
+});
+Clazz.defineMethod (c$, "getMinusSign", 
+ function () {
+var dfs = this.getDecimalFormatSymbols ();
+if (dfs != null) {
+return dfs.getMinusSign ();
+}return '-';
+});
+Clazz.defineMethod (c$, "getDecimalSeparator", 
+ function () {
+var dfs = this.getDecimalFormatSymbols ();
+if (dfs != null) {
+return dfs.getDecimalSeparator ();
+}return '.';
+});
+Clazz.defineMethod (c$, "getDecimalFormatSymbols", 
+ function () {
+var f = this.getFormat ();
+if (Clazz.instanceOf (f, java.text.DecimalFormat)) {
+return (f).getDecimalFormatSymbols ();
+}return null;
+});
+Clazz.overrideMethod (c$, "isLegalInsertText", 
+function (text) {
+if (this.getAllowsInvalid ()) {
+return true;
+}for (var counter = text.length - 1; counter >= 0; counter--) {
+var aChar = text.charAt (counter);
+if (!Character.isDigit (aChar) && this.specialChars.indexOf (aChar) == -1) {
+return false;
+}}
+return true;
+}, "~S");
+Clazz.defineMethod (c$, "isLiteral", 
+function (attrs) {
+if (!Clazz.superCall (this, javax.swing.text.NumberFormatter, "isLiteral", [attrs])) {
+if (attrs == null) {
+return false;
+}var size = attrs.size ();
+if (attrs.get (java.text.NumberFormat.Field.GROUPING_SEPARATOR) != null) {
+size--;
+if (attrs.get (java.text.NumberFormat.Field.INTEGER) != null) {
+size--;
+}}if (attrs.get (java.text.NumberFormat.Field.EXPONENT_SYMBOL) != null) {
+size--;
+}if (attrs.get (java.text.NumberFormat.Field.PERCENT) != null) {
+size--;
+}if (attrs.get (java.text.NumberFormat.Field.PERMILLE) != null) {
+size--;
+}if (attrs.get (java.text.NumberFormat.Field.CURRENCY) != null) {
+size--;
+}if (attrs.get (java.text.NumberFormat.Field.SIGN) != null) {
+size--;
+}if (size == 0) {
+return true;
+}return false;
+}return true;
+}, "java.util.Map");
+Clazz.defineMethod (c$, "isNavigatable", 
+function (index) {
+if (!Clazz.superCall (this, javax.swing.text.NumberFormatter, "isNavigatable", [index])) {
+if (this.getBufferedChar (index) == this.getDecimalSeparator ()) {
+return true;
+}return false;
+}return true;
+}, "~N");
+Clazz.defineMethod (c$, "getFieldFrom", 
+ function (index, direction) {
+if (this.isValidMask ()) {
+var max = this.getFormattedTextField ().getDocument ().getLength ();
+var iterator = this.getIterator ();
+if (index >= max) {
+index += direction;
+}while (index >= 0 && index < max) {
+iterator.setIndex (index);
+var attrs = iterator.getAttributes ();
+if (attrs != null && attrs.size () > 0) {
+var keys = attrs.keySet ().iterator ();
+while (keys.hasNext ()) {
+var key = keys.next ();
+if (Clazz.instanceOf (key, java.text.NumberFormat.Field)) {
+return key;
+}}
+}index += direction;
+}
+}return null;
+}, "~N,~N");
+Clazz.defineMethod (c$, "replace", 
+function (fb, offset, length, string, attr) {
+if (!this.getAllowsInvalid () && length == 0 && string != null && string.length == 1 && this.toggleSignIfNecessary (fb, offset, string.charAt (0))) {
+return;
+}Clazz.superCall (this, javax.swing.text.NumberFormatter, "replace", [fb, offset, length, string, attr]);
+}, "javax.swing.text.DocumentFilter.FilterBypass,~N,~N,~S,javax.swing.text.AttributeSet");
+Clazz.defineMethod (c$, "toggleSignIfNecessary", 
+ function (fb, offset, aChar) {
+if (aChar == this.getMinusSign () || aChar == this.getPositiveSign ()) {
+var field = this.getFieldFrom (offset, -1);
+var newValue;
+try {
+if (field == null || (field !== java.text.NumberFormat.Field.EXPONENT && field !== java.text.NumberFormat.Field.EXPONENT_SYMBOL && field !== java.text.NumberFormat.Field.EXPONENT_SIGN)) {
+newValue = this.toggleSign ((aChar == this.getPositiveSign ()));
+} else {
+newValue = this.toggleExponentSign (offset, aChar);
+}if (newValue != null && this.isValidValue (newValue, false)) {
+var lc = this.getLiteralCountTo (offset);
+var string = this.valueToString (newValue);
+fb.remove (0, fb.getDocument ().getLength ());
+fb.insertString (0, string, null);
+this.updateValue (newValue);
+this.repositionCursor (this.getLiteralCountTo (offset) - lc + offset, 1);
+return true;
+}} catch (pe) {
+if (Clazz.exceptionOf (pe, java.text.ParseException)) {
+this.invalidEdit ();
+} else {
+throw pe;
+}
+}
+}return false;
+}, "javax.swing.text.DocumentFilter.FilterBypass,~N,~S");
+Clazz.defineMethod (c$, "toggleSign", 
+ function (positive) {
+var value = this.stringToValue (this.getFormattedTextField ().getText ());
+if (value != null) {
+var string = value.toString ();
+if (string != null && string.length > 0) {
+if (positive) {
+if (string.charAt (0) == '-') {
+string = string.substring (1);
+}} else {
+if (string.charAt (0) == '+') {
+string = string.substring (1);
+}if (string.length > 0 && string.charAt (0) != '-') {
+string = "-" + string;
+}}if (string != null) {
+var valueClass = this.getValueClass ();
+if (valueClass == null) {
+valueClass = value.getClass ();
+}try {
+var cons = valueClass.getConstructor ( Clazz.newArray (-1, [String]));
+if (cons != null) {
+return cons.newInstance ( Clazz.newArray (-1, [string]));
+}} catch (ex) {
+}
+}}}return null;
+}, "~B");
+Clazz.defineMethod (c$, "toggleExponentSign", 
+ function (offset, aChar) {
+var string = this.getFormattedTextField ().getText ();
+var replaceLength = 0;
+var loc = this.getAttributeStart (java.text.NumberFormat.Field.EXPONENT_SIGN);
+if (loc >= 0) {
+replaceLength = 1;
+offset = loc;
+}if (aChar == this.getPositiveSign ()) {
+string = this.getReplaceString (offset, replaceLength, null);
+} else {
+string = this.getReplaceString (offset, replaceLength,  String.instantialize ( Clazz.newCharArray (-1, [aChar])));
+}return this.stringToValue (string);
+}, "~N,~S");
+});