1 | /*
|
---|
2 | * SVG Salamander
|
---|
3 | * Copyright (c) 2004, Mark McKay
|
---|
4 | * All rights reserved.
|
---|
5 | *
|
---|
6 | * Redistribution and use in source and binary forms, with or
|
---|
7 | * without modification, are permitted provided that the following
|
---|
8 | * conditions are met:
|
---|
9 | *
|
---|
10 | * - Redistributions of source code must retain the above
|
---|
11 | * copyright notice, this list of conditions and the following
|
---|
12 | * disclaimer.
|
---|
13 | * - Redistributions in binary form must reproduce the above
|
---|
14 | * copyright notice, this list of conditions and the following
|
---|
15 | * disclaimer in the documentation and/or other materials
|
---|
16 | * provided with the distribution.
|
---|
17 | *
|
---|
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
---|
19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
---|
20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
---|
21 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
---|
22 | * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
---|
23 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
---|
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
---|
25 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
---|
26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
---|
27 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
---|
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
---|
29 | * OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
30 | *
|
---|
31 | * Mark McKay can be contacted at mark@kitfox.com. Salamander and other
|
---|
32 | * projects can be found at http://www.kitfox.com
|
---|
33 | *
|
---|
34 | * Created on March 18, 2004, 6:52 AM
|
---|
35 | */
|
---|
36 | package com.kitfox.svg;
|
---|
37 |
|
---|
38 | import com.kitfox.svg.xml.StyleAttribute;
|
---|
39 | import java.net.URI;
|
---|
40 | import java.net.URL;
|
---|
41 |
|
---|
42 | /**
|
---|
43 | * @author Mark McKay
|
---|
44 | * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
|
---|
45 | */
|
---|
46 | public class FilterEffects extends SVGElement
|
---|
47 | {
|
---|
48 | public static final String TAG_NAME = "filtereffects";
|
---|
49 |
|
---|
50 | public static final int FP_SOURCE_GRAPHIC = 0;
|
---|
51 | public static final int FP_SOURCE_ALPHA = 1;
|
---|
52 | public static final int FP_BACKGROUND_IMAGE = 2;
|
---|
53 | public static final int FP_BACKGROUND_ALPHA = 3;
|
---|
54 | public static final int FP_FILL_PAINT = 4;
|
---|
55 | public static final int FP_STROKE_PAINT = 5;
|
---|
56 | public static final int FP_CUSTOM = 5;
|
---|
57 | private int filterPrimitiveTypeIn;
|
---|
58 | private String filterPrimitiveRefIn;
|
---|
59 | float x = 0f;
|
---|
60 | float y = 0f;
|
---|
61 | float width = 1f;
|
---|
62 | float height = 1f;
|
---|
63 | String result = "defaultFilterName";
|
---|
64 | URL href = null;
|
---|
65 |
|
---|
66 | /**
|
---|
67 | * Creates a new instance of FillElement
|
---|
68 | */
|
---|
69 | public FilterEffects()
|
---|
70 | {
|
---|
71 | }
|
---|
72 |
|
---|
73 | public String getTagName()
|
---|
74 | {
|
---|
75 | return TAG_NAME;
|
---|
76 | }
|
---|
77 |
|
---|
78 | /**
|
---|
79 | * Called after the start element but before the end element to indicate
|
---|
80 | * each child tag that has been processed
|
---|
81 | */
|
---|
82 | public void loaderAddChild(SVGLoaderHelper helper, SVGElement child) throws SVGElementException
|
---|
83 | {
|
---|
84 | super.loaderAddChild(helper, child);
|
---|
85 |
|
---|
86 | if (child instanceof FilterEffects)
|
---|
87 | {
|
---|
88 | // filterEffects.add(child);
|
---|
89 | }
|
---|
90 | }
|
---|
91 |
|
---|
92 | protected void build() throws SVGException
|
---|
93 | {
|
---|
94 | super.build();
|
---|
95 |
|
---|
96 | StyleAttribute sty = new StyleAttribute();
|
---|
97 | String strn;
|
---|
98 | /*
|
---|
99 | if (getPres(sty.setName("filterUnits")))
|
---|
100 | {
|
---|
101 | strn = sty.getStringValue().toLowerCase();
|
---|
102 | if (strn.equals("userspaceonuse")) filterUnits = FU_USER_SPACE_ON_USE;
|
---|
103 | else filterUnits = FU_OBJECT_BOUNDING_BOX;
|
---|
104 | }
|
---|
105 |
|
---|
106 | if (getPres(sty.setName("primitiveUnits")))
|
---|
107 | {
|
---|
108 | strn = sty.getStringValue().toLowerCase();
|
---|
109 | if (strn.equals("userspaceonuse")) primitiveUnits = PU_USER_SPACE_ON_USE;
|
---|
110 | else primitiveUnits = PU_OBJECT_BOUNDING_BOX;
|
---|
111 | }
|
---|
112 |
|
---|
113 | if (getPres(sty.setName("x"))) x = sty.getFloatValue();
|
---|
114 |
|
---|
115 | if (getPres(sty.setName("y"))) y = sty.getFloatValue();
|
---|
116 |
|
---|
117 | if (getPres(sty.setName("width"))) width = sty.getFloatValue();
|
---|
118 |
|
---|
119 | if (getPres(sty.setName("height"))) height = sty.getFloatValue();
|
---|
120 |
|
---|
121 | try {
|
---|
122 | if (getPres(sty.setName("xlink:href")))
|
---|
123 | {
|
---|
124 | URI src = sty.getURIValue(getXMLBase());
|
---|
125 | href = src.toURL();
|
---|
126 | }
|
---|
127 | }
|
---|
128 | catch (Exception e)
|
---|
129 | {
|
---|
130 | throw new SVGException(e);
|
---|
131 | }
|
---|
132 | */
|
---|
133 | }
|
---|
134 |
|
---|
135 | public float getX()
|
---|
136 | {
|
---|
137 | return x;
|
---|
138 | }
|
---|
139 |
|
---|
140 | public float getY()
|
---|
141 | {
|
---|
142 | return y;
|
---|
143 | }
|
---|
144 |
|
---|
145 | public float getWidth()
|
---|
146 | {
|
---|
147 | return width;
|
---|
148 | }
|
---|
149 |
|
---|
150 | public float getHeight()
|
---|
151 | {
|
---|
152 | return height;
|
---|
153 | }
|
---|
154 |
|
---|
155 | public boolean updateTime(double curTime) throws SVGException
|
---|
156 | {
|
---|
157 | // if (trackManager.getNumTracks() == 0) return false;
|
---|
158 |
|
---|
159 | //Get current values for parameters
|
---|
160 | StyleAttribute sty = new StyleAttribute();
|
---|
161 | boolean stateChange = false;
|
---|
162 |
|
---|
163 | if (getPres(sty.setName("x")))
|
---|
164 | {
|
---|
165 | float newVal = sty.getFloatValueWithUnits();
|
---|
166 | if (newVal != x)
|
---|
167 | {
|
---|
168 | x = newVal;
|
---|
169 | stateChange = true;
|
---|
170 | }
|
---|
171 | }
|
---|
172 |
|
---|
173 | if (getPres(sty.setName("y")))
|
---|
174 | {
|
---|
175 | float newVal = sty.getFloatValueWithUnits();
|
---|
176 | if (newVal != y)
|
---|
177 | {
|
---|
178 | y = newVal;
|
---|
179 | stateChange = true;
|
---|
180 | }
|
---|
181 | }
|
---|
182 |
|
---|
183 | if (getPres(sty.setName("width")))
|
---|
184 | {
|
---|
185 | float newVal = sty.getFloatValueWithUnits();
|
---|
186 | if (newVal != width)
|
---|
187 | {
|
---|
188 | width = newVal;
|
---|
189 | stateChange = true;
|
---|
190 | }
|
---|
191 | }
|
---|
192 |
|
---|
193 | if (getPres(sty.setName("height")))
|
---|
194 | {
|
---|
195 | float newVal = sty.getFloatValueWithUnits();
|
---|
196 | if (newVal != height)
|
---|
197 | {
|
---|
198 | height = newVal;
|
---|
199 | stateChange = true;
|
---|
200 | }
|
---|
201 | }
|
---|
202 |
|
---|
203 | try
|
---|
204 | {
|
---|
205 | if (getPres(sty.setName("xlink:href")))
|
---|
206 | {
|
---|
207 | URI src = sty.getURIValue(getXMLBase());
|
---|
208 | URL newVal = src.toURL();
|
---|
209 |
|
---|
210 | if (!newVal.equals(href))
|
---|
211 | {
|
---|
212 | href = newVal;
|
---|
213 | stateChange = true;
|
---|
214 | }
|
---|
215 | }
|
---|
216 | } catch (Exception e)
|
---|
217 | {
|
---|
218 | throw new SVGException(e);
|
---|
219 | }
|
---|
220 |
|
---|
221 | /*
|
---|
222 | if (getPres(sty.setName("filterUnits")))
|
---|
223 | {
|
---|
224 | int newVal;
|
---|
225 | String strn = sty.getStringValue().toLowerCase();
|
---|
226 | if (strn.equals("userspaceonuse")) newVal = FU_USER_SPACE_ON_USE;
|
---|
227 | else newVal = FU_OBJECT_BOUNDING_BOX;
|
---|
228 | if (newVal != filterUnits)
|
---|
229 | {
|
---|
230 | filterUnits = newVal;
|
---|
231 | stateChange = true;
|
---|
232 | }
|
---|
233 | }
|
---|
234 |
|
---|
235 | if (getPres(sty.setName("primitiveUnits")))
|
---|
236 | {
|
---|
237 | int newVal;
|
---|
238 | String strn = sty.getStringValue().toLowerCase();
|
---|
239 | if (strn.equals("userspaceonuse")) newVal = PU_USER_SPACE_ON_USE;
|
---|
240 | else newVal = PU_OBJECT_BOUNDING_BOX;
|
---|
241 | if (newVal != filterUnits)
|
---|
242 | {
|
---|
243 | primitiveUnits = newVal;
|
---|
244 | stateChange = true;
|
---|
245 | }
|
---|
246 | }
|
---|
247 |
|
---|
248 | */
|
---|
249 |
|
---|
250 | return stateChange;
|
---|
251 | }
|
---|
252 | }
|
---|