svn-document-layout / trunk / org.gvsig.app.document.layout.app / org.gvsig.app.document.layout.app.mainplugin / src / main / java / org / gvsig / app / project / documents / layout / geometryadapters / RectangleAdapter.java @ 5
History | View | Annotate | Download (3.41 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 RectangleAdapter extends PolygonAdapter { |
43 |
|
44 |
public static final String PERSISTENCE_DEFINITION_NAME = "RectangleAdapter"; |
45 |
private static final Logger logger = LoggerFactory.getLogger(RectangleAdapter.class); |
46 |
|
47 |
public RectangleAdapter() {
|
48 |
super();
|
49 |
} |
50 |
|
51 |
/**
|
52 |
* DOCUMENT ME!
|
53 |
*
|
54 |
* @param p
|
55 |
* DOCUMENT ME!
|
56 |
*/
|
57 |
public void obtainShape(Point2D p) { |
58 |
Point2D[] points = getPoints(); |
59 |
|
60 |
try {
|
61 |
Surface surface = (Surface)geomManager.create(TYPES.SURFACE, SUBTYPES.GEOM2D); |
62 |
if (points.length > 0) { |
63 |
surface.addMoveToVertex(geomManager.createPoint(points[0].getX(), points[0].getY(), SUBTYPES.GEOM2D)); |
64 |
} |
65 |
if (points.length > 0) { |
66 |
surface.addVertex(geomManager.createPoint(p.getX(), points[0].getY(), SUBTYPES.GEOM2D));
|
67 |
surface.addVertex(geomManager.createPoint(p.getX(), p.getY(), SUBTYPES.GEOM2D)); |
68 |
surface.addVertex(geomManager.createPoint(points[0].getX(), p.getY(), SUBTYPES.GEOM2D));
|
69 |
surface.addVertex(geomManager.createPoint(points[0].getX(), points[0].getY(), SUBTYPES.GEOM2D)); |
70 |
} |
71 |
|
72 |
setGeometry(surface); |
73 |
} catch (CreateGeometryException e) {
|
74 |
logger.error("Error creating the circle", e);
|
75 |
} |
76 |
} |
77 |
|
78 |
public static void registerPersistent() { |
79 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
80 |
if (manager.getDefinition(PERSISTENCE_DEFINITION_NAME) == null) { |
81 |
DynStruct definition = |
82 |
manager.addDefinition(RectangleAdapter.class, |
83 |
PERSISTENCE_DEFINITION_NAME, |
84 |
"Recangle Adapter persistence definition", null, null); |
85 |
|
86 |
definition.extend(manager |
87 |
.getDefinition(GeometryAdapter.PERSISTENCE_DEFINITION_NAME)); |
88 |
} |
89 |
} |
90 |
} |