JHotDraw 7.5.1

org.jhotdraw.text
Class JavaNumberFormatter

java.lang.Object
  extended by javax.swing.JFormattedTextField.AbstractFormatter
      extended by javax.swing.text.DefaultFormatter
          extended by org.jhotdraw.text.JavaNumberFormatter
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class JavaNumberFormatter
extends javax.swing.text.DefaultFormatter

ScaledNumberFormatter is used to format numbers written in the Java programming syntax.

Version:
$Id: JavaNumberFormatter.java 648 2010-03-21 12:55:45Z rawcoder $
Author:
Werner Randelshofer
See Also:
Serialized Form

Constructor Summary
JavaNumberFormatter()
          Creates a NumberFormatter with the a default NumberFormat instance obtained from NumberFormat.getNumberInstance().
JavaNumberFormatter(double min, double max, double multiplier)
          Creates a NumberFormatter with the specified Format instance.
JavaNumberFormatter(double min, double max, double multiplier, boolean allowsNullValue)
          Creates a NumberFormatter with the specified Format instance.
JavaNumberFormatter(double min, double max, double multiplier, boolean allowsNullValue, java.lang.String unit)
          Creates a NumberFormatter with the specified Format instance.
 
Method Summary
static javax.swing.JFormattedTextField.AbstractFormatterFactory createFormatterFactory(double min, double max, double multiplier)
          Convenience method for creating a formatter factory with a ScalableNumberFormatter and a Java-style DecimalFormat.
static javax.swing.JFormattedTextField.AbstractFormatterFactory createFormatterFactory(double min, double max, double multiplier, boolean allowsNullValue)
          Convenience method for creating a formatter factory with a ScalableNumberFormatter and a Java-style DecimalFormat.
static javax.swing.JFormattedTextField.AbstractFormatterFactory createFormatterFactory(double min, double max, double multiplier, boolean allowsNullValue, java.lang.String unit)
          Convenience method for creating a formatter factory with a ScalableNumberFormatter and a Java-style DecimalFormat.
 boolean getAllowsNullValue()
          Returns true if null values are allowed.
 java.lang.Comparable getMaximum()
          Returns the maximum permissible value.
 int getMaximumFractionDigits()
          Gets the maximum number of digits allowed in the fraction portion of a number.
 int getMaximumIntegerDigits()
          Gets the maximum number of digits allowed in the integer portion of a number.
 java.lang.Comparable getMinimum()
          Returns the minimum permissible value.
 int getMinimumFractionDigits()
          Returns true if null values are allowed.
 int getMinimumIntegerDigits()
          Gets the minimum number of digits allowed in the integer portion of a number.
 int getMinimumNegativeExponent()
          Gets the minimum negative exponent value for scientific notation.
 int getMinimumPositiveExponent()
          Gets the minimum positive exponent value for scientific notation.
 double getMultiplier()
          Gets the multiplier for use in percent, per mille, and similar formats.
 java.lang.String getUnit()
          If non-null the unit string is appended to the value.
 boolean isUsesScientificNotation()
          Returns true if scientific notation is used.
 void setAllowsNullValue(boolean newValue)
          Allows/Disallows null values.
 void setMaximum(java.lang.Comparable max)
          Sets the maximum permissible value.
 void setMaximumFractionDigits(int newValue)
          Sets the maximum number of digits allowed in the fraction portion of a number.
 void setMaximumIntegerDigits(int newValue)
          Sets the maximum number of digits allowed in the integer portion of a number.
 void setMinimum(java.lang.Comparable minimum)
          Sets the minimum permissible value.
 void setMinimumFractionDigits(int newValue)
          Specifies whether ".0" is appended to double and float values.
 void setMinimumIntegerDigits(int newValue)
          Sets the minimum number of digits allowed in the integer portion of a number.
 void setMinimumNegativeExponent(int newValue)
          Sets the minimum negative exponent value for scientific notation.
 void setMinimumPositiveExponent(int newValue)
          Sets the minimum positive exponent value for scientific notation.
 void setMultiplier(double newValue)
          Sets the multiplier for use in percent, per mille, and similar formats.
 void setUnit(java.lang.String value)
          If non-null the unit string is appended to the value.
 void setUsesScientificNotation(boolean newValue)
          Sets whether scientific notation is used.
 java.lang.Object stringToValue(java.lang.String text)
          Returns the Object representation of the String text.
 java.lang.String valueToString(java.lang.Object value)
          Returns a String representation of the Object value.
 
Methods inherited from class javax.swing.text.DefaultFormatter
clone, getAllowsInvalid, getCommitsOnValidEdit, getDocumentFilter, getNavigationFilter, getOverwriteMode, getValueClass, install, setAllowsInvalid, setCommitsOnValidEdit, setOverwriteMode, setValueClass
 
Methods inherited from class javax.swing.JFormattedTextField.AbstractFormatter
getActions, getFormattedTextField, invalidEdit, setEditValid, uninstall
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JavaNumberFormatter

public JavaNumberFormatter()
Creates a NumberFormatter with the a default NumberFormat instance obtained from NumberFormat.getNumberInstance().


JavaNumberFormatter

public JavaNumberFormatter(double min,
                           double max,
                           double multiplier)
Creates a NumberFormatter with the specified Format instance.


JavaNumberFormatter

public JavaNumberFormatter(double min,
                           double max,
                           double multiplier,
                           boolean allowsNullValue)
Creates a NumberFormatter with the specified Format instance.


JavaNumberFormatter

