Class BigDecimalFormatter

java.lang.Object
All Implemented Interfaces:
java.util.EventListener, ITextFormatter, org.eclipse.swt.events.VerifyListener, org.eclipse.swt.internal.SWTEventListener

public class BigDecimalFormatter
extends NumberFormatter
This class provides formatting of BigDecimal values in a FormattedText.

BigDecimalFormatter returns different numeric types based on the current value in the Text field. BigDecimalFormatter is an override of NumberFormatter allowing to guaranty to always return BigDecimal values (Object.toString()).

  • Constructor Details

    • BigDecimalFormatter

      public BigDecimalFormatter()
      Constructs a new instance with all defaults.
      See Also:
      NumberFormatter()
    • BigDecimalFormatter

      public BigDecimalFormatter​(java.util.Locale loc)
      Constructs a new instance with default edit and display masks for the given locale.
      Parameters:
      loc - the locale
    • BigDecimalFormatter

      public BigDecimalFormatter​(java.lang.String editPattern, java.util.Locale loc)
      Constructs a new instance with the given edit mask and locale. Display mask is identical to the edit mask.
      Parameters:
      editPattern - the edit mask
      loc - the locale
    • BigDecimalFormatter

      public BigDecimalFormatter​(java.lang.String editPattern, java.lang.String displayPattern, java.util.Locale loc)
      Constructs a new instance with the given masks and locale.
      Parameters:
      editPattern - the edit mask
      displayPattern - the display mask
      loc - the locale
    • BigDecimalFormatter

      public BigDecimalFormatter​(java.lang.String editPattern, java.lang.String displayPattern)
      Constructs a new instance with the given edit and display masks. Uses the default locale.
      Parameters:
      editPattern - the edit mask
      displayPattern - the display mask
    • BigDecimalFormatter

      public BigDecimalFormatter​(java.lang.String editPattern)
      Constructs a new instance with the given edit mask. Display mask is identical to the edit mask, and locale is the default one.
      Parameters:
      editPattern - the edit mask
  • Method Details

    • getValue

      public java.lang.Object getValue()
      Returns the current value of the text control if it is a valid BigDecimal. If the buffer is flagged as modified, the value is recalculated by parsing with the nfEdit initialized with the edit pattern. If the number is not valid, returns null.
      Specified by:
      getValue in interface ITextFormatter
      Overrides:
      getValue in class NumberFormatter
      Returns:
      current BigDecimal value if valid, else null
      See Also:
      ITextFormatter.getValue()
    • getValueType

      public java.lang.Class<java.math.BigDecimal> getValueType()
      Returns the type of value this ITextFormatter handles, i.e. returns in getValue().
      A BigDecimalFormatter always returns an BigDecimal value.
      Specified by:
      getValueType in interface ITextFormatter
      Overrides:
      getValueType in class NumberFormatter
      Returns:
      The value type.
    • setPatterns

      protected void setPatterns​(java.lang.String edit, java.lang.String display, java.util.Locale loc)
      Sets the patterns and initializes the technical attributes used to manage the operations.

      Override the NumberFormatter implementation to handle large numbers.

      Overrides:
      setPatterns in class NumberFormatter
      Parameters:
      edit - edit pattern
      display - display pattern
      loc - Locale to use
      Throws:
      java.lang.IllegalArgumentException - if a pattern is invalid
      See Also:
      com.wdev91.comp4swt.core.NumberFormatter#setPatterns(java.lang.String, java.lang.String, java.util.Locale)