svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / project / documents / view / toolListeners / snapping / snappers / FinalPointSnapper.java @ 40558
History | View | Annotate | Download (2.91 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 |
|
28 |
import org.gvsig.fmap.geom.Geometry; |
29 |
import org.gvsig.fmap.geom.handler.Handler; |
30 |
import org.gvsig.fmap.mapcontrol.PrimitivesDrawer; |
31 |
import org.gvsig.fmap.mapcontrol.tools.snapping.snappers.ISnapperVectorial; |
32 |
import org.gvsig.fmap.mapcontrol.tools.snapping.snappers.impl.AbstractSnapper; |
33 |
import org.gvsig.i18n.Messages; |
34 |
|
35 |
|
36 |
public class FinalPointSnapper extends AbstractSnapper implements ISnapperVectorial { |
37 |
public Point2D getSnapPoint(Point2D point, Geometry geom, double tolerance, Point2D lastPointEntered) { |
38 |
Point2D resul = null; |
39 |
Handler[] handlers = geom.getHandlers(Geometry.SELECTHANDLER); |
40 |
// Point2D initPoint=handlers[0].getPoint();
|
41 |
// Point2D endPoint=handlers[handlers.length-1].getPoint();
|
42 |
// if (initPoint.equals(endPoint))
|
43 |
// return resul;
|
44 |
|
45 |
double minDist = tolerance;
|
46 |
// double dist = initPoint.distance(point);
|
47 |
// if (dist < minDist) {
|
48 |
// resul = initPoint;
|
49 |
// minDist = dist;
|
50 |
// }
|
51 |
//
|
52 |
// dist = endPoint.distance(point);
|
53 |
// if (dist < minDist) {
|
54 |
// resul = endPoint;
|
55 |
// }
|
56 |
|
57 |
for (int j = 0; j < handlers.length; j++) { |
58 |
Point2D handlerPoint = handlers[j].getPoint();
|
59 |
double dist = handlerPoint.distance(point);
|
60 |
if ((dist < minDist)) {
|
61 |
resul = handlerPoint; |
62 |
minDist = dist; |
63 |
} |
64 |
} |
65 |
|
66 |
return resul;
|
67 |
} |
68 |
|
69 |
public String getToolTipText() { |
70 |
return Messages.getText("Final_point"); |
71 |
} |
72 |
|
73 |
/*
|
74 |
* (non-Javadoc)
|
75 |
* @see org.gvsig.fmap.mapcontrol.tools.snapping.snappers.ISnapper#draw(org.gvsig.fmap.mapcontrol.PrimitivesDrawer, java.awt.geom.Point2D)
|
76 |
*/
|
77 |
public void draw(PrimitivesDrawer primitivesDrawer, Point2D pPixels) { |
78 |
primitivesDrawer.setColor(getColor()); |
79 |
|
80 |
int half = getSizePixels() / 2; |
81 |
primitivesDrawer.drawRect((int) (pPixels.getX() - half),
|
82 |
(int) (pPixels.getY() - half),
|
83 |
getSizePixels(), getSizePixels()); |
84 |
} |
85 |
} |