public JavaNumberFormatter(double min,
                           double max,
                           double multiplier,
                           boolean allowsNullValue,
                           java.lang.String unit)
Creates a NumberFormatter with the specified Format instance.

Method Detail

setMinimum

public void setMinimum(java.lang.Comparable minimum)
Sets the minimum permissible value. If the valueClass has not been specified, and minimum is non null, the valueClass will be set to that of the class of minimum.

Parameters:
minimum - Minimum legal value that can be input
See Also:
DefaultFormatter.setValueClass(java.lang.Class)

getMinimum

public java.lang.Comparable getMinimum()
Returns the minimum permissible value.

Returns:
Minimum legal value that can be input

setMaximum

public void setMaximum(java.lang.Comparable max)
Sets the maximum permissible value. If the valueClass has not been specified, and max is non null, the valueClass will be set to that of the class of max.

Parameters:
max - Maximum legal value that can be input
See Also:
DefaultFormatter.setValueClass(java.lang.Class)

getMaximum

public java.lang.Comparable getMaximum()
Returns the maximum permissible value.

Returns:
Maximum legal value that can be input

setMultiplier

public void setMultiplier(double newValue)
Sets the multiplier for use in percent, per mille, and similar formats.


getMultiplier

public double getMultiplier()
Gets the multiplier for use in percent, per mille, and similar formats.


setAllowsNullValue

public void setAllowsNullValue(boolean newValue)
Allows/Disallows null values.

Parameters:
newValue -

getAllowsNullValue

public boolean getAllowsNullValue()
Returns true if null values are allowed.


setMinimumFractionDigits

public void setMinimumFractionDigits(int newValue)
Specifies whether ".0" is appended to double and float values. By default this is true.

Parameters:
newValue -

getMinimumFractionDigits

public int getMinimumFractionDigits()
Returns true if null values are allowed.


valueToString

public java.lang.String valueToString(java.lang.Object value)
                               throws java.text.ParseException
Returns a String representation of the Object value. This invokes format on the current Format.

Overrides:
valueToString in class javax.swing.text.DefaultFormatter
Parameters:
value - Value to convert
Returns:
String representation of value
Throws:
java.text.ParseException - if there is an error in the conversion

stringToValue

public java.lang.Object stringToValue(java.lang.String text)
                               throws java.text.ParseException
Returns the Object representation of the String text.

Overrides:
stringToValue in class javax.swing.text.DefaultFormatter
Parameters:
text - String to convert
Returns:
Object representation of text
Throws:
java.text.ParseException - if there is an error in the conversion

setUnit

public void setUnit(java.lang.String value)
If non-null the unit string is appended to the value.


getUnit

public java.lang.String getUnit()
If non-null the unit string is appended to the value.


getMinimumIntegerDigits

public int getMinimumIntegerDigits()
Gets the minimum number of digits allowed in the integer portion of a number.


setMinimumIntegerDigits

public void setMinimumIntegerDigits(int newValue)
Sets the minimum number of digits allowed in the integer portion of a number.


getMaximumIntegerDigits

public int getMaximumIntegerDigits()
Gets the maximum number of digits allowed in the integer portion of a number.


setMaximumIntegerDigits

public void setMaximumIntegerDigits(int newValue)
Sets the maximum number of digits allowed in the integer portion of a number.


getMaximumFractionDigits

public int getMaximumFractionDigits()
Gets the maximum number of digits allowed in the fraction portion of a number.


setMaximumFractionDigits

public void setMaximumFractionDigits(int newValue)
Sets the maximum number of digits allowed in the fraction portion of a number.


getMinimumNegativeExponent

public int getMinimumNegativeExponent()
Gets the minimum negative exponent value for scientific notation.


setMinimumNegativeExponent

public void setMinimumNegativeExponent(int newValue)
Sets the minimum negative exponent value for scientific notation.


getMinimumPositiveExponent

public int getMinimumPositiveExponent()
Gets the minimum positive exponent value for scientific notation.


setMinimumPositiveExponent

public void setMinimumPositiveExponent(int newValue)
Sets the minimum positive exponent value for scientific notation.


isUsesScientificNotation

public boolean isUsesScientificNotation()
Returns true if scientific notation is used.


setUsesScientificNotation

public void setUsesScientificNotation(boolean newValue)
Sets whether scientific notation is used.


createFormatterFactory

public static javax.swing.JFormattedTextField.AbstractFormatterFactory createFormatterFactory(double min,
                                                                                              double max,
                                                                                              double multiplier)
Convenience method for creating a formatter factory with a ScalableNumberFormatter and a Java-style DecimalFormat. Doesn't allow null values and doesn't append ".0" to double and float values.


createFormatterFactory

public static javax.swing.JFormattedTextField.AbstractFormatterFactory createFormatterFactory(double min,
                                                                                              double max,
                                                                                              double multiplier,
                                                                                              boolean allowsNullValue)
Convenience method for creating a formatter factory with a ScalableNumberFormatter and a Java-style DecimalFormat.


createFormatterFactory

public static javax.swing.JFormattedTextField.AbstractFormatterFactory createFormatterFactory(double min,
                                                                                              double max,
                                                                                              double multiplier,
                                                                                              boolean allowsNullValue,
                                                                                              java.lang.String unit)
Convenience method for creating a formatter factory with a ScalableNumberFormatter and a Java-style DecimalFormat.


Copyright 1996-2010 (c) by the authors and contributors of the JHotDraw project.
Some rights reserved.