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