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 int
count
Current number of characters in the buffer (except mask characters)protected java.lang.String
editPattern
Edit maskprotected java.lang.StringBuffer
editValue
Buffer for the edit valueprotected int
positions
Number 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 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 thisITextFormatter
handles, i.e.protected int
insertText(java.lang.String txt, int start)
Inserts a sequence of characters in the edit buffer.boolean
isEmpty()
Returnstrue
if 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 boolean
isHexDigit(char ch)
boolean
isValid()
Returnstrue
if current edited value is valid, else returnsfalse
.void
setValue(java.lang.Object value)
Sets the value to edit.void
verifyText(org.eclipse.swt.events.VerifyEvent e)
Handles aVerifyEvent
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
-
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 byFormattedText
when theText
widget gains focus. The value returned is the content of the StringBuildereditValue
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 thisITextFormatter
handles, 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()Returnstrue
if 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()Returnstrue
if 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 aVerifyEvent
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)
-