KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > css > engine > value > css2 > CursorManager


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.css2;
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.AbstractValueManager;
24 import org.apache.batik.css.engine.value.ListValue;
25 import org.apache.batik.css.engine.value.StringMap;
26 import org.apache.batik.css.engine.value.URIValue;
27 import org.apache.batik.css.engine.value.Value;
28 import org.apache.batik.css.engine.value.ValueConstants;
29 import org.apache.batik.css.engine.value.ValueManager;
30 import org.apache.batik.util.CSSConstants;
31 import org.w3c.css.sac.LexicalUnit;
32 import org.w3c.dom.DOMException JavaDoc;
33 import org.w3c.dom.css.CSSPrimitiveValue;
34 import org.w3c.dom.css.CSSValue;
35
36 /**
37  * This class provides a manager for the 'cursor' property values.
38  *
39  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
40  * @version $Id: CursorManager.java,v 1.6 2005/03/27 08:58:31 cam Exp $
41  */

42 public class CursorManager extends AbstractValueManager {
43     
44     /**
45      * The identifier values.
46      */

47     protected final static StringMap values = new StringMap();
48     static {
49     values.put(CSSConstants.CSS_AUTO_VALUE,
50                    ValueConstants.AUTO_VALUE);
51     values.put(CSSConstants.CSS_CROSSHAIR_VALUE,
52                    ValueConstants.CROSSHAIR_VALUE);
53     values.put(CSSConstants.CSS_DEFAULT_VALUE,
54                    ValueConstants.DEFAULT_VALUE);
55     values.put(CSSConstants.CSS_E_RESIZE_VALUE,
56                    ValueConstants.E_RESIZE_VALUE);
57     values.put(CSSConstants.CSS_HELP_VALUE,
58                    ValueConstants.HELP_VALUE);
59     values.put(CSSConstants.CSS_MOVE_VALUE,
60                    ValueConstants.MOVE_VALUE);
61     values.put(CSSConstants.CSS_N_RESIZE_VALUE,
62                    ValueConstants.N_RESIZE_VALUE);
63     values.put(CSSConstants.CSS_NE_RESIZE_VALUE,
64                    ValueConstants.NE_RESIZE_VALUE);
65     values.put(CSSConstants.CSS_NW_RESIZE_VALUE,
66                    ValueConstants.NW_RESIZE_VALUE);
67     values.put(CSSConstants.CSS_POINTER_VALUE,
68                    ValueConstants.POINTER_VALUE);
69     values.put(CSSConstants.CSS_S_RESIZE_VALUE,
70                    ValueConstants.S_RESIZE_VALUE);
71     values.put(CSSConstants.CSS_SE_RESIZE_VALUE,
72                    ValueConstants.SE_RESIZE_VALUE);
73     values.put(CSSConstants.CSS_SW_RESIZE_VALUE,
74                    ValueConstants.SW_RESIZE_VALUE);
75     values.put(CSSConstants.CSS_TEXT_VALUE,
76                    ValueConstants.TEXT_VALUE);
77     values.put(CSSConstants.CSS_W_RESIZE_VALUE,
78                    ValueConstants.W_RESIZE_VALUE);
79     values.put(CSSConstants.CSS_WAIT_VALUE,
80                    ValueConstants.WAIT_VALUE);
81     }
82
83     /**
84      * Implements {@link ValueManager#isInheritedProperty()}.
85      */

86     public boolean isInheritedProperty() {
87     return true;
88     }
89
90     /**
91      * Implements {@link ValueManager#getPropertyName()}.
92      */

93     public String JavaDoc getPropertyName() {
94     return CSSConstants.CSS_CURSOR_PROPERTY;
95     }
96     
97     /**
98      * Implements {@link ValueManager#getDefaultValue()}.
99      */

100     public Value getDefaultValue() {
101         return ValueConstants.AUTO_VALUE;
102     }
103
104     /**
105      * Implements {@link ValueManager#createValue(LexicalUnit,CSSEngine)}.
106      */

107     public Value createValue(LexicalUnit lu, CSSEngine engine)
108         throws DOMException JavaDoc {
109         ListValue result = new ListValue();
110     switch (lu.getLexicalUnitType()) {
111     case LexicalUnit.SAC_INHERIT:
112         return ValueConstants.INHERIT_VALUE;
113
114         case LexicalUnit.SAC_URI:
115             do {
116                 result.append(new URIValue(lu.getStringValue(),
117                                            resolveURI(engine.getCSSBaseURI(),
118                                                       lu.getStringValue())));
119                 lu = lu.getNextLexicalUnit();
120                 if (lu == null) {
121                     throw createMalformedLexicalUnitDOMException();
122                 }
123                 if (lu.getLexicalUnitType() !=
124                     LexicalUnit.SAC_OPERATOR_COMMA) {
125                     throw createInvalidLexicalUnitDOMException
126                         (lu.getLexicalUnitType());
127                 }
128                 lu = lu.getNextLexicalUnit();
129                 if (lu == null) {
130                     throw createMalformedLexicalUnitDOMException();
131                 }
132             } while (lu.getLexicalUnitType() == LexicalUnit.SAC_URI);
133             if (lu.getLexicalUnitType() != LexicalUnit.SAC_IDENT) {
134                 throw createInvalidLexicalUnitDOMException
135                     (lu.getLexicalUnitType());
136             }
137             // Fall through...
138

139         case LexicalUnit.SAC_IDENT:
140             String JavaDoc s = lu.getStringValue().toLowerCase().intern();
141         Object JavaDoc v = values.get(s);
142         if (v == null) {
143         throw createInvalidIdentifierDOMException(lu.getStringValue());
144         }
145             result.append((Value)v);
146             lu = lu.getNextLexicalUnit();
147         }
148         if (lu != null) {
149             throw createInvalidLexicalUnitDOMException
150                 (lu.getLexicalUnitType());
151         }
152         return result;
153     }
154
155     /**
156      * Implements {@link
157      * ValueManager#computeValue(CSSStylableElement,String,CSSEngine,int,StyleMap,Value)}.
158      */

159     public Value computeValue(CSSStylableElement elt,
160                               String JavaDoc pseudo,
161                               CSSEngine engine,
162                               int idx,
163                               StyleMap sm,
164                               Value value) {
165         if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) {
166             ListValue lv = (ListValue)value;
167             int len = lv.getLength();
168             ListValue result = new ListValue(' ');
169             for (int i=0; i<len; i++) {
170                 Value v = lv.item(0);
171                 if (v.getPrimitiveType() == CSSPrimitiveValue.CSS_URI) {
172                     // Reveal the absolute value as the cssText now.
173
result.append(new URIValue(v.getStringValue(),
174                                                v.getStringValue()));
175                 } else {
176                     result.append(v);
177                 }
178             }
179             return result;
180         }
181         return super.computeValue(elt, pseudo, engine, idx, sm, value);
182     }
183
184 }
185
Popular Tags