KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > jdnc > markup > attr > HighlighterAttributes


1 /*
2  * $Id: HighlighterAttributes.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.attr;
9
10 import org.jdesktop.swing.data.MetaData;
11
12 import org.jdesktop.swing.decorator.AlternateRowHighlighter;
13 import org.jdesktop.swing.decorator.ConditionalHighlighter;
14 import org.jdesktop.swing.decorator.Highlighter;
15 import org.jdesktop.jdnc.*;
16 import org.jdesktop.jdnc.markup.*;
17 import org.jdesktop.jdnc.markup.elem.ElementProxy;
18 import org.jdesktop.swing.data.*;
19 import org.jdesktop.swing.table.*;
20
21 import java.awt.Color JavaDoc;
22
23 import net.openmarkup.AttributeApplier;
24 import net.openmarkup.*;
25
26 import org.w3c.dom.Element JavaDoc;
27 import org.w3c.dom.Node JavaDoc;
28 import org.w3c.dom.NodeList JavaDoc;
29
30 /**
31  * Flyweight implementations for highlighter attribute appliers.
32  *
33  * @author Ramesh Gupta
34  */

35 public class HighlighterAttributes {
36     public static final AttributeApplier backgroundApplier = new AttributeApplier() {
37         /**
38          * @tolerant
39          */

40         public void apply(Realizable target, String JavaDoc namespaceURI,
41                           String JavaDoc attributeName, String JavaDoc attributeValue) {
42             Color JavaDoc color = Decoder.decodeColor(attributeValue);
43             ((Highlighter) target.getObject()).setBackground(color);
44         }
45     };
46
47     public static final AttributeApplier highlightColumnApplier = new AttributeApplier() {
48         public void apply(Realizable target, String JavaDoc namespaceURI,
49                           String JavaDoc attributeName, String JavaDoc attributeValue) {
50             int columnIndex = TableColumnAttributes.getModelIndex(target, attributeValue);
51             if (columnIndex >= 0) {
52                 ((ConditionalHighlighter) target.getObject()).setHighlightColumnIndex(columnIndex);
53             }
54         }
55     };
56
57 /*
58     public static final AttributeApplier highlightColumnIndexApplier = new AttributeApplier() {
59         public void apply(Realizable target, String namespaceURI,
60                           String attributeName, String attributeValue) {
61             ((ConditionalHighlighter) target.getObject()).setHighlightColumnIndex(
62                 Integer.parseInt(attributeValue));
63         }
64     };
65 */

66     public static final AttributeApplier evenRowBackgroundApplier = new AttributeApplier() {
67         /**
68          * @tolerant
69          */

70         public void apply(Realizable target, String JavaDoc namespaceURI,
71                           String JavaDoc attributeName, String JavaDoc attributeValue) {
72             Color JavaDoc color = Decoder.decodeColor(attributeValue);
73             ((AlternateRowHighlighter) target.getObject()).setEvenRowBackground(color);
74         }
75     };
76
77     public static final AttributeApplier foregroundApplier = new AttributeApplier() {
78         /**
79          * @tolerant
80          */

81         public void apply(Realizable target, String JavaDoc namespaceURI,
82                           String JavaDoc attributeName, String JavaDoc attributeValue) {
83             Color JavaDoc color = Decoder.decodeColor(attributeValue);
84             ((Highlighter) target.getObject()).setForeground(color);
85         }
86     };
87
88     public static final AttributeApplier maskApplier = new AttributeApplier() {
89         /**
90         * @tolerant
91          */

92         public void apply(Realizable target, String JavaDoc namespaceURI,
93                           String JavaDoc attributeName, String JavaDoc attributeValue) {
94             if (attributeValue.length() > 0) {
95                 ((ConditionalHighlighter) target.getObject()).setMask(
96                     Integer.parseInt(attributeValue));
97             }
98         }
99     };
100
101     public static final AttributeApplier oddRowBackgroundApplier = new AttributeApplier() {
102         /**
103          * @tolerant
104          */

105         public void apply(Realizable target, String JavaDoc namespaceURI,
106                           String JavaDoc attributeName, String JavaDoc attributeValue) {
107             Color JavaDoc color = Decoder.decodeColor(attributeValue);
108             ((AlternateRowHighlighter) target.getObject()).setOddRowBackground(color);
109         }
110     };
111
112     public static final AttributeApplier selectedBackgroundApplier = new AttributeApplier() {
113         /**
114          * @tolerant
115          */

116         public void apply(Realizable target, String JavaDoc namespaceURI,
117                           String JavaDoc attributeName, String JavaDoc attributeValue) {
118             Color JavaDoc color = Decoder.decodeColor(attributeValue);
119             ((Highlighter) target.getObject()).setSelectedBackground(color);
120         }
121     };
122
123     public static final AttributeApplier selectedForegroundApplier = new AttributeApplier() {
124         /**
125          * @tolerant
126          */

127         public void apply(Realizable target, String JavaDoc namespaceURI,
128                           String JavaDoc attributeName, String JavaDoc attributeValue) {
129             Color JavaDoc color = Decoder.decodeColor(attributeValue);
130             ((Highlighter) target.getObject()).setSelectedBackground(color);
131         }
132     };
133
134     public static final AttributeApplier testColumnApplier = new AttributeApplier() {
135         public void apply(Realizable target, String JavaDoc namespaceURI,
136                           String JavaDoc attributeName, String JavaDoc attributeValue) {
137             int columnIndex = TableColumnAttributes.getModelIndex(target, attributeValue);
138             if (columnIndex >= 0) {
139                 ((ConditionalHighlighter) target.getObject()).setTestColumnIndex(columnIndex);
140             }
141         }
142     };
143
144 /*
145     public static final AttributeApplier testColumnIndexApplier = new AttributeApplier() {
146         public void apply(Realizable target, String namespaceURI,
147                           String attributeName, String attributeValue) {
148             System.out.println("Attribute \"" + attributeName + "\" in <" +
149                                target.getLocalName() + "> is deprecated.");
150             ((ConditionalHighlighter) target.getObject()).setTestColumnIndex(
151                 Integer.parseInt(attributeValue));
152         }
153     };
154 */

155 }
156
Popular Tags