Package org.jdesktop.swingx.decorator
Class PatternPredicate
- java.lang.Object
-
- org.jdesktop.swingx.decorator.PatternPredicate
-
- All Implemented Interfaces:
HighlightPredicate
public class PatternPredicate extends java.lang.Object implements HighlightPredicate
Pattern based HighlightPredicate.Turns on the highlight of a single or all columns of the current row if a match of the String representation of cell content against the given Pattern is found.
The match logic can be configured to either test one specific column in the current row or all columns. In the latter case the logic is the same as in RowFilters.GeneralFilter: the row is included if any of the cell contents in the row are matches.
-
-
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 java.util.regex.Pattern
pattern
private int
testColumn
-
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 PatternPredicate(java.lang.String pattern)
Instantiates a Predicate with the given Pattern testing against all columns and highlighting all columns.PatternPredicate(java.lang.String regex, int testColumn)
Instantiates a Predicate with the given regex and test column index in model coordinates.PatternPredicate(java.lang.String regex, int testColumn, int decorateColumn)
Instantiates a Predicate with the given regex and test-/decorate column index in model coordinates.PatternPredicate(java.util.regex.Pattern pattern)
Instantiates a Predicate with the given Pattern testing against all columns and highlighting all columns.PatternPredicate(java.util.regex.Pattern pattern, int testColumn)
Instantiates a Predicate with the given Pattern and testColumn index (in model coordinates) highlighting all columns.PatternPredicate(java.util.regex.Pattern pattern, int testColumn, int decorateColumn)
Instantiates a Predicate with the given Pattern and test-/decorate column index in model coordinates.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getHighlightColumn()
java.util.regex.Pattern
getPattern()
int
getTestColumn()
private boolean
isHighlightCandidate(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(ComponentAdapter adapter)
Test the value.private boolean
testColumn(ComponentAdapter adapter, int testColumn)
-
-
-
Field Detail
-
ALL
public static final int ALL
- See Also:
- Constant Field Values
-
highlightColumn
private int highlightColumn
-
testColumn
private int testColumn
-
pattern
private java.util.regex.Pattern pattern
-
-
Constructor Detail
-
PatternPredicate
public PatternPredicate(java.util.regex.Pattern pattern, int testColumn)
Instantiates a Predicate with the given Pattern and testColumn index (in model coordinates) highlighting all columns. A column index of -1 is interpreted as "all".- Parameters:
pattern
- the Pattern to test the cell value againsttestColumn
- the column index in model coordinates of the cell which contains the value to test against the pattern
-
PatternPredicate
public PatternPredicate(java.util.regex.Pattern pattern)
Instantiates a Predicate with the given Pattern testing against all columns and highlighting all columns.- Parameters:
pattern
- the Pattern to test the cell value against
-
PatternPredicate
public PatternPredicate(java.util.regex.Pattern pattern, int testColumn, int decorateColumn)
Instantiates a Predicate with the given Pattern and test-/decorate column index in model coordinates. A column index of -1 is interpreted as "all".- Parameters:
pattern
- the Pattern to test the cell value againsttestColumn
- the column index in model coordinates of the cell which contains the value to test against the patterndecorateColumn
- the column index in model coordinates of the cell which should be decorated if the test against the value succeeds.
-
PatternPredicate
public PatternPredicate(java.lang.String pattern)
Instantiates a Predicate with the given Pattern testing against all columns and highlighting all columns.- Parameters:
pattern
- the Pattern to test the cell value against
-
PatternPredicate
public PatternPredicate(java.lang.String regex, int testColumn)
Instantiates a Predicate with the given regex and test column index in model coordinates. The pattern string is compiled to a Pattern with flags 0. A column index of -1 is interpreted as "all".- Parameters:
regex
- the regex string to test the cell value againsttestColumn
- the column index in model coordinates of the cell which contains the value to test against the pattern
-
PatternPredicate
public PatternPredicate(java.lang.String regex, int testColumn, int decorateColumn)
Instantiates a Predicate with the given regex and test-/decorate column index in model coordinates. The pattern string is compiled to a Pattern with flags 0. A column index of -1 is interpreted as "all".- Parameters:
regex
- the regex string to test the cell value againsttestColumn
- the column index in model coordinates of the cell which contains the value to test against the patterndecorateColumn
- the column index in model coordinates of the cell which should be decorated if the test against the value succeeds.
-
-
Method Detail
-
isHighlighted
public boolean isHighlighted(java.awt.Component renderer, ComponentAdapter adapter)
Description copied from interface:HighlightPredicate
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(ComponentAdapter adapter)
Test the value. This is called only if the pre-check returned true, because accessing the value might be potentially costly- Parameters:
adapter
-- Returns:
-
testColumn
private boolean testColumn(ComponentAdapter adapter, int testColumn)
- Parameters:
adapter
-testColumn
-- Returns:
-
isHighlightCandidate
private boolean isHighlightCandidate(ComponentAdapter adapter)
A quick pre-check.- Parameters:
adapter
-- Returns:
-
getHighlightColumn
public int getHighlightColumn()
- 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
-
getTestColumn
public int getTestColumn()
- Returns:
- the column to use for testing (in model coordinates)
-
-