Changeset 6002 in josm for trunk/src/com/kitfox/svg/Use.java
- Timestamp:
- 2013-06-11T01:01:28+02:00 (13 years ago)
- File:
-
- 1 edited
-
trunk/src/com/kitfox/svg/Use.java (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/com/kitfox/svg/Use.java
r4256 r6002 1 1 /* 2 * LinearGradient.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 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 24 33 * 25 34 * Created on January 26, 2004, 1:54 AM 26 35 */ 27 28 36 package com.kitfox.svg; 29 37 … … 39 47 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a> 40 48 */ 41 public class Use extends ShapeElement { 42 49 public class Use extends ShapeElement 50 { 51 public static final String TAG_NAME = "use"; 52 43 53 float x = 0f; 44 54 float y = 0f; 45 55 float width = 1f; 46 56 float height = 1f; 47 48 SVGElement href = null; 49 57 // SVGElement href = null; 58 URI href = null; 50 59 AffineTransform refXform; 51 60 52 /** Creates a new instance of LinearGradient */ 53 public Use() { 54 } 55 /* 56 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent) 57 { 58 //Load style string 59 super.loaderStartElement(helper, attrs, parent); 60 61 String x = attrs.getValue("x"); 62 String y = attrs.getValue("y"); 63 String width = attrs.getValue("width"); 64 String height = attrs.getValue("height"); 65 String href = attrs.getValue("xlink:href"); 66 67 if (x != null) this.x = (float)XMLParseUtil.parseRatio(x); 68 if (y != null) this.y = (float)XMLParseUtil.parseRatio(y); 69 if (width != null) this.width = (float)XMLParseUtil.parseRatio(width); 70 if (height != null) this.height = (float)XMLParseUtil.parseRatio(height); 71 72 73 if (href != null) 74 { 75 try { 76 URI src = getXMLBase().resolve(href); 77 this.href = helper.universe.getElement(src); 78 } 79 catch (Exception e) 80 { 81 e.printStackTrace(); 82 } 61 /** 62 * Creates a new instance of LinearGradient 63 */ 64 public Use() 65 { 66 } 67 68 public String getTagName() 69 { 70 return TAG_NAME; 71 } 72 73 protected void build() throws SVGException 74 { 75 super.build(); 76 77 StyleAttribute sty = new StyleAttribute(); 78 79 if (getPres(sty.setName("x"))) 80 { 81 x = sty.getFloatValueWithUnits(); 82 } 83 84 if (getPres(sty.setName("y"))) 85 { 86 y = sty.getFloatValueWithUnits(); 87 } 88 89 if (getPres(sty.setName("width"))) 90 { 91 width = sty.getFloatValueWithUnits(); 92 } 93 94 if (getPres(sty.setName("height"))) 95 { 96 height = sty.getFloatValueWithUnits(); 97 } 98 99 if (getPres(sty.setName("xlink:href"))) 100 { 101 URI src = sty.getURIValue(getXMLBase()); 102 href = src; 103 // href = diagram.getUniverse().getElement(src); 83 104 } 84 105 … … 86 107 refXform = new AffineTransform(); 87 108 refXform.translate(this.x, this.y); 88 refXform.scale(this.width, this.height); 89 } 90 */ 91 protected void build() throws SVGException 92 { 93 super.build(); 94 95 StyleAttribute sty = new StyleAttribute(); 96 97 if (getPres(sty.setName("x"))) x = sty.getFloatValueWithUnits(); 98 99 if (getPres(sty.setName("y"))) y = sty.getFloatValueWithUnits(); 100 101 if (getPres(sty.setName("width"))) width = sty.getFloatValueWithUnits(); 102 103 if (getPres(sty.setName("height"))) height = sty.getFloatValueWithUnits(); 104 105 if (getPres(sty.setName("xlink:href"))) 106 { 107 URI src = sty.getURIValue(getXMLBase()); 108 href = diagram.getUniverse().getElement(src); 109 } 110 111 //Determine use offset/scale 112 refXform = new AffineTransform(); 113 refXform.translate(this.x, this.y); 114 } 115 109 } 110 116 111 public void render(Graphics2D g) throws SVGException 117 112 { … … 122 117 g.transform(refXform); 123 118 124 if (href == null || !(href instanceof RenderableElement)) return; 125 126 RenderableElement rendEle = (RenderableElement)href; 119 SVGElement ref = diagram.getUniverse().getElement(href); 120 121 if (ref == null || !(ref instanceof RenderableElement)) 122 { 123 return; 124 } 125 126 RenderableElement rendEle = (RenderableElement) ref; 127 127 rendEle.pushParentContext(this); 128 128 rendEle.render(g); … … 136 136 public Shape getShape() 137 137 { 138 if (href instanceof ShapeElement) 139 { 140 Shape shape = ((ShapeElement)href).getShape(); 138 SVGElement ref = diagram.getUniverse().getElement(href); 139 if (ref instanceof ShapeElement) 140 { 141 Shape shape = ((ShapeElement) ref).getShape(); 141 142 shape = refXform.createTransformedShape(shape); 142 143 shape = shapeToParent(shape); … … 149 150 public Rectangle2D getBoundingBox() throws SVGException 150 151 { 151 if (href instanceof ShapeElement) 152 { 153 ShapeElement shapeEle = (ShapeElement)href; 152 SVGElement ref = diagram.getUniverse().getElement(href); 153 if (ref instanceof ShapeElement) 154 { 155 ShapeElement shapeEle = (ShapeElement) ref; 154 156 shapeEle.pushParentContext(this); 155 157 Rectangle2D bounds = shapeEle.getBoundingBox(); 156 158 shapeEle.popParentContext(); 157 159 158 160 bounds = refXform.createTransformedShape(bounds).getBounds2D(); 159 161 bounds = boundsToParent(bounds); … … 166 168 167 169 /** 168 * Updates all attributes in this diagram associated with a time event. 169 * Ie, all attributes with track information. 170 * Updates all attributes in this diagram associated with a time event. Ie, 171 * all attributes with track information. 172 * 170 173 * @return - true if this node has changed state as a result of the time 171 174 * update … … 179 182 StyleAttribute sty = new StyleAttribute(); 180 183 boolean shapeChange = false; 184 185 if (getPres(sty.setName("x"))) 186 { 187 float newVal = sty.getFloatValueWithUnits(); 188 if (newVal != x) 189 { 190 x = newVal; 191 shapeChange = true; 192 } 193 } 194 195 if (getPres(sty.setName("y"))) 196 { 197 float newVal = sty.getFloatValueWithUnits(); 198 if (newVal != y) 199 { 200 y = newVal; 201 shapeChange = true; 202 } 203 } 204 205 if (getPres(sty.setName("width"))) 206 { 207 float newVal = sty.getFloatValueWithUnits(); 208 if (newVal != width) 209 { 210 width = newVal; 211 shapeChange = true; 212 } 213 } 214 215 if (getPres(sty.setName("height"))) 216 { 217 float newVal = sty.getFloatValueWithUnits(); 218 if (newVal != height) 219 { 220 height = newVal; 221 shapeChange = true; 222 } 223 } 224 225 if (getPres(sty.setName("xlink:href"))) 226 { 227 URI src = sty.getURIValue(getXMLBase()); 228 // SVGElement newVal = diagram.getUniverse().getElement(src); 229 if (!src.equals(href)) 230 { 231 href = src; 232 shapeChange = true; 233 } 234 } 235 /* 236 if (getPres(sty.setName("xlink:href"))) 237 { 238 URI src = sty.getURIValue(getXMLBase()); 239 href = diagram.getUniverse().getElement(src); 240 } 181 241 182 if (getPres(sty.setName("x"))) 183 { 184 float newVal = sty.getFloatValueWithUnits(); 185 if (newVal != x) 186 { 187 x = newVal; 188 shapeChange = true; 189 } 190 } 191 192 if (getPres(sty.setName("y"))) 193 { 194 float newVal = sty.getFloatValueWithUnits(); 195 if (newVal != y) 196 { 197 y = newVal; 198 shapeChange = true; 199 } 200 } 201 202 if (getPres(sty.setName("width"))) 203 { 204 float newVal = sty.getFloatValueWithUnits(); 205 if (newVal != width) 206 { 207 width = newVal; 208 shapeChange = true; 209 } 210 } 211 212 if (getPres(sty.setName("height"))) 213 { 214 float newVal = sty.getFloatValueWithUnits(); 215 if (newVal != height) 216 { 217 height = newVal; 218 shapeChange = true; 219 } 220 } 221 222 if (getPres(sty.setName("xlink:href"))) 223 { 224 URI src = sty.getURIValue(getXMLBase()); 225 SVGElement newVal = diagram.getUniverse().getElement(src); 226 if (newVal != href) 227 { 228 href = newVal; 229 shapeChange = true; 230 } 231 } 232 /* 233 if (getPres(sty.setName("xlink:href"))) 234 { 235 URI src = sty.getURIValue(getXMLBase()); 236 href = diagram.getUniverse().getElement(src); 237 } 238 239 //Determine use offset/scale 240 refXform = new AffineTransform(); 241 refXform.translate(this.x, this.y); 242 refXform.scale(this.width, this.height); 243 */ 242 //Determine use offset/scale 243 refXform = new AffineTransform(); 244 refXform.translate(this.x, this.y); 245 refXform.scale(this.width, this.height); 246 */ 244 247 if (shapeChange) 245 248 { … … 250 253 // return true; 251 254 } 252 255 253 256 return changeState || shapeChange; 254 257 }
Note:
See TracChangeset
for help on using the changeset viewer.
