Class AutoLookup

  • Direct Known Subclasses:
    GListAutoLookup, GTableAutoLookup

    public abstract class AutoLookup
    extends java.lang.Object
    A class that holds the logic and state for finding matching rows in a widget when a user types in the widget. This class was designed for row-based widgets, such as tables and lists.
    • Constructor Summary

      Constructors 
      Constructor Description
      AutoLookup()  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected boolean canBinarySearchColumn​(int column)
      A method that subclasses can override to affect whether this class uses a binary search for a particular column
      abstract int getCurrentRow()
      Returns the currently selected row
      abstract int getRowCount()
      Returns the total number of rows
      abstract java.lang.String getValueString​(int row, int col)
      Returns a string representation of the item at the given row and column.
      abstract boolean isSorted​(int column)
      Returns true if the given column is sorted.
      abstract boolean isSortedAscending()
      Returns true if the currently sorted column is sorted ascending.
      void keyTyped​(java.awt.event.KeyEvent e)
      Clients call this method when the user types keys
      abstract void matchFound​(int row)
      This method will be called when a match for the call to keyTyped(KeyEvent) is found
      void setColumn​(int column)
      Sets the column that is searched when a lookup is performed
      void setTimeout​(long timeout)
      Sets the delay between keystrokes after which each keystroke is considered a new lookup
      void setTimeoutPredicate​(java.util.function.Predicate<java.lang.Long> p)
      Sets the logic for deciding whether the elapsed time between keystrokes is enough to trigger a new auto lookup or to continue with the previous match.
      • Methods inherited from class java.lang.Object

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

      • AutoLookup

        public AutoLookup()
    • Method Detail

      • getCurrentRow

        public abstract int getCurrentRow()
        Returns the currently selected row
        Returns:
        the row
      • getRowCount

        public abstract int getRowCount()
        Returns the total number of rows
        Returns:
        the row count
      • getValueString

        public abstract java.lang.String getValueString​(int row,
                                                        int col)
        Returns a string representation of the item at the given row and column. The text should match what the user sees.
        Parameters:
        row - the row
        col - the column
        Returns:
        the text
      • isSorted

        public abstract boolean isSorted​(int column)
        Returns true if the given column is sorted. This class will use a binary search if the given column is sorted. Otherwise, a brute-force search will be used.
        Parameters:
        column - the column
        Returns:
        true if sorted
      • canBinarySearchColumn

        protected boolean canBinarySearchColumn​(int column)
        A method that subclasses can override to affect whether this class uses a binary search for a particular column
        Parameters:
        column - the column
        Returns:
        true if the binary search algorithm will work on the given column
      • isSortedAscending

        public abstract boolean isSortedAscending()
        Returns true if the currently sorted column is sorted ascending. This is used in conjunction with isSorted(int). If that method returns false, then this method will not be called.
        Returns:
        true if sorted ascending
      • matchFound

        public abstract void matchFound​(int row)
        This method will be called when a match for the call to keyTyped(KeyEvent) is found
        Parameters:
        row - the matching row
      • setTimeout

        public void setTimeout​(long timeout)
        Sets the delay between keystrokes after which each keystroke is considered a new lookup
        Parameters:
        timeout - the timeout
      • setColumn

        public void setColumn​(int column)
        Sets the column that is searched when a lookup is performed
        Parameters:
        column - the column
      • setTimeoutPredicate

        public void setTimeoutPredicate​(java.util.function.Predicate<java.lang.Long> p)
        Sets the logic for deciding whether the elapsed time between keystrokes is enough to trigger a new auto lookup or to continue with the previous match.

        This method is intended for tests that need precise control over the timeout mechanism.

        Parameters:
        p - the predicate that takes the amount of elapsed time
        See Also:
        setTimeout(long)
      • keyTyped

        public void keyTyped​(java.awt.event.KeyEvent e)
        Clients call this method when the user types keys
        Parameters:
        e - the key event