KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > extension > StylableExtensionElement


1 /*
2
3    Copyright 1999-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
19 package org.apache.batik.extension;
20
21 import java.net.MalformedURLException JavaDoc;
22 import java.net.URL JavaDoc;
23
24 import org.apache.batik.css.engine.CSSStylableElement;
25 import org.apache.batik.css.engine.StyleMap;
26 import org.apache.batik.dom.AbstractDocument;
27 import org.apache.batik.dom.svg.XMLBaseSupport;
28 import org.w3c.dom.Node JavaDoc;
29 import org.w3c.dom.css.CSSStyleDeclaration;
30 import org.w3c.dom.css.CSSValue;
31 import org.w3c.dom.svg.SVGAnimatedString;
32 import org.w3c.dom.svg.SVGStylable;
33
34 /**
35  * This class implements the basic features an element must have in
36  * order to be usable as a foreign element within an SVGOMDocument,
37  * and the support for both the 'style' attribute and the style
38  * attributes (ie: fill="red", ...).
39  *
40  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
41  * @version $Id: StylableExtensionElement.java,v 1.7 2005/02/22 09:13:02 cam Exp $
42  */

43 public abstract class StylableExtensionElement
44     extends ExtensionElement
45     implements CSSStylableElement,
46                SVGStylable {
47
48     /**
49      * The base URL.
50      */

51     protected URL JavaDoc cssBase;
52
53     /**
54      * The computed style map.
55      */

56     protected StyleMap computedStyleMap;
57
58     /**
59      * Creates a new Element object.
60      */

61     protected StylableExtensionElement() {
62     }
63
64     /**
65      * Creates a new Element object.
66      * @param name The element name, for validation purposes.
67      * @param owner The owner document.
68      */

69     protected StylableExtensionElement(String JavaDoc name, AbstractDocument owner) {
70         super(name, owner);
71     }
72
73     // CSSStylableElement //////////////////////////////////////////
74

75     /**
76      * Returns the computed style of this element/pseudo-element.
77      */

78     public StyleMap getComputedStyleMap(String JavaDoc pseudoElement) {
79         return computedStyleMap;
80     }
81
82     /**
83      * Sets the computed style of this element/pseudo-element.
84      */

85     public void setComputedStyleMap(String JavaDoc pseudoElement, StyleMap sm) {
86         computedStyleMap = sm;
87     }
88
89     /**
90      * Returns the ID of this element.
91      */

92     public String JavaDoc getXMLId() {
93         return getAttributeNS(null, "id");
94     }
95
96     /**
97      * Returns the class of this element.
98      */

99     public String JavaDoc getCSSClass() {
100         return getAttributeNS(null, "class");
101     }
102
103     /**
104      * Returns the CSS base URL of this element.
105      */

106     public URL JavaDoc getCSSBase() {
107         if (cssBase == null) {
108             try {
109                 String JavaDoc bu = XMLBaseSupport.getCascadedXMLBase(this);
110                 if (bu == null) {
111                     return null;
112                 }
113                 cssBase = new URL JavaDoc(XMLBaseSupport.getCascadedXMLBase(this));
114             } catch (MalformedURLException JavaDoc e) {
115                 // !!! TODO
116
e.printStackTrace();
117                 throw new InternalError JavaDoc();
118             }
119         }
120         return cssBase;
121     }
122
123     /**
124      * Tells whether this element is an instance of the given pseudo
125      * class.
126      */

127     public boolean isPseudoInstanceOf(String JavaDoc pseudoClass) {
128         if (pseudoClass.equals("first-child")) {
129             Node JavaDoc n = getPreviousSibling();
130             while (n != null && n.getNodeType() != ELEMENT_NODE) {
131                 n = n.getPreviousSibling();
132             }
133             return n == null;
134         }
135         return false;
136     }
137
138     // SVGStylable //////////////////////////////////////////////////
139

140     /**
141      * <b>DOM</b>: Implements {@link org.w3c.dom.svg.SVGStylable#getStyle()}.
142      */

143     public CSSStyleDeclaration getStyle() {
144         throw new InternalError JavaDoc("Not implemented");
145     }
146
147     /**
148      * <b>DOM</b>: Implements {@link
149      * org.w3c.dom.svg.SVGStylable#getPresentationAttribute(String)}.
150      */

151     public CSSValue getPresentationAttribute(String JavaDoc name) {
152         throw new InternalError JavaDoc("Not implemented");
153     }
154
155     /**
156      * <b>DOM</b>: Implements {@link
157      * org.w3c.dom.svg.SVGStylable#getClassName()}.
158      */

159     public SVGAnimatedString getClassName() {
160         throw new InternalError JavaDoc("Not implemented");
161     }
162 }
163
Popular Tags