public abstract class AbstractSearchable extends Object implements Searchable
Modifier and Type | Class and Description |
---|---|
static class |
AbstractSearchable.SearchResult
A convenience class to hold search state.
|
Modifier and Type | Field and Description |
---|---|
protected AbstractSearchable.SearchResult |
lastSearchResult
stores the result of the previous search.
|
static String |
MATCH_HIGHLIGHTER
key for client property to use SearchHighlighter as match marker.
|
private AbstractHighlighter |
matchHighlighter |
Constructor and Description |
---|
AbstractSearchable() |
Modifier and Type | Method and Description |
---|---|
protected abstract void |
addHighlighter(Highlighter highlighter)
Adds the highlighter to the target.
|
protected int |
adjustStartPosition(int startIndex,
boolean backwards)
Called if
startIndex 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 AbstractHighlighter |
createMatchHighlighter()
Creates and returns the Highlighter used as match marker.
|
protected HighlightPredicate |
createMatchPredicate()
Creates and returns a HighlightPredicate appropriate for the current
search result.
|
protected AbstractSearchable.SearchResult |
createSearchResult(Matcher matcher,
int row,
int column)
Factory method to create a SearchResult from the given parameters.
|
protected int |
doSearch(Pattern pattern,
int startIndex,
boolean backwards)
Performs a search starting at the given startIndex
using the pattern;
Pattern . |
protected void |
ensureInsertedSearchHighlighters(Highlighter highlighter)
Ensure that the given Highlighter is the last in the list of
the highlighters registered on the target.
|
protected abstract AbstractSearchable.SearchResult |
findExtendedMatch(Pattern pattern,
int row)
Matches the cell at row/lastFoundColumn against the pattern.
|
protected abstract void |
findMatchAndUpdateState(Pattern pattern,
int startRow,
boolean backwards)
Loops through the searchable until a match is found or the
end is reached.
|
protected AbstractHighlighter |
getConfiguredMatchHighlighter()
Configures and returns the match highlighter for the current match.
|
protected abstract Highlighter[] |
getHighlighters()
Returns the highlighters registered on the search target.
|
protected AbstractHighlighter |
getMatchHighlighter()
Returns the Hihglighter to use as match marker, lazyly created if null.
|
protected abstract int |
getSize()
Returns the size of this searchable.
|
abstract JComponent |
getTarget()
It's the responsibility of subclasses to covariant override.
|
protected boolean |
hasMatch()
Returns a boolean indicating whether the current search result is a match.
|
private boolean |
hasMatch(AbstractSearchable.SearchResult result) |
protected boolean |
isEmpty(String searchString)
Checks if the searchString should be interpreted as empty.
|
protected boolean |
isEqualPattern(Pattern pattern)
Checks if the given Pattern should be considered as the same as
in a previous search.
|
protected boolean |
isEqualStartIndex(int startIndex)
Checks if the startIndex should be considered as the same as in
the previous search.
|
private boolean |
isInPipeline(Highlighter searchHighlighter)
Returns a flag indicating if the given highlighter is last in the
list of highlighters registered on the target.
|
protected boolean |
isTrivialNoMatch(Pattern pattern,
int startIndex)
Returns a boolean indicating if it can be trivially decided to not match.
|
protected boolean |
isValidIndex(int index)
Checks if index is in range: 0 <= index < getSize().
|
protected boolean |
markByHighlighter()
Returns a boolean indicating whether a match should be marked with a
Highlighter.
|
protected abstract void |
moveMatchMarker()
Moves the match marker according to current found state.
|
protected int |
moveStartPosition(int startIndex,
boolean backwards)
Moves the internal start position for matching as appropriate and returns
the new startIndex to use.
|
protected abstract void |
removeHighlighter(Highlighter searchHighlighter)
Removes the highlighter.
|
int |
search(Pattern pattern)
Performs a forward search starting at the beginning
across the Searchable using the pattern;
Pattern . |
int |
search(Pattern pattern,
int startIndex)
Performs a forward search starting at the given startIndex
using the Pattern;
Pattern . |
int |
search(Pattern pattern,
int startIndex,
boolean backwards)
Performs a search starting at the given startIndex
using the pattern;
Pattern . |
int |
search(String searchString)
Performs a forward search starting at the beginning
across the Searchable using String that represents a
regex pattern;
Pattern . |
int |
search(String searchString,
int startIndex)
Performs a forward search starting at the given startIndex
using String that represents a regex
pattern;
Pattern . |
int |
search(String searchString,
int startIndex,
boolean backward)
Performs a search starting at the given startIndex
using String that represents a regex
pattern;
Pattern . |
void |
setMatchHighlighter(AbstractHighlighter hl)
Sets the AbstractHighlighter to use as match marker, if enabled.
|
protected void |
updateState(AbstractSearchable.SearchResult searchResult)
Updates inner searchable state based on provided search result
|
protected final AbstractSearchable.SearchResult lastSearchResult
private AbstractHighlighter matchHighlighter
public static final String MATCH_HIGHLIGHTER
public AbstractSearchable()
public int search(String searchString)
Pattern
.search
in interface Searchable
searchString
- String
that we will try to locatepublic int search(String searchString, int startIndex)
Pattern
.search
in interface Searchable
searchString
- String
that we will try to locatestartIndex
- position in the document in the appropriate coordinates
from which we will start search or -1 to start from the beginningpublic int search(String searchString, int startIndex, boolean backward)
Pattern
. The search direction
depends on the boolean parameter: forward/backward if false/true, respectively.search
in interface Searchable
searchString
- String
that we will try to locatestartIndex
- position in the document in the appropriate coordinates
from which we will start search or -1 to start from the beginningbackward
- true
if we should perform search towards the beginningpublic int search(Pattern pattern)
Pattern
.search
in interface Searchable
pattern
- Pattern
that we will try to locatepublic int search(Pattern pattern, int startIndex)
Pattern
.search
in interface Searchable
pattern
- Pattern
that we will try to locatestartIndex
- position in the document in the appropriate coordinates
from which we will start search or -1 to start from the beginningpublic int search(Pattern pattern, int startIndex, boolean backwards)
Pattern
.
The search direction depends on the boolean parameter:
forward/backward if false/true, respectively.Updates visible and internal search state.
search
in interface Searchable
pattern
- Pattern
that we will try to locatestartIndex
- 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 beginningprotected int doSearch(Pattern pattern, int startIndex, boolean backwards)
Pattern
.
The search direction depends on the boolean parameter:
forward/backward if false/true, respectively.Updates internal search state.
pattern
- Pattern
that we will try to locatestartIndex
- 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 beginningprotected abstract void findMatchAndUpdateState(Pattern pattern, int startRow, boolean backwards)
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 beginningprotected boolean isTrivialNoMatch(Pattern pattern, int startIndex)
This implementation returns true if pattern is null or startIndex exceeds the upper size limit.
pattern
- Pattern
that we will try to locatestartIndex
- position in the document in the appropriate coordinates
from which we will start search or -1 to start from the beginningprotected int adjustStartPosition(int startIndex, boolean backwards)
startIndex
is different from last search
and make sure a backwards/forwards search starts at last/first row,
respectively.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 beginningstartIndex
protected int moveStartPosition(int startIndex, boolean backwards)
This implementation returns a by 1 decremented/incremented startIndex depending on backwards true/false, respectively.
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 towards the beginningstartIndex
protected boolean isEqualPattern(Pattern pattern)
This implementation compares the patterns' regex.
pattern
- Pattern
that we will compare with last requestPattern
is the same as the stored from
the previous search attemptprotected boolean isEqualStartIndex(int startIndex)
startIndex
- startIndex
that we will compare with the index
stored by the previous search requestprotected boolean isEmpty(String searchString)
This implementation returns true if string is null or has zero length.
searchString
- String
that we should evaluateString
should be interpreted as emptyprotected abstract AbstractSearchable.SearchResult findExtendedMatch(Pattern pattern, int row)
pattern
- Pattern
that we will try to matchrow
- position at which we will get the value to match with the provided Pattern
AbstractSearchable.SearchResult
protected AbstractSearchable.SearchResult createSearchResult(Matcher matcher, int row, int column)
matcher
- the matcher after a successful find. Must not be null.row
- the found indexcolumn
- the found columnSearchResult
protected boolean isValidIndex(int index)
index
- possible start position that we will check for validitytrue
if given parameter is valid indexprotected abstract int getSize()
protected void updateState(AbstractSearchable.SearchResult searchResult)
searchResult
- SearchResult
that represents the new state
of this AbstractSearchable
protected abstract void moveMatchMarker()
public abstract JComponent getTarget()
protected abstract void removeHighlighter(Highlighter searchHighlighter)
searchHighlighter
- the Highlighter to remove.protected abstract Highlighter[] getHighlighters()
protected abstract void addHighlighter(Highlighter highlighter)
highlighter
- the Highlighter to add.protected void ensureInsertedSearchHighlighters(Highlighter highlighter)
highlighter
- the Highlighter to be inserted as last.private boolean isInPipeline(Highlighter searchHighlighter)
searchHighlighter
- the highlighter to check for being lastprotected int convertColumnIndexToModel(int viewColumn)
This implementation returns the view coordinate, that is assumes that both coordinate systems are the same.
viewColumn
- the column index in view coordinates, must be a valid index
in that system.private boolean hasMatch(AbstractSearchable.SearchResult result)
result
- true
if the result
contains a match;
false
otherwiseprotected boolean hasMatch()
PENDING JW: move to SearchResult?
protected boolean markByHighlighter()
This implementation returns true if the target component has a client property for key MATCH_HIGHLIGHTER with value Boolean.TRUE, false otherwise. The SearchFactory sets that client property in incremental search mode, that is when triggering a search via the JXFindBar as installed by the factory.
SearchFactory
public void setMatchHighlighter(AbstractHighlighter hl)
hl
- the Highlighter to use as match marker.protected AbstractHighlighter getMatchHighlighter()
protected AbstractHighlighter createMatchHighlighter()
protected AbstractHighlighter getConfiguredMatchHighlighter()
protected HighlightPredicate createMatchPredicate()
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses