KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > jdnc > markup > elem > PatternHighlighterElement


1 /*
2  * $Id: PatternHighlighterElement.java,v 1.1.1.1 2004/06/16 01:43:40 davidson1 Exp $
3  *
4  * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
5  * Santa Clara, California 95054, U.S.A. All rights reserved.
6  */

7
8 package org.jdesktop.jdnc.markup.elem;
9
10 import java.util.Map JavaDoc;
11 import java.util.regex.Pattern JavaDoc;
12
13 import org.w3c.dom.Element JavaDoc;
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 /**
24  *
25  * @author Ramesh Gupta
26  */

27 public class PatternHighlighterElement extends HighlighterElement {
28     public PatternHighlighterElement(Element JavaDoc element, ElementType elementType) {
29         super(element, elementType);
30     }
31
32     protected void applyAttributesAfter() {
33         super.applyAttributesAfter();
34         applyExpressionAttribute(); // combo attribute
35
applyAttribute(Namespace.JDNC, Attributes.MASK);
36         applyAttribute(Namespace.JDNC, Attributes.TEST_COLUMN);
37         applyAttribute(Namespace.JDNC, Attributes.HIGHLIGHT_COLUMN);
38 // applyAttribute(Namespace.JDNC, Attributes.HIGHLIGHT_COLUMN_INDEX);
39
}
40
41     private void applyExpressionAttribute() {
42         // Identical to PatternFilterElement.applyExpressionAttribute
43
if (object != null) {
44             // processes both Attributes.EXPRESSION and Attributes.MATCH
45
String JavaDoc 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 JavaDoc ex) {
54             logException("Bad regular expression \"" + expression +
55                  "\" or match flags", ex);
56                 }
57             }
58         }
59     }
60
61     protected Map JavaDoc registerAttributeHandlers() {
62         Map JavaDoc 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.TEST_COLUMN_INDEX,
69
// testColumnIndexAttrHandler);
70
handlerMap.put(Namespace.JDNC + ":" + Attributes.HIGHLIGHT_COLUMN,
71                            highlightColumnAttrHandler);
72             //handlerMap.put(Namespace.JDNC + ":" + Attributes.HIGHLIGHT_COLUMN_INDEX,
73
// highlightColumnIndexAttrHandler);
74

75         // Register null appliers. These attributes are handled elsewhere
76
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     /*
95     private static final AttributeHandler testColumnIndexAttrHandler =
96         new AttributeHandler(Namespace.JDNC, Attributes.TEST_COLUMN_INDEX,
97                              HighlighterAttributes.testColumnIndexApplier);
98         */

99     private static final AttributeHandler highlightColumnAttrHandler =
100         new AttributeHandler(Namespace.JDNC, Attributes.HIGHLIGHT_COLUMN,
101                              HighlighterAttributes.highlightColumnApplier);
102     /*
103     private static final AttributeHandler highlightColumnIndexAttrHandler =
104         new AttributeHandler(Namespace.JDNC, Attributes.HIGHLIGHT_COLUMN_INDEX,
105                              HighlighterAttributes.highlightColumnIndexApplier);
106         */

107 }
108
Popular Tags