Example usage for java.awt.geom Point2D getX

List of usage examples for java.awt.geom Point2D getX

Introduction

In this page you can find the example usage for java.awt.geom Point2D getX.

Prototype

public abstract double getX();

Source Link

Document

Returns the X coordinate of this Point2D in double precision.

Usage

From source file:org.eurocarbdb.application.glycoworkbench.plugin.PeakAnnotationCalibrationPanel.java

public Point2D screenToDataCoords(Point2D p) {

    Rectangle2D data_area = theChartPanel.getScreenDataArea();
    double x = thePlot.getDomainAxis().java2DToValue(p.getX(), data_area, thePlot.getDomainAxisEdge());
    double y = thePlot.getRangeAxis().java2DToValue(p.getY(), data_area, thePlot.getRangeAxisEdge());
    return new Point2D.Double(x, y);
}

From source file:util.ModSpringLayout1.java

protected void moveNodes() {

    synchronized (getSize()) {
        try {/*from   w  w w . j av  a 2 s .  c o  m*/
            for (V v : getGraph().getVertices()) {
                if (isLocked(v)) {
                    continue;
                }
                SpringVertexData vd = getSpringVertexData(v);
                if (vd == null) {
                    continue;
                }
                Point2D xyd = transform(v);

                vd.dx += vd.repulsiondx + vd.edgedx;
                vd.dy += vd.repulsiondy + vd.edgedy;

                // keeps nodes from moving any faster than 5 per time unit
                xyd.setLocation(xyd.getX() + Math.max(-5, Math.min(5, vd.dx)),
                        xyd.getY() + Math.max(-5, Math.min(5, vd.dy)));

                Dimension d = getSize();
                int width = d.width;
                int height = d.height;

                if (xyd.getX() < 0) {
                    xyd.setLocation(0, xyd.getY());//                     setX(0);
                } else if (xyd.getX() > width) {
                    xyd.setLocation(width, xyd.getY()); //setX(width);
                }
                if (xyd.getY() < 0) {
                    xyd.setLocation(xyd.getX(), 0);//setY(0);
                } else if (xyd.getY() > height) {
                    xyd.setLocation(xyd.getX(), height); //setY(height);
                }

            }
        } catch (ConcurrentModificationException cme) {
            moveNodes();
        }
    }
}

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

/**
 * Find the way-points in a given polygon
 * /*from  ww  w  .j  a  va  2s. 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);
    }
}

From source file:org.esa.snap.graphbuilder.gpf.ui.worldmap.NestWorldMapPane.java

private PixelPos getProductCenter(final Product product) {
    final GeoCoding geoCoding = product.getSceneGeoCoding();
    PixelPos centerPos = null;//from w  w w.  ja v a  2s.c o m
    if (geoCoding != null) {
        final float pixelX = (float) Math.floor(0.5f * product.getSceneRasterWidth()) + 0.5f;
        final float pixelY = (float) Math.floor(0.5f * product.getSceneRasterHeight()) + 0.5f;
        final GeoPos geoPos = geoCoding.getGeoPos(new PixelPos(pixelX, pixelY), null);
        final AffineTransform transform = layerCanvas.getViewport().getModelToViewTransform();
        final Point2D point2D = transform.transform(new Point2D.Double(geoPos.getLon(), geoPos.getLat()), null);
        centerPos = new PixelPos((float) point2D.getX(), (float) point2D.getY());
    }
    return centerPos;
}

From source file:org.geopublishing.atlasViewer.swing.ClickInfoDialog.java

/**
 * Update with info-dialog with the new {@link ObjectSelectionEvent}
 *///from   ww w .  j  a  va  2 s .  c  o  m
public void setSelectionEvent(final ObjectSelectionEvent<?> objectSelectionEvent) {

    clickInfoPanel.setSelectionEvent(objectSelectionEvent);

    XMapPane source = objectSelectionEvent.getSource();

    // Set the title of the dialog to the translated title the layer
    try {
        String title = objectSelectionEvent.getSourceLayer().getTitle();
        if (atlasConfig != null) {
            setTitle(atlasConfig.getDataPool().get(title).getTitle().toString());
        } else {
            title = StringUtils.right(title, 25);
            setTitle(title);
        }
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
    }

    XMapPane mapPane = objectSelectionEvent.getSource();
    // If it is a feature, let it blink for a moment
    if (source instanceof XMapPane && objectSelectionEvent instanceof FeatureSelectedEvent) {

        mapPane.blink(((FeatureSelectedEvent) objectSelectionEvent).getSelectionResult());
    } else {
        // Create a fake Feature and let it blink a moment
        final GridCoverageValueSelectedEvent gridSelection = (GridCoverageValueSelectedEvent) objectSelectionEvent;

        // TODO Help Martin, warum kann ich kein feake Feature mit correctem
        // CRS erstellen?
        Point2D selectionPoint = gridSelection.getSelectionPoint();

        CoordinateReferenceSystem crs = mapPane.getMapContext().getCoordinateReferenceSystem();

        SimpleFeatureType fakeFeatureType = FeatureUtil.createFeatureType(Point.class, crs);

        SimpleFeature fakeFeature = FeatureUtil.createFeatureInstance(fakeFeatureType, true,
                "fake raster selection",
                new DirectPosition2D(crs, selectionPoint.getX(), selectionPoint.getY()));

        System.out.println("crs = " + fakeFeature.getFeatureType().getCoordinateReferenceSystem());

        mapPane.blink(fakeFeature);
    }
}

