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 / PolygonAdapter.java @ 524
History | View | Annotate | Download (3.35 KB)
1 |
/* 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.geom.Point2D; |
25 |
|
26 |
import org.slf4j.Logger; |
27 |
import org.slf4j.LoggerFactory; |
28 |
|
29 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
30 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
31 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
32 |
import org.gvsig.fmap.geom.primitive.Surface; |
33 |
import org.gvsig.tools.ToolsLocator; |
34 |
import org.gvsig.tools.dynobject.DynStruct; |
35 |
import org.gvsig.tools.persistence.PersistenceManager; |
36 |
|
37 |
/**
|
38 |
* DOCUMENT ME!
|
39 |
*
|
40 |
* @author Vicente Caballero Navarro
|
41 |
*/
|
42 |
public class PolygonAdapter extends PolyLineAdapter { |
43 |
|
44 |
public static final String PERSISTENCE_DEFINITION_NAME = "PolygonAdapter"; |
45 |
private static final Logger logger = LoggerFactory |
46 |
.getLogger(PolygonAdapter.class); |
47 |
|
48 |
public PolygonAdapter() {
|
49 |
super();
|
50 |
} |
51 |
|
52 |
/**
|
53 |
* DOCUMENT ME!
|
54 |
*
|
55 |
* @param p
|
56 |
* DOCUMENT ME!
|
57 |
*/
|
58 |
public void obtainShape(Point2D p) { |
59 |
Point2D[] points = getPoints(); |
60 |
|
61 |
try {
|
62 |
Surface surface = (Surface)geomManager.create(TYPES.SURFACE, SUBTYPES.GEOM2D); |
63 |
if (points.length > 0) { |
64 |
surface.addVertex(geomManager.createPoint(points[0].getX(), points[0].getY(), SUBTYPES.GEOM2D)); |
65 |
} |
66 |
for (int i = 1; i < points.length; i++) { |
67 |
surface.addVertex(geomManager.createPoint(points[i].getX(), points[i].getY(), SUBTYPES.GEOM2D)); |
68 |
} |
69 |
if (points.length > 0) { |
70 |
surface.addVertex(geomManager.createPoint(p.getX(), p.getY(), SUBTYPES.GEOM2D)); |
71 |
surface.addVertex(geomManager.createPoint(points[0].getX(), points[0].getY(), SUBTYPES.GEOM2D)); |
72 |
} |
73 |
|
74 |
setGeometry(surface); |
75 |
} catch (CreateGeometryException e) {
|
76 |
logger.error("Error creating the circle", e);
|
77 |
} |
78 |
} |
79 |
|
80 |
public static void registerPersistent() { |
81 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
82 |
if (manager.getDefinition(PERSISTENCE_DEFINITION_NAME) == null) { |
83 |
DynStruct definition = |
84 |
manager.addDefinition(PolygonAdapter.class, |
85 |
PERSISTENCE_DEFINITION_NAME, |
86 |
"Polygon Adapter persistence definition", null, null); |
87 |
|
88 |
definition.extend(manager |
89 |
.getDefinition(GeometryAdapter.PERSISTENCE_DEFINITION_NAME)); |
90 |
} |
91 |
} |
92 |
} |