1 | /*
|
---|
2 | * Stop.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, 1:56 AM
|
---|
26 | */
|
---|
27 |
|
---|
28 | package com.kitfox.svg;
|
---|
29 |
|
---|
30 | import com.kitfox.svg.xml.StyleAttribute;
|
---|
31 | import java.awt.Shape;
|
---|
32 | import java.awt.geom.Area;
|
---|
33 | import java.util.Iterator;
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * @author Mark McKay
|
---|
37 | * @author <a href="mailto:mark@kitfox.com">Mark McKay</a>
|
---|
38 | */
|
---|
39 | public class ClipPath extends SVGElement
|
---|
40 | {
|
---|
41 |
|
---|
42 | public static final int CP_USER_SPACE_ON_USE = 0;
|
---|
43 | public static final int CP_OBJECT_BOUNDING_BOX = 1;
|
---|
44 |
|
---|
45 | int clipPathUnits = CP_USER_SPACE_ON_USE;
|
---|
46 |
|
---|
47 | /** Creates a new instance of Stop */
|
---|
48 | public ClipPath() {
|
---|
49 | }
|
---|
50 | /*
|
---|
51 | public void loaderStartElement(SVGLoaderHelper helper, Attributes attrs, SVGElement parent)
|
---|
52 | {
|
---|
53 | //Load style string
|
---|
54 | super.loaderStartElement(helper, attrs, parent);
|
---|
55 |
|
---|
56 | String clipPathUnits = attrs.getValue("clipPathUnits");
|
---|
57 |
|
---|
58 | if (clipPathUnits.equals("objectBoundingBox")) this.clipPathUnits = CP_OBJECT_BOUNDING_BOX;
|
---|
59 |
|
---|
60 | }
|
---|
61 | */
|
---|
62 | /**
|
---|
63 | * Called after the start element but before the end element to indicate
|
---|
64 | * each child tag that has been processed
|
---|
65 | */
|
---|
66 | public void loaderAddChild(SVGLoaderHelper helper, SVGElement child) throws SVGElementException
|
---|
67 | {
|
---|
68 | super.loaderAddChild(helper, child);
|
---|
69 |
|
---|
70 | // if (child instanceof ShapeElement) members.add(child);
|
---|
71 | }
|
---|
72 |
|
---|
73 | /*
|
---|
74 | public void loaderEndElement(SVGLoaderHelper helper)
|
---|
75 | {
|
---|
76 | // super.loaderEndElement(helper);
|
---|
77 |
|
---|
78 | // build();
|
---|
79 | }
|
---|
80 | */
|
---|
81 |
|
---|
82 | protected void build() throws SVGException
|
---|
83 | {
|
---|
84 | super.build();
|
---|
85 |
|
---|
86 | StyleAttribute sty = new StyleAttribute();
|
---|
87 |
|
---|
88 | clipPathUnits = (getPres(sty.setName("clipPathUnits"))
|
---|
89 | && sty.getStringValue().equals("objectBoundingBox"))
|
---|
90 | ? CP_OBJECT_BOUNDING_BOX
|
---|
91 | : CP_USER_SPACE_ON_USE;
|
---|
92 | }
|
---|
93 |
|
---|
94 | public int getClipPathUnits()
|
---|
95 | {
|
---|
96 | return clipPathUnits;
|
---|
97 | }
|
---|
98 |
|
---|
99 | public Shape getClipPathShape()
|
---|
100 | {
|
---|
101 | if (children.size() == 0) return null;
|
---|
102 | if (children.size() == 1) return ((ShapeElement)children.get(0)).getShape();
|
---|
103 |
|
---|
104 | Area clipArea = null;
|
---|
105 | for (Iterator it = children.iterator(); it.hasNext();)
|
---|
106 | {
|
---|
107 | ShapeElement se = (ShapeElement)it.next();
|
---|
108 |
|
---|
109 | if (clipArea == null)
|
---|
110 | {
|
---|
111 | Shape shape = se.getShape();
|
---|
112 | if (shape != null) clipArea = new Area(se.getShape());
|
---|
113 | continue;
|
---|
114 | }
|
---|
115 |
|
---|
116 | Shape shape = se.getShape();
|
---|
117 | if (shape != null) clipArea.intersect(new Area(shape));
|
---|
118 | }
|
---|
119 |
|
---|
120 | return clipArea;
|
---|
121 | }
|
---|
122 |
|
---|
123 | /**
|
---|
124 | * Updates all attributes in this diagram associated with a time event.
|
---|
125 | * Ie, all attributes with track information.
|
---|
126 | * @return - true if this node has changed state as a result of the time
|
---|
127 | * update
|
---|
128 | */
|
---|
129 | public boolean updateTime(double curTime) throws SVGException
|
---|
130 | {
|
---|
131 | // if (trackManager.getNumTracks() == 0) return false;
|
---|
132 |
|
---|
133 | //Get current values for parameters
|
---|
134 | StyleAttribute sty = new StyleAttribute();
|
---|
135 | boolean shapeChange = false;
|
---|
136 |
|
---|
137 |
|
---|
138 | if (getPres(sty.setName("clipPathUnits")))
|
---|
139 | {
|
---|
140 | String newUnitsStrn = sty.getStringValue();
|
---|
141 | int newUnits = newUnitsStrn.equals("objectBoundingBox")
|
---|
142 | ? CP_OBJECT_BOUNDING_BOX
|
---|
143 | : CP_USER_SPACE_ON_USE;
|
---|
144 |
|
---|
145 | if (newUnits != clipPathUnits)
|
---|
146 | {
|
---|
147 | clipPathUnits = newUnits;
|
---|
148 | shapeChange = true;
|
---|
149 | }
|
---|
150 | }
|
---|
151 |
|
---|
152 | if (shapeChange)
|
---|
153 | {
|
---|
154 | build();
|
---|
155 | }
|
---|
156 |
|
---|
157 | return shapeChange;
|
---|
158 | }
|
---|
159 | }
|
---|