svn-document-layout / trunk / org.gvsig.app.document.layout2.app / org.gvsig.app.document.layout2.app.mainplugin / src / main / java / org / gvsig / app / project / documents / layout / geometryadapters / CircleAdapter.java @ 1735
History | View | Annotate | Download (4.74 KB)
1 | 5 | jldominguez | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
||
4 | * of the Valencian Government (CIT)
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 2
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | */
|
||
22 | package org.gvsig.app.project.documents.layout.geometryadapters; |
||
23 | |||
24 | import java.awt.Color; |
||
25 | import java.awt.Graphics2D; |
||
26 | import java.awt.geom.AffineTransform; |
||
27 | import java.awt.geom.Point2D; |
||
28 | |||
29 | import org.slf4j.Logger; |
||
30 | import org.slf4j.LoggerFactory; |
||
31 | |||
32 | import org.gvsig.fmap.geom.Geometry; |
||
33 | import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
||
34 | import org.gvsig.fmap.geom.Geometry.TYPES; |
||
35 | import org.gvsig.fmap.geom.exception.CreateGeometryException; |
||
36 | import org.gvsig.fmap.geom.primitive.Circle; |
||
37 | import org.gvsig.fmap.mapcontext.MapContextLocator; |
||
38 | import org.gvsig.fmap.mapcontext.MapContextManager; |
||
39 | import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol; |
||
40 | import org.gvsig.tools.ToolsLocator; |
||
41 | import org.gvsig.tools.dynobject.DynStruct; |
||
42 | import org.gvsig.tools.persistence.PersistenceManager; |
||
43 | |||
44 | public class CircleAdapter extends GeometryAdapter { |
||
45 | public static final String PERSISTENCE_DEFINITION_NAME = "CircleAdapter"; |
||
46 | private static final Logger logger = LoggerFactory |
||
47 | .getLogger(CircleAdapter.class); |
||
48 | private Point2D pointPosition = new Point2D.Double(); |
||
49 | private AffineTransform identity = new AffineTransform(); |
||
50 | |||
51 | private MapContextManager mapContextManager = MapContextLocator
|
||
52 | .getMapContextManager(); |
||
53 | |||
54 | public CircleAdapter() {
|
||
55 | super();
|
||
56 | } |
||
57 | |||
58 | /**
|
||
59 | * DOCUMENT ME!
|
||
60 | *
|
||
61 | * @param g
|
||
62 | * DOCUMENT ME!
|
||
63 | * @param at
|
||
64 | * DOCUMENT ME!
|
||
65 | * @param andLastPoint
|
||
66 | * DOCUMENT ME!
|
||
67 | */
|
||
68 | public void paint(Graphics2D g, AffineTransform at, boolean andLastPoint) { |
||
69 | if (getPoints().length > 0) { |
||
70 | if (andLastPoint) {
|
||
71 | obtainShape(pointPosition); |
||
72 | } |
||
73 | |||
74 | Geometry shapeAux = getGeometry(at); |
||
75 | |||
76 | ILineSymbol symbol = |
||
77 | (ILineSymbol) mapContextManager.getSymbolManager() |
||
78 | .createSymbol(ILineSymbol.SYMBOL_NAME); |
||
79 | ILineSymbol redOutline = |
||
80 | (ILineSymbol) MapContextLocator.getSymbolManager() |
||
81 | .createSymbol(ILineSymbol.SYMBOL_NAME); |
||
82 | redOutline.setLineColor(Color.red);
|
||
83 | symbol.draw(g, identity, shapeAux, null, null); |
||
84 | } |
||
85 | } |
||
86 | |||
87 | /**
|
||
88 | * DOCUMENT ME!
|
||
89 | *
|
||
90 | * @param p
|
||
91 | * DOCUMENT ME!
|
||
92 | */
|
||
93 | public void pointPosition(Point2D p) { |
||
94 | pointPosition = p; |
||
95 | } |
||
96 | |||
97 | /**
|
||
98 | * DOCUMENT ME!
|
||
99 | *
|
||
100 | * @param p
|
||
101 | * DOCUMENT ME!
|
||
102 | * @throws CreateGeometryException
|
||
103 | */
|
||
104 | public void obtainShape(Point2D p) { |
||
105 | Point2D[] points = getPoints(); |
||
106 | |||
107 | double x = (points[0]).getX(); |
||
108 | double y = (points[0]).getY(); |
||
109 | double r = p.distance(points[0]); |
||
110 | |||
111 | try {
|
||
112 | Circle circle = (Circle)geomManager.create(TYPES.CIRCLE, SUBTYPES.GEOM2D); |
||
113 | 102 | jldominguez | |
114 | double flatness = geomManager.getFlatness();
|
||
115 | |||
116 | geomManager.setFlatness(0.01);
|
||
117 | 5 | jldominguez | circle.setPoints(geomManager.createPoint(x, y, SUBTYPES.GEOM2D), r) ; |
118 | 102 | jldominguez | geomManager.setFlatness(flatness); |
119 | |||
120 | 5 | jldominguez | setGeometry(circle); |
121 | } catch (CreateGeometryException e) {
|
||
122 | logger.error("Error creating the circle", e);
|
||
123 | } |
||
124 | } |
||
125 | |||
126 | public static void registerPersistent() { |
||
127 | PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
||
128 | if (manager.getDefinition(PERSISTENCE_DEFINITION_NAME) == null) { |
||
129 | DynStruct definition = |
||
130 | manager.addDefinition(CircleAdapter.class, |
||
131 | PERSISTENCE_DEFINITION_NAME, |
||
132 | "Circle Adapter persistence definition", null, null); |
||
133 | |||
134 | definition.extend(manager |
||
135 | .getDefinition(GeometryAdapter.PERSISTENCE_DEFINITION_NAME)); |
||
136 | } |
||
137 | } |
||
138 | } |