001: /*
002:
003: Licensed to the Apache Software Foundation (ASF) under one or more
004: contributor license agreements. See the NOTICE file distributed with
005: this work for additional information regarding copyright ownership.
006: The ASF licenses this file to You under the Apache License, Version 2.0
007: (the "License"); you may not use this file except in compliance with
008: the License. You may obtain a copy of the License at
009:
010: http://www.apache.org/licenses/LICENSE-2.0
011:
012: Unless required by applicable law or agreed to in writing, software
013: distributed under the License is distributed on an "AS IS" BASIS,
014: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: See the License for the specific language governing permissions and
016: limitations under the License.
017:
018: */
019: package org.apache.batik.css.engine.value.svg;
020:
021: import org.apache.batik.css.engine.CSSEngine;
022: import org.apache.batik.css.engine.value.AbstractValueManager;
023: import org.apache.batik.css.engine.value.FloatValue;
024: import org.apache.batik.css.engine.value.Value;
025: import org.apache.batik.css.engine.value.ValueManager;
026: import org.apache.batik.util.SVGTypes;
027:
028: import org.w3c.css.sac.LexicalUnit;
029: import org.w3c.dom.DOMException;
030: import org.w3c.dom.css.CSSPrimitiveValue;
031:
032: /**
033: * This class provides a manager for the '*-opacity' property values.
034: *
035: * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
036: * @version $Id: OpacityManager.java 475685 2006-11-16 11:16:05Z cam $
037: */
038: public class OpacityManager extends AbstractValueManager {
039:
040: /**
041: * Whether the managed property is inherited.
042: */
043: protected boolean inherited;
044:
045: /**
046: * The managed property name.
047: */
048: protected String property;
049:
050: /**
051: * Creates a new OpacityManager.
052: */
053: public OpacityManager(String prop, boolean inherit) {
054: property = prop;
055: inherited = inherit;
056: }
057:
058: /**
059: * Implements {@link ValueManager#isInheritedProperty()}.
060: */
061: public boolean isInheritedProperty() {
062: return inherited;
063: }
064:
065: /**
066: * Implements {@link ValueManager#isAnimatableProperty()}.
067: */
068: public boolean isAnimatableProperty() {
069: return true;
070: }
071:
072: /**
073: * Implements {@link ValueManager#isAdditiveProperty()}.
074: */
075: public boolean isAdditiveProperty() {
076: return true;
077: }
078:
079: /**
080: * Implements {@link ValueManager#getPropertyType()}.
081: */
082: public int getPropertyType() {
083: return SVGTypes.TYPE_NUMBER_OR_INHERIT;
084: }
085:
086: /**
087: * Implements {@link ValueManager#getPropertyName()}.
088: */
089: public String getPropertyName() {
090: return property;
091: }
092:
093: /**
094: * Implements {@link ValueManager#getDefaultValue()}.
095: */
096: public Value getDefaultValue() {
097: return SVGValueConstants.NUMBER_1;
098: }
099:
100: /**
101: * Implements {@link ValueManager#createValue(LexicalUnit,CSSEngine)}.
102: */
103: public Value createValue(LexicalUnit lu, CSSEngine engine)
104: throws DOMException {
105: switch (lu.getLexicalUnitType()) {
106: case LexicalUnit.SAC_INHERIT:
107: return SVGValueConstants.INHERIT_VALUE;
108:
109: case LexicalUnit.SAC_INTEGER:
110: return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, lu
111: .getIntegerValue());
112:
113: case LexicalUnit.SAC_REAL:
114: return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, lu
115: .getFloatValue());
116: }
117: throw createInvalidLexicalUnitDOMException(lu
118: .getLexicalUnitType());
119: }
120:
121: /**
122: * Implements {@link ValueManager#createFloatValue(short,float)}.
123: */
124: public Value createFloatValue(short type, float floatValue)
125: throws DOMException {
126: if (type == CSSPrimitiveValue.CSS_NUMBER) {
127: return new FloatValue(type, floatValue);
128: }
129: throw createInvalidFloatTypeDOMException(type);
130: }
131: }
|