JHotDraw 7.3.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 527 2009-06-07 14:28:19Z 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 scaleFactor)
          Creates a NumberFormatter with the specified Format instance.
JavaNumberFormatter(double min, double max, double scaleFactor, boolean allowsNullValue, boolean appendsDotZero)
          Creates a NumberFormatter with the specified Format instance.
 
Method Summary
static javax.swing.JFormattedTextField.AbstractFormatterFactory createFormatterFactory(double min, double max, double scaleFactor)
          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 scaleFactor, boolean allowsNullValue, boolean appendsDotZero)
          Convenience method for creating a formatter factory with a ScalableNumberFormatter and a Java-style DecimalFormat.
 boolean getAllowsNullValue()
          Returns true if null values are allowed.
 boolean getAppendsDotZero()
          Returns true if null values are allowed.
 java.lang.Comparable getMaximum()
          Returns the maximum permissible value.
 java.lang.Comparable getMinimum()
          Returns the minimum permissible value.
 double getScaleFactor()
          Returns the scale factor of the number formatter.
 void setAllowsNullValue(boolean newValue)
          Allows/Disallows null values.
 void setAppendsDotZero(boolean newValue)
          Specifies whether ".0" is appended to double and float values.
 void setMaximum(java.lang.Comparable max)
          Sets the maximum permissible value.
 void setMinimum(java.lang.Comparable minimum)
          Sets the minimum permissible value.
 void setScaleFactor(double newValue)
          Changes the scale factor of the number formatter.
 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 scaleFactor)
Creates a NumberFormatter with the specified Format instance.


JavaNumberFormatter

public JavaNumberFormatter(double min,
                           double max,
                           double scaleFactor,
                           boolean allowsNullValue,
                           boolean appendsDotZero)
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

setScaleFactor

public void setScaleFactor(double newValue)
Changes the scale factor of the number formatter.

Parameters:
newValue -

getScaleFactor

public double getScaleFactor()
Returns the scale factor of the number formatter.


setAllowsNullValue

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

Parameters:
newValue -

getAllowsNullValue

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


setAppendsDotZero

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

Parameters:
newValue -

getAppendsDotZero

public boolean getAppendsDotZero()
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

createFormatterFactory

public static javax.swing.JFormattedTextField.AbstractFormatterFactory createFormatterFactory(double min,
                                                                                              double max,
                                                                                              double scaleFactor)
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 scaleFactor,
                                                                                              boolean allowsNullValue,
                                                                                              boolean appendsDotZero)
Convenience method for creating a formatter factory with a ScalableNumberFormatter and a Java-style DecimalFormat.


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