Class PercentFormatter

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

public class PercentFormatter
extends NumberFormatter
Formatter for percent values.

This formatter extends the NumberFormatter : - add the percent symbol in the suffix area. - convert the number value in a percent : multiply by 100 on setValue() and divide by 100 on getValue().

  • Constructor Details

    • PercentFormatter

      public PercentFormatter()
      Constructs a new instance with all defaults :
      • edit mask from NumberPatterns for the default locale
      • display mask identical to the edit mask
      • default locale
    • PercentFormatter

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

      public PercentFormatter​(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 - edit mask
      loc - locale
    • PercentFormatter

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

      public PercentFormatter​(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 - edit mask
      displayPattern - display mask
    • PercentFormatter

      public PercentFormatter​(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 - edit mask
  • Method Details

    • getValue

      public java.lang.Object getValue()
      Returns the current value of the text control if it is a valid Number. 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 number value if valid, null else
      See Also:
      ITextFormatter.getValue()
    • 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 add the percent symbol to the masks.

      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)
    • setValue

      public void setValue​(java.lang.Object value)
      Sets the value to edit. The value provided must be a Number. The value provided is multiplied by 100.
      Specified by:
      setValue in interface ITextFormatter
      Overrides:
      setValue in class NumberFormatter
      Parameters:
      value - number value
      Throws:
      java.lang.IllegalArgumentException - if not a number
      See Also:
      ITextFormatter.setValue(java.lang.Object)