From source file:org.jax.bham.test.HaplotypeAssociationTestGraphPanel.java

/**
 * Gets the index of the interval with the highest value that falls
 * under the given Java2D coordinates//  w  w w.  jav a2s.  c  o m
 * @param x
 *          the Java2D X coordinate
 * @param y
 *          the Java2D Y coordinate
 * @return
 *          the interval index
 */
private int getMaximalIntervalIndex(int x, int y) {
    int clickIndex = -1;

    int[] chromosomes = this.getSelectedChromosomes();

    if (chromosomes.length == 1) {
        RealValuedBasePairInterval[] selectedValuesList = this.chromosomeToNegLogValueMap.get(chromosomes[0]);

        if (selectedValuesList != null) {
            Point2D clickedGraphPoint = JFreeChartUtil.java2DPointToGraphPoint(new Point(x, y),
                    this.chartPanel);

            // exhaustive search for the maximum clicked index (this could
            // be a binary search, but this seems to perform OK for now)
            double graphX = clickedGraphPoint.getX();
            int valueCount = selectedValuesList.length;
            double biggestClickedValue = Double.NEGATIVE_INFINITY;
            for (int i = 0; i < valueCount; i++) {
                RealValuedBasePairInterval currValue = selectedValuesList[i];
                if (currValue.getStartInBasePairs() < graphX && currValue.getEndInBasePairs() > graphX
                        && currValue.getRealValue() > biggestClickedValue) {
                    biggestClickedValue = currValue.getRealValue();
                    clickIndex = i;
                }
            }

            // if we didn't click on anything grab the nearest item
            // (again this could and should be faster)
            if (clickIndex == -1 && valueCount >= 1) {
                clickIndex = 0;
                double nearestDistance = Math.min(
                        Math.abs(selectedValuesList[0].getStartInBasePairs() - graphX),
                        Math.abs(selectedValuesList[0].getEndInBasePairs() - graphX));
                for (int i = 1; i < valueCount; i++) {
                    BasePairInterval currValue = selectedValuesList[i];
                    double currDistance = Math.min(Math.abs(currValue.getStartInBasePairs() - graphX),
                            Math.abs(currValue.getEndInBasePairs() - graphX));
                    if (currDistance < nearestDistance) {
                        nearestDistance = currDistance;
                        clickIndex = i;
                    }
                }
            }
        }
    }

    return clickIndex;
}

From source file:com.net2plan.gui.utils.topologyPane.jung.JUNGCanvas.java

/**
 * Converts a point from the SWING coordinates system into a point from the JUNG coordinates system.
 *
 * @param jungLayoutCoord (@code Point2D) on the SWING canvas.
 * @return (@code Point2D) on the JUNG canvas.
 *//*from   w  w w . j  a v  a2s  .c  om*/
@Override
public Point2D getCanvasPointFromNetPlanPoint(Point2D npCoord) {
    Point2D layoutOrViewCoordinates = vv.getRenderContext().getMultiLayerTransformer()
            .inverseTransform(Layer.LAYOUT, npCoord);
    layoutOrViewCoordinates.setLocation(layoutOrViewCoordinates.getX(), -layoutOrViewCoordinates.getY());

    return layoutOrViewCoordinates;
}

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

/**
 * Find a way-point at a given position//from w  w  w  .jav a2 s.  c  o m
 * 
 * @param point the position
 * @return the way-point
 */
