KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > css > dom > CSSOMSVGStyleDeclaration


1 /*
2
3    Copyright 2002-2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.css.dom;
19
20 import org.apache.batik.css.engine.CSSEngine;
21 import org.apache.batik.css.engine.SVGCSSEngine;
22 import org.apache.batik.css.engine.value.Value;
23 import org.apache.batik.css.engine.value.svg.SVGColorManager;
24 import org.apache.batik.css.engine.value.svg.SVGPaintManager;
25 import org.w3c.dom.DOMException JavaDoc;
26 import org.w3c.dom.css.CSSRule;
27 import org.w3c.dom.css.CSSValue;
28
29 /**
30  * This class represents a SVG style declaration.
31  *
32  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
33  * @version $Id: CSSOMSVGStyleDeclaration.java,v 1.6 2004/08/18 07:12:47 vhardy Exp $
34  */

35 public class CSSOMSVGStyleDeclaration extends CSSOMStyleDeclaration {
36     
37     /**
38      * The CSS engine.
39      */

40     protected CSSEngine cssEngine;
41
42     /**
43      * Creates a new CSSOMSVGStyleDeclaration.
44      */

45     public CSSOMSVGStyleDeclaration(ValueProvider vp,
46                                     CSSRule parent,
47                                     CSSEngine eng) {
48         super(vp, parent);
49         cssEngine = eng;
50     }
51
52     /**
53      * Creates the CSS value associated with the given property.
54      */

55     protected CSSValue createCSSValue(String JavaDoc name) {
56         int idx = cssEngine.getPropertyIndex(name);
57         if (idx > SVGCSSEngine.FINAL_INDEX) {
58             if (cssEngine.getValueManagers()[idx] instanceof SVGPaintManager) {
59                 return new StyleDeclarationPaintValue(name);
60             }
61             if (cssEngine.getValueManagers()[idx] instanceof SVGColorManager) {
62                 return new StyleDeclarationColorValue(name);
63             }
64         } else {
65             switch (idx) {
66             case SVGCSSEngine.FILL_INDEX:
67             case SVGCSSEngine.STROKE_INDEX:
68                 return new StyleDeclarationPaintValue(name);
69
70             case SVGCSSEngine.FLOOD_COLOR_INDEX:
71             case SVGCSSEngine.LIGHTING_COLOR_INDEX:
72             case SVGCSSEngine.STOP_COLOR_INDEX:
73                 return new StyleDeclarationColorValue(name);
74             }
75         }
76         return super.createCSSValue(name);
77     }
78
79     /**
80      * This class represents a CSS value returned by this declaration.
81      */

82     public class StyleDeclarationColorValue
83         extends CSSOMSVGColor
84         implements CSSOMSVGColor.ValueProvider {
85         
86         /**
87          * The property name.
88          */

89         protected String JavaDoc property;
90
91         /**
92          * Creates a new StyleDeclarationColorValue.
93          */

94         public StyleDeclarationColorValue(String JavaDoc prop) {
95             super(null);
96             valueProvider = this;
97             setModificationHandler(new AbstractModificationHandler() {
98                     protected Value getValue() {
99                         return StyleDeclarationColorValue.this.getValue();
100                     }
101                     public void textChanged(String JavaDoc text) throws DOMException JavaDoc {
102                         if (handler == null) {
103                             throw new DOMException JavaDoc
104                                 (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
105                         }
106                         String JavaDoc prio = getPropertyPriority(property);
107                         CSSOMSVGStyleDeclaration.this.
108                             handler.propertyChanged(property, text, prio);
109                     }
110                 });
111
112             property = prop;
113         }
114
115         // ValueProvider ///////////////////////////////
116

117         /**
118          * Returns the current value associated with this object.
119          */

120         public Value getValue() {
121             return CSSOMSVGStyleDeclaration.this.
122                 valueProvider.getValue(property);
123         }
124
125     }
126
127     /**
128      * This class represents a CSS value returned by this declaration.
129      */

130     public class StyleDeclarationPaintValue
131         extends CSSOMSVGPaint
132         implements CSSOMSVGPaint.ValueProvider {
133         
134         /**
135          * The property name.
136          */

137         protected String JavaDoc property;
138
139         /**
140          * Creates a new StyleDeclarationPaintValue.
141          */

142         public StyleDeclarationPaintValue(String JavaDoc prop) {
143             super(null);
144             valueProvider = this;
145             setModificationHandler(new AbstractModificationHandler() {
146                     protected Value getValue() {
147                         return StyleDeclarationPaintValue.this.getValue();
148                     }
149                     public void textChanged(String JavaDoc text) throws DOMException JavaDoc {
150                         if (handler == null) {
151                             throw new DOMException JavaDoc
152                                 (DOMException.NO_MODIFICATION_ALLOWED_ERR, "");
153                         }
154                         String JavaDoc prio = getPropertyPriority(property);
155                         CSSOMSVGStyleDeclaration.this.
156                             handler.propertyChanged(property, text, prio);
157                     }
158                 });
159
160             property = prop;
161         }
162
163         // ValueProvider ///////////////////////////////
164

165         /**
166          * Returns the current value associated with this object.
167          */

168         public Value getValue() {
169             return CSSOMSVGStyleDeclaration.this.
170                 valueProvider.getValue(property);
171         }
172
173     }
174     
175 }
176
Popular Tags