Class PatternPredicate

java.lang.Object
org.jdesktop.swingx.decorator.PatternPredicate
All Implemented Interfaces:
HighlightPredicate

public class PatternPredicate extends 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.

Author:
Jeanette Winzenburg
  • Field Details

  • Constructor Details

    • PatternPredicate

      public PatternPredicate(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 against
      testColumn - the column index in model coordinates of the cell which contains the value to test against the pattern
    • PatternPredicate

      public PatternPredicate(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(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 against
      testColumn - the column index in model coordinates of the cell which contains the value to test against the pattern
      decorateColumn - the column index in model coordinates of the cell which should be decorated if the test against the value succeeds.
    • PatternPredicate

      public PatternPredicate(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(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 against
      testColumn - the column index in model coordinates of the cell which contains the value to test against the pattern
    • PatternPredicate

      public PatternPredicate(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 against
      testColumn - the column index in model coordinates of the cell which contains the value to test against the pattern
      decorateColumn - the column index in model coordinates of the cell which should be decorated if the test against the value succeeds.
  • Method Details

    • isHighlighted

      public boolean isHighlighted(Component renderer, ComponentAdapter adapter)
      Returns a boolean to indicate whether the component should be highlighted.

      Note: both parameters should be considered strictly read-only!

      Implemented to return true if the match of cell content's String representation against the Pattern if found and the adapter's view column maps to the decorateColumn/s. Otherwise returns false.

      Specified by:
      isHighlighted in interface HighlightPredicate
      Parameters:
      renderer - the cell renderer component that is to be decorated, must not be null
      adapter - the ComponentAdapter for this decorate operation, most not be null
      Returns:
      a boolean to indicate whether the component should be highlighted.
    • getHighlightColumn

      public int getHighlightColumn()
      Returns:
      returns the column index to decorate (in model coordinates)
    • getPattern

      public 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)