1 /*
2
3 Licensed to the Apache Software Foundation (ASF) under one or more
4 contributor license agreements. See the NOTICE file distributed with
5 this work for additional information regarding copyright ownership.
6 The ASF licenses this file to You under the Apache License, Version 2.0
7 (the "License"); you may not use this file except in compliance with
8 the License. You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17
18 */
19 package org.apache.batik.css.engine.value.svg;
20
21 import org.apache.batik.css.engine.CSSEngine;
22 import org.apache.batik.css.engine.value.AbstractValueManager;
23 import org.apache.batik.css.engine.value.FloatValue;
24 import org.apache.batik.css.engine.value.Value;
25 import org.apache.batik.css.engine.value.ValueManager;
26 import org.apache.batik.util.SVGTypes;
27
28 import org.w3c.css.sac.LexicalUnit;
29 import org.w3c.dom.DOMException;
30 import org.w3c.dom.css.CSSPrimitiveValue;
31
32 /**
33 * This class provides a manager for the '*-opacity' property values.
34 *
35 * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
36 * @version $Id: OpacityManager.java 1733416 2016-03-03 07:07:13Z gadams $
37 */
38 public class OpacityManager extends AbstractValueManager {
39
40 /**
41 * Whether the managed property is inherited.
42 */
43 protected boolean inherited;
44
45 /**
46 * The managed property name.
47 */
48 protected String property;
49
50 /**
51 * Creates a new OpacityManager.
52 */
53 public OpacityManager(String prop, boolean inherit) {
54 property = prop;
55 inherited = inherit;
56 }
57
58 /**
59 * Implements {@link ValueManager#isInheritedProperty()}.
60 */
61 public boolean isInheritedProperty() {
62 return inherited;
63 }
64
65 /**
66 * Implements {@link ValueManager#isAnimatableProperty()}.
67 */
68 public boolean isAnimatableProperty() {
69 return true;
70 }
71
72 /**
73 * Implements {@link ValueManager#isAdditiveProperty()}.
74 */
75 public boolean isAdditiveProperty() {
76 return true;
77 }
78
79 /**
80 * Implements {@link ValueManager#getPropertyType()}.
81 */
82 public int getPropertyType() {
83 return SVGTypes.TYPE_NUMBER_OR_INHERIT;
84 }
85
86 /**
87 * Implements {@link ValueManager#getPropertyName()}.
88 */
89 public String getPropertyName() {
90 return property;
91 }
92
93 /**
94 * Implements {@link ValueManager#getDefaultValue()}.
95 */
96 public Value getDefaultValue() {
97 return SVGValueConstants.NUMBER_1;
98 }
99
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,
111 lu.getIntegerValue());
112
113 case LexicalUnit.SAC_REAL:
114 return new FloatValue(CSSPrimitiveValue.CSS_NUMBER,
115 lu.getFloatValue());
116 }
117 throw createInvalidLexicalUnitDOMException(lu.getLexicalUnitType());
118 }
119
120 /**
121 * Implements {@link ValueManager#createFloatValue(short,float)}.
122 */
123 public Value createFloatValue(short type, float floatValue)
124 throws DOMException {
125 if (type == CSSPrimitiveValue.CSS_NUMBER) {
126 return new FloatValue(type, floatValue);
127 }
128 throw createInvalidFloatTypeDOMException(type);
129 }
130 }
131