source: josm/trunk/src/com/kitfox/svg/Circle.java@ 4453

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

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

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