public W findWaypoint(Point point) {
    Rectangle viewPort = getMapKit().getMainMap().getViewportBounds();

    final int overlap = getMaxOverlap(); // the overlap is the reason why
    // the point is used instead of
    // a GeoPosition

    final int x = viewPort.x + point.x;
    final int y = viewPort.y + point.y;
    final int zoom = getMapKit().getMainMap().getZoom();
    final PixelConverter converter = getMapKit().getMainMap().getTileFactory().getTileProvider().getConverter();

    final Dimension mapSize = TileProviderUtils
            .getMapSize(getMapKit().getMainMap().getTileFactory().getTileProvider(), zoom);
    final int width = mapSize.width
            * getMapKit().getMainMap().getTileFactory().getTileProvider().getTileWidth(zoom);
    final int height = mapSize.height
            * getMapKit().getMainMap().getTileFactory().getTileProvider().getTileHeight(zoom);

    final GeoPosition topLeft = converter
            .pixelToGeo(new Point(Math.max(x - overlap, 0), Math.max(y - overlap, 0)), zoom);
    final GeoPosition bottomRight = converter
            .pixelToGeo(new Point(Math.min(x + overlap, width), Math.min(y + overlap, height)), zoom);

    BoundingBox searchBox;
    try {
        searchBox = createSearchBB(topLeft, bottomRight);

        Set<W> wps = waypoints.query(searchBox, new Verifier<W, BoundingBox>() {

            @Override
            public boolean verify(W wp, BoundingBox box) {
                try {
                    Point2D wpPixel = converter.geoToPixel(wp.getPosition(), zoom);

                    int relX = x - (int) wpPixel.getX();
                    int relY = y - (int) wpPixel.getY();

                    Area area = wp.getMarker().getArea(zoom);
                    if (area != null && area.contains(relX, relY)) {
                        // match
                        return true;
                    }
                } catch (IllegalGeoPositionException e) {
                    log.debug("Error converting waypoint position", e); //$NON-NLS-1$
                }

                return false;
            }
        });

        if (wps == null || wps.isEmpty()) {
            return null;
        } else {
            if (wps.size() == 1) {
                return wps.iterator().next();
            } else {
                List<W> sorted = new ArrayList<W>(wps);
                Collections.sort(sorted, new Comparator<W>() {

                    @Override
                    public int compare(W o1, W o2) {
                        double a1 = o1.getMarker().getArea(zoom).getArea();
                        double a2 = o2.getMarker().getArea(zoom).getArea();

                        // compare size
                        if (a1 < a2) {
                            return -1;
                        } else if (a2 < a1) {
                            return 1;
                        } else {
                            return 0;
                        }
                    }

                });
                return sorted.get(0);
            }
        }
    } catch (IllegalGeoPositionException e) {
        return null;
    }
}

From source file:org.jax.bham.test.PhylogenyAssociationTestGraphPanel.java

/**
 * Gets the index of the interval with the highest value that falls
 * under the given Java2D coordinates/*  ww w .jav  a  2s .c o m*/
 * @param x
 *          the Java2D X coordinate
 * @param y
 *          the Java2D Y coordinate
 * @return
 *          the interval index
 */
private int getMaximalIntervalIndex(int x, int y) {
    int clickIndex = -1;

    int[] chromosomes = this.getSelectedChromosomes();

    if (chromosomes.length == 1) {
        List<PhylogenyTestResult> selectedPhyloAssociationTests = this.chromosomeResultsCache
                .get(chromosomes[0]);

        if (selectedPhyloAssociationTests != null) {
            RealValuedBasePairInterval[] selectedValuesList = selectedPhyloAssociationTests
                    .toArray(new RealValuedBasePairInterval[selectedPhyloAssociationTests.size()]);

            Point2D clickedGraphPoint = JFreeChartUtil.java2DPointToGraphPoint(new Point(x, y),
                    this.chartPanel);

            // exhaustive search for the maximum clicked index (this could
            // be a binary search, but this seems to perform OK for now)
            double graphX = clickedGraphPoint.getX();
            int valueCount = selectedValuesList.length;
            double biggestClickedValue = Double.NEGATIVE_INFINITY;
            for (int i = 0; i < valueCount; i++) {
                RealValuedBasePairInterval currValue = selectedValuesList[i];
                if (currValue.getStartInBasePairs() < graphX && currValue.getEndInBasePairs() > graphX
                        && currValue.getRealValue() > biggestClickedValue) {
                    biggestClickedValue = currValue.getRealValue();
                    clickIndex = i;
                }
            }

            // if we didn't click on anything grab the nearest item
            // (again this could and should be faster)
            if (clickIndex == -1 && valueCount >= 1) {
                clickIndex = 0;
                double nearestDistance = Math.min(
                        Math.abs(selectedValuesList[0].getStartInBasePairs() - graphX),
                        Math.abs(selectedValuesList[0].getEndInBasePairs() - graphX));
                for (int i = 1; i < valueCount; i++) {
                    BasePairInterval currValue = selectedValuesList[i];
                    double currDistance = Math.min(Math.abs(currValue.getStartInBasePairs() - graphX),
                            Math.abs(currValue.getEndInBasePairs() - graphX));
                    if (currDistance < nearestDistance) {
                        nearestDistance = currDistance;
                        clickIndex = i;
                    }
                }
            }
        }
    }

    return clickIndex;
}

From source file:org.apache.fontbox.cff.CharStringRenderer.java

private void rmoveTo(Number dx, Number dy) {
    Point2D point = referencePoint;
    if (point == null) {
        point = path.getCurrentPoint();/*from   www  .j  ava  2 s .  com*/
        if (point == null) {
            point = sidebearingPoint;
        }
    }
    referencePoint = null;
    path.moveTo((float) (point.getX() + dx.doubleValue()), (float) (point.getY() + dy.doubleValue()));
}