[8084] | 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.awt.geom.Point2D;
|
---|
| 40 | import java.net.URI;
|
---|
| 41 | import java.net.URL;
|
---|
| 42 | import java.util.ArrayList;
|
---|
| 43 |
|
---|
| 44 | /**
|
---|
| 45 | * @author Mark McKay
|
---|
| 46 | * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
|
---|
| 47 | */
|
---|
| 48 | public class Filter extends SVGElement
|
---|
| 49 | {
|
---|
| 50 |
|
---|
| 51 | public static final String TAG_NAME = "filter";
|
---|
| 52 | public static final int FU_OBJECT_BOUNDING_BOX = 0;
|
---|
| 53 | public static final int FU_USER_SPACE_ON_USE = 1;
|
---|
| 54 | protected int filterUnits = FU_OBJECT_BOUNDING_BOX;
|
---|
| 55 | public static final int PU_OBJECT_BOUNDING_BOX = 0;
|
---|
| 56 | public static final int PU_USER_SPACE_ON_USE = 1;
|
---|
| 57 | protected int primitiveUnits = PU_OBJECT_BOUNDING_BOX;
|
---|
| 58 | float x = 0f;
|
---|
| 59 | float y = 0f;
|
---|
| 60 | float width = 1f;
|
---|
| 61 | float height = 1f;
|
---|
| 62 | Point2D filterRes = new Point2D.Double();
|
---|
| 63 | URL href = null;
|
---|
| 64 | final ArrayList filterEffects = new ArrayList();
|
---|
| 65 |
|
---|
| 66 | /**
|
---|
| 67 | * Creates a new instance of FillElement
|
---|
| 68 | */
|
---|
| 69 | public Filter()
|
---|
| 70 | {
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | public String getTagName()
|
---|
| 74 | {
|
---|
| 75 | return TAG_NAME;
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | protected void build() throws SVGException
|
---|
| 79 | {
|
---|
| 80 | super.build();
|
---|
| 81 |
|
---|
| 82 | StyleAttribute sty = new StyleAttribute();
|
---|
| 83 | String strn;
|
---|
| 84 |
|
---|
| 85 | if (getPres(sty.setName("filterUnits")))
|
---|
| 86 | {
|
---|
| 87 | strn = sty.getStringValue().toLowerCase();
|
---|
| 88 | if (strn.equals("userspaceonuse"))
|
---|
| 89 | {
|
---|
| 90 | filterUnits = FU_USER_SPACE_ON_USE;
|
---|
| 91 | } else
|
---|
| 92 | {
|
---|
| 93 | filterUnits = FU_OBJECT_BOUNDING_BOX;
|
---|
| 94 | }
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | if (getPres(sty.setName("primitiveUnits")))
|
---|
| 98 | {
|
---|
| 99 | strn = sty.getStringValue().toLowerCase();
|
---|
| 100 | if (strn.equals("userspaceonuse"))
|
---|
| 101 | {
|
---|
| 102 | primitiveUnits = PU_USER_SPACE_ON_USE;
|
---|
| 103 | } else
|
---|
| 104 | {
|
---|
| 105 | primitiveUnits = PU_OBJECT_BOUNDING_BOX;
|
---|
| 106 | }
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | if (getPres(sty.setName("x")))
|
---|
| 110 | {
|
---|
| 111 | x = sty.getFloatValueWithUnits();
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | if (getPres(sty.setName("y")))
|
---|
| 115 | {
|
---|
| 116 | y = sty.getFloatValueWithUnits();
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | if (getPres(sty.setName("width")))
|
---|
| 120 | {
|
---|
| 121 | width = sty.getFloatValueWithUnits();
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | if (getPres(sty.setName("height")))
|
---|
| 125 | {
|
---|
| 126 | height = sty.getFloatValueWithUnits();
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | try
|
---|
| 130 | {
|
---|
| 131 | if (getPres(sty.setName("xlink:href")))
|
---|
| 132 | {
|
---|
| 133 | URI src = sty.getURIValue(getXMLBase());
|
---|
| 134 | href = src.toURL();
|
---|
| 135 | }
|
---|
| 136 | } catch (Exception e)
|
---|
| 137 | {
|
---|
| 138 | throw new SVGException(e);
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | public float getX()
|
---|
| 144 | {
|
---|
| 145 | return x;
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | public float getY()
|
---|
| 149 | {
|
---|
| 150 | return y;
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 | public float getWidth()
|
---|
| 154 | {
|
---|
| 155 | return width;
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 | public float getHeight()
|
---|
| 159 | {
|
---|
| 160 | return height;
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | public boolean updateTime(double curTime) throws SVGException
|
---|
| 164 | {
|
---|
| 165 | // if (trackManager.getNumTracks() == 0) return false;
|
---|
| 166 |
|
---|
| 167 | //Get current values for parameters
|
---|
| 168 | StyleAttribute sty = new StyleAttribute();
|
---|
| 169 | boolean stateChange = false;
|
---|
| 170 |
|
---|
| 171 | if (getPres(sty.setName("x")))
|
---|
| 172 | {
|
---|
| 173 | float newVal = sty.getFloatValueWithUnits();
|
---|
| 174 | if (newVal != x)
|
---|
| 175 | {
|
---|
| 176 | x = newVal;
|
---|
| 177 | stateChange = true;
|
---|
| 178 | }
|
---|
| 179 | }
|
---|
| 180 |
|
---|
| 181 | if (getPres(sty.setName("y")))
|
---|
| 182 | {
|
---|
| 183 | float newVal = sty.getFloatValueWithUnits();
|
---|
| 184 | if (newVal != y)
|
---|
| 185 | {
|
---|
| 186 | y = newVal;
|
---|
| 187 | stateChange = true;
|
---|
| 188 | }
|
---|
| 189 | }
|
---|
| 190 |
|
---|
| 191 | if (getPres(sty.setName("width")))
|
---|
| 192 | {
|
---|
| 193 | float newVal = sty.getFloatValueWithUnits();
|
---|
| 194 | if (newVal != width)
|
---|
| 195 | {
|
---|
| 196 | width = newVal;
|
---|
| 197 | stateChange = true;
|
---|
| 198 | }
|
---|
| 199 | }
|
---|
| 200 |
|
---|
| 201 | if (getPres(sty.setName("height")))
|
---|
| 202 | {
|
---|
| 203 | float newVal = sty.getFloatValueWithUnits();
|
---|
| 204 | if (newVal != height)
|
---|
| 205 | {
|
---|
| 206 | height = newVal;
|
---|
| 207 | stateChange = true;
|
---|
| 208 | }
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 | try
|
---|
| 212 | {
|
---|
| 213 | if (getPres(sty.setName("xlink:href")))
|
---|
| 214 | {
|
---|
| 215 | URI src = sty.getURIValue(getXMLBase());
|
---|
| 216 | URL newVal = src.toURL();
|
---|
| 217 |
|
---|
| 218 | if (!newVal.equals(href))
|
---|
| 219 | {
|
---|
| 220 | href = newVal;
|
---|
| 221 | stateChange = true;
|
---|
| 222 | }
|
---|
| 223 | }
|
---|
| 224 | } catch (Exception e)
|
---|
| 225 | {
|
---|
| 226 | throw new SVGException(e);
|
---|
| 227 | }
|
---|
| 228 |
|
---|
| 229 | if (getPres(sty.setName("filterUnits")))
|
---|
| 230 | {
|
---|
| 231 | int newVal;
|
---|
| 232 | String strn = sty.getStringValue().toLowerCase();
|
---|
| 233 | if (strn.equals("userspaceonuse"))
|
---|
| 234 | {
|
---|
| 235 | newVal = FU_USER_SPACE_ON_USE;
|
---|
| 236 | } else
|
---|
| 237 | {
|
---|
| 238 | newVal = FU_OBJECT_BOUNDING_BOX;
|
---|
| 239 | }
|
---|
| 240 | if (newVal != filterUnits)
|
---|
| 241 | {
|
---|
| 242 | filterUnits = newVal;
|
---|
| 243 | stateChange = true;
|
---|
| 244 | }
|
---|
| 245 | }
|
---|
| 246 |
|
---|
| 247 | if (getPres(sty.setName("primitiveUnits")))
|
---|
| 248 | {
|
---|
| 249 | int newVal;
|
---|
| 250 | String strn = sty.getStringValue().toLowerCase();
|
---|
| 251 | if (strn.equals("userspaceonuse"))
|
---|
| 252 | {
|
---|
| 253 | newVal = PU_USER_SPACE_ON_USE;
|
---|
| 254 | } else
|
---|
| 255 | {
|
---|
| 256 | newVal = PU_OBJECT_BOUNDING_BOX;
|
---|
| 257 | }
|
---|
| 258 | if (newVal != filterUnits)
|
---|
| 259 | {
|
---|
| 260 | primitiveUnits = newVal;
|
---|
| 261 | stateChange = true;
|
---|
| 262 | }
|
---|
| 263 | }
|
---|
| 264 |
|
---|
| 265 |
|
---|
| 266 |
|
---|
| 267 | return stateChange;
|
---|
| 268 | }
|
---|
| 269 | }
|
---|