001/*
002 * SVG Salamander
003 * Copyright (c) 2004, Mark McKay
004 * All rights reserved.
005 *
006 * Redistribution and use in source and binary forms, with or 
007 * without modification, are permitted provided that the following
008 * conditions are met:
009 *
010 *   - Redistributions of source code must retain the above 
011 *     copyright notice, this list of conditions and the following
012 *     disclaimer.
013 *   - Redistributions in binary form must reproduce the above
014 *     copyright notice, this list of conditions and the following
015 *     disclaimer in the documentation and/or other materials 
016 *     provided with the distribution.
017 *
018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
019 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
020 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
021 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
022 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
023 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
025 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
026 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
027 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
028 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
029 * OF THE POSSIBILITY OF SUCH DAMAGE. 
030 * 
031 * Mark McKay can be contacted at mark@kitfox.com.  Salamander and other
032 * projects can be found at http://www.kitfox.com
033 *
034 * Created on March 18, 2004, 6:52 AM
035 */
036package com.kitfox.svg;
037
038import com.kitfox.svg.xml.StyleAttribute;
039import java.net.URI;
040import java.net.URL;
041
042/**
043 * @author Mark McKay
044 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
045 */
046public class FilterEffects extends SVGElement
047{
048    public static final String TAG_NAME = "filtereffects";
049    
050    public static final int FP_SOURCE_GRAPHIC = 0;
051    public static final int FP_SOURCE_ALPHA = 1;
052    public static final int FP_BACKGROUND_IMAGE = 2;
053    public static final int FP_BACKGROUND_ALPHA = 3;
054    public static final int FP_FILL_PAINT = 4;
055    public static final int FP_STROKE_PAINT = 5;
056    public static final int FP_CUSTOM = 5;
057    private int filterPrimitiveTypeIn;
058    private String filterPrimitiveRefIn;
059    float x = 0f;
060    float y = 0f;
061    float width = 1f;
062    float height = 1f;
063    String result = "defaultFilterName";
064    URL href = null;
065
066    /**
067     * Creates a new instance of FillElement
068     */
069    public FilterEffects()
070    {
071    }
072
073    @Override
074    public String getTagName()
075    {
076        return TAG_NAME;
077    }
078
079    /**
080     * Called after the start element but before the end element to indicate
081     * each child tag that has been processed
082     */
083    @Override
084    public void loaderAddChild(SVGLoaderHelper helper, SVGElement child) throws SVGElementException
085    {
086        super.loaderAddChild(helper, child);
087
088        if (child instanceof FilterEffects)
089        {
090//            filterEffects.add(child);
091        }
092    }
093
094    @Override
095    protected void build() throws SVGException
096    {
097        super.build();
098
099        /*StyleAttribute sty = new StyleAttribute();
100          String strn;
101        
102         if (getPres(sty.setName("filterUnits")))
103         {
104         strn = sty.getStringValue().toLowerCase();
105         if (strn.equals("userspaceonuse")) filterUnits = FU_USER_SPACE_ON_USE;
106         else filterUnits = FU_OBJECT_BOUNDING_BOX;
107         }
108
109         if (getPres(sty.setName("primitiveUnits")))
110         {
111         strn = sty.getStringValue().toLowerCase();
112         if (strn.equals("userspaceonuse")) primitiveUnits = PU_USER_SPACE_ON_USE;
113         else primitiveUnits = PU_OBJECT_BOUNDING_BOX;
114         }
115
116         if (getPres(sty.setName("x"))) x = sty.getFloatValue();
117
118         if (getPres(sty.setName("y"))) y = sty.getFloatValue();
119
120         if (getPres(sty.setName("width"))) width = sty.getFloatValue();
121
122         if (getPres(sty.setName("height"))) height = sty.getFloatValue();
123
124         try {
125         if (getPres(sty.setName("xlink:href")))
126         {
127         URI src = sty.getURIValue(getXMLBase());
128         href = src.toURL();
129         }
130         }
131         catch (Exception e)
132         {
133         throw new SVGException(e);
134         }
135         */
136    }
137
138    public float getX()
139    {
140        return x;
141    }
142
143    public float getY()
144    {
145        return y;
146    }
147
148    public float getWidth()
149    {
150        return width;
151    }
152
153    public float getHeight()
154    {
155        return height;
156    }
157
158    @Override
159    public boolean updateTime(double curTime) throws SVGException
160    {
161//        if (trackManager.getNumTracks() == 0) return false;
162
163        //Get current values for parameters
164        StyleAttribute sty = new StyleAttribute();
165        boolean stateChange = false;
166
167        if (getPres(sty.setName("x")))
168        {
169            float newVal = sty.getFloatValueWithUnits();
170            if (newVal != x)
171            {
172                x = newVal;
173                stateChange = true;
174            }
175        }
176
177        if (getPres(sty.setName("y")))
178        {
179            float newVal = sty.getFloatValueWithUnits();
180            if (newVal != y)
181            {
182                y = newVal;
183                stateChange = true;
184            }
185        }
186
187        if (getPres(sty.setName("width")))
188        {
189            float newVal = sty.getFloatValueWithUnits();
190            if (newVal != width)
191            {
192                width = newVal;
193                stateChange = true;
194            }
195        }
196
197        if (getPres(sty.setName("height")))
198        {
199            float newVal = sty.getFloatValueWithUnits();
200            if (newVal != height)
201            {
202                height = newVal;
203                stateChange = true;
204            }
205        }
206
207        try
208        {
209            if (getPres(sty.setName("xlink:href")))
210            {
211                URI src = sty.getURIValue(getXMLBase());
212                URL newVal = src.toURL();
213
214                if (!newVal.equals(href))
215                {
216                    href = newVal;
217                    stateChange = true;
218                }
219            }
220        } catch (Exception e)
221        {
222            throw new SVGException(e);
223        }
224
225        /*
226         if (getPres(sty.setName("filterUnits")))
227         {
228         int newVal;
229         String strn = sty.getStringValue().toLowerCase();
230         if (strn.equals("userspaceonuse")) newVal = FU_USER_SPACE_ON_USE;
231         else newVal = FU_OBJECT_BOUNDING_BOX;
232         if (newVal != filterUnits)
233         {
234         filterUnits = newVal;
235         stateChange = true;
236         }
237         }
238
239         if (getPres(sty.setName("primitiveUnits")))
240         {
241         int newVal;
242         String strn = sty.getStringValue().toLowerCase();
243         if (strn.equals("userspaceonuse")) newVal = PU_USER_SPACE_ON_USE;
244         else newVal = PU_OBJECT_BOUNDING_BOX;
245         if (newVal != filterUnits)
246         {
247         primitiveUnits = newVal;
248         stateChange = true;
249         }
250         }
251
252         */
253
254        return stateChange;
255    }
256}