Class IPAddressFormatter
java.lang.Object
org.eclipse.nebula.widgets.formattedtext.AbstractFormatter
org.eclipse.nebula.widgets.formattedtext.IPAddressFormatter
- All Implemented Interfaces:
java.util.EventListener
,ITextFormatter
,org.eclipse.swt.events.VerifyListener
,org.eclipse.swt.internal.SWTEventListener
public class IPAddressFormatter extends AbstractFormatter
-
Field Summary
Fields Modifier and Type Field Description protected org.eclipse.swt.widgets.Listener
keyListener
Key listenerFields inherited from class org.eclipse.nebula.widgets.formattedtext.AbstractFormatter
EMPTY, ignore, SPACE, text
-
Constructor Summary
Constructors Constructor Description IPAddressFormatter()
An empty constructer.
An ip address will have an unique format,so there is no necessary to offer an new format -
Method Summary
Modifier and Type Method Description void
detach()
Called when the formatter is replaced by an other one in theFormattedText
control.java.lang.String
getDisplayString()
Returns the current value formatted for display.java.lang.String
getEditString()
Returns the current value formatted for input.java.lang.Object
getValue()
Returns the current value of the text control if it is a valid ip address.
If invalid, returnsnull
.java.lang.Class<java.lang.String>
getValueType()
Returns the type of value thisITextFormatter
handles, i.e. returns inITextFormatter.getValue()
.boolean
isEmpty()
Returnstrue
if current edited value is empty, else returnsfalse
.boolean
isValid()
Returnstrue
if current edited value is valid, else returnsfalse
.void
setText(org.eclipse.swt.widgets.Text text)
Sets theText
widget that will be managed by this formatter.void
setValue(java.lang.Object value)
Sets the value to edit.void
verifyText(org.eclipse.swt.events.VerifyEvent e)
Methods inherited from class org.eclipse.nebula.widgets.formattedtext.AbstractFormatter
beep, setIgnore, updateText, updateText
-
Field Details
-
keyListener
protected org.eclipse.swt.widgets.Listener keyListenerKey listener
-
-
Constructor Details
-
IPAddressFormatter
public IPAddressFormatter()An empty constructer.
An ip address will have an unique format,so there is no necessary to offer an new format
-
-
Method Details
-
detach
public void detach()Called when the formatter is replaced by an other one in theFormattedText
control. Allow to release ressources like additionnal listeners.Removes the
KeyListener
on the text widget.- Specified by:
detach
in interfaceITextFormatter
- Overrides:
detach
in classAbstractFormatter
- See Also:
ITextFormatter.detach()
-
setText
public void setText(org.eclipse.swt.widgets.Text text)Sets theText
widget that will be managed by this formatter.The ancestor is overrided to add a key listener on the text widget.
- Specified by:
setText
in interfaceITextFormatter
- Overrides:
setText
in classAbstractFormatter
- Parameters:
text
- Text widget- See Also:
ITextFormatter.setText(Text)
-
getDisplayString
public java.lang.String getDisplayString()Returns the current value formatted for display. This method is called byFormattedText
when theText
widget looses focus. In case the input is invalid (eg. not an invalid ip address), the edit string is returned in place of the display string.- Returns:
- display string if valid, edit string else
- See Also:
ITextFormatter.getDisplayString()
-
getEditString
public java.lang.String getEditString()Returns the current value formatted for input. This method is called byFormattedText
when theText
widget gains focus. The value returned is the content of the StringBuilder used as cache.- Returns:
- edit string
- See Also:
ITextFormatter.getEditString()
-
getValue
public java.lang.Object getValue()Returns the current value of the text control if it is a valid ip address.
If invalid, returnsnull
.- Returns:
- current ip address if valid in which the spaces has been removed,
null
else - See Also:
ITextFormatter.getValue()
-
isValid
public boolean isValid()Returnstrue
if current edited value is valid, else returnsfalse
.- 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 valid ip address in String format.- Parameters:
value
- new ip address- Throws:
java.lang.IllegalArgumentException
- if not an invalid ip- See Also:
ITextFormatter.setValue(java.lang.Object)
-
verifyText
public void verifyText(org.eclipse.swt.events.VerifyEvent e) -
getValueType
public java.lang.Class<java.lang.String> getValueType()Description copied from interface:ITextFormatter
Returns the type of value thisITextFormatter
handles, i.e. returns inITextFormatter.getValue()
.- Returns:
- The value type.
-
isEmpty
public boolean isEmpty()Description copied from interface:ITextFormatter
Returnstrue
if current edited value is empty, else returnsfalse
. An empty value depends of the formatter and is not just an empty string in the Text widget.- Returns:
- true if empty, else false
-