svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.snapping.app / org.gvsig.snapping.app.mainplugin / src / main / java / org / gvsig / app / project / documents / view / toolListeners / snapping / snappers / CentroidPointSnapper.java @ 47355
History | View | Annotate | Download (2.98 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
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 3
|
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 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.app.project.documents.view.toolListeners.snapping.snappers; |
25 |
|
26 |
import java.awt.geom.Point2D; |
27 |
import org.gvsig.fmap.geom.Geometry; |
28 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
29 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
30 |
import org.gvsig.fmap.geom.primitive.Envelope; |
31 |
import org.gvsig.fmap.geom.primitive.Point; |
32 |
import org.gvsig.fmap.mapcontrol.PrimitivesDrawer; |
33 |
import org.gvsig.fmap.mapcontrol.tools.snapping.snappers.ISnapperVectorial; |
34 |
import org.gvsig.fmap.mapcontrol.tools.snapping.snappers.impl.AbstractSnapper; |
35 |
import org.gvsig.i18n.Messages; |
36 |
import org.slf4j.Logger; |
37 |
import org.slf4j.LoggerFactory; |
38 |
|
39 |
|
40 |
/**
|
41 |
* Central point snapper.
|
42 |
*
|
43 |
* @author Vicente Caballero Navarro
|
44 |
*/
|
45 |
public class CentroidPointSnapper extends AbstractSnapper |
46 |
implements ISnapperVectorial {
|
47 |
|
48 |
private static final Logger LOGGER = LoggerFactory.getLogger(CentroidPointSnapper.class); |
49 |
|
50 |
@Override
|
51 |
public Point2D getSnapPoint(Point2D point, Geometry geom, |
52 |
double tolerance, Point2D lastPointEntered) { |
53 |
Point2D resul = null; |
54 |
|
55 |
Point centroid;
|
56 |
try {
|
57 |
centroid = geom.centroid(); |
58 |
Point2D.Double pointCentroid = new Point2D.Double(centroid.getX(),centroid.getY()); |
59 |
|
60 |
double dist = pointCentroid.distance(point);
|
61 |
|
62 |
if ((dist < tolerance)) {
|
63 |
resul = pointCentroid; |
64 |
} |
65 |
} catch (Exception ex) { |
66 |
LOGGER.warn("Can't get centroid.", ex);
|
67 |
} |
68 |
|
69 |
return resul;
|
70 |
} |
71 |
|
72 |
@Override
|
73 |
public String getToolTipText() { |
74 |
return Messages.getText("_Centroid_point"); |
75 |
} |
76 |
|
77 |
@Override
|
78 |
public void draw(PrimitivesDrawer primitivesDrawer, Point2D pPixels) { |
79 |
primitivesDrawer.setColor(getColor()); |
80 |
|
81 |
int half = getSizePixels() / 2; |
82 |
primitivesDrawer.drawOval((int) (pPixels.getX() - half),
|
83 |
(int) (pPixels.getY() - half), getSizePixels(), getSizePixels());
|
84 |
} |
85 |
} |