Example usage for java.awt.geom Point2D getY

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

Introduction

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

Prototype

public abstract double getY();

Source Link

Document

Returns the Y coordinate of this Point2D in double precision.

Usage

From source file:org.apache.fop.render.rtf.RTFHandler.java

/** {@inheritDoc} */
public void endInstreamForeignObject(InstreamForeignObject ifo) {
    if (bDefer) {
        return;/* w w  w .  j  a v  a  2  s.  co  m*/
    }

    try {
        XMLObj child = ifo.getChildXMLObj();
        Document doc = child.getDOMDocument();
        String ns = child.getNamespaceURI();

        ImageInfo info = new ImageInfo(null, null);
        // Set the resolution to that of the FOUserAgent
        FOUserAgent ua = ifo.getUserAgent();
        ImageSize size = new ImageSize();
        size.setResolution(ua.getSourceResolution());

        // Set the image size to the size of the svg.
        Point2D csize = new Point2D.Float(-1, -1);
        Point2D intrinsicDimensions = child.getDimension(csize);
        if (intrinsicDimensions == null) {
            ResourceEventProducer eventProducer = ResourceEventProducer.Provider
                    .get(getUserAgent().getEventBroadcaster());
            eventProducer.ifoNoIntrinsicSize(this, child.getLocator());
            return;
        }
        size.setSizeInMillipoints((int) Math.round(intrinsicDimensions.getX() * 1000),
                (int) Math.round(intrinsicDimensions.getY() * 1000));
        size.calcPixelsFromSize();
        info.setSize(size);

        ImageXMLDOM image = new ImageXMLDOM(info, doc, ns);

        FOUserAgent userAgent = ifo.getUserAgent();
        ImageManager manager = userAgent.getFactory().getImageManager();
        Map hints = ImageUtil.getDefaultHints(ua.getImageSessionContext());
        Image converted = manager.convertImage(image, FLAVORS, hints);
        putGraphic(ifo, converted);

    } catch (ImageException ie) {
        ResourceEventProducer eventProducer = ResourceEventProducer.Provider
                .get(getUserAgent().getEventBroadcaster());
        eventProducer.imageError(this, null, ie, null);
    } catch (IOException ioe) {
        ResourceEventProducer eventProducer = ResourceEventProducer.Provider
                .get(getUserAgent().getEventBroadcaster());
        eventProducer.imageIOError(this, null, ioe, null);
    }
}

From source file:org.gumtree.vis.awt.JChartPanel.java

protected Point2D translateScreenToChart(Point2D point) {
    EntityCollection entities = getChartRenderingInfo().getEntityCollection();
    ChartEntity entity = entities.getEntity(point.getX(), point.getY());
    if (entity instanceof XYItemEntity) {
        XYDataset dataset = ((XYItemEntity) entity).getDataset();
        int item = ((XYItemEntity) entity).getItem();
        double chartX = dataset.getXValue(0, item);
        double chartY = dataset.getYValue(0, item);
        //           double chartZ = ((XYZDataset) dataset).getZValue(0, item);
        return new Point2D.Double(chartX, chartY);
    }//from w  w  w. j ava 2s  .  c o  m
    return null;
}

From source file:com.net2plan.libraries.GraphUtils.java

/** Computes the Haversine distance between two points, that is, the shortest distance over the Earth's surface.
 * /*from  ww  w .  j a v a 2 s.  c  om*/
 * <p><b>Important</b>: It is assumed an Earth's radius equal to {@link com.net2plan.utils.Constants#EARTH_RADIUS_IN_KM Constants.EARTH_RADIUS_IN_KM }</p>
 * 
 * <p><b>Important</b>: Coordinates are assumed to be given in degress, conversions to radians are made internally.</p>
 * 
 * @param point1 Point 1 (x-coord is equal to longitude, y-coord is equal to latitude)
 * @param point2 Point 2 (x-coord is equal to longitude, y-coord is equal to latitude)
 * @return Haversine distance between two points
 * @see <a href="http://www.movable-type.co.uk/scripts/latlong.html">Calculate distance, bearing and more between Latitude/Longitude points</a> */
