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
All other characters are considered as separators.
String values in a
FormattedText.
Pattern Characters
| Symbol | Meaning |
|---|---|
# |
Digit |
A |
Alphanumeric |
U |
Alphanumeric converted in uppercase |
L |
Alphanumeric converted in lowercase |
Examples
newFormatter("(###) UUU-AAAA");setValue("123aBcDeF"); -> will display as "(123) ABC-DeF".-
Field Summary
Fields Modifier and Type Field Description protected intcountCurrent number of characters in the buffer (except mask characters)protected java.lang.StringeditPatternEdit maskprotected java.lang.StringBuffereditValueBuffer for the edit valueprotected intpositionsNumber of editable positions in the maskFields 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 voidclearText(int start, int len)Clear a part of the edition cache.java.lang.StringgetDisplayString()Returns the current value formatted for display.java.lang.StringgetEditString()Returns the current value formatted for editing.java.lang.ObjectgetValue()Returns the current value.java.lang.Class<java.lang.String>getValueType()Returns the type of value thisITextFormatterhandles, i.e.protected intinsertText(java.lang.String txt, int start)Inserts a sequence of characters in the edit buffer.booleanisEmpty()Returnstrueif current edited value is empty, else returnsfalse.
A value is considered as empty in a MaskFormatter if the edit buffer contains no characters except the mask characters.protected booleanisHexDigit(char ch)booleanisValid()Returnstrueif current edited value is valid, else returnsfalse.voidsetValue(java.lang.Object value)Sets the value to edit.voidverifyText(org.eclipse.swt.events.VerifyEvent e)Handles aVerifyEventsent when the text is about to be modified.Methods inherited from class org.eclipse.nebula.widgets.formattedtext.AbstractFormatter
beep, detach, setIgnore, setText, updateText, updateText
-
Field Details
-
editPattern
protected java.lang.String editPatternEdit mask -
editValue
protected java.lang.StringBuffer editValueBuffer for the edit value -
positions
protected int positionsNumber of editable positions in the mask -
count
protected int countCurrent 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 indexlen- 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 byFormattedTextwhen theTextwidget gains focus. The value returned is the content of the StringBuildereditValueused 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 thisITextFormatterhandles, i.e. returns ingetValue().
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 insertstart- Starting position of insertion- Returns:
- New position of the cursor
-
isEmpty
public boolean isEmpty()Returnstrueif current edited value is empty, else returnsfalse.
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()Returnstrueif current edited value is valid, else returnsfalse. 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 aString.- 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 aVerifyEventsent 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)
-