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 listener

    Fields 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 the FormattedText 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, returns null.
    java.lang.Class<java.lang.String> getValueType()
    Returns the type of value this ITextFormatter handles, i.e. returns in ITextFormatter.getValue().
    boolean isEmpty()
    Returns true if current edited value is empty, else returns false.
    boolean isValid()
    Returns true if current edited value is valid, else returns false.
    void setText​(org.eclipse.swt.widgets.Text text)
    Sets the Text 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

    Methods inherited from class java.lang.Object

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

    • keyListener

      protected org.eclipse.swt.widgets.Listener keyListener
      Key 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 the FormattedText control. Allow to release ressources like additionnal listeners.

      Removes the KeyListener on the text widget.

      Specified by:
      detach in interface ITextFormatter
      Overrides:
      detach in class AbstractFormatter
      See Also:
      ITextFormatter.detach()
    • setText

      public void setText​(org.eclipse.swt.widgets.Text text)
      Sets the Text 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 interface ITextFormatter
      Overrides:
      setText in class AbstractFormatter
      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 by FormattedText when the Text 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 by FormattedText when the Text 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, returns null.
      Returns:
      current ip address if valid in which the spaces has been removed, null else
      See Also:
      ITextFormatter.getValue()
    • isValid

      public boolean isValid()
      Returns true if current edited value is valid, else returns false.
      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 this ITextFormatter handles, i.e. returns in ITextFormatter.getValue().
      Returns:
      The value type.
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: ITextFormatter
      Returns true if current edited value is empty, else returns false. An empty value depends of the formatter and is not just an empty string in the Text widget.
      Returns:
      true if empty, else false