public static double computeHaversineDistanceInKm(Point2D point1, Point2D point2) {
    double lon1 = point1.getX();
    double lat1 = point1.getY();
    double lon2 = point2.getX();
    double lat2 = point2.getY();

    double dLat = Math.toRadians(lat2 - lat1);
    double dLon = Math.toRadians(lon2 - lon1);
    double sindLat = Math.sin(dLat / 2);
    double sindLon = Math.sin(dLon / 2);
    double a = Math.pow(sindLat, 2)
            + Math.pow(sindLon, 2) * Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2));
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    return Constants.EARTH_RADIUS_IN_KM * c;
}

From source file:org.gumtree.vis.plot1d.Plot1DPanel.java

private int followDomainTrace(int seriesIndex, int domainLocation) {
    if (seriesIndex >= getDataset().getSeriesCount()) {
        return -1;
    }// w  w  w  . j a va 2  s . c  om
    double xInChart = ChartMaskingUtilities.translateScreenX(domainLocation, getScreenDataArea(), getChart());
    XYDataset dataset = getChart().getXYPlot().getDataset();
    IXYErrorDataset patternDataset = (IXYErrorDataset) dataset;
    int itemIndex = patternDataset.getItemFromX(seriesIndex, xInChart);
    if (itemIndex >= 0 && itemIndex < patternDataset.getItemCount(seriesIndex)) {
        double chartX = patternDataset.getXValue(seriesIndex, itemIndex);
        double chartY = patternDataset.getYValue(seriesIndex, itemIndex);
        Point2D axisTrace = ChartMaskingUtilities.translateChartPoint(new Point2D.Double(chartX, chartY),
                getScreenDataArea(), getChart());
        setChartX(chartX);
        setChartY(chartY);
        setSeriesIndex(seriesIndex);
        setItemIndex(itemIndex);
        if (dataset instanceof IXYErrorDataset) {
            setChartError(((IXYErrorDataset) dataset).getYError(seriesIndex, itemIndex));

        }
        setHorizontalTraceLocation((int) axisTrace.getX());
        setVerticalTraceLocation((int) axisTrace.getY());
        if (getHorizontalAxisTrace() || getVerticalAxisTrace() || isToolTipFollowerEnabled()) {
            repaint();
        }
        return seriesIndex;
    }
    return -1;
}

From source file:org.gumtree.vis.awt.JChartPanel.java

private void moveSelectedText(MouseEvent e) {
    Point2D screenPoint = translateScreenToJava2D(e.getPoint());
    Rectangle2D screenArea = getScreenDataArea();
    if (screenArea.contains(screenPoint)) {

        if (textMovePoint != null) {
            //               Point2D point = translateScreenToChart(translateScreenToJava2D(e.getPoint()));
            double screenX = ChartMaskingUtilities.translateScreenX(e.getX() / getScaleX(), getScreenDataArea(),
                    getChart());/*w  ww  .j a v a2  s . c  o  m*/
            double screenY = ChartMaskingUtilities.translateScreenY(e.getY(), getScreenDataArea(), getChart(),
                    0);
            //               Point2D point = translateScreenToChart(translateScreenToJava2D(e.getPoint()));
            Point2D point = new Point2D.Double(screenX, screenY);
            selectedTextWrapper.setRect(selectedTextWrapper.getMinX() + point.getX() - textMovePoint.getX(),
                    selectedTextWrapper.getMinY() + point.getY() - textMovePoint.getY(),
                    selectedTextWrapper.getWidth(), selectedTextWrapper.getHeight());
            if (point != null) {
                this.textMovePoint = point;
            }
            repaint();
        }
    }
}

From source file:org.gumtree.vis.awt.JChartPanel.java

private void selectText(double xNew, double yNew) {
    for (Entry<Rectangle2D, String> item : textContentMap.entrySet()) {
        Rectangle2D rect = item.getKey();
        Point2D screenPoint = ChartMaskingUtilities.translateChartPoint(
                new Point2D.Double(rect.getMinX(), rect.getMinY()), getScreenDataArea(), getChart());
        Rectangle2D screenRect = new Rectangle2D.Double(screenPoint.getX(), screenPoint.getY() - 15,
                rect.getWidth(), rect.getHeight());
        if (screenRect.contains(xNew, yNew)) {
            if (selectedTextWrapper == rect) {
                selectedTextWrapper = null;
            } else {
                selectedTextWrapper = rect;
                setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
                return;
            }//from  w  ww .  j a  v a2s .  c o m
        }
    }
    if (selectedTextWrapper != null) {
        selectedTextWrapper = null;
    }
}

