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

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

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

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 void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
58 {
59 //Load style string
60 super.loaderStartElement(helper, attrs, parent);
61
62 String transform = attrs.getValue("transform");
63 if (transform != null)
64 {
65 xform = parseTransform(transform);
66 }
67 }
68*/
69
70 protected void build() throws SVGException
71 {
72 super.build();
73
74 StyleAttribute sty = new StyleAttribute();
75
76 if (getPres(sty.setName("transform")))
77 {
78 xform = parseTransform(sty.getStringValue());
79 }
80 }
81
82 protected Shape shapeToParent(Shape shape)
83 {
84 if (xform == null) return shape;
85 return xform.createTransformedShape(shape);
86 }
87
88 protected Rectangle2D boundsToParent(Rectangle2D rect)
89 {
90 if (xform == null) return rect;
91 return xform.createTransformedShape(rect).getBounds2D();
92 }
93
94 /**
95 * Updates all attributes in this diagram associated with a time event.
96 * Ie, all attributes with track information.
97 * @return - true if this node has changed state as a result of the time
98 * update
99 */
100 public boolean updateTime(double curTime) throws SVGException
101 {
102 StyleAttribute sty = new StyleAttribute();
103
104 if (getPres(sty.setName("transform")))
105 {
106 AffineTransform newXform = parseTransform(sty.getStringValue());
107 if (!newXform.equals(xform))
108 {
109 xform = newXform;
110 return true;
111 }
112 }
113
114 return false;
115 }
116}
Note: See TracBrowser for help on using the repository browser.