Statistics
| Revision:

root / tags / v2_0_0_Build_2047 / applications / appgvSIG / appgvSIG / src / org / gvsig / app / project / documents / view / toolListeners / snapping / snappers / CentralPointSnapper.java @ 38317

History | View | Annotate | Download (2.19 KB)

1 29598 jpiera
package org.gvsig.app.project.documents.view.toolListeners.snapping.snappers;
2 23642 vcaballero
3
import java.awt.geom.Point2D;
4
5
import org.gvsig.fmap.geom.Geometry;
6
import org.gvsig.fmap.geom.handler.CenterHandler;
7
import org.gvsig.fmap.geom.handler.Handler;
8 30349 jpiera
import org.gvsig.fmap.mapcontrol.PrimitivesDrawer;
9 23642 vcaballero
import org.gvsig.fmap.mapcontrol.tools.snapping.snappers.ISnapperVectorial;
10 30349 jpiera
import org.gvsig.fmap.mapcontrol.tools.snapping.snappers.impl.AbstractSnapper;
11 38226 jldominguez
import org.gvsig.i18n.Messages;
12 23642 vcaballero
13
14
/**
15
 * Central point snapper.
16
 *
17
 * @author Vicente Caballero Navarro
18
 */
19
public class CentralPointSnapper extends AbstractSnapper
20
    implements ISnapperVectorial {
21
        /* (non-Javadoc)
22
     * @see com.iver.cit.gvsig.gui.cad.snapping.ISnapper#getSnapPoint(Point2D point,
23
     * IGeometry geom,double tolerance, Point2D lastPointEntered)
24
     */
25
        public Point2D getSnapPoint(Point2D point, Geometry geom,
26
        double tolerance, Point2D lastPointEntered) {
27
        Point2D resul = null;
28
29
        Handler[] handlers = geom.getHandlers(Geometry.SELECTHANDLER);
30
31
        double minDist = tolerance;
32
33
        for (int j = 0; j < handlers.length; j++) {
34
            if (handlers[j] instanceof CenterHandler) {
35
                Point2D handlerPoint = handlers[j].getPoint();
36
                double dist = handlerPoint.distance(point);
37
38
                if ((dist < minDist)) {
39
                    resul = handlerPoint;
40
                    minDist = dist;
41
                }
42
            }
43
        }
44
45
        return resul;
46
    }
47
        /* (non-Javadoc)
48
     * @see com.iver.cit.gvsig.gui.cad.snapping.ISnapper#getToolTipText()
49
     */
50
    public String getToolTipText() {
51 38226 jldominguez
        return Messages.getText("Central_point");
52 23642 vcaballero
    }
53
54 30349 jpiera
    /*
55
     * (non-Javadoc)
56
     * @see org.gvsig.fmap.mapcontrol.tools.snapping.snappers.ISnapper#draw(org.gvsig.fmap.mapcontrol.PrimitivesDrawer, java.awt.geom.Point2D)
57 23642 vcaballero
     */
58 30349 jpiera
    public void draw(PrimitivesDrawer primitivesDrawer, Point2D pPixels) {
59
            primitivesDrawer.setColor(getColor());
60 23642 vcaballero
61
        int half = getSizePixels() / 2;
62 30349 jpiera
        primitivesDrawer.drawOval((int) (pPixels.getX() - half),
63 23642 vcaballero
            (int) (pPixels.getY() - half), getSizePixels(), getSizePixels());
64
    }
65
}