From source file:edu.purdue.cc.bionet.ui.GraphVisualizer.java

/**
 * Scales to the given zoom level, 1.0 being 100%, centered on the 
 * given point.//from   w  ww . ja  v a 2  s  .  c o  m
 * 
 * @param level The level to zoom to.
 * @param center The center point for the scaling operation.
 * @return The new zoom level.
 */
public float scaleTo(float level, Point2D center) {
    if (this.scrollPane == null)
        return 1.0f;
    float oldZoom = this.currentZoom;
    this.currentZoom = Math.max(minimumZoom, level);
    //      this.absoluteViewScaler.scale( this, level, center );
    Dimension viewSize;
    if (level < 1.0f) {
        viewSize = this.scrollPane.getSize();
    } else {
        viewSize = this.scrollPane.getViewport().getExtentSize();
    }
    Dimension newSize = new Dimension((int) (viewSize.width * currentZoom),
            (int) (viewSize.height * currentZoom));
    this.setPreferredSize(newSize);
    this.setSize(newSize);
    //      new LayoutScaler( this.getGraphLayout( )).setSize( newSize );
    if (Float.compare(level, 1.0f) <= 0)
        this.center();

    // translate the new view position so the mouse is in the same place
    // on the scaled view.
    JViewport vp = this.scrollPane.getViewport();
    double centerX = center.getX();
    double centerY = center.getY();
    double viewPortMouseX = centerX - vp.getViewPosition().getX();
    double viewPortMouseY = centerY - vp.getViewPosition().getY();
    centerX *= currentZoom / oldZoom;
    centerY *= currentZoom / oldZoom;
    viewPortMouseX = centerX - viewPortMouseX;
    viewPortMouseY = centerY - viewPortMouseY;
    vp.setViewPosition(new Point((int) viewPortMouseX, (int) viewPortMouseY));

    return this.currentZoom;
}

From source file:edu.pitt.dbmi.odie.ui.jfreechart.EnhancedChartComposite.java

public void mouseMove(MouseEvent event) {

    // handle axis trace
    if (this.horizontalAxisTrace || this.verticalAxisTrace) {
        this.horizontalTraceLineY = event.y;
        this.verticalTraceLineX = event.x;
        this.canvas.redraw();
    }/*from www  .j  a  v a2s.c om*/

    // handle tool tips in a simple way
    if (this.displayToolTips) {
        String s = getToolTipText(event);
        if (s == null && this.canvas.getToolTipText() != null
                || s != null && !s.equals(this.canvas.getToolTipText()))
            this.canvas.setToolTipText(s);
    }

    // new entity code
    Point2D javaPoint = translateScreenToJava2D(new Point(event.x, event.y));
    ChartEntity entity = getEntityForLocation(javaPoint.getX(), javaPoint.getY());

    // handle zoom box

    if (this.zoomPoint != null) {
        boolean hZoom, vZoom;
        Rectangle scaledDataArea = getScreenDataArea(this.zoomPoint.x, this.zoomPoint.y);
        org.eclipse.swt.graphics.Point movingPoint = getPointInRectangle(event.x, event.y, scaledDataArea);
        if (this.orientation == PlotOrientation.HORIZONTAL) {
            hZoom = this.rangeZoomable;
            vZoom = this.domainZoomable;
        } else {
            hZoom = this.domainZoomable;
            vZoom = this.rangeZoomable;
        }
        if (hZoom && vZoom) {
            // selected rectangle shouldn't extend outside the data area...
            this.zoomRectangle = new Rectangle(this.zoomPoint.x, this.zoomPoint.y,
                    movingPoint.x - this.zoomPoint.x, movingPoint.y - this.zoomPoint.y);
        } else if (hZoom) {
            this.zoomRectangle = new Rectangle(this.zoomPoint.x, scaledDataArea.y,
                    movingPoint.x - this.zoomPoint.x, scaledDataArea.height);
        } else if (vZoom) {
            int ymax = Math.max(movingPoint.y, scaledDataArea.y);
            this.zoomRectangle = new Rectangle(scaledDataArea.x, this.zoomPoint.y, scaledDataArea.width,
                    ymax - this.zoomPoint.y);
        }
        this.canvas.redraw();
    } else if (this.selectionPoint != null) {
        Rectangle scaledDataArea = getScreenDataArea(this.selectionPoint.x, this.selectionPoint.y);

        org.eclipse.swt.graphics.Point movingPoint = getPointInRectangle(event.x, event.y, scaledDataArea);

        if (this.orientation == PlotOrientation.VERTICAL) {
            Point2D selectionPointJava = translateScreenToJava2D(
                    new Point(this.selectionPoint.x, scaledDataArea.y));
            this.selectionRectangle = new Rectangle((int) selectionPointJava.getX(),
                    (int) selectionPointJava.getY(), (int) ((movingPoint.x - this.selectionPoint.x) / scaleX),
                    (int) (scaledDataArea.height / scaleY));
        } else {
            int ymax = Math.max(movingPoint.y, scaledDataArea.y);

            Point2D selectionPointJava = translateScreenToJava2D(
                    new Point(scaledDataArea.x, this.selectionPoint.y));
            this.selectionRectangle = new Rectangle((int) selectionPointJava.getX(),
                    (int) selectionPointJava.getY(), (int) (scaledDataArea.width / scaleX),
                    (int) ((ymax - this.selectionPoint.y) / scaleY));
        }

        this.canvas.redraw();
    }

    Object[] listeners = this.chartMouseListeners.getListeners(ChartMouseListener.class);
    if (listeners.length == 0) {
        return;
    }

    // pass mouse move event if some ChartMouseListener are listening
    java.awt.event.MouseEvent mouseEvent = SWTUtils.toAwtMouseEvent(event);
    ChartMouseEvent chartEvent = new ChartMouseEvent(getChart(), mouseEvent, entity);
    for (int i = listeners.length - 1; i >= 0; i -= 1) {
        ((ChartMouseListener) listeners[i]).chartMouseMoved(chartEvent);
    }
}

