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 / QuadrantPointSnapper.java @ 40558
History | View | Annotate | Download (3.46 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.CuadrantHandler; |
30 |
import org.gvsig.fmap.geom.handler.Handler; |
31 |
import org.gvsig.fmap.mapcontrol.PrimitivesDrawer; |
32 |
import org.gvsig.fmap.mapcontrol.tools.snapping.snappers.ISnapperVectorial; |
33 |
import org.gvsig.fmap.mapcontrol.tools.snapping.snappers.impl.AbstractSnapper; |
34 |
import org.gvsig.i18n.Messages; |
35 |
|
36 |
|
37 |
/**
|
38 |
* Quadrant point snapper.
|
39 |
*
|
40 |
* @author Vicente Caballero Navarro
|
41 |
*/
|
42 |
public class QuadrantPointSnapper extends AbstractSnapper |
43 |
implements ISnapperVectorial {
|
44 |
/* (non-Javadoc)
|
45 |
* @see com.iver.cit.gvsig.gui.cad.snapping.ISnapper#getSnapPoint(Point2D point,
|
46 |
* IGeometry geom,double tolerance, Point2D lastPointEntered)
|
47 |
*/
|
48 |
public Point2D getSnapPoint(Point2D point, Geometry geom, |
49 |
double tolerance, Point2D lastPointEntered) { |
50 |
Point2D resul = null; |
51 |
|
52 |
Handler[] handlers = geom.getHandlers(Geometry.SELECTHANDLER); |
53 |
|
54 |
double minDist = tolerance;
|
55 |
|
56 |
for (int j = 0; j < handlers.length; j++) { |
57 |
if (handlers[j] instanceof CuadrantHandler) { |
58 |
Point2D handlerPoint = handlers[j].getPoint();
|
59 |
double dist = handlerPoint.distance(point);
|
60 |
|
61 |
if ((dist < minDist)) {
|
62 |
resul = handlerPoint; |
63 |
minDist = dist; |
64 |
} |
65 |
} |
66 |
} |
67 |
|
68 |
return resul;
|
69 |
} |
70 |
|
71 |
/* (non-Javadoc)
|
72 |
* @see com.iver.cit.gvsig.gui.cad.snapping.ISnapper#getToolTipText()
|
73 |
*/
|
74 |
public String getToolTipText() { |
75 |
return Messages.getText("Quadrant_point"); |
76 |
} |
77 |
|
78 |
/* (non-Javadoc)
|
79 |
* @see com.iver.cit.gvsig.gui.cad.snapping.ISnapper#draw(java.awt.Graphics, java.awt.geom.Point2D)
|
80 |
*/
|
81 |
public void draw(PrimitivesDrawer primitivesDrawer, Point2D pPixels) { |
82 |
primitivesDrawer.setColor(getColor()); |
83 |
|
84 |
int half = getSizePixels() / 2; |
85 |
int x1 = (int) (pPixels.getX() - half); |
86 |
int x2 = (int) (pPixels.getX() + half); |
87 |
int x3 = (int) pPixels.getX(); |
88 |
int y1 = (int) (pPixels.getY() - half); |
89 |
int y2 = (int) (pPixels.getY() + half); |
90 |
int y3 = (int) pPixels.getY(); |
91 |
|
92 |
primitivesDrawer.drawLine(x1, y3, x3, y1); |
93 |
primitivesDrawer.drawLine(x1, y3, x3, y2); |
94 |
primitivesDrawer.drawLine(x2, y3, x3, y1); |
95 |
primitivesDrawer.drawLine(x2, y3, x3, y2); |
96 |
} |
97 |
} |