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.bridge;
020:
021: import java.util.HashMap;
022: import java.util.Iterator;
023: import java.util.LinkedList;
024:
025: import org.apache.batik.dom.anim.AnimationTarget;
026: import org.apache.batik.dom.anim.AnimationTargetListener;
027: import org.apache.batik.dom.svg.SVGAnimationTargetContext;
028:
029: import org.w3c.dom.Element;
030:
031: /**
032: * Abstract bridge class for those elements that can be animated.
033: *
034: * @author <a href="mailto:cam%40mcc%2eid%2eau">Cameron McCormack</a>
035: * @version $Id: AnimatableSVGBridge.java 490655 2006-12-28 05:19:44Z cam $
036: */
037: public abstract class AnimatableSVGBridge extends AbstractSVGBridge
038: implements SVGAnimationTargetContext {
039:
040: /**
041: * The element that has been handled by this bridge.
042: */
043: protected Element e;
044:
045: /**
046: * The bridge context to use for dynamic updates.
047: */
048: protected BridgeContext ctx;
049:
050: /**
051: * Map of CSS property names to {@link LinkedList}s of
052: * {@link AnimationTargetListener}s.
053: */
054: protected HashMap targetListeners;
055:
056: // SVGAnimationTargetContext /////////////////////////////////////////////
057:
058: /**
059: * Adds a listener for changes to the given attribute value.
060: */
061: public void addTargetListener(String pn, AnimationTargetListener l) {
062: if (targetListeners == null) {
063: targetListeners = new HashMap();
064: }
065: LinkedList ll = (LinkedList) targetListeners.get(pn);
066: if (ll == null) {
067: ll = new LinkedList();
068: targetListeners.put(pn, ll);
069: }
070: ll.add(l);
071: }
072:
073: /**
074: * Removes a listener for changes to the given attribute value.
075: */
076: public void removeTargetListener(String pn,
077: AnimationTargetListener l) {
078: LinkedList ll = (LinkedList) targetListeners.get(pn);
079: ll.remove(l);
080: }
081:
082: /**
083: * Fires the listeners registered for changes to the base value of the
084: * given CSS property.
085: */
086: protected void fireBaseAttributeListeners(String pn) {
087: if (targetListeners != null) {
088: LinkedList ll = (LinkedList) targetListeners.get(pn);
089: if (ll != null) {
090: Iterator it = ll.iterator();
091: while (it.hasNext()) {
092: AnimationTargetListener l = (AnimationTargetListener) it
093: .next();
094: l.baseValueChanged((AnimationTarget) e, null, pn,
095: true);
096: }
097: }
098: }
099: }
100: }
|