Class MaskFormatter

java.lang.Object
org.eclipse.nebula.widgets.formattedtext.AbstractFormatter
org.eclipse.nebula.widgets.formattedtext.MaskFormatter
All Implemented Interfaces:
java.util.EventListener, ITextFormatter, org.eclipse.swt.events.VerifyListener, org.eclipse.swt.internal.SWTEventListener

public class MaskFormatter
extends AbstractFormatter
This class provides formatting of String values in a FormattedText.

Pattern Characters

Symbol Meaning
# Digit
A Alphanumeric
U Alphanumeric converted in uppercase
L Alphanumeric converted in lowercase
All other characters are considered as separators.

Examples

newFormatter("(###) UUU-AAAA");
setValue("123aBcDeF"); -> will display as "(123) ABC-DeF".
  • Field Summary

    Fields 
    Modifier and Type Field Description
    protected int count
    Current number of characters in the buffer (except mask characters)
    protected java.lang.String editPattern
    Edit mask
    protected java.lang.StringBuffer editValue
    Buffer for the edit value
    protected int positions
    Number of editable positions in the mask

    Fields inherited from class org.eclipse.nebula.widgets.formattedtext.AbstractFormatter

    EMPTY, ignore, SPACE, text
  • Constructor Summary

    Constructors 
    Constructor Description
    MaskFormatter​(java.lang.String editPattern)
    Constructs a new instance with the given edit mask.
  • Method Summary

    Modifier and Type Method Description
    protected void clearText​(int start, int len)
    Clear a part of the edition cache.
    java.lang.String getDisplayString()
    Returns the current value formatted for display.
    java.lang.String getEditString()
    Returns the current value formatted for editing.
    java.lang.Object getValue()
    Returns the current value.
    java.lang.Class<java.lang.String> getValueType()
    Returns the type of value this ITextFormatter handles, i.e.
    protected int insertText​(java.lang.String txt, int start)
    Inserts a sequence of characters in the edit buffer.
    boolean isEmpty()
    Returns true if current edited value is empty, else returns false.
    A value is considered as empty in a MaskFormatter if the edit buffer contains no characters except the mask characters.
    protected boolean isHexDigit​(char ch)  
    boolean isValid()
    Returns true if current edited value is valid, else returns false.
    void setValue​(java.lang.Object value)
    Sets the value to edit.
    void verifyText​(org.eclipse.swt.events.VerifyEvent e)
    Handles a VerifyEvent sent when the text is about to be modified.

    Methods inherited from class org.eclipse.nebula.widgets.formattedtext.AbstractFormatter

    beep, detach, setIgnore, setText, updateText, updateText

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • editPattern

      protected java.lang.String editPattern
      Edit mask
    • editValue

      protected java.lang.StringBuffer editValue
      Buffer for the edit value
    • positions

      protected int positions
      Number of editable positions in the mask
    • count

      protected int count
      Current number of characters in the buffer (except mask characters)
  • Constructor Details

    • MaskFormatter

      public MaskFormatter​(java.lang.String editPattern)
      Constructs a new instance with the given edit mask.
      Parameters:
      editPattern - edit mask
  • Method Details

    • clearText

      protected void clearText​(int start, int len)
      Clear a part of the edition cache. Mask characters are preserved in their positions.
      Parameters:
      start - beginning index
      len - length of portion to clear
    • getDisplayString

      public java.lang.String getDisplayString()
      Returns the current value formatted for display.

      There is no difference in this formatter between edit and display values. So this method returns the edit string.

      Returns:
      display string
      See Also:
      ITextFormatter.getDisplayString()
    • getEditString

      public java.lang.String getEditString()
      Returns the current value formatted for editing. This method is called by FormattedText when the Text widget gains focus. The value returned is the content of the StringBuilder editValue used as cache.
      Returns:
      edit string
      See Also:
      ITextFormatter.getEditString()
    • getValue

      public java.lang.Object getValue()
      Returns the current value. The value returned is the content of the edit cache without any mask characters.
      Returns:
      current string value
      See Also:
      ITextFormatter.getValue()
    • getValueType

      public java.lang.Class<java.lang.String> getValueType()
      Returns the type of value this ITextFormatter handles, i.e. returns in getValue().
      A MaskFormatter always returns a String value.
      Returns:
      The value type.
    • insertText

      protected int insertText​(java.lang.String txt, int start)
      Inserts a sequence of characters in the edit buffer. The current content of the buffer is override. The new position of the cursor is computed and returned. Mask characters are preserved in their positions.
      Parameters:
      txt - String of characters to insert
      start - Starting position of insertion
      Returns:
      New position of the cursor
    • isEmpty

      public boolean isEmpty()
      Returns true if current edited value is empty, else returns false.
      A value is considered as empty in a MaskFormatter if the edit buffer contains no characters except the mask characters.
      Returns:
      true if empty, else false
    • isValid

      public boolean isValid()
      Returns true if current edited value is valid, else returns false. An empty value is considered as valid.
      Returns:
      true if valid, else false
      See Also:
      ITextFormatter.isValid()
    • setValue

      public void setValue​(java.lang.Object value)
      Sets the value to edit. The value provided must be a String.
      Parameters:
      value - string value
      Throws:
      java.lang.IllegalArgumentException - if not a string
      See Also:
      ITextFormatter.setValue(java.lang.Object)
    • verifyText

      public void verifyText​(org.eclipse.swt.events.VerifyEvent e)
      Handles a VerifyEvent sent when the text is about to be modified. This method is the entry point of all operations of formatting.
      See Also:
      VerifyListener.verifyText(org.eclipse.swt.events.VerifyEvent)
    • isHexDigit

      protected boolean isHexDigit​(char ch)