jdk/src/share/classes/javax/swing/text/NumberFormatter.java
author ohair
Tue, 28 Dec 2010 15:53:50 -0800
changeset 7668 d4a77089c587
parent 7014 eb4fcf73ee99
child 20458 f2423fb3fd19
child 20800 1f6b7d81410d
permissions -rw-r--r--
6962318: Update copyright year Reviewed-by: xdono
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 7014
diff changeset
     2
 * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1299
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1299
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1299
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1299
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1299
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package javax.swing.text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.lang.reflect.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.text.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * <code>NumberFormatter</code> subclasses <code>InternationalFormatter</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * adding special behavior for numbers. Among the specializations are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * (these are only used if the <code>NumberFormatter</code> does not display
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * invalid nubers, eg <code>setAllowsInvalid(false)</code>):
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *   <li>Pressing +/- (- is determined from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *       <code>DecimalFormatSymbols</code> associated with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *       <code>DecimalFormat</code>) in any field but the exponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *       field will attempt to change the sign of the number to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *       positive/negative.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *   <li>Pressing +/- (- is determined from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *       <code>DecimalFormatSymbols</code> associated with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *       <code>DecimalFormat</code>) in the exponent field will
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *       attemp to change the sign of the exponent to positive/negative.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * If you are displaying scientific numbers, you may wish to turn on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * overwrite mode, <code>setOverwriteMode(true)</code>. For example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * DecimalFormat decimalFormat = new DecimalFormat("0.000E0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * NumberFormatter textFormatter = new NumberFormatter(decimalFormat);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * textFormatter.setOverwriteMode(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * textFormatter.setAllowsInvalid(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * If you are going to allow the user to enter decimal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * values, you should either force the DecimalFormat to contain at least
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * one decimal (<code>#.0###</code>), or allow the value to be invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <code>setAllowsInvalid(true)</code>. Otherwise users may not be able to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * input decimal values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <code>NumberFormatter</code> provides slightly different behavior to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <code>stringToValue</code> than that of its superclass. If you have
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * specified a Class for values, {@link #setValueClass}, that is one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * of <code>Integer</code>, <code>Long</code>, <code>Float</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * <code>Double</code>, <code>Byte</code> or <code>Short</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * the Format's <code>parseObject</code> returns an instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * <code>Number</code>, the corresponding instance of the value class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * will be created using the constructor appropriate for the primitive
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * type the value class represents. For example:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * <code>setValueClass(Integer.class)</code> will cause the resulting
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * value to be created via
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * <code>new Integer(((Number)formatter.parseObject(string)).intValue())</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * This is typically useful if you
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * wish to set a min/max value as the various <code>Number</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * implementations are generally not comparable to each other. This is also
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * useful if for some reason you need a specific <code>Number</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * implementation for your values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
public class NumberFormatter extends InternationalFormatter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    /** The special characters from the Format instance. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    private String specialChars;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * Creates a <code>NumberFormatter</code> with the a default
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * <code>NumberFormat</code> instance obtained from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * <code>NumberFormat.getNumberInstance()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    public NumberFormatter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        this(NumberFormat.getNumberInstance());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * Creates a NumberFormatter with the specified Format instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @param format Format used to dictate legal values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    public NumberFormatter(NumberFormat format) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        super(format);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        setFormat(format);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        setAllowsInvalid(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        setCommitsOnValidEdit(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        setOverwriteMode(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * Sets the format that dictates the legal values that can be edited
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * and displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * If you have used the nullary constructor the value of this property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * will be determined for the current locale by way of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * <code>NumberFormat.getNumberInstance()</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @param format NumberFormat instance used to dictate legal values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public void setFormat(Format format) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        super.setFormat(format);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        DecimalFormatSymbols dfs = getDecimalFormatSymbols();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        if (dfs != null) {
7014
eb4fcf73ee99 6432566: Replace usage of StringBuffer with StringBuilder in Swing
rupashka
parents: 5506
diff changeset
   134
            StringBuilder sb = new StringBuilder();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            sb.append(dfs.getCurrencySymbol());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            sb.append(dfs.getDecimalSeparator());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            sb.append(dfs.getGroupingSeparator());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            sb.append(dfs.getInfinity());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            sb.append(dfs.getInternationalCurrencySymbol());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            sb.append(dfs.getMinusSign());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            sb.append(dfs.getMonetaryDecimalSeparator());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            sb.append(dfs.getNaN());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            sb.append(dfs.getPercent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            sb.append('+');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            specialChars = sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            specialChars = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * Invokes <code>parseObject</code> on <code>f</code>, returning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * its value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    Object stringToValue(String text, Format f) throws ParseException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        if (f == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            return text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        Object value = f.parseObject(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        return convertValueToValueClass(value, getValueClass());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * Converts the passed in value to the passed in class. This only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * works if <code>valueClass</code> is one of <code>Integer</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * <code>Long</code>, <code>Float</code>, <code>Double</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * <code>Byte</code> or <code>Short</code> and <code>value</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * is an instanceof <code>Number</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    private Object convertValueToValueClass(Object value, Class valueClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        if (valueClass != null && (value instanceof Number)) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   175
            Number numberValue = (Number)value;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            if (valueClass == Integer.class) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   177
                return Integer.valueOf(numberValue.intValue());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            else if (valueClass == Long.class) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   180
                return Long.valueOf(numberValue.longValue());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            else if (valueClass == Float.class) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   183
                return Float.valueOf(numberValue.floatValue());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            else if (valueClass == Double.class) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   186
                return Double.valueOf(numberValue.doubleValue());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            else if (valueClass == Byte.class) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   189
                return Byte.valueOf(numberValue.byteValue());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            else if (valueClass == Short.class) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   192
                return Short.valueOf(numberValue.shortValue());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * Returns the character that is used to toggle to positive values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    private char getPositiveSign() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        return '+';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * Returns the character that is used to toggle to negative values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    private char getMinusSign() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        DecimalFormatSymbols dfs = getDecimalFormatSymbols();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        if (dfs != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            return dfs.getMinusSign();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        return '-';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * Returns the character that is used to toggle to negative values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    private char getDecimalSeparator() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        DecimalFormatSymbols dfs = getDecimalFormatSymbols();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        if (dfs != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            return dfs.getDecimalSeparator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        return '.';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * Returns the DecimalFormatSymbols from the Format instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    private DecimalFormatSymbols getDecimalFormatSymbols() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        Format f = getFormat();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        if (f instanceof DecimalFormat) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            return ((DecimalFormat)f).getDecimalFormatSymbols();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * Subclassed to return false if <code>text</code> contains in an invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * character to insert, that is, it is not a digit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * (<code>Character.isDigit()</code>) and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * not one of the characters defined by the DecimalFormatSymbols.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    boolean isLegalInsertText(String text) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        if (getAllowsInvalid()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        for (int counter = text.length() - 1; counter >= 0; counter--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            char aChar = text.charAt(counter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            if (!Character.isDigit(aChar) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                           specialChars.indexOf(aChar) == -1){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * Subclassed to treat the decimal separator, grouping separator,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * exponent symbol, percent, permille, currency and sign as literals.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    boolean isLiteral(Map attrs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        if (!super.isLiteral(attrs)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            if (attrs == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            int size = attrs.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            if (attrs.get(NumberFormat.Field.GROUPING_SEPARATOR) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                size--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                if (attrs.get(NumberFormat.Field.INTEGER) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                    size--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            if (attrs.get(NumberFormat.Field.EXPONENT_SYMBOL) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                size--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            if (attrs.get(NumberFormat.Field.PERCENT) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                size--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            if (attrs.get(NumberFormat.Field.PERMILLE) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                size--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            if (attrs.get(NumberFormat.Field.CURRENCY) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                size--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            if (attrs.get(NumberFormat.Field.SIGN) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                size--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            }
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
   294
            return size == 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * Subclassed to make the decimal separator navigatable, as well
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * as making the character between the integer field and the next
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * field navigatable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    boolean isNavigatable(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        if (!super.isNavigatable(index)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            // Don't skip the decimal, it causes wierd behavior
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
   307
            return getBufferedChar(index) == getDecimalSeparator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * Returns the first <code>NumberFormat.Field</code> starting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * <code>index</code> incrementing by <code>direction</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    private NumberFormat.Field getFieldFrom(int index, int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        if (isValidMask()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            int max = getFormattedTextField().getDocument().getLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            AttributedCharacterIterator iterator = getIterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            if (index >= max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                index += direction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            while (index >= 0 && index < max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                iterator.setIndex(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                Map attrs = iterator.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                if (attrs != null && attrs.size() > 0) {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
   330
                    for (Object key : attrs.keySet()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                        if (key instanceof NumberFormat.Field) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                            return (NumberFormat.Field)key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                index += direction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * Overriden to toggle the value if the positive/minus sign
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * is inserted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    void replace(DocumentFilter.FilterBypass fb, int offset, int length,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                String string, AttributeSet attr) throws BadLocationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        if (!getAllowsInvalid() && length == 0 && string != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            string.length() == 1 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            toggleSignIfNecessary(fb, offset, string.charAt(0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        super.replace(fb, offset, length, string, attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * Will change the sign of the integer or exponent field if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * <code>aChar</code> is the positive or minus sign. Returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * true if a sign change was attempted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    private boolean toggleSignIfNecessary(DocumentFilter.FilterBypass fb,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                                              int offset, char aChar) throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                              BadLocationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        if (aChar == getMinusSign() || aChar == getPositiveSign()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            NumberFormat.Field field = getFieldFrom(offset, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            Object newValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                if (field == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                    (field != NumberFormat.Field.EXPONENT &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                     field != NumberFormat.Field.EXPONENT_SYMBOL &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                     field != NumberFormat.Field.EXPONENT_SIGN)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                    newValue = toggleSign((aChar == getPositiveSign()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                    // exponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                    newValue = toggleExponentSign(offset, aChar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                if (newValue != null && isValidValue(newValue, false)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                    int lc = getLiteralCountTo(offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                    String string = valueToString(newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                    fb.remove(0, fb.getDocument().getLength());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                    fb.insertString(0, string, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                    updateValue(newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                    repositionCursor(getLiteralCountTo(offset) -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                                     lc + offset, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            } catch (ParseException pe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                invalidEdit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * Invoked to toggle the sign. For this to work the value class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * must have a single arg constructor that takes a String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    private Object toggleSign(boolean positive) throws ParseException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        Object value = stringToValue(getFormattedTextField().getText());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        if (value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            // toString isn't localized, so that using +/- should work
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            // correctly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            String string = value.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            if (string != null && string.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                if (positive) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                    if (string.charAt(0) == '-') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                        string = string.substring(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                    if (string.charAt(0) == '+') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                        string = string.substring(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                    if (string.length() > 0 && string.charAt(0) != '-') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                        string = "-" + string;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                if (string != null) {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
   424
                    Class<?> valueClass = getValueClass();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                    if (valueClass == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                        valueClass = value.getClass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                        Constructor cons = valueClass.getConstructor(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                                              new Class[] { String.class });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                        if (cons != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                            return cons.newInstance(new Object[]{string});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                    } catch (Throwable ex) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * Invoked to toggle the sign of the exponent (for scientific
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * numbers).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    private Object toggleExponentSign(int offset, char aChar) throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                             BadLocationException, ParseException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        String string = getFormattedTextField().getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        int replaceLength = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        int loc = getAttributeStart(NumberFormat.Field.EXPONENT_SIGN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        if (loc >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            replaceLength = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            offset = loc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        if (aChar == getPositiveSign()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            string = getReplaceString(offset, replaceLength, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            string = getReplaceString(offset, replaceLength,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                                      new String(new char[] { aChar }));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        return stringToValue(string);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
}