[4256] | 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 com.kitfox.svg.xml.StyleAttribute;
|
---|
| 31 | import java.awt.*;
|
---|
| 32 | import java.awt.geom.*;
|
---|
| 33 | import java.net.*;
|
---|
| 34 | import java.util.*;
|
---|
| 35 |
|
---|
| 36 | import com.kitfox.svg.xml.*;
|
---|
| 37 | import org.xml.sax.*;
|
---|
| 38 |
|
---|
| 39 | /**
|
---|
| 40 | * @author Mark McKay
|
---|
| 41 | * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
|
---|
| 42 | */
|
---|
| 43 | public class FilterEffects extends SVGElement
|
---|
| 44 | {
|
---|
| 45 | public static final int FP_SOURCE_GRAPHIC = 0;
|
---|
| 46 | public static final int FP_SOURCE_ALPHA = 1;
|
---|
| 47 | public static final int FP_BACKGROUND_IMAGE = 2;
|
---|
| 48 | public static final int FP_BACKGROUND_ALPHA = 3;
|
---|
| 49 | public static final int FP_FILL_PAINT = 4;
|
---|
| 50 | public static final int FP_STROKE_PAINT = 5;
|
---|
| 51 | public static final int FP_CUSTOM = 5;
|
---|
| 52 |
|
---|
| 53 | private int filterPrimitiveTypeIn;
|
---|
| 54 | private String filterPrimitiveRefIn;
|
---|
| 55 |
|
---|
| 56 |
|
---|
| 57 | float x = 0f;
|
---|
| 58 | float y = 0f;
|
---|
| 59 | float width = 1f;
|
---|
| 60 | float height = 1f;
|
---|
| 61 |
|
---|
| 62 | String result = "defaultFilterName";
|
---|
| 63 |
|
---|
| 64 |
|
---|
| 65 |
|
---|
| 66 | URL href = null;
|
---|
| 67 |
|
---|
| 68 |
|
---|
| 69 | /** Creates a new instance of FillElement */
|
---|
| 70 | public FilterEffects() {
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | /**
|
---|
| 74 | * Called after the start element but before the end element to indicate
|
---|
| 75 | * each child tag that has been processed
|
---|
| 76 | */
|
---|
| 77 | public void loaderAddChild(SVGLoaderHelper helper, SVGElement child) throws SVGElementException
|
---|
| 78 | {
|
---|
| 79 | super.loaderAddChild(helper, child);
|
---|
| 80 |
|
---|
| 81 | if (child instanceof FilterEffects)
|
---|
| 82 | {
|
---|
| 83 | // filterEffects.add(child);
|
---|
| 84 | }
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | protected void build() throws SVGException
|
---|
| 88 | {
|
---|
| 89 | super.build();
|
---|
| 90 |
|
---|
| 91 | StyleAttribute sty = new StyleAttribute();
|
---|
| 92 | String strn;
|
---|
| 93 | /*
|
---|
| 94 | if (getPres(sty.setName("filterUnits")))
|
---|
| 95 | {
|
---|
| 96 | strn = sty.getStringValue().toLowerCase();
|
---|
| 97 | if (strn.equals("userspaceonuse")) filterUnits = FU_USER_SPACE_ON_USE;
|
---|
| 98 | else filterUnits = FU_OBJECT_BOUNDING_BOX;
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | if (getPres(sty.setName("primitiveUnits")))
|
---|
| 102 | {
|
---|
| 103 | strn = sty.getStringValue().toLowerCase();
|
---|
| 104 | if (strn.equals("userspaceonuse")) primitiveUnits = PU_USER_SPACE_ON_USE;
|
---|
| 105 | else primitiveUnits = PU_OBJECT_BOUNDING_BOX;
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | if (getPres(sty.setName("x"))) x = sty.getFloatValue();
|
---|
| 109 |
|
---|
| 110 | if (getPres(sty.setName("y"))) y = sty.getFloatValue();
|
---|
| 111 |
|
---|
| 112 | if (getPres(sty.setName("width"))) width = sty.getFloatValue();
|
---|
| 113 |
|
---|
| 114 | if (getPres(sty.setName("height"))) height = sty.getFloatValue();
|
---|
| 115 |
|
---|
| 116 | try {
|
---|
| 117 | if (getPres(sty.setName("xlink:href")))
|
---|
| 118 | {
|
---|
| 119 | URI src = sty.getURIValue(getXMLBase());
|
---|
| 120 | href = src.toURL();
|
---|
| 121 | }
|
---|
| 122 | }
|
---|
| 123 | catch (Exception e)
|
---|
| 124 | {
|
---|
| 125 | throw new SVGException(e);
|
---|
| 126 | }
|
---|
| 127 | */
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | public float getX() { return x; }
|
---|
| 131 | public float getY() { return y; }
|
---|
| 132 | public float getWidth() { return width; }
|
---|
| 133 | public float getHeight() { return height; }
|
---|
| 134 |
|
---|
| 135 | public boolean updateTime(double curTime) throws SVGException
|
---|
| 136 | {
|
---|
| 137 | // if (trackManager.getNumTracks() == 0) return false;
|
---|
| 138 |
|
---|
| 139 | //Get current values for parameters
|
---|
| 140 | StyleAttribute sty = new StyleAttribute();
|
---|
| 141 | boolean stateChange = false;
|
---|
| 142 |
|
---|
| 143 | if (getPres(sty.setName("x")))
|
---|
| 144 | {
|
---|
| 145 | float newVal = sty.getFloatValueWithUnits();
|
---|
| 146 | if (newVal != x)
|
---|
| 147 | {
|
---|
| 148 | x = newVal;
|
---|
| 149 | stateChange = true;
|
---|
| 150 | }
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 | if (getPres(sty.setName("y")))
|
---|
| 154 | {
|
---|
| 155 | float newVal = sty.getFloatValueWithUnits();
|
---|
| 156 | if (newVal != y)
|
---|
| 157 | {
|
---|
| 158 | y = newVal;
|
---|
| 159 | stateChange = true;
|
---|
| 160 | }
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | if (getPres(sty.setName("width")))
|
---|
| 164 | {
|
---|
| 165 | float newVal = sty.getFloatValueWithUnits();
|
---|
| 166 | if (newVal != width)
|
---|
| 167 | {
|
---|
| 168 | width = newVal;
|
---|
| 169 | stateChange = true;
|
---|
| 170 | }
|
---|
| 171 | }
|
---|
| 172 |
|
---|
| 173 | if (getPres(sty.setName("height")))
|
---|
| 174 | {
|
---|
| 175 | float newVal = sty.getFloatValueWithUnits();
|
---|
| 176 | if (newVal != height)
|
---|
| 177 | {
|
---|
| 178 | height = newVal;
|
---|
| 179 | stateChange = true;
|
---|
| 180 | }
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | try {
|
---|
| 184 | if (getPres(sty.setName("xlink:href")))
|
---|
| 185 | {
|
---|
| 186 | URI src = sty.getURIValue(getXMLBase());
|
---|
| 187 | URL newVal = src.toURL();
|
---|
| 188 |
|
---|
| 189 | if (!newVal.equals(href))
|
---|
| 190 | {
|
---|
| 191 | href = newVal;
|
---|
| 192 | stateChange = true;
|
---|
| 193 | }
|
---|
| 194 | }
|
---|
| 195 | }
|
---|
| 196 | catch (Exception e)
|
---|
| 197 | {
|
---|
| 198 | throw new SVGException(e);
|
---|
| 199 | }
|
---|
| 200 |
|
---|
| 201 | /*
|
---|
| 202 | if (getPres(sty.setName("filterUnits")))
|
---|
| 203 | {
|
---|
| 204 | int newVal;
|
---|
| 205 | String strn = sty.getStringValue().toLowerCase();
|
---|
| 206 | if (strn.equals("userspaceonuse")) newVal = FU_USER_SPACE_ON_USE;
|
---|
| 207 | else newVal = FU_OBJECT_BOUNDING_BOX;
|
---|
| 208 | if (newVal != filterUnits)
|
---|
| 209 | {
|
---|
| 210 | filterUnits = newVal;
|
---|
| 211 | stateChange = true;
|
---|
| 212 | }
|
---|
| 213 | }
|
---|
| 214 |
|
---|
| 215 | if (getPres(sty.setName("primitiveUnits")))
|
---|
| 216 | {
|
---|
| 217 | int newVal;
|
---|
| 218 | String strn = sty.getStringValue().toLowerCase();
|
---|
| 219 | if (strn.equals("userspaceonuse")) newVal = PU_USER_SPACE_ON_USE;
|
---|
| 220 | else newVal = PU_OBJECT_BOUNDING_BOX;
|
---|
| 221 | if (newVal != filterUnits)
|
---|
| 222 | {
|
---|
| 223 | primitiveUnits = newVal;
|
---|
| 224 | stateChange = true;
|
---|
| 225 | }
|
---|
| 226 | }
|
---|
| 227 |
|
---|
| 228 | */
|
---|
| 229 |
|
---|
| 230 | return stateChange;
|
---|
| 231 | }
|
---|
| 232 | }
|
---|
| 233 |
|
---|