Revision 436 trunk/org.gvsig.app.document.layout2.app/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/geometryadapters/GeometryAdapter.java
GeometryAdapter.java | ||
---|---|---|
16 | 16 |
* along with this program; if not, write to the Free Software |
17 | 17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
18 | 18 |
* |
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib??ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 | 19 |
*/ |
41 | 20 |
package org.gvsig.app.project.documents.layout.geometryadapters; |
42 | 21 |
|
43 | 22 |
import java.awt.Graphics2D; |
44 | 23 |
import java.awt.geom.AffineTransform; |
45 |
import java.awt.geom.Arc2D; |
|
46 |
import java.awt.geom.FlatteningPathIterator; |
|
47 |
import java.awt.geom.NoninvertibleTransformException; |
|
48 | 24 |
import java.awt.geom.Point2D; |
49 | 25 |
import java.awt.geom.Rectangle2D; |
50 | 26 |
import java.util.ArrayList; |
... | ... | |
55 | 31 |
import org.gvsig.fmap.geom.Geometry; |
56 | 32 |
import org.gvsig.fmap.geom.GeometryLocator; |
57 | 33 |
import org.gvsig.fmap.geom.GeometryManager; |
58 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
|
59 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
|
60 | 34 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
61 |
import org.gvsig.fmap.geom.primitive.Circle; |
|
62 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
|
63 |
import org.gvsig.fmap.geom.primitive.Point; |
|
64 |
import org.gvsig.fmap.geom.type.GeometryTypeNotSupportedException; |
|
65 |
import org.gvsig.fmap.geom.type.GeometryTypeNotValidException; |
|
66 | 35 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
67 | 36 |
import org.gvsig.tools.ToolsLocator; |
68 | 37 |
import org.gvsig.tools.dynobject.DynStruct; |
... | ... | |
71 | 40 |
import org.gvsig.tools.persistence.Persistent; |
72 | 41 |
import org.gvsig.tools.persistence.PersistentState; |
73 | 42 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
74 |
import org.gvsig.app.project.documents.layout.geometryadapters.PrintingCircle2D; |
|
75 | 43 |
|
76 | 44 |
/** |
77 | 45 |
* Abstract adaptor to relate the geometries with the fframes and to be able to |
78 | 46 |
* integrate them in the Layout. |
79 |
*
|
|
47 |
* |
|
80 | 48 |
* @author Vicente Caballero Navarro |
81 | 49 |
*/ |
82 | 50 |
public abstract class GeometryAdapter implements Persistent, Cloneable { |
... | ... | |
84 | 52 |
public static final String PERSISTENCE_DEFINITION_NAME = "GeometryAdapter"; |
85 | 53 |
|
86 | 54 |
private static final String POINTS_FIELD = "points"; |
87 |
|
|
55 |
|
|
88 | 56 |
protected static final GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
89 | 57 |
|
90 | 58 |
private List<Point2D> points = new ArrayList<Point2D>(); |
... | ... | |
96 | 64 |
|
97 | 65 |
/** |
98 | 66 |
* Add a point to de geometry. |
99 |
* |
|
100 |
* @param point |
|
101 |
* Point that is added. |
|
102 |
* |
|
67 |
* |
|
68 |
* @param point Point that is added. |
|
69 |
* |
|
103 | 70 |
* @return Number of points that contains the geometry. |
104 | 71 |
*/ |
105 | 72 |
public int addPoint(Point2D point) { |
... | ... | |
117 | 84 |
|
118 | 85 |
/** |
119 | 86 |
* Adds the GeneralPathX with all the points of the geometry. |
120 |
* |
|
121 |
* @param gpx |
|
122 |
* GeneralPathX |
|
87 |
* |
|
88 |
* @param gpx GeneralPathX |
|
123 | 89 |
*/ |
124 | 90 |
protected void setGeometry(Geometry geometry) { |
125 | 91 |
this.geometry = geometry; |
... | ... | |
127 | 93 |
|
128 | 94 |
/** |
129 | 95 |
* Obtains the geometry passing him as parameter the last point. |
130 |
* |
|
131 |
* @param p |
|
132 |
* Last Point. |
|
133 |
* @throws CreateGeometryException |
|
96 |
* |
|
97 |
* @param p Last Point. |
|
98 |
* @throws CreateGeometryException |
|
134 | 99 |
*/ |
135 | 100 |
public abstract void obtainShape(Point2D p); |
136 | 101 |
|
137 | 102 |
/** |
138 | 103 |
* Applies the transformation to all the points of the geometry. |
139 |
* |
|
140 |
* @param at |
|
141 |
* AffineTransform |
|
104 |
* |
|
105 |
* @param at AffineTransform |
|
142 | 106 |
*/ |
143 | 107 |
public void applyTransform(AffineTransform at) { |
144 | 108 |
for (int i = 0; i < points.size(); i++) { |
... | ... | |
150 | 114 |
|
151 | 115 |
/** |
152 | 116 |
* It draws the geometry on the Graphics that is passed like parameter. |
153 |
* |
|
154 |
* @param g |
|
155 |
* Graphics |
|
156 |
* @param at |
|
157 |
* AffineTransform |
|
158 |
* @param symbol |
|
159 |
* FSymbol |
|
117 |
* |
|
118 |
* @param g Graphics |
|
119 |
* @param at AffineTransform |
|
120 |
* @param symbol FSymbol |
|
160 | 121 |
*/ |
161 |
public void draw(Graphics2D g, AffineTransform at, ISymbol symbol){ |
|
122 |
public void draw(Graphics2D g, AffineTransform at, ISymbol symbol) {
|
|
162 | 123 |
symbol.draw(g, at, geometry, null, null); |
163 | 124 |
} |
164 | 125 |
|
165 | 126 |
/** |
166 | 127 |
* It print the geometry on the Graphics that is passed like parameter. |
167 |
* |
|
168 |
* @param g |
|
169 |
* Graphics |
|
170 |
* @param at |
|
171 |
* AffineTransform |
|
172 |
* @param symbol |
|
173 |
* ISymbol |
|
128 |
* |
|
129 |
* @param g Graphics |
|
130 |
* @param at AffineTransform |
|
131 |
* @param symbol ISymbol |
|
174 | 132 |
* @param properties |
175 | 133 |
*/ |
176 | 134 |
public void print(Graphics2D g, AffineTransform at, |
177 |
ISymbol symbol, PrintAttributes properties){ |
|
178 |
Geometry geom = getGeometry(); |
|
179 |
if (geom instanceof Circle) { |
|
180 |
// circles must be handled differently in order to print really round geometries |
|
181 |
// as the flatness used for screen may not be good for printing |
|
182 |
Circle circle = ((Circle) geom); |
|
183 |
PrintingCircle2D printCircle = new PrintingCircle2D(circle); |
|
184 |
geom = printCircle; |
|
185 |
|
|
186 |
} |
|
135 |
ISymbol symbol, PrintAttributes properties) { |
|
136 |
Geometry geom = getGeometry(); |
|
187 | 137 |
symbol.print(g, at, geom, properties); |
188 | 138 |
} |
189 | 139 |
|
190 | 140 |
/** |
191 | 141 |
* Paints the geometry on the Graphics adding him the last point if the |
192 | 142 |
* parameter andLastPoint is true. |
193 |
* |
|
194 |
* @param g |
|
195 |
* Graphics |
|
196 |
* @param at |
|
197 |
* AffineTransform |
|
198 |
* @param andLastPoint |
|
199 |
* If true add last point. |
|
143 |
* |
|
144 |
* @param g Graphics |
|
145 |
* @param at AffineTransform |
|
146 |
* @param andLastPoint If true add last point. |
|
200 | 147 |
*/ |
201 | 148 |
public abstract void paint(Graphics2D g, AffineTransform at, |
202 |
boolean andLastPoint); |
|
149 |
boolean andLastPoint);
|
|
203 | 150 |
|
204 | 151 |
/** |
205 | 152 |
* Set the point of cursor. |
206 |
* |
|
207 |
* @param p |
|
208 |
* Point of cursor. |
|
153 |
* |
|
154 |
* @param p Point of cursor. |
|
209 | 155 |
*/ |
210 | 156 |
public abstract void pointPosition(Point2D p); |
211 | 157 |
|
212 | 158 |
/** |
213 | 159 |
* Obtains the shape of the Geometry. |
214 |
*
|
|
160 |
* |
|
215 | 161 |
* @return Geometry. |
216 | 162 |
* @deprecated |
217 | 163 |
*/ |
218 |
public Geometry getGeometry(AffineTransform at){ |
|
164 |
public Geometry getGeometry(AffineTransform at) {
|
|
219 | 165 |
Geometry clonedGeom = geometry.cloneGeometry(); |
220 | 166 |
clonedGeom.transform(at); |
221 | 167 |
return clonedGeom; |
222 | 168 |
} |
223 |
|
|
169 |
|
|
224 | 170 |
/** |
225 | 171 |
* Returns the geometry to draw |
226 |
* @return
|
|
227 |
* the geometry
|
|
172 |
* |
|
173 |
* @return the geometry
|
|
228 | 174 |
*/ |
229 |
public Geometry getGeometry(){ |
|
175 |
public Geometry getGeometry() {
|
|
230 | 176 |
return geometry; |
231 | 177 |
} |
232 | 178 |
|
233 | 179 |
/** |
234 | 180 |
* Returns all the points of Geometry. |
235 |
*
|
|
181 |
* |
|
236 | 182 |
* @return Array of points. |
237 | 183 |
*/ |
238 | 184 |
public Point2D[] getPoints() { |
... | ... | |
241 | 187 |
|
242 | 188 |
/** |
243 | 189 |
* Draws a handler in each vertex of the Geometry. |
244 |
* |
|
245 |
* @param g |
|
246 |
* Graphics |
|
247 |
* @param at |
|
248 |
* AffineTransform. |
|
190 |
* |
|
191 |
* @param g Graphics |
|
192 |
* @param at AffineTransform. |
|
249 | 193 |
*/ |
250 | 194 |
public void drawVertex(Graphics2D g, AffineTransform at) { |
251 | 195 |
Point2D[] ps = getPoints(); |
... | ... | |
256 | 200 |
|
257 | 201 |
for (int i = 0; i < pointRes.length; i++) { |
258 | 202 |
g.fillRect((int) pointRes[i].getX() - d, (int) pointRes[i].getY() |
259 |
- d, d * 2, d * 2); |
|
203 |
- d, d * 2, d * 2);
|
|
260 | 204 |
} |
261 | 205 |
} |
262 | 206 |
|
263 | 207 |
/** |
264 | 208 |
* Modifies a point of the Geometry from an index by the one that is passed |
265 | 209 |
* like parameter. |
266 |
* |
|
267 |
* @param pos |
|
268 |
* Index |
|
269 |
* @param point |
|
270 |
* Point |
|
210 |
* |
|
211 |
* @param pos Index |
|
212 |
* @param point Point |
|
271 | 213 |
*/ |
272 | 214 |
public void changePoint(int pos, Point2D point) { |
273 | 215 |
this.points.set(pos, point); |
... | ... | |
275 | 217 |
|
276 | 218 |
/** |
277 | 219 |
* Add all the points of Geometry. |
278 |
* |
|
279 |
* @param points |
|
280 |
* All points. |
|
220 |
* |
|
221 |
* @param points All points. |
|
281 | 222 |
*/ |
282 | 223 |
public void setPoints(Point2D[] points) { |
283 | 224 |
this.points.clear(); |
... | ... | |
329 | 270 |
public static void registerPersistent() { |
330 | 271 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
331 | 272 |
if (manager.getDefinition(PERSISTENCE_DEFINITION_NAME) == null) { |
332 |
DynStruct definition =
|
|
333 |
manager.addDefinition(GeometryAdapter.class, |
|
334 |
PERSISTENCE_DEFINITION_NAME, |
|
335 |
"GeometryAdapter persistence definition", null, null); |
|
273 |
DynStruct definition |
|
274 |
= manager.addDefinition(GeometryAdapter.class,
|
|
275 |
PERSISTENCE_DEFINITION_NAME,
|
|
276 |
"GeometryAdapter persistence definition", null, null);
|
|
336 | 277 |
|
337 | 278 |
definition.addDynFieldList(POINTS_FIELD) |
338 |
.setClassOfItems(Point2D.class).setMandatory(true); |
|
279 |
.setClassOfItems(Point2D.class).setMandatory(true);
|
|
339 | 280 |
} |
340 | 281 |
|
341 | 282 |
CircleAdapter.registerPersistent(); |
... | ... | |
346 | 287 |
} |
347 | 288 |
|
348 | 289 |
public void loadFromState(PersistentState state) |
349 |
throws PersistenceException { |
|
290 |
throws PersistenceException {
|
|
350 | 291 |
points = state.getList(POINTS_FIELD); |
351 | 292 |
obtainShape((Point2D) points.get(points.size() - 1)); |
352 | 293 |
} |
Also available in: Unified diff