source: josm/trunk/src/com/kitfox/svg/Ellipse.java@ 4256

Last change on this file since 4256 was 4256, checked in by bastiK, 13 years ago

see #6560 - basic svg support, includes kitfox svgsalamander, r 98, patched

File size: 5.4 KB
Line 
1/*
2 * Rect.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 January 26, 2004, 5:25 PM
26 */
27
28package com.kitfox.svg;
29
30import com.kitfox.svg.xml.StyleAttribute;
31import com.kitfox.svg.xml.*;
32import org.xml.sax.*;
33
34import java.awt.*;
35import java.awt.geom.*;
36
37/**
38 * @author Mark McKay
39 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
40 */
41public class Ellipse extends ShapeElement {
42
43 float cx = 0.0f;
44 float cy = 0.0f;
45 float rx = 0.0f;
46 float ry = 0.0f;
47
48 Ellipse2D.Float ellipse = new Ellipse2D.Float();
49
50 /** Creates a new instance of Rect */
51 public Ellipse() {
52 }
53/*
54 protected void init(String idIn, Style parentStyle, String cx, String cy, String rx, String ry) {
55 super.init(idIn, parentStyle);
56
57 this.cx = parseDouble(cx);
58 this.cy = parseDouble(cy);
59 this.rx = parseDouble(rx);
60 this.ry = parseDouble(ry);
61
62 setBounds(this.cx - this.rx, this.cy - this.ry, this.rx * 2.0, this.ry * 2.0);
63 }
64*/
65 /*
66 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
67 {
68 //Load style string
69 super.loaderStartElement(helper, attrs, parent);
70
71 String cx = attrs.getValue("cx");
72 String cy = attrs.getValue("cy");
73 String rx = attrs.getValue("rx");
74 String ry = attrs.getValue("ry");
75
76 this.cx = XMLParseUtil.parseDouble(cx);
77 this.cy = XMLParseUtil.parseDouble(cy);
78 this.rx = XMLParseUtil.parseDouble(rx);
79 this.ry = XMLParseUtil.parseDouble(ry);
80
81 build();
82 }
83 */
84
85 /*
86 public void loaderEndElement(SVGLoaderHelper helper)
87 {
88 super.loaderEndElement(helper);
89
90 build();
91 }
92 */
93
94 protected void build() throws SVGException
95 {
96 super.build();
97
98 StyleAttribute sty = new StyleAttribute();
99
100 if (getPres(sty.setName("cx"))) cx = sty.getFloatValueWithUnits();
101
102 if (getPres(sty.setName("cy"))) cy = sty.getFloatValueWithUnits();
103
104 if (getPres(sty.setName("rx"))) rx = sty.getFloatValueWithUnits();
105
106 if (getPres(sty.setName("ry"))) ry = sty.getFloatValueWithUnits();
107
108 ellipse.setFrame(cx - rx, cy - ry, rx * 2f, ry * 2f);
109 }
110
111 public void render(Graphics2D g) throws SVGException
112 {
113 beginLayer(g);
114 renderShape(g, ellipse);
115 finishLayer(g);
116 }
117
118 public Shape getShape()
119 {
120 return shapeToParent(ellipse);
121 }
122
123 public Rectangle2D getBoundingBox() throws SVGException
124 {
125 return boundsToParent(includeStrokeInBounds(ellipse.getBounds2D()));
126 }
127
128 /**
129 * Updates all attributes in this diagram associated with a time event.
130 * Ie, all attributes with track information.
131 * @return - true if this node has changed state as a result of the time
132 * update
133 */
134 public boolean updateTime(double curTime) throws SVGException
135 {
136// if (trackManager.getNumTracks() == 0) return false;
137 boolean changeState = super.updateTime(curTime);
138
139 //Get current values for parameters
140 StyleAttribute sty = new StyleAttribute();
141 boolean shapeChange = false;
142
143 if (getPres(sty.setName("cx")))
144 {
145 float newCx = sty.getFloatValueWithUnits();
146 if (newCx != cx)
147 {
148 cx = newCx;
149 shapeChange = true;
150 }
151 }
152
153 if (getPres(sty.setName("cy")))
154 {
155 float newCy = sty.getFloatValueWithUnits();
156 if (newCy != cy)
157 {
158 cy = newCy;
159 shapeChange = true;
160 }
161 }
162
163 if (getPres(sty.setName("rx")))
164 {
165 float newRx = sty.getFloatValueWithUnits();
166 if (newRx != rx)
167 {
168 rx = newRx;
169 shapeChange = true;
170 }
171 }
172
173 if (getPres(sty.setName("ry")))
174 {
175 float newRy = sty.getFloatValueWithUnits();
176 if (newRy != ry)
177 {
178 ry = newRy;
179 shapeChange = true;
180 }
181 }
182
183 if (shapeChange)
184 {
185 build();
186// ellipse.setFrame(cx - rx, cy - ry, rx * 2f, ry * 2f);
187// return true;
188 }
189
190 return changeState || shapeChange;
191 }
192}
Note: See TracBrowser for help on using the repository browser.