Example usage for java.awt Polygon translate

List of usage examples for java.awt Polygon translate

Introduction

In this page you can find the example usage for java.awt Polygon translate.

Prototype

public void translate(int deltaX, int deltaY) 

Source Link

Document

Translates the vertices of the Polygon by deltaX along the x axis and by deltaY along the y axis.

Usage

From source file:oct.analysis.application.OCTSelection.java

protected void drawSelectButton(Graphics g, int imageOffsetX, int imageOffsetY) {
    Polygon buttonOutline = getSelectionButtonShape();
    buttonOutline.translate(imageOffsetX, imageOffsetY);
    g.setColor(Color.lightGray);//from   w w  w  .  ja  va2  s  .c o  m
    g.drawPolygon(buttonOutline);
    g.fillPolygon(buttonOutline);
    Polygon button = new Polygon();
    button.addPoint(imageOffsetX + xPositionOnOct - 5, imageOffsetY);
    button.addPoint(imageOffsetX + xPositionOnOct - 5, imageOffsetY + 15);
    button.addPoint(imageOffsetX + xPositionOnOct, imageOffsetY + 20);
    button.addPoint(imageOffsetX + xPositionOnOct + 5, imageOffsetY + 15);
    button.addPoint(imageOffsetX + xPositionOnOct + 5, imageOffsetY);
    g.setColor(Color.DARK_GRAY);
    g.drawPolygon(button);
}

From source file:de.fhg.igd.mapviewer.waypoints.CustomWaypointPainter.java

/**
 * Find the way-points in a given polygon
 * // www.  j a  v a 2  s . c  o  m
 * @param poly the polygon
 * @return the way-points in the polygon area
 */
public Set<W> findWaypoints(final Polygon poly) {
    Rectangle viewPort = getMapKit().getMainMap().getViewportBounds();

    final int zoom = getMapKit().getMainMap().getZoom();
    final PixelConverter converter = getMapKit().getMainMap().getTileFactory().getTileProvider().getConverter();

    de.fhg.igd.geom.Point2D[] points = new de.fhg.igd.geom.Point2D[poly.npoints];

    // create a metamodel polygon
    for (int i = 0; i < poly.npoints; i++) {
        int worldX = viewPort.x + poly.xpoints[i];
        int worldY = viewPort.y + poly.ypoints[i];

        // convert to geo position
        GeoPosition pos = converter.pixelToGeo(new Point(worldX, worldY), zoom);

        // convert to common CRS
        try {
            pos = GeotoolsConverter.getInstance().convert(pos, SelectableWaypoint.COMMON_EPSG);
        } catch (IllegalGeoPositionException e) {
            log.warn("Error converting polygon point for query"); //$NON-NLS-1$
            return new HashSet<W>();
        }

        points[i] = new de.fhg.igd.geom.Point2D(pos.getX(), pos.getY());
    }

    final de.fhg.igd.geom.shape.Polygon verifyPolygon = new de.fhg.igd.geom.shape.Polygon(points);

    // we need a 3D search bounding box for the R-Tree
    BoundingBox searchBox = verifyPolygon.getBoundingBox();
    searchBox.setMinZ(-2.0);
    searchBox.setMaxZ(2.0);

    poly.translate(viewPort.x, viewPort.y);
    try {
        Set<W> wps = waypoints.query(searchBox, new Verifier<W, BoundingBox>() {

            @Override
            public boolean verify(W wp, BoundingBox second) {
                try {
                    Point2D wpPixel = converter.geoToPixel(wp.getPosition(), zoom);
                    int dx = (int) wpPixel.getX();
                    int dy = (int) wpPixel.getY();

                    poly.translate(-dx, -dy);
                    try {
                        Area area = wp.getMarker().getArea(zoom);
                        if (area != null) {
                            return area.containedIn(poly);
                        } else {
                            // something that has not been painted yet may
                            // not be selected
                            return false;
                        }
                    } finally {
                        poly.translate(dx, dy);
                    }
                } catch (IllegalGeoPositionException e) {
                    log.warn("Could not convert waypoint position to pixel", e);
                    // fall back to simple method
                    return verifyPolygon.contains(wp.getBoundingBox().toExtent());
                }
            }

        });

        if (wps == null) {
            return new HashSet<W>();
        } else {
            return wps;
        }
    } finally {
        poly.translate(-viewPort.x, -viewPort.y);
    }
}