gausselim
Class RealFractionFormatter

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

public class RealFractionFormatter
extends javax.swing.text.DefaultFormatter

Formatter for BigDecimals that can parse simple fractions (BigDecimal/BigDecimal).

Author:
Steven Van Impe (steven.vanimpe@ugent.be)
See Also:
Serialized Form

Constructor Summary
RealFractionFormatter(java.math.MathContext mc)
          Create a formatter that parses BigDecimals.
 
Method Summary
 java.lang.Object stringToValue(java.lang.String string)
          Parse the specified string into a BigDecimal.
 java.lang.String valueToString(java.lang.Object value)
          Format a BigDecimal.
 
Methods inherited from class javax.swing.text.DefaultFormatter
clone, getAllowsInvalid, getCommitsOnValidEdit, getOverwriteMode, getValueClass, install, setAllowsInvalid, setCommitsOnValidEdit, setOverwriteMode, setValueClass
 
Methods inherited from class javax.swing.JFormattedTextField.AbstractFormatter
uninstall
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RealFractionFormatter

public RealFractionFormatter(java.math.MathContext mc)
Create a formatter that parses BigDecimals.

Method Detail

stringToValue

public java.lang.Object stringToValue(java.lang.String string)
                               throws java.text.ParseException
Parse the specified string into a BigDecimal. The first forward slash (if present) is used as the division sign. The BigDecimal(String, MathContext) constructor is used to parse the numerator and denominator (if present). In case of a division by zero only the numerator is returned.

Overrides:
stringToValue in class javax.swing.text.DefaultFormatter
Throws:
java.text.ParseException

valueToString

public java.lang.String valueToString(java.lang.Object value)
                               throws java.text.ParseException
Format a BigDecimal. Uses the toString() method. A null value is formatted as unknown.

Overrides:
valueToString in class javax.swing.text.DefaultFormatter
Throws:
java.text.ParseException