Class TextFieldLinker.LinkerState

  • Enclosing class:
    TextFieldLinker

    protected class TextFieldLinker.LinkerState
    extends java.lang.Object
    A class to track the internal state gathered from the text fields
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected LinkerState()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      TextFieldLinker.LinkerState copy()
      Copy the state
      boolean equals​(java.lang.Object o)  
      int getGlobalCaret()
      Get the composite caret location
      int getGlobalCaret​(int omitSep)
      Get the composite caret location, omitting the given separator.
      java.lang.String getText()
      Get the whole composite string
      java.lang.String getText​(int omitSep)
      Get the composite string, omitting the given separator.
      java.lang.String getTextBeforeCursor​(int field)
      Get the composite text preceding the caret in the given field
      boolean isAfterSep​(int field)
      Figure out whether the caret in the given field immediately proceeds a separator.
      boolean isBeforeSep​(int field)
      Figure out whether the caret in the given field immediately precedes a separator.
      void navigateFieldLeft​(int field)
      Change focus to the given field as if navigating left.
      void navigateFieldRight​(int field)
      Change focus to the given field as if navigating right.
      void reformat()
      Re-parse the composite string and place the components into their proper fields
      protected void removeSep​(int sep)
      Remove the given separator from the composite text.
      void reset()
      Erase the state Blank all the fields, and put the caret at the front of the first field.
      void setGlobalCaret​(int caret)
      Set the composite caret location
      int setText​(java.lang.String text)
      Set the composite text
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • LinkerState

        protected LinkerState()
    • Method Detail

      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • reset

        public void reset()
        Erase the state Blank all the fields, and put the caret at the front of the first field.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getText

        public java.lang.String getText()
        Get the whole composite string
        Returns:
        the text
      • getText

        public java.lang.String getText​(int omitSep)
        Get the composite string, omitting the given separator. This is used as a helper to delete the separator when backspace/delete is pressed at a boundary.
        Parameters:
        omitSep - the separator to omit, or -1 to omit nothing
        Returns:
        the text
      • getGlobalCaret

        public int getGlobalCaret()
        Get the composite caret location
        Returns:
        the location (including separators)
      • getGlobalCaret

        public int getGlobalCaret​(int omitSep)
        Get the composite caret location, omitting the given separator.
        Parameters:
        omitSep - the separator to omit, or -1 to omit nothing
        Returns:
        the location
      • getTextBeforeCursor

        public java.lang.String getTextBeforeCursor​(int field)
        Get the composite text preceding the caret in the given field
        Parameters:
        field - the field whose caret to use
        Returns:
        the text
      • isAfterSep

        public boolean isAfterSep​(int field)
        Figure out whether the caret in the given field immediately proceeds a separator. In other words, the caret must be to the far left (position 0), and the given field must not be the first field. If true, the caret immediately follows separator index field - 1.
        Parameters:
        field - the field index to check
        Returns:
        true if the caret immediately follows a separator.
      • isBeforeSep

        public boolean isBeforeSep​(int field)
        Figure out whether the caret in the given field immediately precedes a separator. In other words, the caret must be to the far right, and the given field must not be the last field. If true, the caret immediately precedes separator index field.
        Parameters:
        field - the field index to check
        Returns:
        true if the caret immediately precedes a separator.
      • navigateFieldLeft

        public void navigateFieldLeft​(int field)
        Change focus to the given field as if navigating left. The caret will be moved to the rightmost position, because we're moving left from the leftmost position of the field to the right.
        Parameters:
        field - the field index to be given focus.
      • navigateFieldRight

        public void navigateFieldRight​(int field)
        Change focus to the given field as if navigating right. The caret will be moved to the leftmost position, because we're moving right from the rightmost position of the field to the left.
        Parameters:
        field - the field index to be given focus.
      • removeSep

        protected void removeSep​(int sep)
        Remove the given separator from the composite text.
        Parameters:
        sep - the separator to remove, by index
      • setText

        public int setText​(java.lang.String text)
        Set the composite text
        Parameters:
        text - the new text
      • setGlobalCaret

        public void setGlobalCaret​(int caret)
                            throws javax.swing.text.BadLocationException
        Set the composite caret location
        Parameters:
        caret - the new caret location
        Throws:
        javax.swing.text.BadLocationException - if the location exceeds the text length
      • reformat

        public void reformat()
        Re-parse the composite string and place the components into their proper fields