001/* 002 * SVG Salamander 003 * Copyright (c) 2004, Mark McKay 004 * All rights reserved. 005 * 006 * Redistribution and use in source and binary forms, with or 007 * without modification, are permitted provided that the following 008 * conditions are met: 009 * 010 * - Redistributions of source code must retain the above 011 * copyright notice, this list of conditions and the following 012 * disclaimer. 013 * - Redistributions in binary form must reproduce the above 014 * copyright notice, this list of conditions and the following 015 * disclaimer in the documentation and/or other materials 016 * provided with the distribution. 017 * 018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 019 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 020 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 021 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 022 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 023 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 025 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 026 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 027 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 028 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 029 * OF THE POSSIBILITY OF SUCH DAMAGE. 030 * 031 * Mark McKay can be contacted at mark@kitfox.com. Salamander and other 032 * projects can be found at http://www.kitfox.com 033 * 034 * Created on March 18, 2004, 6:52 AM 035 */ 036package com.kitfox.svg; 037 038import com.kitfox.svg.xml.StyleAttribute; 039import java.net.URI; 040import java.net.URL; 041 042/** 043 * @author Mark McKay 044 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a> 045 */ 046public class FilterEffects extends SVGElement 047{ 048 public static final String TAG_NAME = "filtereffects"; 049 050 public static final int FP_SOURCE_GRAPHIC = 0; 051 public static final int FP_SOURCE_ALPHA = 1; 052 public static final int FP_BACKGROUND_IMAGE = 2; 053 public static final int FP_BACKGROUND_ALPHA = 3; 054 public static final int FP_FILL_PAINT = 4; 055 public static final int FP_STROKE_PAINT = 5; 056 public static final int FP_CUSTOM = 5; 057 private int filterPrimitiveTypeIn; 058 private String filterPrimitiveRefIn; 059 float x = 0f; 060 float y = 0f; 061 float width = 1f; 062 float height = 1f; 063 String result = "defaultFilterName"; 064 URL href = null; 065 066 /** 067 * Creates a new instance of FillElement 068 */ 069 public FilterEffects() 070 { 071 } 072 073 public String getTagName() 074 { 075 return TAG_NAME; 076 } 077 078 /** 079 * Called after the start element but before the end element to indicate 080 * each child tag that has been processed 081 */ 082 public void loaderAddChild(SVGLoaderHelper helper, SVGElement child) throws SVGElementException 083 { 084 super.loaderAddChild(helper, child); 085 086 if (child instanceof FilterEffects) 087 { 088// filterEffects.add(child); 089 } 090 } 091 092 protected void build() throws SVGException 093 { 094 super.build(); 095 096 StyleAttribute sty = new StyleAttribute(); 097 String strn; 098 /* 099 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}