com.jgoodies.validation.tutorial.formatted.formatter
Class CustomNumberFormatter

java.lang.Object
  extended by javax.swing.JFormattedTextField.AbstractFormatter
      extended by javax.swing.text.DefaultFormatter
          extended by javax.swing.text.InternationalFormatter
              extended by javax.swing.text.NumberFormatter
                  extended by com.jgoodies.validation.tutorial.formatted.formatter.CustomNumberFormatter
All Implemented Interfaces:
Serializable, Cloneable

public final class CustomNumberFormatter
extends NumberFormatter

Unlike its superclass NumberFormatter, this class converts non-negative integers to natural language strings: Zero, One, Two, Three, More than three.

Version:
$Revision: 1.10 $
Author:
Karsten Lentzsch
See Also:
JFormattedTextField, Serialized Form

Constructor Summary
CustomNumberFormatter()
          Constructs a CustomNumberFormatter.
CustomNumberFormatter(NumberFormat numberFormat)
          Constructs a CustomNumberFormatter using the given NumberFormat to convert strings to values.
 
Method Summary
 String valueToString(Object value)
          Returns a String representation of the Object value.
 
Methods inherited from class javax.swing.text.NumberFormatter
setFormat
 
Methods inherited from class javax.swing.text.InternationalFormatter
clone, getActions, getFields, getFormat, getMaximum, getMinimum, install, setMaximum, setMinimum, stringToValue
 
Methods inherited from class javax.swing.text.DefaultFormatter
getAllowsInvalid, getCommitsOnValidEdit, getDocumentFilter, getNavigationFilter, getOverwriteMode, getValueClass, setAllowsInvalid, setCommitsOnValidEdit, setOverwriteMode, setValueClass
 
Methods inherited from class javax.swing.JFormattedTextField.AbstractFormatter
getFormattedTextField, invalidEdit, setEditValid, uninstall
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CustomNumberFormatter

public CustomNumberFormatter()
Constructs a CustomNumberFormatter.


CustomNumberFormatter

public CustomNumberFormatter(NumberFormat numberFormat)
Constructs a CustomNumberFormatter using the given NumberFormat to convert strings to values.

Parameters:
numberFormat - the NumberFormat used to parse numbers
Method Detail

valueToString

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

In addition to the superclass behavior, this method formats the numbers for zero, one, two, and three to the natural language strings.

Overrides:
valueToString in class InternationalFormatter
Parameters:
value - Value to convert
Returns:
String representation of value
Throws:
ParseException - if there is an error in the conversion


Copyright © 2003-2008 JGoodies Karsten Lentzsch. All Rights Reserved.