01: /*
02:
03: Licensed to the Apache Software Foundation (ASF) under one or more
04: contributor license agreements. See the NOTICE file distributed with
05: this work for additional information regarding copyright ownership.
06: The ASF licenses this file to You under the Apache License, Version 2.0
07: (the "License"); you may not use this file except in compliance with
08: the License. You may obtain a copy of the License at
09:
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.bridge;
20:
21: import org.apache.batik.anim.AbstractAnimation;
22: import org.apache.batik.dom.anim.AnimationTarget;
23: import org.apache.batik.anim.ColorAnimation;
24: import org.apache.batik.anim.values.AnimatableColorValue;
25: import org.apache.batik.anim.values.AnimatablePaintValue;
26: import org.apache.batik.anim.values.AnimatableValue;
27: import org.apache.batik.util.SVGTypes;
28:
29: /**
30: * Bridge class for the 'animateColor' animation element.
31: *
32: * @author <a href="mailto:cam%40mcc%2eid%2eau">Cameron McCormack</a>
33: * @version $Id: SVGAnimateColorElementBridge.java 475477 2006-11-15 22:44:28Z cam $
34: */
35: public class SVGAnimateColorElementBridge extends
36: SVGAnimateElementBridge {
37:
38: /**
39: * Returns 'animateColor'.
40: */
41: public String getLocalName() {
42: return SVG_ANIMATE_COLOR_TAG;
43: }
44:
45: /**
46: * Returns a new instance of this bridge.
47: */
48: public Bridge getInstance() {
49: return new SVGAnimateColorElementBridge();
50: }
51:
52: /**
53: * Creates the animation object for the animation element.
54: */
55: protected AbstractAnimation createAnimation(AnimationTarget target) {
56: AnimatableValue from = parseAnimatableValue(SVG_FROM_ATTRIBUTE);
57: AnimatableValue to = parseAnimatableValue(SVG_TO_ATTRIBUTE);
58: AnimatableValue by = parseAnimatableValue(SVG_BY_ATTRIBUTE);
59: return new ColorAnimation(timedElement, this , parseCalcMode(),
60: parseKeyTimes(), parseKeySplines(), parseAdditive(),
61: parseAccumulate(), parseValues(), from, to, by);
62: }
63:
64: /**
65: * Returns whether the animation element being handled by this bridge can
66: * animate attributes of the specified type.
67: * @param type one of the TYPE_ constants defined in {@link SVGTypes}.
68: */
69: protected boolean canAnimateType(int type) {
70: return type == SVGTypes.TYPE_COLOR
71: || type == SVGTypes.TYPE_PAINT;
72: }
73:
74: /**
75: * Returns whether the specified {@link AnimatableValue} is of a type allowed
76: * by this animation.
77: */
78: protected boolean checkValueType(AnimatableValue v) {
79: if (v instanceof AnimatablePaintValue) {
80: return ((AnimatablePaintValue) v).getPaintType() == AnimatablePaintValue.PAINT_COLOR;
81: }
82: return v instanceof AnimatableColorValue;
83: }
84: }
|