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

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

Add patch to svgsalamander to fix bug in the importvec plugin

File size: 3.4 KB
Line 
1/*
2 * BoundedElement.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, 9:00 AM
26 */
27
28package com.kitfox.svg;
29
30import com.kitfox.svg.xml.StyleAttribute;
31import java.awt.Shape;
32import java.awt.geom.AffineTransform;
33import java.awt.geom.Rectangle2D;
34
35
36/**
37 * Maintains bounding box for this element
38 *
39 * @author Mark McKay
40 * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
41 */
42public class TransformableElement extends SVGElement
43{
44
45 AffineTransform xform = null;
46// AffineTransform invXform = null;
47
48 /** Creates a new instance of BoundedElement */
49 public TransformableElement() {
50 }
51
52 public TransformableElement(String id, SVGElement parent)
53 {
54 super(id, parent);
55 }
56
57 public AffineTransform getXForm()
58 {
59 return xform;
60 }
61/*
62 public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
63 {
64 //Load style string
65 super.loaderStartElement(helper, attrs, parent);
66
67 String transform = attrs.getValue("transform");
68 if (transform != null)
69 {
70 xform = parseTransform(transform);
71 }
72 }
73*/
74
75 protected void build() throws SVGException
76 {
77 super.build();
78
79 StyleAttribute sty = new StyleAttribute();
80
81 if (getPres(sty.setName("transform")))
82 {
83 xform = parseTransform(sty.getStringValue());
84 }
85 }
86
87 protected Shape shapeToParent(Shape shape)
88 {
89 if (xform == null) return shape;
90 return xform.createTransformedShape(shape);
91 }
92
93 protected Rectangle2D boundsToParent(Rectangle2D rect)
94 {
95 if (xform == null) return rect;
96 return xform.createTransformedShape(rect).getBounds2D();
97 }
98
99 /**
100 * Updates all attributes in this diagram associated with a time event.
101 * Ie, all attributes with track information.
102 * @return - true if this node has changed state as a result of the time
103 * update
104 */
105 public boolean updateTime(double curTime) throws SVGException
106 {
107 StyleAttribute sty = new StyleAttribute();
108
109 if (getPres(sty.setName("transform")))
110 {
111 AffineTransform newXform = parseTransform(sty.getStringValue());
112 if (!newXform.equals(xform))
113 {
114 xform = newXform;
115 return true;
116 }
117 }
118
119 return false;
120 }
121}
Note: See TracBrowser for help on using the repository browser.