jdk/src/share/classes/javax/swing/text/NumberFormatter.java
author prr
Fri, 23 May 2014 09:05:24 -0700
changeset 24567 a0ebe5fd56ff
parent 22574 7f8ce0c8c20a
child 25193 187a455af8f8
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 21278
diff changeset
     2
 * Copyright (c) 2000, 2014, 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
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20854
diff changeset
    37
 * invalid numbers, for example, <code>setAllowsInvalid(false)</code>):
2
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
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20854
diff changeset
    47
 *       attempt to change the sign of the exponent to positive/negative.
2
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
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 7668
diff changeset
    88
 * of all JavaBeans&trade;
2
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
 */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 21278
diff changeset
    94
@SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
public class NumberFormatter extends InternationalFormatter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    /** The special characters from the Format instance. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private String specialChars;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * Creates a <code>NumberFormatter</code> with the a default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * <code>NumberFormat</code> instance obtained from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * <code>NumberFormat.getNumberInstance()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public NumberFormatter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        this(NumberFormat.getNumberInstance());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * Creates a NumberFormatter with the specified Format instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @param format Format used to dictate legal values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public NumberFormatter(NumberFormat format) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        super(format);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        setFormat(format);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        setAllowsInvalid(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        setCommitsOnValidEdit(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        setOverwriteMode(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * Sets the format that dictates the legal values that can be edited
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * and displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * If you have used the nullary constructor the value of this property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * will be determined for the current locale by way of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * <code>NumberFormat.getNumberInstance()</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * @param format NumberFormat instance used to dictate legal values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public void setFormat(Format format) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        super.setFormat(format);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        DecimalFormatSymbols dfs = getDecimalFormatSymbols();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        if (dfs != null) {
7014
eb4fcf73ee99 6432566: Replace usage of StringBuffer with StringBuilder in Swing
rupashka
parents: 5506
diff changeset
   137
            StringBuilder sb = new StringBuilder();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            sb.append(dfs.getCurrencySymbol());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            sb.append(dfs.getDecimalSeparator());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            sb.append(dfs.getGroupingSeparator());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            sb.append(dfs.getInfinity());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            sb.append(dfs.getInternationalCurrencySymbol());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            sb.append(dfs.getMinusSign());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            sb.append(dfs.getMonetaryDecimalSeparator());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            sb.append(dfs.getNaN());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            sb.append(dfs.getPercent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            sb.append('+');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            specialChars = sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            specialChars = "";
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * Invokes <code>parseObject</code> on <code>f</code>, returning
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * its value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    Object stringToValue(String text, Format f) throws ParseException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        if (f == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            return text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        Object value = f.parseObject(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        return convertValueToValueClass(value, getValueClass());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * Converts the passed in value to the passed in class. This only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * works if <code>valueClass</code> is one of <code>Integer</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * <code>Long</code>, <code>Float</code>, <code>Double</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * <code>Byte</code> or <code>Short</code> and <code>value</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * is an instanceof <code>Number</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    private Object convertValueToValueClass(Object value, Class valueClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        if (valueClass != null && (value instanceof Number)) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   178
            Number numberValue = (Number)value;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            if (valueClass == Integer.class) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   180
                return Integer.valueOf(numberValue.intValue());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            else if (valueClass == Long.class) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   183
                return Long.valueOf(numberValue.longValue());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            else if (valueClass == Float.class) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   186
                return Float.valueOf(numberValue.floatValue());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            else if (valueClass == Double.class) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   189
                return Double.valueOf(numberValue.doubleValue());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            else if (valueClass == Byte.class) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   192
                return Byte.valueOf(numberValue.byteValue());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            else if (valueClass == Short.class) {
438
2ae294e4518c 6613529: Avoid duplicate object creation within JDK packages
dav
parents: 2
diff changeset
   195
                return Short.valueOf(numberValue.shortValue());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * Returns the character that is used to toggle to positive values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    private char getPositiveSign() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        return '+';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * Returns the character that is used to toggle to negative values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    private char getMinusSign() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        DecimalFormatSymbols dfs = getDecimalFormatSymbols();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        if (dfs != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            return dfs.getMinusSign();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        return '-';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * Returns the character that is used to toggle to negative values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    private char getDecimalSeparator() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        DecimalFormatSymbols dfs = getDecimalFormatSymbols();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        if (dfs != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            return dfs.getDecimalSeparator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        return '.';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * Returns the DecimalFormatSymbols from the Format instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    private DecimalFormatSymbols getDecimalFormatSymbols() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        Format f = getFormat();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        if (f instanceof DecimalFormat) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            return ((DecimalFormat)f).getDecimalFormatSymbols();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * Subclassed to return false if <code>text</code> contains in an invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * character to insert, that is, it is not a digit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * (<code>Character.isDigit()</code>) and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * not one of the characters defined by the DecimalFormatSymbols.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    boolean isLegalInsertText(String text) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        if (getAllowsInvalid()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        for (int counter = text.length() - 1; counter >= 0; counter--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            char aChar = text.charAt(counter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            if (!Character.isDigit(aChar) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                           specialChars.indexOf(aChar) == -1){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * Subclassed to treat the decimal separator, grouping separator,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * exponent symbol, percent, permille, currency and sign as literals.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    boolean isLiteral(Map attrs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        if (!super.isLiteral(attrs)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            if (attrs == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            int size = attrs.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            if (attrs.get(NumberFormat.Field.GROUPING_SEPARATOR) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                size--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                if (attrs.get(NumberFormat.Field.INTEGER) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                    size--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            if (attrs.get(NumberFormat.Field.EXPONENT_SYMBOL) != 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.PERCENT) != 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.PERMILLE) != 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.CURRENCY) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                size--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            if (attrs.get(NumberFormat.Field.SIGN) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                size--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            }
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
   297
            return size == 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    /**
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20854
diff changeset
   303
     * Subclassed to make the decimal separator navigable, as well
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * as making the character between the integer field and the next
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20854
diff changeset
   305
     * field navigable.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    boolean isNavigatable(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        if (!super.isNavigatable(index)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            // 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
   310
            return getBufferedChar(index) == getDecimalSeparator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * Returns the first <code>NumberFormat.Field</code> starting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * <code>index</code> incrementing by <code>direction</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    private NumberFormat.Field getFieldFrom(int index, int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        if (isValidMask()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            int max = getFormattedTextField().getDocument().getLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            AttributedCharacterIterator iterator = getIterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            if (index >= max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                index += direction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            while (index >= 0 && index < max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                iterator.setIndex(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                Map attrs = iterator.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                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
   333
                    for (Object key : attrs.keySet()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                        if (key instanceof NumberFormat.Field) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                            return (NumberFormat.Field)key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                index += direction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * Overriden to toggle the value if the positive/minus sign
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * is inserted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    void replace(DocumentFilter.FilterBypass fb, int offset, int length,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                String string, AttributeSet attr) throws BadLocationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        if (!getAllowsInvalid() && length == 0 && string != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            string.length() == 1 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            toggleSignIfNecessary(fb, offset, string.charAt(0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        super.replace(fb, offset, length, string, attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * Will change the sign of the integer or exponent field if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * <code>aChar</code> is the positive or minus sign. Returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * true if a sign change was attempted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    private boolean toggleSignIfNecessary(DocumentFilter.FilterBypass fb,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                                              int offset, char aChar) throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                              BadLocationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        if (aChar == getMinusSign() || aChar == getPositiveSign()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            NumberFormat.Field field = getFieldFrom(offset, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            Object newValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                if (field == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                    (field != NumberFormat.Field.EXPONENT &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                     field != NumberFormat.Field.EXPONENT_SYMBOL &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                     field != NumberFormat.Field.EXPONENT_SIGN)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                    newValue = toggleSign((aChar == getPositiveSign()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                    // exponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                    newValue = toggleExponentSign(offset, aChar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                if (newValue != null && isValidValue(newValue, false)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                    int lc = getLiteralCountTo(offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                    String string = valueToString(newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                    fb.remove(0, fb.getDocument().getLength());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                    fb.insertString(0, string, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                    updateValue(newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                    repositionCursor(getLiteralCountTo(offset) -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                                     lc + offset, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            } catch (ParseException pe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                invalidEdit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * Invoked to toggle the sign. For this to work the value class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * must have a single arg constructor that takes a String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    private Object toggleSign(boolean positive) throws ParseException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        Object value = stringToValue(getFormattedTextField().getText());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        if (value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            // toString isn't localized, so that using +/- should work
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            // correctly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            String string = value.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            if (string != null && string.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                if (positive) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                    if (string.charAt(0) == '-') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                        string = string.substring(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                    if (string.charAt(0) == '+') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                        string = string.substring(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                    if (string.length() > 0 && string.charAt(0) != '-') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                        string = "-" + string;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                if (string != null) {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 438
diff changeset
   427
                    Class<?> valueClass = getValueClass();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                    if (valueClass == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                        valueClass = value.getClass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                    try {
20800
1f6b7d81410d 8013744: Better tabling for AWT
alexsch
parents: 7668
diff changeset
   433
                        ReflectUtil.checkPackageAccess(valueClass);
1f6b7d81410d 8013744: Better tabling for AWT
alexsch
parents: 7668
diff changeset
   434
                        SwingUtilities2.checkAccess(valueClass.getModifiers());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                        Constructor cons = valueClass.getConstructor(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                                              new Class[] { String.class });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                        if (cons != null) {
20800
1f6b7d81410d 8013744: Better tabling for AWT
alexsch
parents: 7668
diff changeset
   438
                            SwingUtilities2.checkAccess(cons.getModifiers());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                            return cons.newInstance(new Object[]{string});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                    } catch (Throwable ex) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * Invoked to toggle the sign of the exponent (for scientific
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * numbers).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    private Object toggleExponentSign(int offset, char aChar) throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                             BadLocationException, ParseException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        String string = getFormattedTextField().getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        int replaceLength = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        int loc = getAttributeStart(NumberFormat.Field.EXPONENT_SIGN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        if (loc >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            replaceLength = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            offset = loc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        if (aChar == getPositiveSign()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            string = getReplaceString(offset, replaceLength, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            string = getReplaceString(offset, replaceLength,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                                      new String(new char[] { aChar }));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        return stringToValue(string);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
}