Changeset 6002 in josm for trunk/src/com/kitfox/svg/Rect.java
- Timestamp:
- 2013-06-11T01:01:28+02:00 (13 years ago)
- File:
-
- 1 edited
-
trunk/src/com/kitfox/svg/Rect.java (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/com/kitfox/svg/Rect.java
r4256 r6002 1 1 /* 2 * Rect.java 2 * SVG Salamander 3 * Copyright (c) 2004, Mark McKay 4 * All rights reserved. 3 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: 4 9 * 5 * The Salamander Project - 2D and 3D graphics libraries in Java 6 * Copyright (C) 2004 Mark McKay 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. 7 17 * 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 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, 5:25 PM 26 35 */ 27 28 36 package com.kitfox.svg; 29 37 30 38 import com.kitfox.svg.xml.StyleAttribute; 31 32 import java.awt.*; 33 import java.awt.geom.*; 39 import java.awt.Graphics2D; 40 import java.awt.Shape; 41 import java.awt.geom.Rectangle2D; 42 import java.awt.geom.RectangularShape; 43 import java.awt.geom.RoundRectangle2D; 34 44 import java.io.IOException; 35 45 import java.io.ObjectInputStream; … … 40 50 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a> 41 51 */ 42 public class Rect extends ShapeElement { 52 public class Rect extends ShapeElement 53 { 54 public static final String TAG_NAME = "rect"; 43 55 44 56 float x = 0f; … … 48 60 float rx = 0f; 49 61 float ry = 0f; 50 51 62 RectangularShape rect; 52 63 53 /** Creates a new instance of Rect */ 54 public Rect() { 55 } 56 57 private void writeObject(ObjectOutputStream out) throws IOException 64 /** 65 * Creates a new instance of Rect 66 */ 67 public Rect() 68 { 69 } 70 71 public String getTagName() 72 { 73 return TAG_NAME; 74 } 75 76 private void writeObject(ObjectOutputStream out) throws IOException 58 77 { 59 78 out.writeFloat(x); … … 64 83 out.writeFloat(ry); 65 84 } 66 85 67 86 private void readObject(ObjectInputStream in) throws IOException 68 87 { … … 73 92 rx = in.readFloat(); 74 93 ry = in.readFloat(); 75 94 76 95 if (rx == 0f && ry == 0f) 77 96 { 78 97 rect = new Rectangle2D.Float(x, y, width, height); 79 } 80 else 98 } else 81 99 { 82 100 rect = new RoundRectangle2D.Float(x, y, width, height, rx * 2, ry * 2); 83 101 } 84 102 } 85 103 86 104 /* 87 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent) 88 { 89 //Load style string 90 super.loaderStartElement(helper, attrs, parent); 91 92 String x = attrs.getValue("x"); 93 String y = attrs.getValue("y"); 94 String width = attrs.getValue("width"); 95 String height = attrs.getValue("height"); 96 String rx = attrs.getValue("rx"); 97 String ry = attrs.getValue("ry"); 98 99 if (rx == null) rx = ry; 100 if (ry == null) ry = rx; 101 102 this.x = XMLParseUtil.parseFloat(x); 103 this.y = XMLParseUtil.parseFloat(y); 104 this.width = XMLParseUtil.parseFloat(width); 105 this.height = XMLParseUtil.parseFloat(height); 106 if (rx != null) 107 { 108 this.rx = XMLParseUtil.parseFloat(rx); 109 this.ry = XMLParseUtil.parseFloat(ry); 110 } 111 112 build(); 113 // setBounds(this.x, this.y, this.width, this.height); 114 } 115 */ 116 105 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent) 106 { 107 //Load style string 108 super.loaderStartElement(helper, attrs, parent); 109 110 String x = attrs.getValue("x"); 111 String y = attrs.getValue("y"); 112 String width = attrs.getValue("width"); 113 String height = attrs.getValue("height"); 114 String rx = attrs.getValue("rx"); 115 String ry = attrs.getValue("ry"); 116 117 if (rx == null) rx = ry; 118 if (ry == null) ry = rx; 119 120 this.x = XMLParseUtil.parseFloat(x); 121 this.y = XMLParseUtil.parseFloat(y); 122 this.width = XMLParseUtil.parseFloat(width); 123 this.height = XMLParseUtil.parseFloat(height); 124 if (rx != null) 125 { 126 this.rx = XMLParseUtil.parseFloat(rx); 127 this.ry = XMLParseUtil.parseFloat(ry); 128 } 129 130 build(); 131 // setBounds(this.x, this.y, this.width, this.height); 132 } 133 */ 117 134 protected void build() throws SVGException 118 135 { 119 136 super.build(); 120 137 121 138 StyleAttribute sty = new StyleAttribute(); 122 139 123 140 // SVGElement parent = this.getParent(); 124 141 // if (parent instanceof RenderableElement) … … 128 145 // bounds = null; 129 146 // } 130 131 132 if (getPres(sty.setName("x"))) x = sty.getFloatValueWithUnits(); 133 134 if (getPres(sty.setName("y"))) y = sty.getFloatValueWithUnits(); 135 136 if (getPres(sty.setName("width"))) width = sty.getFloatValueWithUnits(); 137 138 if (getPres(sty.setName("height"))) height = sty.getFloatValueWithUnits(); 147 148 149 if (getPres(sty.setName("x"))) 150 { 151 x = sty.getFloatValueWithUnits(); 152 } 153 154 if (getPres(sty.setName("y"))) 155 { 156 y = sty.getFloatValueWithUnits(); 157 } 158 159 if (getPres(sty.setName("width"))) 160 { 161 width = sty.getFloatValueWithUnits(); 162 } 163 164 if (getPres(sty.setName("height"))) 165 { 166 height = sty.getFloatValueWithUnits(); 167 } 139 168 140 169 boolean rxSet = false; 141 if (getPres(sty.setName("rx"))) { rx = sty.getFloatValueWithUnits(); rxSet = true; } 142 170 if (getPres(sty.setName("rx"))) 171 { 172 rx = sty.getFloatValueWithUnits(); 173 rxSet = true; 174 } 175 143 176 boolean rySet = false; 144 if (getPres(sty.setName("ry"))) { ry = sty.getFloatValueWithUnits(); rySet = true; } 145 146 if (!rxSet) rx = ry; 147 if (!rySet) ry = rx; 148 149 177 if (getPres(sty.setName("ry"))) 178 { 179 ry = sty.getFloatValueWithUnits(); 180 rySet = true; 181 } 182 183 if (!rxSet) 184 { 185 rx = ry; 186 } 187 if (!rySet) 188 { 189 ry = rx; 190 } 191 192 150 193 if (rx == 0f && ry == 0f) 151 194 { 152 195 rect = new Rectangle2D.Float(x, y, width, height); 153 } 154 else 196 } else 155 197 { 156 198 rect = new RoundRectangle2D.Float(x, y, width, height, rx * 2, ry * 2); … … 176 218 177 219 /** 178 * Updates all attributes in this diagram associated with a time event. 179 * Ie, all attributes with track information. 220 * Updates all attributes in this diagram associated with a time event. Ie, 221 * all attributes with track information. 222 * 180 223 * @return - true if this node has changed state as a result of the time 181 224 * update … … 189 232 StyleAttribute sty = new StyleAttribute(); 190 233 boolean shapeChange = false; 191 234 192 235 if (getPres(sty.setName("x"))) 193 236 { … … 263 306 // return true; 264 307 } 265 308 266 309 return changeState || shapeChange; 267 310 }
Note:
See TracChangeset
for help on using the changeset viewer.
