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 September 21, 2004, 11:34 PM
025 */
026
027 package com.kitfox.svg.animation;
028
029 import com.kitfox.svg.xml.StyleAttribute;
030 import java.awt.*;
031 import java.awt.geom.*;
032 import java.util.*;
033
034 import com.kitfox.svg.pathcmd.*;
035 import com.kitfox.svg.*;
036 import com.kitfox.svg.xml.*;
037
038 /**
039 * A track holds the animation events for a single parameter of a single SVG
040 * element. It also contains the default value for the element, should the
041 * user want to see the 'unanimated' value.
042 *
043 * @author Mark McKay
044 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
045 */
046 public class TrackPath extends TrackBase
047 {
048
049 public TrackPath(AnimationElement ele) throws SVGElementException
050 {
051 super(ele.getParent(), ele);
052 }
053
054 public boolean getValue(StyleAttribute attrib, double curTime)
055 {
056 GeneralPath path = getValue(curTime);
057 if (path == null) return false;
058
059 attrib.setStringValue(PathUtil.buildPathString(path));
060 return true;
061 }
062
063 public GeneralPath getValue(double curTime)
064 {
065 GeneralPath retVal = null;
066 AnimationTimeEval state = new AnimationTimeEval();
067
068 for (Iterator it = animEvents.iterator(); it.hasNext();)
069 {
070 AnimateBase ele = (AnimateBase)it.next();
071 Animate eleAnim = (Animate)ele;
072 ele.evalParametric(state, curTime);
073
074 //Reject value if it is in the invalid state
075 if (Double.isNaN(state.interp)) continue;
076
077 if (retVal == null)
078 {
079 retVal = eleAnim.evalPath(state.interp);
080 continue;
081 }
082
083 GeneralPath curPath = eleAnim.evalPath(state.interp);
084 switch (ele.getAdditiveType())
085 {
086 case AnimationElement.AD_REPLACE:
087 retVal = curPath;
088 break;
089 case AnimationElement.AD_SUM:
090 throw new RuntimeException("Not implemented");
091 // retVal = new Color(curCol.getRed() + retVal.getRed(), curCol.getGreen() + retVal.getGreen(), curCol.getBlue() + retVal.getBlue());
092 // break;
093 default:
094 throw new RuntimeException();
095 }
096 }
097
098 return retVal;
099 }
100 }