KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > css > engine > value > svg > SVGPaintManager


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.engine.value.svg;
19
20 import org.apache.batik.css.engine.CSSEngine;
21 import org.apache.batik.css.engine.CSSStylableElement;
22 import org.apache.batik.css.engine.StyleMap;
23 import org.apache.batik.css.engine.value.ListValue;
24 import org.apache.batik.css.engine.value.URIValue;
25 import org.apache.batik.css.engine.value.Value;
26 import org.apache.batik.css.engine.value.ValueManager;
27 import org.apache.batik.util.CSSConstants;
28 import org.w3c.css.sac.LexicalUnit;
29 import org.w3c.dom.css.CSSPrimitiveValue;
30 import org.w3c.dom.css.CSSValue;
31 import org.w3c.dom.DOMException JavaDoc;
32
33 /**
34  * This class provides a manager for the SVGPaint property values.
35  *
36  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
37  * @version $Id: SVGPaintManager.java,v 1.7 2005/03/27 08:58:31 cam Exp $
38  */

39 public class SVGPaintManager extends SVGColorManager {
40     
41     /**
42      * Creates a new SVGPaintManager.
43      */

44     public SVGPaintManager(String JavaDoc prop) {
45         super(prop);
46     }
47
48     /**
49      * Creates a new SVGPaintManager.
50      * @param prop The property name.
51      * @param v The default value.
52      */

53     public SVGPaintManager(String JavaDoc prop, Value v) {
54         super(prop, v);
55     }
56
57     /**
58      * Implements {@link ValueManager#isInheritedProperty()}.
59      */

60     public boolean isInheritedProperty() {
61     return true;
62     }
63
64     /**
65      * Implements {@link ValueManager#createValue(LexicalUnit,CSSEngine)}.
66      */

67     public Value createValue(LexicalUnit lu, CSSEngine engine)
68         throws DOMException JavaDoc {
69     switch (lu.getLexicalUnitType()) {
70         case LexicalUnit.SAC_IDENT:
71             if (lu.getStringValue().equalsIgnoreCase
72                 (CSSConstants.CSS_NONE_VALUE)) {
73                 return SVGValueConstants.NONE_VALUE;
74             }
75             // Fall through
76
default:
77             return super.createValue(lu, engine);
78         case LexicalUnit.SAC_URI:
79         }
80         String JavaDoc value = lu.getStringValue();
81         String JavaDoc uri = resolveURI(engine.getCSSBaseURI(), value);
82         lu = lu.getNextLexicalUnit();
83         if (lu == null) {
84             return new URIValue(value, uri);
85         }
86
87         ListValue result = new ListValue(' ');
88         result.append(new URIValue(value, uri));
89
90     if (lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
91             if (lu.getStringValue().equalsIgnoreCase
92                 (CSSConstants.CSS_NONE_VALUE)) {
93                 result.append(SVGValueConstants.NONE_VALUE);
94                 return result;
95             }
96         }
97         Value v = super.createValue(lu, engine);
98         if (v.getCssValueType() == CSSValue.CSS_CUSTOM) {
99             ListValue lv = (ListValue)v;
100             for (int i = 0; i < lv.getLength(); i++) {
101                 result.append(lv.item(i));
102             }
103         } else {
104             result.append(v);
105         }
106         return result;
107     }
108
109     /**
110      * Implements {@link
111      * ValueManager#computeValue(CSSStylableElement,String,CSSEngine,int,StyleMap,Value)}.
112      */

113     public Value computeValue(CSSStylableElement elt,
114                               String JavaDoc pseudo,
115                               CSSEngine engine,
116                               int idx,
117                               StyleMap sm,
118                               Value value) {
119         if (value == SVGValueConstants.NONE_VALUE) {
120             return value;
121         }
122         if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) {
123             ListValue lv = (ListValue)value;
124             Value v = lv.item(0);
125             if (v.getPrimitiveType() == CSSPrimitiveValue.CSS_URI) {
126                 v = lv.item(1);
127                 if (v == SVGValueConstants.NONE_VALUE) {
128                     return value;
129                 }
130                 Value t = super.computeValue(elt, pseudo, engine, idx, sm, v);
131                 if (t != v) {
132                     ListValue result = new ListValue(' ');
133                     result.append(lv.item(0));
134                     result.append(t);
135                     if (lv.getLength() == 3) {
136                         result.append(lv.item(1));
137                     }
138                     return result;
139                 }
140                 return value;
141             }
142         }
143         return super.computeValue(elt, pseudo, engine, idx, sm, value);
144     }
145 }
146
Popular Tags