001    /*
002     * Stop.java
003     *
004     *
005     *  The Salamander Project - 2D and 3D graphics libraries in Java
006     *  Copyright (C) 2004 Mark McKay
007     *
008     *  This library is free software; you can redistribute it and/or
009     *  modify it under the terms of the GNU Lesser General Public
010     *  License as published by the Free Software Foundation; either
011     *  version 2.1 of the License, or (at your option) any later version.
012     *
013     *  This library is distributed in the hope that it will be useful,
014     *  but WITHOUT ANY WARRANTY; without even the implied warranty of
015     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016     *  Lesser General Public License for more details.
017     *
018     *  You should have received a copy of the GNU Lesser General Public
019     *  License along with this library; if not, write to the Free Software
020     *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
021     *
022     *  Mark McKay can be contacted at mark@kitfox.com.  Salamander and other
023     *  projects can be found at http://www.kitfox.com
024     *
025     * Created on January 26, 2004, 1:56 AM
026     */
027    
028    package com.kitfox.svg;
029    
030    import com.kitfox.svg.xml.StyleAttribute;
031    import java.awt.*;
032    import java.util.*;
033    
034    import com.kitfox.svg.xml.*;
035    import org.xml.sax.*;
036    
037    /**
038     * @author Mark McKay
039     * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
040     */
041    public class Stop extends SVGElement {
042    
043        float offset = 0f;
044        float opacity = 1f;
045        Color color = Color.black;
046    
047        /** Creates a new instance of Stop */
048        public Stop() {
049        }
050    /*
051        public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
052        {
053                    //Load style string
054            super.loaderStartElement(helper, attrs, parent);
055    
056            String offset = attrs.getValue("offset");
057            this.offset = (float)XMLParseUtil.parseRatio(offset);
058    
059            buildStop();
060        }
061        */
062        
063        protected void build() throws SVGException
064        {
065            super.build();
066            
067            StyleAttribute sty = new StyleAttribute();
068            
069            if (getPres(sty.setName("offset")))
070            {
071                offset = sty.getFloatValue();
072                String units = sty.getUnits();
073                if (units != null && units.equals("%")) offset /= 100f;
074                if (offset > 1) offset = 1;
075                if (offset < 0) offset = 0;
076            }
077            
078            if (getStyle(sty.setName("stop-color"))) color = sty.getColorValue();
079    
080            if (getStyle(sty.setName("stop-opacity"))) opacity = sty.getRatioValue();
081        }
082    
083        /**
084         * Updates all attributes in this diagram associated with a time event.
085         * Ie, all attributes with track information.
086         * @return - true if this node has changed state as a result of the time
087         * update
088         */
089        public boolean updateTime(double curTime) throws SVGException
090        {
091    //        if (trackManager.getNumTracks() == 0) return false;
092    
093            //Get current values for parameters
094            StyleAttribute sty = new StyleAttribute();
095            boolean shapeChange = false;
096            
097            if (getPres(sty.setName("offset")))
098            {
099                float newVal = sty.getFloatValue();
100                if (newVal != offset)
101                {
102                    offset = newVal;
103                    shapeChange = true;
104                }
105            }
106            
107            if (getPres(sty.setName("stop-color")))
108            {
109                Color newVal = sty.getColorValue();
110                if (newVal != color)
111                {
112                    color = newVal;
113                    shapeChange = true;
114                }
115            }
116            
117            if (getPres(sty.setName("stop-opacity")))
118            {
119                float newVal = sty.getFloatValue();
120                if (newVal != opacity)
121                {
122                    opacity = newVal;
123                    shapeChange = true;
124                }
125            }
126            
127            return shapeChange;
128        }
129    }