KickJava   Java API By Example, From Geeks To Geeks.

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


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.value.AbstractValueManager;
22 import org.apache.batik.css.engine.value.FloatValue;
23 import org.apache.batik.css.engine.value.Value;
24 import org.apache.batik.css.engine.value.ValueManager;
25 import org.w3c.css.sac.LexicalUnit;
26 import org.w3c.dom.DOMException JavaDoc;
27 import org.w3c.dom.css.CSSPrimitiveValue;
28
29 /**
30  * This class provides a manager for the '*-opacity' property values.
31  *
32  * @author <a HREF="mailto:stephane@hillion.org">Stephane Hillion</a>
33  * @version $Id: OpacityManager.java,v 1.6 2005/03/27 08:58:31 cam Exp $
34  */

35 public class OpacityManager extends AbstractValueManager {
36     
37     /**
38      * Whether the managed property is inherited.
39      */

40     protected boolean inherited;
41
42     /**
43      * The managed property name.
44      */

45     protected String JavaDoc property;
46
47     /**
48      * Creates a new OpacityManager.
49      */

50     public OpacityManager(String JavaDoc prop, boolean inherit) {
51         property = prop;
52         inherited = inherit;
53     }
54
55     /**
56      * Implements {@link ValueManager#isInheritedProperty()}.
57      */

58     public boolean isInheritedProperty() {
59     return inherited;
60     }
61
62     /**
63      * Implements {@link ValueManager#getPropertyName()}.
64      */

65     public String JavaDoc getPropertyName() {
66     return property;
67     }
68     
69     /**
70      * Implements {@link ValueManager#getDefaultValue()}.
71      */

72     public Value getDefaultValue() {
73         return SVGValueConstants.NUMBER_1;
74     }
75
76     /**
77      * Implements {@link ValueManager#createValue(LexicalUnit,CSSEngine)}.
78      */

79     public Value createValue(LexicalUnit lu, CSSEngine engine)
80         throws DOMException JavaDoc {
81     switch (lu.getLexicalUnitType()) {
82     case LexicalUnit.SAC_INHERIT:
83         return SVGValueConstants.INHERIT_VALUE;
84
85         case LexicalUnit.SAC_INTEGER:
86             return new FloatValue(CSSPrimitiveValue.CSS_NUMBER,
87                                   lu.getIntegerValue());
88
89         case LexicalUnit.SAC_REAL:
90             return new FloatValue(CSSPrimitiveValue.CSS_NUMBER,
91                                   lu.getFloatValue());
92         }
93         throw createInvalidLexicalUnitDOMException(lu.getLexicalUnitType());
94     }
95
96     /**
97      * Implements {@link ValueManager#createFloatValue(short,float)}.
98      */

99     public Value createFloatValue(short type, float floatValue)
100         throws DOMException JavaDoc {
101     if (type == CSSPrimitiveValue.CSS_NUMBER) {
102         return new FloatValue(type, floatValue);
103     }
104         throw createInvalidFloatTypeDOMException(type);
105     }
106 }
107
Popular Tags