Package docking.widgets
Class AutoLookup
java.lang.Object
docking.widgets.AutoLookup
- Direct Known Subclasses:
GListAutoLookup
,GTableAutoLookup
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
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
canBinarySearchColumn
(int column) A method that subclasses can override to affect whether this class uses a binary search for a particular columnabstract int
Returns the currently selected rowabstract int
Returns the total number of rowsabstract 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
Returns true if the currently sorted column is sorted ascending.void
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
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 Details
-
KEY_TYPING_TIMEOUT
public static final long KEY_TYPING_TIMEOUT- See Also:
-
-
Constructor Details
-
AutoLookup
public AutoLookup()
-
-
Method Details
-
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
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
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:
-
keyTyped
Clients call this method when the user types keys- Parameters:
e
- the key event
-