Class DecimalTextField

All Implemented Interfaces:
CyclerListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, Scrollable, SwingConstants
Direct Known Subclasses:
CurrencyTextField, PIANumberField

public class DecimalTextField extends ValidatedTextField
A textfield that understands a percentage-type number (i.e. a number consisting of an integer, a decimal separator, and a fractional portion i.e. 23.00). This component will format the numeric data appropriately for a given Locale, as well as perform manipulations on the data as it is input by the user.
See Also:
  • Field Details

    • LOCALE

      public static final Locale LOCALE
    • MAX_INTS

      public static final int MAX_INTS
      See Also:
    • doc

      protected com.portal.pfc.ui.DecimalDoc doc
    • numformat

      protected NumberFormat numformat
    • processWithoutParsing

      protected boolean processWithoutParsing
    • formatNumberAsNegative

      protected boolean formatNumberAsNegative
    • isSpinning

      protected boolean isSpinning
    • numFractionalDigits

      protected int numFractionalDigits
    • numIntegerDigits

      protected int numIntegerDigits
    • propHandler

      protected PropertyChangeSupport propHandler
    • rounding

      protected int rounding
  • Constructor Details

    • DecimalTextField

      public DecimalTextField()
      Constructs a new DecimalTextField. The number of columns is set to zero and the initial text is set to 0.00
    • DecimalTextField

      public DecimalTextField(int columns)
      Constructs a new DecimalTextField containing the specified number of columns. The initial text is set to 0.00
      Parameters:
      columns - The number of columns to use in calculating the preferred width.
  • Method Details

    • getValue

      public Object getValue()
      Used to retrieve the value of component as an Object (BigDecimal) instead of a String (using getText()).
      Specified by:
      getValue in class ValidatedTextField
      Returns:
      the numeric value of the component
    • setValue

      public void setValue(Object value)
      Used to set the value of component as an Object (Number) instead of a String (using setText()).
    • setRounding

      public void setRounding(int r)
      Determines the rounding used when retrieving this value.
      Parameters:
      r - the rounding option. Should be one of the BigDecimal.ROUND* types.
    • getRounding

      public int getRounding()
      Retrieves the rounding used when retrieving this value.
      Returns:
      the rounding option.
    • setNumIntegerDigits

      public void setNumIntegerDigits(int num)
      This method will modify the number of digits allowed in this textfield before the decimal separator.
      Parameters:
      the - number of digits allowed after the decimal separator
    • getNumIntegerDigits

      public int getNumIntegerDigits()
    • setNumFractionalDigits

      public void setNumFractionalDigits(int num)
      This method will modify the number of digits allowed in this textfield after the decimal separator. Once the number of digits is entered, any additional data is ignored.
      The default is 2.
      Parameters:
      the - number of digits allowed after the decimal separator
    • getNumFractionalDigits

      public int getNumFractionalDigits()
      This method retrieves the number of digits allowed in this textfield after the decimal separator.
      Returns:
      the number of digits allowed after the decimal separator
    • setText

      public void setText(String s)
      Sets the text of this textfield to the specified text, granted the specified text contains numeric data only. If the specified text contains alphabetic characters (including the currency symbol and/or the grouping separator) the text is rejected.
      Overrides:
      setText in class JTextComponent
      Parameters:
      str - the new text to display
    • replaceSelection

      public void replaceSelection(String s)
      Replaces the currently selected content with the specified text, granted the specified text contains numeric data only. If the specified text contains alphabetic characters (including the currency symbol and/or the grouping separator) the text is rejected. If there is no selection this amounts to an insert of the specified text.
      Overrides:
      replaceSelection in class JTextComponent
      Parameters:
      str - the new text to use when replacing the selected text
    • valueChange

      public void valueChange(CyclerEvent e)
      Implements the CyclerListener interface. This method retrieves the currently selected text (or the entire text if there is no selection), turns it into a number, and increments/decrements it appropriately.
      Specified by:
      valueChange in interface CyclerListener
      Specified by:
      valueChange in class ValidatedTextField
      Parameters:
      e - the event generated from the Cycler action
    • getNumberFormat

      protected NumberFormat getNumberFormat()
    • stripNonNumerics

      protected String stripNonNumerics(String str)
    • changeIt

      protected double changeIt(int type, double value)
    • changeIt

      protected long changeIt(int type, long value, long max)
    • changeIt

      protected double changeIt(int type, double value, double max)
    • getMaxValue

      protected long getMaxValue(int len)
    • isValidInput

      protected boolean isValidInput(String s)
      Description copied from class: ValidatedTextField
      This method verifies that the specified string doesn't contain alphabetic characters.
      Overrides:
      isValidInput in class ValidatedTextField
      Returns:
      true if the input contains numeric data only; false otherwise
    • representsNegative

      protected boolean representsNegative(String s)
    • formatText

      protected void formatText()
    • createDefaultModel

      protected Document createDefaultModel()
      Overrides:
      createDefaultModel in class JTextField