Class SearchPredicate
- java.lang.Object
-
- org.jdesktop.swingx.decorator.SearchPredicate
-
- All Implemented Interfaces:
HighlightPredicate
public class SearchPredicate extends java.lang.Object implements HighlightPredicate
Pattern based HighlightPredicate for searching. Highlights the current adapter cell if the value matches the pattern. The highlight scope can be limited to a certain column and row.Note: this differs from PatternPredicate in that it is focused on the current cell (highlight coordinates == test coordinates) while the PatternPredicate can have separate test and highlight coordinates.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.jdesktop.swingx.decorator.HighlightPredicate
HighlightPredicate.AndHighlightPredicate, HighlightPredicate.ColumnHighlightPredicate, HighlightPredicate.ColumnTypeHighlightPredicate, HighlightPredicate.DepthHighlightPredicate, HighlightPredicate.EqualsHighlightPredicate, HighlightPredicate.IdentifierHighlightPredicate, HighlightPredicate.NotHighlightPredicate, HighlightPredicate.OrHighlightPredicate, HighlightPredicate.RowGroupHighlightPredicate, HighlightPredicate.TypeHighlightPredicate
-
-
Field Summary
Fields Modifier and Type Field Description static int
ALL
private int
highlightColumn
private int
highlightRow
static java.lang.String
MATCH_ALL
private java.util.regex.Pattern
pattern
-
Fields inherited from interface org.jdesktop.swingx.decorator.HighlightPredicate
ALWAYS, BIG_DECIMAL_NEGATIVE, EDITABLE, EMPTY_INTEGER_ARRAY, EMPTY_OBJECT_ARRAY, EMPTY_PREDICATE_ARRAY, EVEN, HAS_FOCUS, INTEGER_NEGATIVE, IS_FOLDER, IS_LEAF, IS_SELECTED, IS_TEXT_TRUNCATED, NEVER, ODD, READ_ONLY, ROLLOVER_CELL, ROLLOVER_COLUMN, ROLLOVER_ROW
-
-
Constructor Summary
Constructors Constructor Description SearchPredicate(java.lang.String regex)
Instantiates a Predicate with a Pattern compiled from the given regular expression.SearchPredicate(java.lang.String regex, int column)
Instantiates a Predicate with a Pattern compiled from the given regular expression.SearchPredicate(java.lang.String regex, int row, int column)
Instantiates a Predicate with a Pattern compiled from the given regular expression.SearchPredicate(java.util.regex.Pattern pattern)
Instantiates a Predicate with the given Pattern.SearchPredicate(java.util.regex.Pattern pattern, int column)
Instantiates a Predicate with the given Pattern.SearchPredicate(java.util.regex.Pattern pattern, int row, int column)
Instantiates a Predicate with the given Pattern.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getHighlightColumn()
int
getHighlightRow()
java.util.regex.Pattern
getPattern()
private boolean
isEnabled()
private boolean
isHighlightCandidate(java.awt.Component renderer, ComponentAdapter adapter)
A quick pre-check.boolean
isHighlighted(java.awt.Component renderer, ComponentAdapter adapter)
Returns a boolean to indicate whether the component should be highlighted.private boolean
test(java.awt.Component renderer, ComponentAdapter adapter)
Test the value.
-
-
-
Field Detail
-
ALL
public static final int ALL
- See Also:
- Constant Field Values
-
MATCH_ALL
public static final java.lang.String MATCH_ALL
- See Also:
- Constant Field Values
-
highlightColumn
private int highlightColumn
-
highlightRow
private int highlightRow
-
pattern
private java.util.regex.Pattern pattern
-
-
Constructor Detail
-
SearchPredicate
public SearchPredicate(java.util.regex.Pattern pattern)
Instantiates a Predicate with the given Pattern. All matching cells are highlighted.- Parameters:
pattern
- the Pattern to test the cell value against
-
SearchPredicate
public SearchPredicate(java.util.regex.Pattern pattern, int column)
Instantiates a Predicate with the given Pattern. Highlighting is limited to matching cells in the given column.- Parameters:
pattern
- the Pattern to test the cell value againstcolumn
- the column to limit the highlight to
-
SearchPredicate
public SearchPredicate(java.util.regex.Pattern pattern, int row, int column)
Instantiates a Predicate with the given Pattern. Highlighting is limited to matching cells in the given column and row. A value of -1 indicates all rows/columns.Note: the coordinates are asymmetric - rows are in view- and column in model-coordinates - due to corresponding methods in ComponentAdapter. Hmm... no need to? This happens on the current adapter state which is view always, so could use view only?
- Parameters:
pattern
- the Pattern to test the cell value againstrow
- the row index in view coordinates to limit the highlight.column
- the column in model coordinates to limit the highlight to
-
SearchPredicate
public SearchPredicate(java.lang.String regex)
Instantiates a Predicate with a Pattern compiled from the given regular expression. All matching cells are highlighted.- Parameters:
regex
- the regular expression to test the cell value against
-
SearchPredicate
public SearchPredicate(java.lang.String regex, int column)
Instantiates a Predicate with a Pattern compiled from the given regular expression. Highlighting is applied to matching cells in all rows, but only in the given column. A value of ALL indicates all columns.- Parameters:
regex
- the regular expression to test the cell value againstcolumn
- the column index in model coordinates to limit the highlight to
-
SearchPredicate
public SearchPredicate(java.lang.String regex, int row, int column)
Instantiates a Predicate with a Pattern compiled from the given regular expression. Highlighting is limited to matching cells in the given column and row. A value of ALL indicates all rows/columns.Note: the coordinates are asymmetric - rows are in view- and column in model-coordinates - due to corresponding methods in ComponentAdapter. Hmm... no need to? This happens on the current adapter state which is view always, so could use view only?
- Parameters:
regex
- the Pattern to test the cell value againstrow
- the row index in view coordinates to limit the highlight.column
- the column in model coordinates to limit the highlight to
-
-
Method Detail
-
getHighlightColumn
public int getHighlightColumn()
- Returns:
- returns the column index to decorate (in model coordinates)
-
getHighlightRow
public int getHighlightRow()
- Returns:
- returns the column index to decorate (in model coordinates)
-
getPattern
public java.util.regex.Pattern getPattern()
- Returns:
- returns the Pattern to test the cell value against
-
isHighlighted
public boolean isHighlighted(java.awt.Component renderer, ComponentAdapter adapter)
Returns a boolean to indicate whether the component should be highlighted.Note: both parameters should be considered strictly read-only!
- Specified by:
isHighlighted
in interfaceHighlightPredicate
- Parameters:
renderer
- the cell renderer component that is to be decorated, must not be nulladapter
- the ComponentAdapter for this decorate operation, most not be null- Returns:
- a boolean to indicate whether the component should be highlighted.
-
test
private boolean test(java.awt.Component renderer, ComponentAdapter adapter)
Test the value. This is called only if the pre-check returned true, because accessing the value might be potentially costly- Parameters:
renderer
-adapter
-- Returns:
-
isHighlightCandidate
private boolean isHighlightCandidate(java.awt.Component renderer, ComponentAdapter adapter)
A quick pre-check.- Parameters:
renderer
-adapter
-- Returns:
-
isEnabled
private boolean isEnabled()
-
-