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 java.awt.*;
031    import java.awt.geom.*;
032    
033    import com.kitfox.svg.xml.*;
034    
035    /**
036     * @author Mark McKay
037     * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
038     */
039    public class Symbol extends Group
040    {
041        AffineTransform viewXform;
042        Rectangle2D viewBox;
043    
044        /** Creates a new instance of Stop */
045        public Symbol() {
046        }
047    /*
048        public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
049        {
050                    //Load style string
051            super.loaderStartElement(helper, attrs, parent);
052    
053            String viewBoxStrn = attrs.getValue("viewBox");
054            if (viewBoxStrn != null)
055            {
056                float[] dim = XMLParseUtil.parseFloatList(viewBoxStrn);
057                viewBox = new Rectangle2D.Float(dim[0], dim[1], dim[2], dim[3]);
058            }
059        }
060    */
061        /*
062        public void loaderEndElement(SVGLoaderHelper helper)
063        {
064            if (viewBox == null)
065            {
066                viewBox = super.getBoundingBox();
067            }
068    
069            //Transform pattern onto unit square
070            viewXform = new AffineTransform();
071            viewXform.scale(1.0 / viewBox.getWidth(), 1.0 / viewBox.getHeight());
072            viewXform.translate(-viewBox.getX(), -viewBox.getY());
073        }
074    */
075        
076        protected void build() throws SVGException
077        {
078            super.build();
079            
080            StyleAttribute sty = new StyleAttribute();
081            
082    //        sty = getPres("unicode");
083    //        if (sty != null) unicode = sty.getStringValue();
084    
085    
086            if (getPres(sty.setName("viewBox")))
087            {
088                float[] dim = sty.getFloatList();
089                viewBox = new Rectangle2D.Float(dim[0], dim[1], dim[2], dim[3]);
090            }
091            
092            if (viewBox == null)
093            {
094    //            viewBox = super.getBoundingBox();
095                viewBox = new Rectangle(0, 0, 1, 1);
096            }
097    
098            //Transform pattern onto unit square
099            viewXform = new AffineTransform();
100            viewXform.scale(1.0 / viewBox.getWidth(), 1.0 / viewBox.getHeight());
101            viewXform.translate(-viewBox.getX(), -viewBox.getY());
102        }
103    
104        protected boolean outsideClip(Graphics2D g) throws SVGException
105        {
106            Shape clip = g.getClip();
107    //        g.getClipBounds(clipBounds);
108            Rectangle2D rect = super.getBoundingBox();
109            if (clip == null || clip.intersects(rect))
110            {
111                return false;
112            }
113    
114            return true;
115    
116        }
117    
118        public void render(Graphics2D g) throws SVGException
119        {
120            AffineTransform oldXform = g.getTransform();
121            g.transform(viewXform);
122    
123            super.render(g);
124    
125            g.setTransform(oldXform);
126        }
127    
128        public Shape getShape()
129        {
130            Shape shape = super.getShape();
131            return viewXform.createTransformedShape(shape);
132        }
133    
134        public Rectangle2D getBoundingBox() throws SVGException
135        {
136            Rectangle2D rect = super.getBoundingBox();
137            return viewXform.createTransformedShape(rect).getBounds2D();
138        }
139    
140        /**
141         * Updates all attributes in this diagram associated with a time event.
142         * Ie, all attributes with track information.
143         * @return - true if this node has changed state as a result of the time
144         * update
145         */
146        public boolean updateTime(double curTime) throws SVGException
147        {
148    //        if (trackManager.getNumTracks() == 0) return false;
149            boolean changeState = super.updateTime(curTime);
150            
151            //View box properties do not change
152            
153            return changeState;
154        }
155    
156    }