1 7 8 package org.jdesktop.swing.decorator; 9 10 import java.util.regex.Pattern ; 11 import java.util.regex.PatternSyntaxException ; 12 13 import java.awt.Color ; 14 15 20 public class PatternHighlighter extends ConditionalHighlighter 21 implements PatternMatcher { 22 26 public PatternHighlighter() { 27 this(null, null, null, 0, 0); } 30 31 50 public PatternHighlighter(Color background, Color foreground, 51 String regExString, int matchFlags, int testColumn) throws PatternSyntaxException { 52 this(background, foreground, regExString, matchFlags, testColumn, -1); 53 } 54 55 84 public PatternHighlighter(Color background, Color foreground, String regExString, 85 int matchFlags, int testColumn, int decorateColumn) throws PatternSyntaxException { 86 super(background, foreground, testColumn, decorateColumn); 87 setPattern(regExString, matchFlags); 88 } 89 90 99 protected boolean test(ComponentAdapter adapter) { 100 if (pattern == null) { 101 return false; 102 } 103 104 int testColumnV = adapter.modelToView(testColumn); 106 if (testColumnV < 0) { 107 return false; } 109 Object value = adapter.getFilteredValueAt(adapter.row, testColumnV); 110 111 if (value == null) { 112 return false; 113 } 114 else { 115 boolean matches = pattern.matcher(value.toString()).matches(); 116 return matches; 117 } 118 } 119 120 127 public Pattern getPattern() { 128 return pattern; 129 } 130 131 public void setPattern(String regularExpr, int matchFlags) { 132 if ((regularExpr == null) || (regularExpr.length() == 0)) { 133 regularExpr = ".*"; 134 } 135 setPattern(Pattern.compile(regularExpr, matchFlags)); 136 } 137 138 145 public void setPattern(Pattern pattern) { 146 this.pattern = pattern; 147 } 148 149 protected Pattern pattern = null; 150 } | Popular Tags |