Class TableSearchable
- All Implemented Interfaces:
Searchable
- Author:
- Jeanette Winzenburg, EUG https://github.com/homebeaver (use in JXTreeTable)
-
Nested Class Summary
Nested classes/interfaces inherited from class org.jdesktop.swingx.search.AbstractSearchable
AbstractSearchable.SearchResult
-
Field Summary
FieldsFields inherited from class org.jdesktop.swingx.search.AbstractSearchable
lastSearchResult, MATCH_HIGHLIGHTER
-
Constructor Summary
ConstructorsConstructorDescriptionTableSearchable
(JXTable table) Instantiates a TableSearchable with the given table as target. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addHighlighter
(Highlighter highlighter) Adds the highlighter to the target.protected int
adjustStartPosition
(int startIndex, boolean backwards) Called ifstartIndex
is different from last search and make sure a backwards/forwards search starts at last/first row, respectively.protected int
convertColumnIndexToModel
(int viewColumn) Converts and returns the given column index from view coordinates to model coordinates.protected AbstractSearchable.SearchResult
findExtendedMatch
(Pattern pattern, int row) Matches the cell at row/lastFoundColumn against the pattern.protected void
findMatchAndUpdateState
(Pattern pattern, int startRow, boolean backwards) Loops through the searchable until a match is found or the end is reached.protected AbstractSearchable.SearchResult
findMatchAt
(Pattern pattern, int row, int column) Matches the cell content at row/col against the given Pattern.protected Highlighter[]
Returns the highlighters registered on the search target.protected int
getSize()
Returns the size of this searchable.It's the responsibility of subclasses to covariant override.protected boolean
isEqualStartIndex
(int startIndex) Checks if the startIndex should be considered as the same as in the previous search.protected void
Configures the match highlighter to the current match.protected void
Moves the row selection to the matching cell and ensures its visibility, if any.protected void
Moves the match marker according to current found state.protected int
moveStartPosition
(int startRow, boolean backwards) Moves the internal start position for matching as appropriate and returns the new startIndex to use.protected void
removeHighlighter
(Highlighter searchHighlighter) Removes the highlighter.Methods inherited from class org.jdesktop.swingx.search.AbstractSearchable
createMatchHighlighter, createMatchPredicate, createSearchResult, doSearch, ensureInsertedSearchHighlighters, getConfiguredMatchHighlighter, getMatchHighlighter, hasMatch, isEmpty, isEqualPattern, isTrivialNoMatch, isValidIndex, markByHighlighter, search, search, search, search, search, search, setMatchHighlighter, updateState
-
Field Details
-
table
The target JXTable.
-
-
Constructor Details
-
TableSearchable
Instantiates a TableSearchable with the given table as target.- Parameters:
table
- the JXTable to search.
-
-
Method Details
-
findMatchAndUpdateState
Loops through the searchable until a match is found or the end is reached. Updates internal search state.This implementation loops through the cells in a row to find a match.
- Specified by:
findMatchAndUpdateState
in classAbstractSearchable
- Parameters:
pattern
-Pattern
that we will try to locatestartRow
- position in the document in the appropriate coordinates from which we will start search or -1 to start from the beginningbackwards
-true
if we should perform search towards the beginning
-
findExtendedMatch
Matches the cell at row/lastFoundColumn against the pattern. Called if sameRowIndex && !hasEqualRegEx. PRE: lastFoundColumn valid.Implemented to search for an extension in the cell given by row and foundColumn.
- Specified by:
findExtendedMatch
in classAbstractSearchable
- Parameters:
pattern
-Pattern
that we will try to matchrow
- position at which we will get the value to match with the providedPattern
- Returns:
- result of the match;
AbstractSearchable.SearchResult
-
findMatchAt
Matches the cell content at row/col against the given Pattern. Returns an appropriate SearchResult if matching or null if no matching- Parameters:
pattern
-Pattern
that we will try to locaterow
- a valid row index in view coordinatescolumn
- a valid column index in view coordinates- Returns:
- an appropriate
SearchResult
if matching or null
-
adjustStartPosition
protected int adjustStartPosition(int startIndex, boolean backwards) Called ifstartIndex
is different from last search and make sure a backwards/forwards search starts at last/first row, respectively.Overridden to adjust the column index to -1.
- Overrides:
adjustStartPosition
in classAbstractSearchable
- Parameters:
startIndex
- position in the document in the appropriate coordinates from which we will start search or -1 to start from the beginningbackwards
-true
if we should perform search from towards the beginning- Returns:
- adjusted
startIndex
-
moveStartPosition
protected int moveStartPosition(int startRow, boolean backwards) Moves the internal start position for matching as appropriate and returns the new startIndex to use. Called if search was messaged with the same startIndex as previously.This implementation returns a by 1 decremented/incremented startIndex depending on backwards true/false, respectively.
Overridden to loop through all columns in a row.
- Overrides:
moveStartPosition
in classAbstractSearchable
- Parameters:
startRow
- position in the document in the appropriate coordinates from which we will start search or -1 to start from the beginningbackwards
-true
if we should perform search towards the beginning- Returns:
- adjusted
startIndex
-
isEqualStartIndex
protected boolean isEqualStartIndex(int startIndex) Checks if the startIndex should be considered as the same as in the previous search.Overridden to check the column index of last find.
- Overrides:
isEqualStartIndex
in classAbstractSearchable
- Parameters:
startIndex
-startIndex
that we will compare with the index stored by the previous search request- Returns:
- true if the startIndex should be re-matched, false if not.
-
getSize
protected int getSize()Returns the size of this searchable.- Specified by:
getSize
in classAbstractSearchable
- Returns:
- size of this searchable
-
getTarget
It's the responsibility of subclasses to covariant override.- Specified by:
getTarget
in classAbstractSearchable
- Returns:
- the target component
-
moveMatchByHighlighter
protected void moveMatchByHighlighter()Configures the match highlighter to the current match. Ensures that the matched cell is visible, if there is a match. PRE: markByHighlighter -
convertColumnIndexToModel
protected int convertColumnIndexToModel(int viewColumn) Converts and returns the given column index from view coordinates to model coordinates.This implementation returns the view coordinate, that is assumes that both coordinate systems are the same.
Overridden to convert the column index in the table's view coordinate system to model coordinate.
PENDING JW: this is only necessary because the SearchPredicate wants its highlight column in model coordinates. But code comments in the SearchPredicate seem to indicate that we probably want to revise that (legacy?).
- Overrides:
convertColumnIndexToModel
in classAbstractSearchable
- Parameters:
viewColumn
- the column index in view coordinates, must be a valid index in that system.- Returns:
- the column index in model coordinates.
-
moveMatchBySelection
protected void moveMatchBySelection()Moves the row selection to the matching cell and ensures its visibility, if any. Does nothing if there is no match. -
moveMatchMarker
protected void moveMatchMarker()Moves the match marker according to current found state.- Specified by:
moveMatchMarker
in classAbstractSearchable
-
removeHighlighter
Removes the highlighter.- Specified by:
removeHighlighter
in classAbstractSearchable
- Parameters:
searchHighlighter
- the Highlighter to remove.
-
getHighlighters
Returns the highlighters registered on the search target.- Specified by:
getHighlighters
in classAbstractSearchable
- Returns:
- all registered highlighters
-
addHighlighter
Adds the highlighter to the target.- Specified by:
addHighlighter
in classAbstractSearchable
- Parameters:
highlighter
- the Highlighter to add.
-