KickJava   Java API By Example, From Geeks To Geeks.

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


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.CSSStylableElement;
22 import org.apache.batik.css.engine.SVGCSSEngine;
23 import org.apache.batik.css.engine.value.Value;
24 import org.apache.batik.css.engine.value.svg.SVGColorManager;
25 import org.apache.batik.css.engine.value.svg.SVGPaintManager;
26 import org.w3c.dom.css.CSSValue;
27
28 /**
29  * This class represents the computed style of an SVG element.
30  *
31  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
32  * @version $Id: CSSOMSVGComputedStyle.java,v 1.6 2004/08/18 07:12:47 vhardy Exp $
33  */

34 public class CSSOMSVGComputedStyle extends CSSOMComputedStyle {
35     
36     /**
37      * Creates a new computed style.
38      */

39     public CSSOMSVGComputedStyle(CSSEngine e,
40                                  CSSStylableElement elt,
41                                  String JavaDoc pseudoElt) {
42         super(e, elt, pseudoElt);
43     }
44
45     /**
46      * Creates a CSSValue to manage the value at the given index.
47      */

48     protected CSSValue createCSSValue(int idx) {
49         if (idx > SVGCSSEngine.FINAL_INDEX) {
50             if (cssEngine.getValueManagers()[idx] instanceof SVGPaintManager) {
51                 return new ComputedCSSPaintValue(idx);
52             }
53             if (cssEngine.getValueManagers()[idx] instanceof SVGColorManager) {
54                 return new ComputedCSSColorValue(idx);
55             }
56         } else {
57             switch (idx) {
58             case SVGCSSEngine.FILL_INDEX:
59             case SVGCSSEngine.STROKE_INDEX:
60                 return new ComputedCSSPaintValue(idx);
61
62             case SVGCSSEngine.FLOOD_COLOR_INDEX:
63             case SVGCSSEngine.LIGHTING_COLOR_INDEX:
64             case SVGCSSEngine.STOP_COLOR_INDEX:
65                 return new ComputedCSSColorValue(idx);
66             }
67         }
68         return super.createCSSValue(idx);
69     }
70
71     /**
72      * To manage a computed color CSSValue.
73      */

74     protected class ComputedCSSColorValue
75         extends CSSOMSVGColor
76         implements CSSOMSVGColor.ValueProvider {
77         
78         /**
79          * The index of the associated value.
80          */

81         protected int index;
82
83         /**
84          * Creates a new ComputedCSSColorValue.
85          */

86         public ComputedCSSColorValue(int idx) {
87             super(null);
88             valueProvider = this;
89             index = idx;
90         }
91
92         /**
93          * Returns the Value associated with this object.
94          */

95         public Value getValue() {
96             return cssEngine.getComputedStyle(element, pseudoElement, index);
97         }
98     }
99
100     /**
101      * To manage a computed paint CSSValue.
102      */

103     public class ComputedCSSPaintValue
104         extends CSSOMSVGPaint
105         implements CSSOMSVGPaint.ValueProvider {
106         
107         /**
108          * The index of the associated value.
109          */

110         protected int index;
111
112         /**
113          * Creates a new ComputedCSSPaintValue.
114          */

115         public ComputedCSSPaintValue(int idx) {
116             super(null);
117             valueProvider = this;
118             index = idx;
119         }
120
121         /**
122          * Returns the Value associated with this object.
123          */

124         public Value getValue() {
125             return cssEngine.getComputedStyle(element, pseudoElement, index);
126         }
127     }
128 }
129
Popular Tags