1 | /*
|
---|
2 | * SVG Salamander
|
---|
3 | * Copyright (c) 2004, Mark McKay
|
---|
4 | * All rights reserved.
|
---|
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:
|
---|
9 | *
|
---|
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.
|
---|
17 | *
|
---|
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
|
---|
33 | *
|
---|
34 | * Created on January 26, 2004, 1:56 AM
|
---|
35 | */
|
---|
36 | package com.kitfox.svg;
|
---|
37 |
|
---|
38 | import com.kitfox.svg.xml.StyleAttribute;
|
---|
39 | import java.awt.Graphics2D;
|
---|
40 | import java.awt.Rectangle;
|
---|
41 | import java.awt.Shape;
|
---|
42 | import java.awt.geom.AffineTransform;
|
---|
43 | import java.awt.geom.Rectangle2D;
|
---|
44 |
|
---|
45 | /**
|
---|
46 | * @author Mark McKay
|
---|
47 | * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
|
---|
48 | */
|
---|
49 | public class Symbol extends Group
|
---|
50 | {
|
---|
51 |
|
---|
52 | public static final String TAG_NAME = "symbol";
|
---|
53 | AffineTransform viewXform;
|
---|
54 | Rectangle2D viewBox;
|
---|
55 |
|
---|
56 | /**
|
---|
57 | * Creates a new instance of Stop
|
---|
58 | */
|
---|
59 | public Symbol()
|
---|
60 | {
|
---|
61 | }
|
---|
62 |
|
---|
63 | public String getTagName()
|
---|
64 | {
|
---|
65 | return TAG_NAME;
|
---|
66 | }
|
---|
67 |
|
---|
68 | protected void build() throws SVGException
|
---|
69 | {
|
---|
70 | super.build();
|
---|
71 |
|
---|
72 | StyleAttribute sty = new StyleAttribute();
|
---|
73 |
|
---|
74 | // sty = getPres("unicode");
|
---|
75 | // if (sty != null) unicode = sty.getStringValue();
|
---|
76 |
|
---|
77 |
|
---|
78 | if (getPres(sty.setName("viewBox")))
|
---|
79 | {
|
---|
80 | float[] dim = sty.getFloatList();
|
---|
81 | viewBox = new Rectangle2D.Float(dim[0], dim[1], dim[2], dim[3]);
|
---|
82 | }
|
---|
83 |
|
---|
84 | if (viewBox == null)
|
---|
85 | {
|
---|
86 | // viewBox = super.getBoundingBox();
|
---|
87 | viewBox = new Rectangle(0, 0, 1, 1);
|
---|
88 | }
|
---|
89 |
|
---|
90 | //Transform pattern onto unit square
|
---|
91 | viewXform = new AffineTransform();
|
---|
92 | viewXform.scale(1.0 / viewBox.getWidth(), 1.0 / viewBox.getHeight());
|
---|
93 | viewXform.translate(-viewBox.getX(), -viewBox.getY());
|
---|
94 | }
|
---|
95 |
|
---|
96 | protected boolean outsideClip(Graphics2D g) throws SVGException
|
---|
97 | {
|
---|
98 | Shape clip = g.getClip();
|
---|
99 | // g.getClipBounds(clipBounds);
|
---|
100 | Rectangle2D rect = super.getBoundingBox();
|
---|
101 | if (clip == null || clip.intersects(rect))
|
---|
102 | {
|
---|
103 | return false;
|
---|
104 | }
|
---|
105 |
|
---|
106 | return true;
|
---|
107 |
|
---|
108 | }
|
---|
109 |
|
---|
110 | public void render(Graphics2D g) throws SVGException
|
---|
111 | {
|
---|
112 | AffineTransform oldXform = g.getTransform();
|
---|
113 | g.transform(viewXform);
|
---|
114 |
|
---|
115 | super.render(g);
|
---|
116 |
|
---|
117 | g.setTransform(oldXform);
|
---|
118 | }
|
---|
119 |
|
---|
120 | public Shape getShape()
|
---|
121 | {
|
---|
122 | Shape shape = super.getShape();
|
---|
123 | return viewXform.createTransformedShape(shape);
|
---|
124 | }
|
---|
125 |
|
---|
126 | public Rectangle2D getBoundingBox() throws SVGException
|
---|
127 | {
|
---|
128 | Rectangle2D rect = super.getBoundingBox();
|
---|
129 | return viewXform.createTransformedShape(rect).getBounds2D();
|
---|
130 | }
|
---|
131 |
|
---|
132 | /**
|
---|
133 | * Updates all attributes in this diagram associated with a time event. Ie,
|
---|
134 | * all attributes with track information.
|
---|
135 | *
|
---|
136 | * @return - true if this node has changed state as a result of the time
|
---|
137 | * update
|
---|
138 | */
|
---|
139 | public boolean updateTime(double curTime) throws SVGException
|
---|
140 | {
|
---|
141 | // if (trackManager.getNumTracks() == 0) return false;
|
---|
142 | boolean changeState = super.updateTime(curTime);
|
---|
143 |
|
---|
144 | //View box properties do not change
|
---|
145 |
|
---|
146 | return changeState;
|
---|
147 | }
|
---|
148 | }
|
---|