KickJava   Java API By Example, From Geeks To Geeks.

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


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 manager for the 'enable-background' property values.
35  *
36  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
37  * @version $Id: EnableBackgroundManager.java,v 1.5 2005/03/27 08:58:31 cam Exp $
38  */

39 public class EnableBackgroundManager extends LengthManager {
40     
41     /**
42      * The length orientation.
43      */

44     protected int orientation;
45
46     /**
47      * Implements {@link ValueManager#isInheritedProperty()}.
48      */

49     public boolean isInheritedProperty() {
50     return false;
51     }
52
53     /**
54      * Implements {@link ValueManager#getPropertyName()}.
55      */

56     public String JavaDoc getPropertyName() {
57     return CSSConstants.CSS_ENABLE_BACKGROUND_PROPERTY;
58     }
59     
60     /**
61      * Implements {@link ValueManager#getDefaultValue()}.
62      */

63     public Value getDefaultValue() {
64         return SVGValueConstants.ACCUMULATE_VALUE;
65     }
66
67     /**
68      * Implements {@link ValueManager#createValue(LexicalUnit,CSSEngine)}.
69      */

70     public Value createValue(LexicalUnit lu, CSSEngine engine)
71         throws DOMException JavaDoc {
72         switch (lu.getLexicalUnitType()) {
73         case LexicalUnit.SAC_INHERIT:
74             return SVGValueConstants.INHERIT_VALUE;
75
76         default:
77             throw createInvalidLexicalUnitDOMException
78                 (lu.getLexicalUnitType());
79
80         case LexicalUnit.SAC_IDENT:
81             String JavaDoc id = lu.getStringValue().toLowerCase().intern();
82             if (id == CSSConstants.CSS_ACCUMULATE_VALUE) {
83                 return SVGValueConstants.ACCUMULATE_VALUE;
84             }
85             if (id != CSSConstants.CSS_NEW_VALUE) {
86                 throw createInvalidIdentifierDOMException(id);
87             }
88             ListValue result = new ListValue(' ');
89             result.append(SVGValueConstants.NEW_VALUE);
90             lu = lu.getNextLexicalUnit();
91             if (lu == null) {
92                 return result;
93             }
94             result.append(super.createValue(lu, engine));
95             for (int i = 1; i < 4; i++) {
96                 lu = lu.getNextLexicalUnit();
97                 if (lu == null){
98                     throw createMalformedLexicalUnitDOMException();
99                 }
100                 result.append(super.createValue(lu, engine));
101             }
102             return result;
103         }
104     }
105
106     /**
107      * Implements {@link
108      * ValueManager#createStringValue(short,String,CSSEngine)}.
109      */

110     public Value createStringValue(short type, String JavaDoc value,
111                                    CSSEngine engine) {
112     if (type != CSSPrimitiveValue.CSS_IDENT) {
113             throw createInvalidStringTypeDOMException(type);
114     }
115     if (!value.equalsIgnoreCase(CSSConstants.CSS_ACCUMULATE_VALUE)) {
116             throw createInvalidIdentifierDOMException(value);
117         }
118     return SVGValueConstants.ACCUMULATE_VALUE;
119     }
120
121     /**
122      * Implements {@link ValueManager#createFloatValue(short,float)}.
123      */

124     public Value createFloatValue(short unitType, float floatValue)
125     throws DOMException JavaDoc {
126         throw createDOMException();
127     }
128
129     /**
130      * Implements {@link
131      * ValueManager#computeValue(CSSStylableElement,String,CSSEngine,int,StyleMap,Value)}.
132      */

133     public Value computeValue(CSSStylableElement elt,
134                               String JavaDoc pseudo,
135                               CSSEngine engine,
136                               int idx,
137                               StyleMap sm,
138                               Value value) {
139         if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) {
140             ListValue lv = (ListValue)value;
141             if (lv.getLength() == 5) {
142                 Value lv1 = lv.item(1);
143                 orientation = HORIZONTAL_ORIENTATION;
144                 Value v1 = super.computeValue(elt, pseudo, engine,
145                                               idx, sm, lv1);
146                 Value lv2 = lv.item(2);
147                 orientation = VERTICAL_ORIENTATION;
148                 Value v2 = super.computeValue(elt, pseudo, engine,
149                                               idx, sm, lv2);
150                 Value lv3 = lv.item(3);
151                 orientation = HORIZONTAL_ORIENTATION;
152                 Value v3 = super.computeValue(elt, pseudo, engine,
153                                               idx, sm, lv3);
154                 Value lv4 = lv.item(4);
155                 orientation = VERTICAL_ORIENTATION;
156                 Value v4 = super.computeValue(elt, pseudo, engine,
157                                               idx, sm, lv4);
158
159                 if (lv1 != v1 || lv2 != v2 ||
160                     lv3 != v3 || lv4 != v4) {
161                     ListValue result = new ListValue(' ');
162                     result.append(lv.item(0));
163                     result.append(v1);
164                     result.append(v2);
165                     result.append(v3);
166                     result.append(v4);
167                     return result;
168                 }
169             }
170         }
171         return value;
172     }
173
174     /**
175      * Indicates the orientation of the property associated with
176      * this manager.
177      */

178     protected int getOrientation() {
179         return orientation;
180     }
181
182 }
183
Popular Tags