001    /*
002     * TrackManager.java
003     *
004     *  The Salamander Project - 2D and 3D graphics libraries in Java
005     *  Copyright (C) 2004 Mark McKay
006     *
007     *  This library is free software; you can redistribute it and/or
008     *  modify it under the terms of the GNU Lesser General Public
009     *  License as published by the Free Software Foundation; either
010     *  version 2.1 of the License, or (at your option) any later version.
011     *
012     *  This library is distributed in the hope that it will be useful,
013     *  but WITHOUT ANY WARRANTY; without even the implied warranty of
014     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015     *  Lesser General Public License for more details.
016     *
017     *  You should have received a copy of the GNU Lesser General Public
018     *  License along with this library; if not, write to the Free Software
019     *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020     *
021     *  Mark McKay can be contacted at mark@kitfox.com.  Salamander and other
022     *  projects can be found at http://www.kitfox.com
023     *
024     * Created on August 15, 2004, 11:34 PM
025     */
026    
027    package com.kitfox.svg.animation;
028    
029    import java.util.*;
030    
031    import com.kitfox.svg.xml.*;
032    import com.kitfox.svg.*;
033    
034    /**
035     * A track holds the animation events for a single parameter of a single SVG 
036     * element.  It also contains the default value for the element, should the
037     * user want to see the 'unanimated' value.
038     *
039     * @author Mark McKay
040     * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
041     */
042    abstract public class TrackBase
043    {
044        protected final String attribName;
045        protected final int attribType;  //AnimationElement.AT_*
046     
047        /** Element we're animating */
048        protected final SVGElement parent;
049        
050        //It doesn't make sense to sort this, since some events will depend on
051        // other events - in many cases, there will be no meaningful sorted order.
052        final ArrayList animEvents = new ArrayList();
053        
054        /** Creates a new instance of TrackManager */
055    //    public TrackBase(SVGElement parent)
056    //    {
057    //        this(parent, "", AnimationElement.AT_AUTO);
058    //    }
059        
060        /**
061         * Creates a track that would be valid for the name and type of element
062         * passed in.  Does not actually add this elemnt to the track.
063         */
064        public TrackBase(SVGElement parent, AnimationElement ele) throws SVGElementException
065        {
066            this(parent, ele.getAttribName(), ele.getAttribType());
067        }
068        
069        public TrackBase(SVGElement parent, String attribName, int attribType) throws SVGElementException
070        {
071            this.parent = parent;
072            this.attribName = attribName;
073            this.attribType = attribType;
074            
075            //Make sure parent has an attribute we will write to
076            if (attribType == AnimationElement.AT_AUTO 
077                && !parent.hasAttribute(attribName, AnimationElement.AT_CSS)
078                && !parent.hasAttribute(attribName, AnimationElement.AT_XML))
079            {
080                parent.addAttribute(attribName, AnimationElement.AT_CSS, "");
081            }
082            else if (!parent.hasAttribute(attribName, attribType))
083            {
084                parent.addAttribute(attribName, attribType, "");
085            }
086        }
087        
088        public String getAttribName() { return attribName; }
089        public int getAttribType() { return attribType; }
090        
091        public void addElement(AnimationElement ele)
092        {
093            animEvents.add(ele);
094        }
095        
096        /**
097         * Returns a StyleAttribute representing the value of this track at the
098         * passed time.  If this track does not apply, returns null.
099         * @return - True if successful, false if a value could not be obtained
100         */
101        abstract public boolean getValue(StyleAttribute attrib, double curTime) throws SVGException;
102        
103    }