001    /*
002     * FillElement.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 March 18, 2004, 6:52 AM
026     */
027    
028    package com.kitfox.svg;
029    
030    import com.kitfox.svg.xml.StyleAttribute;
031    import java.awt.*;
032    import java.awt.geom.*;
033    import java.net.*;
034    import java.util.*;
035    
036    import com.kitfox.svg.xml.*;
037    import org.xml.sax.*;
038    
039    /**
040     * @author Mark McKay
041     * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
042     */
043    public class FilterEffects extends SVGElement 
044    {
045        public static final int FP_SOURCE_GRAPHIC = 0;
046        public static final int FP_SOURCE_ALPHA = 1;
047        public static final int FP_BACKGROUND_IMAGE = 2;
048        public static final int FP_BACKGROUND_ALPHA = 3;
049        public static final int FP_FILL_PAINT = 4;
050        public static final int FP_STROKE_PAINT = 5;
051        public static final int FP_CUSTOM = 5;
052    
053        private int filterPrimitiveTypeIn;
054        private String filterPrimitiveRefIn;
055        
056        
057        float x = 0f;
058        float y = 0f;
059        float width = 1f;
060        float height = 1f;
061        
062        String result = "defaultFilterName";
063        
064        
065        
066        URL href = null;
067    
068    
069        /** Creates a new instance of FillElement */
070        public FilterEffects() {
071        }
072    
073        /**
074         * Called after the start element but before the end element to indicate
075         * each child tag that has been processed
076         */
077        public void loaderAddChild(SVGLoaderHelper helper, SVGElement child) throws SVGElementException
078        {
079            super.loaderAddChild(helper, child);
080    
081            if (child instanceof FilterEffects)
082            {
083    //            filterEffects.add(child);
084            }
085        }
086        
087        protected void build() throws SVGException
088        {
089            super.build();
090            
091            StyleAttribute sty = new StyleAttribute();
092            String strn;
093            /*
094            if (getPres(sty.setName("filterUnits")))
095            {
096                strn = sty.getStringValue().toLowerCase();
097                if (strn.equals("userspaceonuse")) filterUnits = FU_USER_SPACE_ON_USE;
098                else filterUnits = FU_OBJECT_BOUNDING_BOX;
099            }
100    
101            if (getPres(sty.setName("primitiveUnits")))
102            {
103                strn = sty.getStringValue().toLowerCase();
104                if (strn.equals("userspaceonuse")) primitiveUnits = PU_USER_SPACE_ON_USE;
105                else primitiveUnits = PU_OBJECT_BOUNDING_BOX;
106            }
107    
108            if (getPres(sty.setName("x"))) x = sty.getFloatValue();
109    
110            if (getPres(sty.setName("y"))) y = sty.getFloatValue();
111    
112            if (getPres(sty.setName("width"))) width = sty.getFloatValue();
113    
114            if (getPres(sty.setName("height"))) height = sty.getFloatValue();
115    
116            try {
117                if (getPres(sty.setName("xlink:href")))
118                {
119                    URI src = sty.getURIValue(getXMLBase());
120                    href = src.toURL();
121                }
122            }
123            catch (Exception e)
124            {
125                throw new SVGException(e);
126            }
127    */
128        }
129    
130        public float getX() { return x; }
131        public float getY() { return y; }
132        public float getWidth() { return width; }
133        public float getHeight() { return height; }
134        
135        public boolean updateTime(double curTime) throws SVGException
136        {
137    //        if (trackManager.getNumTracks() == 0) return false;
138    
139            //Get current values for parameters
140            StyleAttribute sty = new StyleAttribute();
141            boolean stateChange = false;
142            
143            if (getPres(sty.setName("x")))
144            {
145                float newVal = sty.getFloatValueWithUnits();
146                if (newVal != x)
147                {
148                    x = newVal;
149                    stateChange = true;
150                }
151            }
152            
153            if (getPres(sty.setName("y")))
154            {
155                float newVal = sty.getFloatValueWithUnits();
156                if (newVal != y)
157                {
158                    y = newVal;
159                    stateChange = true;
160                }
161            }
162            
163            if (getPres(sty.setName("width")))
164            {
165                float newVal = sty.getFloatValueWithUnits();
166                if (newVal != width)
167                {
168                    width = newVal;
169                    stateChange = true;
170                }
171            }
172            
173            if (getPres(sty.setName("height")))
174            {
175                float newVal = sty.getFloatValueWithUnits();
176                if (newVal != height)
177                {
178                    height = newVal;
179                    stateChange = true;
180                }
181            }
182            
183            try {
184                if (getPres(sty.setName("xlink:href")))
185                {
186                    URI src = sty.getURIValue(getXMLBase());
187                    URL newVal = src.toURL();
188                    
189                    if (!newVal.equals(href))
190                    {
191                        href = newVal;
192                        stateChange = true;
193                    }
194                }
195            }
196            catch (Exception e)
197            {
198                throw new SVGException(e);
199            }
200    
201            /*
202            if (getPres(sty.setName("filterUnits")))
203            {
204                int newVal;
205                String strn = sty.getStringValue().toLowerCase();
206                if (strn.equals("userspaceonuse")) newVal = FU_USER_SPACE_ON_USE;
207                else newVal = FU_OBJECT_BOUNDING_BOX;
208                if (newVal != filterUnits)
209                {
210                    filterUnits = newVal;
211                    stateChange = true;
212                }
213            }
214    
215            if (getPres(sty.setName("primitiveUnits")))
216            {
217                int newVal;
218                String strn = sty.getStringValue().toLowerCase();
219                if (strn.equals("userspaceonuse")) newVal = PU_USER_SPACE_ON_USE;
220                else newVal = PU_OBJECT_BOUNDING_BOX;
221                if (newVal != filterUnits)
222                {
223                    primitiveUnits = newVal;
224                    stateChange = true;
225                }
226            }
227    
228            */
229            
230            return stateChange;
231        }
232    }
233