1 7 8 package org.jdesktop.jdnc.markup.elem; 9 10 import java.util.Map ; 11 import java.util.regex.Pattern ; 12 13 import org.w3c.dom.Element ; 14 import org.jdesktop.swing.decorator.*; 15 import net.openmarkup.AttributeHandler; 16 import net.openmarkup.ElementType; 17 import org.jdesktop.jdnc.markup.Attributes; 18 import org.jdesktop.jdnc.markup.Namespace; 19 import org.jdesktop.jdnc.markup.attr.Decoder; 20 import org.jdesktop.jdnc.markup.attr.HighlighterAttributes; 21 import org.jdesktop.jdnc.markup.attr.NullAttribute; 22 23 27 public class PatternHighlighterElement extends HighlighterElement { 28 public PatternHighlighterElement(Element element, ElementType elementType) { 29 super(element, elementType); 30 } 31 32 protected void applyAttributesAfter() { 33 super.applyAttributesAfter(); 34 applyExpressionAttribute(); applyAttribute(Namespace.JDNC, Attributes.MASK); 36 applyAttribute(Namespace.JDNC, Attributes.TEST_COLUMN); 37 applyAttribute(Namespace.JDNC, Attributes.HIGHLIGHT_COLUMN); 38 } 40 41 private void applyExpressionAttribute() { 42 if (object != null) { 44 String expression = getAttributeNSOptional(Namespace.JDNC, Attributes.EXPRESSION); 46 if (expression.length() > 0) { 47 try { 48 int matchFlags = Decoder.decodePatternMatchFlags( 49 getAttributeNSOptional(Namespace.JDNC, Attributes.MATCH)); 50 ((PatternMatcher) object).setPattern( 51 Pattern.compile(expression, matchFlags)); 52 } 53 catch (Exception ex) { 54 logException("Bad regular expression \"" + expression + 55 "\" or match flags", ex); 56 } 57 } 58 } 59 } 60 61 protected Map registerAttributeHandlers() { 62 Map handlerMap = super.registerAttributeHandlers(); 63 if (handlerMap != null) { 64 handlerMap.put(Namespace.JDNC + ":" + Attributes.MASK, 65 maskAttrHandler); 66 handlerMap.put(Namespace.JDNC + ":" + Attributes.TEST_COLUMN, 67 testColumnAttrHandler); 68 handlerMap.put(Namespace.JDNC + ":" + Attributes.HIGHLIGHT_COLUMN, 71 highlightColumnAttrHandler); 72 75 handlerMap.put(Namespace.JDNC + ":" + Attributes.ID, 77 NullAttribute.idHandler); 78 handlerMap.put(Namespace.JDNC + ":" + Attributes.EXPRESSION, 79 exprHandler); 80 } 81 return handlerMap; 82 } 83 84 private static final AttributeHandler exprHandler = 85 new AttributeHandler(Namespace.JDNC, Attributes.EXPRESSION, NullAttribute.nullApplier); 86 87 88 private static final AttributeHandler maskAttrHandler = 89 new AttributeHandler(Namespace.JDNC, Attributes.MASK, 90 HighlighterAttributes.maskApplier); 91 private static final AttributeHandler testColumnAttrHandler = 92 new AttributeHandler(Namespace.JDNC, Attributes.TEST_COLUMN, 93 HighlighterAttributes.testColumnApplier); 94 99 private static final AttributeHandler highlightColumnAttrHandler = 100 new AttributeHandler(Namespace.JDNC, Attributes.HIGHLIGHT_COLUMN, 101 HighlighterAttributes.highlightColumnApplier); 102 107 } 108 | Popular Tags |