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.dom.svg;
020:
021: import java.util.Iterator;
022: import java.util.LinkedList;
023:
024: import org.apache.batik.anim.values.AnimatableValue;
025:
026: /**
027: * An abstract base class for the <code>SVGAnimated*</code> classes, that
028: * implements an {@link AnimatedAttributeListener} list.
029: *
030: * @author <a href="mailto:cam%40mcc%2eid%2eau">Cameron McCormack</a>
031: * @version $Id: AbstractSVGAnimatedValue.java 490655 2006-12-28 05:19:44Z cam $
032: */
033: public abstract class AbstractSVGAnimatedValue implements
034: AnimatedLiveAttributeValue {
035:
036: /**
037: * The associated element.
038: */
039: protected AbstractElement element;
040:
041: /**
042: * The namespace URI of the attribute.
043: */
044: protected String namespaceURI;
045:
046: /**
047: * The local name of the attribute.
048: */
049: protected String localName;
050:
051: /**
052: * Whether there is a current animated value.
053: */
054: protected boolean hasAnimVal;
055:
056: /**
057: * Listener list.
058: */
059: protected LinkedList listeners = new LinkedList();
060:
061: /**
062: * Creates a new AbstractSVGAnimatedValue.
063: */
064: public AbstractSVGAnimatedValue(AbstractElement elt, String ns,
065: String ln) {
066: element = elt;
067: namespaceURI = ns;
068: localName = ln;
069: }
070:
071: /**
072: * Returns the namespace URI of the attribute.
073: */
074: public String getNamespaceURI() {
075: return namespaceURI;
076: }
077:
078: /**
079: * Returns the local name of the attribute.
080: */
081: public String getLocalName() {
082: return localName;
083: }
084:
085: /**
086: * Returns whether this animated value has a specified value.
087: * @return true if the DOM attribute is specified or if the attribute has
088: * an animated value, false otherwise
089: */
090: public boolean isSpecified() {
091: return hasAnimVal
092: || element.hasAttributeNS(namespaceURI, localName);
093: }
094:
095: /**
096: * Updates the animated value with the given {@link AnimatableValue}.
097: */
098: protected abstract void updateAnimatedValue(AnimatableValue val);
099:
100: /**
101: * Adds a listener for changes to the animated value.
102: */
103: public void addAnimatedAttributeListener(
104: AnimatedAttributeListener aal) {
105: if (!listeners.contains(aal)) {
106: listeners.add(aal);
107: }
108: }
109:
110: /**
111: * Removes a listener for changes to the animated value.
112: */
113: public void removeAnimatedAttributeListener(
114: AnimatedAttributeListener aal) {
115: listeners.remove(aal);
116: }
117:
118: /**
119: * Fires the listeners for the base value.
120: */
121: protected void fireBaseAttributeListeners() {
122: if (element instanceof SVGOMElement) {
123: ((SVGOMElement) element).fireBaseAttributeListeners(
124: namespaceURI, localName);
125: }
126: }
127:
128: /**
129: * Fires the listeners for the animated value.
130: */
131: protected void fireAnimatedAttributeListeners() {
132: Iterator i = listeners.iterator();
133: while (i.hasNext()) {
134: AnimatedAttributeListener listener = (AnimatedAttributeListener) i
135: .next();
136: listener.animatedAttributeChanged(element, this);
137: }
138: }
139: }
|