Package docking.widgets
Class AutoLookup
- java.lang.Object
-
- docking.widgets.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.
-
-
Field Summary
Fields Modifier and Type Field Description static long
KEY_TYPING_TIMEOUT
-
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 columnabstract int
getCurrentRow()
Returns the currently selected rowabstract int
getRowCount()
Returns the total number of rowsabstract 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 keysabstract void
matchFound(int row)
This method will be called when a match for the call tokeyTyped(KeyEvent)
is foundvoid
setColumn(int column)
Sets the column that is searched when a lookup is performedvoid
setTimeout(long timeout)
Sets the delay between keystrokes after which each keystroke is considered a new lookupvoid
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.
-
-
-
Field Detail
-
KEY_TYPING_TIMEOUT
public static final long KEY_TYPING_TIMEOUT
- See Also:
- Constant Field Values
-
-
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 rowcol
- 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 withisSorted(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 tokeyTyped(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
-
-