001    /*
002     * TimeDiscrete.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, 3:33 AM
025     */
026    
027    package com.kitfox.svg.animation;
028    
029    import java.util.Collections;
030    import java.util.Iterator;
031    import java.util.List;
032    import java.util.regex.Pattern;
033    
034    
035    /**
036     * This represents a summation of other time elements.  It is used for complex
037     * timing events with offsets.
038     *
039     * @author Mark McKay
040     * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
041     */
042    public class TimeCompound extends TimeBase
043    {
044        static final Pattern patPlus = Pattern.compile("\\+");
045        
046        /**
047         * This is a list of times.  This element's time is calculated as the greatest
048         * member that is less than the current time.
049        */
050        final List componentTimes;
051    
052        private AnimationElement parent;
053        
054        /** Creates a new instance of TimeDiscrete */
055        public TimeCompound(List timeBases)
056        {
057            componentTimes = Collections.unmodifiableList(timeBases);
058        }
059        
060        public double evalTime()
061        {
062            double agg = 0.0;
063            
064            for (Iterator it = componentTimes.iterator(); it.hasNext();)
065            {
066                TimeBase timeEle = (TimeBase)it.next();
067                double time = timeEle.evalTime();
068                agg += time;
069            }
070            
071            return agg;
072        }
073        
074        public void setParentElement(AnimationElement ele)
075        {
076            this.parent = ele;
077            
078            for (Iterator it = componentTimes.iterator(); it.hasNext();)
079            {
080                TimeBase timeEle = (TimeBase)it.next();
081                timeEle.setParentElement(ele);
082            }
083        }
084    }