1 | /*
|
---|
2 | * FillElement.java
|
---|
3 | *
|
---|
4 | *
|
---|
5 | * The Salamander Project - 2D and 3D graphics libraries in Java
|
---|
6 | * Copyright (C) 2004 Mark McKay
|
---|
7 | *
|
---|
8 | * This library is free software; you can redistribute it and/or
|
---|
9 | * modify it under the terms of the GNU Lesser General Public
|
---|
10 | * License as published by the Free Software Foundation; either
|
---|
11 | * version 2.1 of the License, or (at your option) any later version.
|
---|
12 | *
|
---|
13 | * This library is distributed in the hope that it will be useful,
|
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
16 | * Lesser General Public License for more details.
|
---|
17 | *
|
---|
18 | * You should have received a copy of the GNU Lesser General Public
|
---|
19 | * License along with this library; if not, write to the Free Software
|
---|
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
21 | *
|
---|
22 | * Mark McKay can be contacted at mark@kitfox.com. Salamander and other
|
---|
23 | * projects can be found at http://www.kitfox.com
|
---|
24 | *
|
---|
25 | * Created on March 18, 2004, 6:52 AM
|
---|
26 | */
|
---|
27 |
|
---|
28 | package com.kitfox.svg;
|
---|
29 |
|
---|
30 | import java.awt.geom.*;
|
---|
31 | import java.net.*;
|
---|
32 | import java.util.*;
|
---|
33 |
|
---|
34 | import com.kitfox.svg.xml.*;
|
---|
35 |
|
---|
36 | /**
|
---|
37 | * @author Mark McKay
|
---|
38 | * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
|
---|
39 | */
|
---|
40 | public class Filter extends SVGElement
|
---|
41 | {
|
---|
42 | public static final int FU_OBJECT_BOUNDING_BOX = 0;
|
---|
43 | public static final int FU_USER_SPACE_ON_USE = 1;
|
---|
44 |
|
---|
45 | protected int filterUnits = FU_OBJECT_BOUNDING_BOX;
|
---|
46 |
|
---|
47 | public static final int PU_OBJECT_BOUNDING_BOX = 0;
|
---|
48 | public static final int PU_USER_SPACE_ON_USE = 1;
|
---|
49 |
|
---|
50 | protected int primitiveUnits = PU_OBJECT_BOUNDING_BOX;
|
---|
51 |
|
---|
52 | float x = 0f;
|
---|
53 | float y = 0f;
|
---|
54 | float width = 1f;
|
---|
55 | float height = 1f;
|
---|
56 |
|
---|
57 | Point2D filterRes = new Point2D.Double();
|
---|
58 |
|
---|
59 | URL href = null;
|
---|
60 |
|
---|
61 | final ArrayList filterEffects = new ArrayList();
|
---|
62 |
|
---|
63 | /** Creates a new instance of FillElement */
|
---|
64 | public Filter() {
|
---|
65 | }
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * Called after the start element but before the end element to indicate
|
---|
69 | * each child tag that has been processed
|
---|
70 | */
|
---|
71 | public void loaderAddChild(SVGLoaderHelper helper, SVGElement child) throws SVGElementException
|
---|
72 | {
|
---|
73 | super.loaderAddChild(helper, child);
|
---|
74 |
|
---|
75 | if (child instanceof FilterEffects)
|
---|
76 | {
|
---|
77 | filterEffects.add(child);
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | protected void build() throws SVGException
|
---|
82 | {
|
---|
83 | super.build();
|
---|
84 |
|
---|
85 | StyleAttribute sty = new StyleAttribute();
|
---|
86 | String strn;
|
---|
87 |
|
---|
88 | if (getPres(sty.setName("filterUnits")))
|
---|
89 | {
|
---|
90 | strn = sty.getStringValue().toLowerCase();
|
---|
91 | if (strn.equals("userspaceonuse")) filterUnits = FU_USER_SPACE_ON_USE;
|
---|
92 | else filterUnits = FU_OBJECT_BOUNDING_BOX;
|
---|
93 | }
|
---|
94 |
|
---|
95 | if (getPres(sty.setName("primitiveUnits")))
|
---|
96 | {
|
---|
97 | strn = sty.getStringValue().toLowerCase();
|
---|
98 | if (strn.equals("userspaceonuse")) primitiveUnits = PU_USER_SPACE_ON_USE;
|
---|
99 | 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 |
|
---|