From source file:org.gumtree.vis.awt.JChartPanel.java

@Override
public void mousePressed(MouseEvent e) {
    if (selectedTextWrapper != null && getCursor() == Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)) {
        Point2D screenXY = ChartMaskingUtilities.translateChartPoint(
                new Point2D.Double(selectedTextWrapper.getMinX(), selectedTextWrapper.getMinY()),
                getScreenDataArea(), getChart());
        Rectangle2D screenRect = new Rectangle2D.Double(screenXY.getX(), screenXY.getY() - 15,
                selectedTextWrapper.getWidth(), selectedTextWrapper.getHeight());
        if (screenRect.contains(e.getX(), e.getY())) {

            double screenX = ChartMaskingUtilities.translateScreenX(e.getX() / getScaleX(), getScreenDataArea(),
                    getChart());/*from w  ww  .ja  v a  2s. c  o m*/
            double screenY = ChartMaskingUtilities.translateScreenY(e.getY(), getScreenDataArea(), getChart(),
                    0);
            //         Point2D point = translateScreenToChart(translateScreenToJava2D(e.getPoint()));
            Point2D point = new Point2D.Double(screenX, screenY);
            if (point != null) {
                this.textMovePoint = point;
            }
        } else {
            this.textMovePoint = null;
        }
    } else {
        super.mousePressed(e);
    }
}

From source file:org.gumtree.vis.awt.JChartPanel.java

@Override
public void mouseMoved(MouseEvent e) {
    //        if (isMaskingEnabled() && (e.getModifiers() & maskingKeyMask) != 0) {
    if (selectedTextWrapper == null && isMaskingEnabled()) {
        int cursorType = findCursorOnSelectedItem(e.getX(), e.getY());
        setCursor(Cursor.getPredefinedCursor(cursorType));
    } else {//from   w  w  w  . ja  va  2 s . c om
        Cursor newCursor = defaultCursor;
        if (selectedTextWrapper != null) {
            Point2D screenXY = ChartMaskingUtilities.translateChartPoint(
                    new Point2D.Double(selectedTextWrapper.getMinX(), selectedTextWrapper.getMinY()),
                    getScreenDataArea(), getChart());
            Rectangle2D screenRect = new Rectangle2D.Double(screenXY.getX(), screenXY.getY() - 15,
                    selectedTextWrapper.getWidth(), selectedTextWrapper.getHeight());
            if (screenRect.contains(e.getX(), e.getY())) {
                newCursor = Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR);
            }
        }
        if (newCursor != getCursor()) {
            setCursor(newCursor);
        }
    }
    Line2D oldSelection = selectedMarker;
    findSelectedMarker(e.getPoint());
    if (selectedMarker != oldSelection) {
        repaint();
    }
}