org.jdesktop.swingx.search
Class AbstractSearchable

java.lang.Object
  extended by org.jdesktop.swingx.search.AbstractSearchable
All Implemented Interfaces:
Searchable
Direct Known Subclasses:
ListSearchable, TableSearchable, TreeSearchable

public abstract class AbstractSearchable
extends java.lang.Object
implements Searchable

An abstract implementation of Searchable supporting incremental search. Keeps internal state to represent the previous search result. For all methods taking a String as parameter: compiles the String to a Pattern as-is and routes to the central method taking a Pattern.

Author:
Jeanette Winzenburg

Nested Class Summary
static class AbstractSearchable.SearchResult
          A convenience class to hold search state.
 
Field Summary
static java.lang.String MATCH_HIGHLIGHTER
          key for client property to use SearchHighlighter as match marker.
 
Constructor Summary
AbstractSearchable()
           
 
Method Summary
abstract  javax.swing.JComponent getTarget()
          It's the responsibility of subclasses to covariant override.
 int search(java.util.regex.Pattern pattern)
          Performs a forward search starting at the beginning across the Searchable using the pattern; Pattern.
 int search(java.util.regex.Pattern pattern, int startIndex)
          Performs a forward search starting at the given startIndex using the Pattern; Pattern.
 int search(java.util.regex.Pattern pattern, int startIndex, boolean backwards)
          Performs a search starting at the given startIndex using the pattern; Pattern.
 int search(java.lang.String searchString)
          Performs a forward search starting at the beginning across the Searchable using String that represents a regex pattern; Pattern.
 int search(java.lang.String searchString, int startIndex)
          Performs a forward search starting at the given startIndex using String that represents a regex pattern; Pattern.
 int search(java.lang.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.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MATCH_HIGHLIGHTER

public static final java.lang.String MATCH_HIGHLIGHTER
key for client property to use SearchHighlighter as match marker.

See Also:
Constant Field Values
Constructor Detail

AbstractSearchable

public AbstractSearchable()
Method Detail

search

public int search(java.lang.String searchString)
Performs a forward search starting at the beginning across the Searchable using String that represents a regex pattern; Pattern.

Specified by:
search in interface Searchable
Parameters:
searchString - String that we will try to locate
Returns:
the position of the match in appropriate coordinates or -1 if no match found.

search

public int search(java.lang.String searchString,
                  int startIndex)
Performs a forward search starting at the given startIndex using String that represents a regex pattern; Pattern.

Specified by:
search in interface Searchable
Parameters:
searchString - String that we will try to locate
startIndex - position in the document in the appropriate coordinates from which we will start search or -1 to start from the beginning
Returns:
the position of the match in appropriate coordinates or -1 if no match found.

search

public int search(java.lang.String searchString,
                  int startIndex,
                  boolean backward)
Performs a search starting at the given startIndex using String that represents a regex pattern; Pattern. The search direction depends on the boolean parameter: forward/backward if false/true, respectively.

Specified by:
search in interface Searchable
Parameters:
searchString - String that we will try to locate
startIndex - position in the document in the appropriate coordinates from which we will start search or -1 to start from the beginning
backward - true if we should perform search towards the beginning
Returns:
the position of the match in appropriate coordinates or -1 if no match found.

search

public int search(java.util.regex.Pattern pattern)
Performs a forward search starting at the beginning across the Searchable using the pattern; Pattern.

Specified by:
search in interface Searchable
Parameters:
pattern - Pattern that we will try to locate
Returns:
the position of the match in appropriate coordinates or -1 if no match found.

search

public int search(java.util.regex.Pattern pattern,
                  int startIndex)
Performs a forward search starting at the given startIndex using the Pattern; Pattern.

Specified by:
search in interface Searchable
Parameters:
pattern - Pattern that we will try to locate
startIndex - position in the document in the appropriate coordinates from which we will start search or -1 to start from the beginning
Returns:
the position of the match in appropriate coordinates or -1 if no match found.

search

public int search(java.util.regex.Pattern pattern,
                  int startIndex,
                  boolean backwards)
Performs a search starting at the given startIndex using the pattern; Pattern. The search direction depends on the boolean parameter: forward/backward if false/true, respectively.

Updates visible and internal search state.

Specified by:
search in interface Searchable
Parameters:
pattern - Pattern that we will try to locate
startIndex - position in the document in the appropriate coordinates from which we will start search or -1 to start from the beginning
backwards - true if we should perform search towards the beginning
Returns:
the position of the match in appropriate coordinates or -1 if no match found.

getTarget

public abstract javax.swing.JComponent getTarget()
It's the responsibility of subclasses to covariant override.

Returns:
the target component

setMatchHighlighter

public void setMatchHighlighter(AbstractHighlighter hl)
Sets the AbstractHighlighter to use as match marker, if enabled. A null value will re-install the default.

Parameters:
hl - the Highlighter to use as match marker.