KickJava   Java API By Example, From Geeks To Geeks.

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


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.LengthManager;
24 import org.apache.batik.css.engine.value.ListValue;
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.DOMException JavaDoc;
30 import org.w3c.dom.css.CSSPrimitiveValue;
31 import org.w3c.dom.css.CSSValue;
32
33 /**
34  * This class provides a factory for the 'stroke-dasharray' property values.
35  *
36  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
37  * @version $Id: StrokeDasharrayManager.java,v 1.6 2005/03/27 08:58:31 cam Exp $
38  */

39 public class StrokeDasharrayManager extends LengthManager {
40     
41     /**
42      * Implements {@link ValueManager#isInheritedProperty()}.
43      */

44     public boolean isInheritedProperty() {
45     return true;
46     }
47
48     /**
49      * Implements {@link ValueManager#getPropertyName()}.
50      */

51     public String JavaDoc getPropertyName() {
52     return CSSConstants.CSS_STROKE_DASHARRAY_PROPERTY;
53     }
54     
55     /**
56      * Implements {@link ValueManager#getDefaultValue()}.
57      */

58     public Value getDefaultValue() {
59         return SVGValueConstants.NONE_VALUE;
60     }
61
62     /**
63      * Implements {@link ValueManager#createValue(LexicalUnit,CSSEngine)}.
64      */

65     public Value createValue(LexicalUnit lu, CSSEngine engine)
66         throws DOMException JavaDoc {
67         switch (lu.getLexicalUnitType()) {
68         case LexicalUnit.SAC_INHERIT:
69             return SVGValueConstants.INHERIT_VALUE;
70
71     case LexicalUnit.SAC_IDENT:
72         if (lu.getStringValue().equalsIgnoreCase
73                 (CSSConstants.CSS_NONE_VALUE)) {
74         return SVGValueConstants.NONE_VALUE;
75         }
76             throw createInvalidIdentifierDOMException(lu.getStringValue());
77
78     default:
79             ListValue lv = new ListValue(' ');
80             do {
81                 Value v = super.createValue(lu, engine);
82                 lv.append(v);
83                 lu = lu.getNextLexicalUnit();
84                 if (lu != null &&
85                     lu.getLexicalUnitType() ==
86                     LexicalUnit.SAC_OPERATOR_COMMA) {
87                     lu = lu.getNextLexicalUnit();
88                 }
89             } while (lu != null);
90             return lv;
91         }
92     }
93
94     /**
95      * Implements {@link
96      * ValueManager#createStringValue(short,String,CSSEngine)}.
97      */

98     public Value createStringValue(short type, String JavaDoc value, CSSEngine engine)
99         throws DOMException JavaDoc {
100         if (type != CSSPrimitiveValue.CSS_IDENT) {
101             throw createInvalidStringTypeDOMException(type);
102         }
103         if (value.equalsIgnoreCase(CSSConstants.CSS_NONE_VALUE)) {
104             return SVGValueConstants.NONE_VALUE;
105         }
106         throw createInvalidIdentifierDOMException(value);
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         switch (value.getCssValueType()) {
120         case CSSValue.CSS_PRIMITIVE_VALUE:
121             return value;
122         }
123         
124         ListValue lv = (ListValue)value;
125         ListValue result = new ListValue(' ');
126         for (int i = 0; i < lv.getLength(); i++) {
127             result.append(super.computeValue(elt, pseudo, engine, idx, sm,
128                                              lv.item(i)));
129         }
130         return result;
131     }
132
133     /**
134      * Indicates the orientation of the property associated with
135      * this manager.
136      */

137     protected int getOrientation() {
138         return BOTH_ORIENTATION;
139     }
140 }
141
Popular Tags