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