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 com.kitfox.svg.xml.StyleAttribute;
030    import java.util.*;
031    
032    import com.kitfox.svg.*;
033    import com.kitfox.svg.xml.*;
034    
035    /**
036     * A track holds the animation events for a single parameter of a single SVG
037     * element.  It also contains the default value for the element, should the
038     * user want to see the 'unanimated' value.
039     *
040     * @author Mark McKay
041     * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
042     */
043    public class TrackDouble extends TrackBase
044    {
045        public TrackDouble(AnimationElement ele) throws SVGElementException
046        {
047            super(ele.getParent(), ele);
048        }
049    
050        public boolean getValue(StyleAttribute attrib, double curTime)
051        {
052            double val = getValue(curTime);
053            if (Double.isNaN(val)) return false;
054    
055            attrib.setStringValue("" + val);
056            return true;
057        }
058    
059        public double getValue(double curTime)
060        {
061            double retVal = Double.NaN;
062            
063            StyleAttribute attr = null;
064            switch (attribType)
065            {
066                case AnimationElement.AT_CSS:
067                    attr = parent.getStyleAbsolute(attribName);
068                    retVal = attr.getDoubleValue();
069                    break;
070                case AnimationElement.AT_XML:
071                    attr = parent.getPresAbsolute(attribName);
072                    retVal = attr.getDoubleValue();
073                    break;
074                case AnimationElement.AT_AUTO:
075                    attr = parent.getStyleAbsolute(attribName);
076                    if (attr == null) attr = parent.getPresAbsolute(attribName);
077                    retVal = attr.getDoubleValue();
078                    break;
079            }
080            
081            
082            
083            AnimationTimeEval state = new AnimationTimeEval();
084    //        boolean pastEnd = true;
085    
086            for (Iterator it = animEvents.iterator(); it.hasNext();)
087            {
088                Animate ele = (Animate)it.next();
089                ele.evalParametric(state, curTime);
090    
091                //Go to next element if this one does not affect processing
092                if (Double.isNaN(state.interp)) continue;
093    
094                switch (ele.getAdditiveType())
095                {
096                    case AnimationElement.AD_SUM:
097                        retVal += ele.eval(state.interp);
098                        break;
099                    case AnimationElement.AD_REPLACE:
100                        retVal = ele.eval(state.interp);
101                        break;
102                }
103                
104                //Evalutae accumulation if applicable
105                if (state.rep > 0)
106                {
107                    switch (ele.getAccumulateType())
108                    {
109                        case AnimationElement.AC_SUM:
110                            retVal += ele.repeatSkipSize(state.rep);
111                            break;
112                    }
113                    
114                }
115            }
116    
117            return retVal;
118        }
119    }