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