Example usage for java.awt.geom Rectangle2D getMinY

List of usage examples for java.awt.geom Rectangle2D getMinY

Introduction

In this page you can find the example usage for java.awt.geom Rectangle2D getMinY.

Prototype

public double getMinY() 

Source Link

Document

Returns the smallest Y coordinate of the framing rectangle of the Shape in double precision.

Usage

From source file:com.rapidminer.gui.plotter.charts.AbstractChartPanel.java

private void shrinkSelectionYAxis(double x, double y, Selection selectionObject, ValueAxis axis, int axisIndex,
        double zoomFactor) {
    Rectangle2D scaledDataArea = getScreenDataArea((int) x, (int) y);

    double minY = scaledDataArea.getMinY();
    double maxY = scaledDataArea.getMaxY();
    double partToTop = (y - minY) / (maxY - minY);

    double lowerDomain = axis.getLowerBound();
    double upperDomain = axis.getUpperBound();
    double middlePointTop = lowerDomain + (upperDomain - lowerDomain) * (1d - partToTop);
    double width = (upperDomain - lowerDomain) * zoomFactor;
    Range axisRange = new Range(middlePointTop - width / 2d, middlePointTop + width / 2d);
    for (String axisName : axisNameResolver.resolveYAxis(axisIndex)) {
        selectionObject.addDelimiter(axisName, axisRange);
    }/*from  w  w w  .j a va  2 s. c  o m*/
}

From source file:com.rapidminer.gui.plotter.charts.AbstractChartPanel.java

/**
 * Draws a horizontal line used to trace the mouse position to the vertical axis.
 * //from w ww . j a v  a  2s .c o  m
 * @param g2
 *            the graphics device.
 * @param y
 *            the y-coordinate of the trace line.
 */
private void drawVerticalAxisTrace(Graphics2D g2, int y) {

    Rectangle2D dataArea = getScreenDataArea();

    g2.setXORMode(Color.orange);
    if ((int) dataArea.getMinY() < y && y < (int) dataArea.getMaxY()) {

        if (this.horizontalTraceLine != null) {
            g2.draw(this.horizontalTraceLine);
            this.horizontalTraceLine.setLine((int) dataArea.getMinX(), y, (int) dataArea.getMaxX(), y);
        } else {
            this.horizontalTraceLine = new Line2D.Float((int) dataArea.getMinX(), y, (int) dataArea.getMaxX(),
                    y);
        }
        g2.draw(this.horizontalTraceLine);
    }

    // Reset to the default 'overwrite' mode
    g2.setPaintMode();
}

From source file:com.rapidminer.gui.plotter.charts.AbstractChartPanel.java

/**
 * Returns a point based on (x, y) but constrained to be within the bounds of the given
 * rectangle. This method could be moved to JCommon.
 * /*from  w w w .  ja  v a  2 s. com*/
 * @param x
 *            the x-coordinate.
 * @param y
 *            the y-coordinate.
 * @param area
 *            the rectangle (<code>null</code> not permitted).
 * 
 * @return A point within the rectangle.
 */
private Point2D getPointInRectangle(int x, int y, Rectangle2D area) {
    double xx = Math.max(area.getMinX(), Math.min(x, area.getMaxX()));
    double yy = Math.max(area.getMinY(), Math.min(y, area.getMaxY()));
    return new Point2D.Double(xx, yy);
}

From source file:com.isti.traceview.common.TraceViewChartPanel.java

/**
 * Handles a 'mouse dragged' event./*from   w w w . j av  a2  s.c om*/
 * 
 * @param e
 *            the mouse event.
 */
public void mouseDragged(MouseEvent e) {
    // if the popup menu has already been triggered, then ignore dragging...
    if (this.popup != null && this.popup.isShowing()) {
        return;
    }
    // if no initial zoom point was set, ignore dragging...
    if (this.zoomPoint == null) {
        return;
    }
    Graphics2D g2 = (Graphics2D) getGraphics();

    // Erase the previous zoom rectangle (if any)...
    drawZoomRectangle(g2);

    boolean hZoom = false;
    boolean vZoom = false;
    if (this.orientation == PlotOrientation.HORIZONTAL) {
        hZoom = this.rangeZoomable;
        vZoom = this.domainZoomable;
    } else {
        hZoom = this.domainZoomable;
        vZoom = this.rangeZoomable;
    }
    Rectangle2D scaledDataArea = getScreenDataArea((int) this.zoomPoint.getX(), (int) this.zoomPoint.getY());
    if (hZoom && vZoom) {
        // selected rectangle shouldn't extend outside the data area...
        double xmax = Math.min(e.getX(), scaledDataArea.getMaxX());
        double ymax = Math.min(e.getY(), scaledDataArea.getMaxY());
        this.zoomRectangle = new Rectangle2D.Double(this.zoomPoint.getX(), this.zoomPoint.getY(),
                xmax - this.zoomPoint.getX(), ymax - this.zoomPoint.getY());
    } else if (hZoom) {
        double xmax = Math.min(e.getX(), scaledDataArea.getMaxX());
        this.zoomRectangle = new Rectangle2D.Double(this.zoomPoint.getX(), scaledDataArea.getMinY(),
                xmax - this.zoomPoint.getX(), scaledDataArea.getHeight());
    } else if (vZoom) {
        double ymax = Math.min(e.getY(), scaledDataArea.getMaxY());
        this.zoomRectangle = new Rectangle2D.Double(scaledDataArea.getMinX(), this.zoomPoint.getY(),
                scaledDataArea.getWidth(), ymax - this.zoomPoint.getY());
    }

    // Draw the new zoom rectangle...
    drawZoomRectangle(g2);
    g2.dispose();
}

From source file:org.rdv.viz.chart.ChartPanel.java

/**
 * Handles a 'mouse released' event.  On Windows, we need to check if this
 * is a popup trigger, but only if we haven't already been tracking a zoom
 * rectangle./*from w ww .jav a2  s . c  o m*/
 *
 * @param e  information about the event.
 */
public void mouseReleased(MouseEvent e) {

    if (this.zoomRectangle != null) {
        boolean hZoom = false;
        boolean vZoom = false;
        if (this.orientation == PlotOrientation.HORIZONTAL) {
            hZoom = this.rangeZoomable;
            vZoom = this.domainZoomable;
        } else {
            hZoom = this.domainZoomable;
            vZoom = this.rangeZoomable;
        }

        boolean zoomTrigger1 = hZoom && Math.abs(e.getX() - this.zoomPoint.getX()) >= this.zoomTriggerDistance;
        boolean zoomTrigger2 = vZoom && Math.abs(e.getY() - this.zoomPoint.getY()) >= this.zoomTriggerDistance;
        if (zoomTrigger1 || zoomTrigger2) {
            if ((hZoom && (e.getX() < this.zoomPoint.getX()))
                    || (vZoom && (e.getY() < this.zoomPoint.getY()))) {
                // restore the the range for the domain and range axis from
                // the history
                Plot p = this.chart.getPlot();
                if (p instanceof XYPlot && !rangeHistory.empty()) {
                    XYPlot xyPlot = (XYPlot) p;
                    ValueAxis rangeAxis = xyPlot.getRangeAxis();
                    ValueAxis domainAxis = xyPlot.getDomainAxis();

                    if (rangeAxis.getRange().equals(rangeHistory.pop())
                            && domainAxis.getRange().equals(rangeHistory.pop())) {
                        xyPlot.getRangeAxis().setRange(rangeHistory.pop());
                        xyPlot.getDomainAxis().setRange(rangeHistory.pop());

                        if (!rangeHistory.empty()) {
                            rangeHistory.push(domainAxis.getRange());
                            rangeHistory.push(rangeAxis.getRange());
                        }
                    } else {
                        rangeHistory.clear();
                        restoreAutoBounds();
                    }
                } else {
                    restoreAutoBounds();
                }

            } else {
                double x, y, w, h;
                Rectangle2D screenDataArea = getScreenDataArea((int) this.zoomPoint.getX(),
                        (int) this.zoomPoint.getY());
                double maxX = screenDataArea.getMaxX();
                double maxY = screenDataArea.getMaxY();
                // for mouseReleased event, (horizontalZoom || verticalZoom)
                // will be true, so we can just test for either being false;
                // otherwise both are true
                if (!vZoom) {
                    x = this.zoomPoint.getX();
                    y = screenDataArea.getMinY();
                    w = Math.min(this.zoomRectangle.getWidth(), maxX - this.zoomPoint.getX());
                    h = screenDataArea.getHeight();
                } else if (!hZoom) {
                    x = screenDataArea.getMinX();
                    y = this.zoomPoint.getY();
                    w = screenDataArea.getWidth();
                    h = Math.min(this.zoomRectangle.getHeight(), maxY - this.zoomPoint.getY());
                } else {
                    x = this.zoomPoint.getX();
                    y = this.zoomPoint.getY();
                    w = Math.min(this.zoomRectangle.getWidth(), maxX - this.zoomPoint.getX());
                    h = Math.min(this.zoomRectangle.getHeight(), maxY - this.zoomPoint.getY());
                }
                Rectangle2D zoomArea = new Rectangle2D.Double(x, y, w, h);
                zoom(zoomArea);
            }
            this.zoomPoint = null;
            this.zoomRectangle = null;
        } else {
            // Erase the zoom rectangle
            Graphics2D g2 = (Graphics2D) getGraphics();
            drawZoomRectangle(g2);
            g2.dispose();
            this.zoomPoint = null;
            this.zoomRectangle = null;
        }

    }

    else if (e.isPopupTrigger()) {
        if (this.popup != null) {
            displayPopupMenu(e.getX(), e.getY());
        }
    }

}

From source file:com.rapidminer.gui.plotter.charts.AbstractChartPanel.java

/**
 * Draws a vertical line used to trace the mouse position to the horizontal axis.
 * /*from   ww w  . j a va2  s  .c  o m*/
 * @param g2
 *            the graphics device.
 * @param x
 *            the x-coordinate of the trace line.
 */
private void drawHorizontalAxisTrace(Graphics2D g2, int x) {

    Rectangle2D dataArea = getScreenDataArea();

    g2.setXORMode(Color.orange);
    if ((int) dataArea.getMinX() < x && x < (int) dataArea.getMaxX()) {

        if (this.verticalTraceLine != null) {
            g2.draw(this.verticalTraceLine);
            this.verticalTraceLine.setLine(x, (int) dataArea.getMinY(), x, (int) dataArea.getMaxY());
        } else {
            this.verticalTraceLine = new Line2D.Float(x, (int) dataArea.getMinY(), x, (int) dataArea.getMaxY());
        }
        g2.draw(this.verticalTraceLine);
    }

    // Reset to the default 'overwrite' mode
    g2.setPaintMode();
}

From source file:org.rdv.viz.chart.ChartPanel.java

/**
 * Handles a 'mouse dragged' event./*from w w  w.  j  ava  2  s.  c o  m*/
 *
 * @param e  the mouse event.
 */
public void mouseDragged(MouseEvent e) {

    // if the popup menu has already been triggered, then ignore dragging...
    if (this.popup != null && this.popup.isShowing()) {
        return;
    }
    // if no initial zoom point was set, ignore dragging...
    if (this.zoomPoint == null) {
        return;
    }
    Graphics2D g2 = (Graphics2D) getGraphics();

    // Erase the previous zoom rectangle (if any)...
    drawZoomRectangle(g2);

    boolean hZoom = false;
    boolean vZoom = false;
    if (this.orientation == PlotOrientation.HORIZONTAL) {
        hZoom = this.rangeZoomable;
        vZoom = this.domainZoomable;
    } else {
        hZoom = this.domainZoomable;
        vZoom = this.rangeZoomable;
    }
    Rectangle2D scaledDataArea = getScreenDataArea((int) this.zoomPoint.getX(), (int) this.zoomPoint.getY());
    if (hZoom && vZoom) {
        // selected rectangle shouldn't extend outside the data area...
        double xmax = Math.min(e.getX(), scaledDataArea.getMaxX());
        double ymax = Math.min(e.getY(), scaledDataArea.getMaxY());
        this.zoomRectangle = new Rectangle2D.Double(this.zoomPoint.getX(), this.zoomPoint.getY(),
                xmax - this.zoomPoint.getX(), ymax - this.zoomPoint.getY());
    } else if (hZoom) {
        double xmax = Math.min(e.getX(), scaledDataArea.getMaxX());
        this.zoomRectangle = new Rectangle2D.Double(this.zoomPoint.getX(), scaledDataArea.getMinY(),
                xmax - this.zoomPoint.getX(), scaledDataArea.getHeight());
    } else if (vZoom) {
        double ymax = Math.min(e.getY(), scaledDataArea.getMaxY());
        this.zoomRectangle = new Rectangle2D.Double(scaledDataArea.getMinX(), this.zoomPoint.getY(),
                scaledDataArea.getWidth(), ymax - this.zoomPoint.getY());
    }

    // Draw the new zoom rectangle...
    drawZoomRectangle(g2);

    g2.dispose();

}

From source file:com.isti.traceview.common.TraceViewChartPanel.java

/**
 * Zooms in on a selected region.//w w w . j  av  a 2 s.co  m
 * 
 * @param selection
 *            the selected region.
 */
public void zoom(Rectangle2D selection) {

    // get the origin of the zoom selection in the Java2D space used for
    // drawing the chart (that is, before any scaling to fit the panel)
    Point2D selectOrigin = translateScreenToJava2D(
            new Point((int) Math.ceil(selection.getX()), (int) Math.ceil(selection.getY())));
    PlotRenderingInfo plotInfo = this.info.getPlotInfo();
    Rectangle2D scaledDataArea = getScreenDataArea((int) selection.getCenterX(), (int) selection.getCenterY());
    if ((selection.getHeight() > 0) && (selection.getWidth() > 0)) {

        double hLower = (selection.getMinX() - scaledDataArea.getMinX()) / scaledDataArea.getWidth();
        double hUpper = (selection.getMaxX() - scaledDataArea.getMinX()) / scaledDataArea.getWidth();
        double vLower = (scaledDataArea.getMaxY() - selection.getMaxY()) / scaledDataArea.getHeight();
        double vUpper = (scaledDataArea.getMaxY() - selection.getMinY()) / scaledDataArea.getHeight();

        Plot p = this.chart.getPlot();
        if (p instanceof Zoomable) {
            Zoomable z = (Zoomable) p;
            if (z.getOrientation() == PlotOrientation.HORIZONTAL) {
                z.zoomDomainAxes(vLower, vUpper, plotInfo, selectOrigin);
                z.zoomRangeAxes(hLower, hUpper, plotInfo, selectOrigin);
            } else {
                z.zoomDomainAxes(hLower, hUpper, plotInfo, selectOrigin);
                z.zoomRangeAxes(vLower, vUpper, plotInfo, selectOrigin);
            }
        }
    }
}

From source file:org.rdv.viz.chart.ChartPanel.java

/**
 * Zooms in on a selected region./* ww  w . j  a va2 s .  co m*/
 *
 * @param selection  the selected region.
 */
public void zoom(Rectangle2D selection) {

    // get the origin of the zoom selection in the Java2D space used for
    // drawing the chart (that is, before any scaling to fit the panel)
    Point2D selectOrigin = translateScreenToJava2D(
            new Point((int) Math.ceil(selection.getX()), (int) Math.ceil(selection.getY())));
    PlotRenderingInfo plotInfo = this.info.getPlotInfo();
    Rectangle2D scaledDataArea = getScreenDataArea((int) selection.getCenterX(), (int) selection.getCenterY());
    if ((selection.getHeight() > 0) && (selection.getWidth() > 0)) {

        double hLower = (selection.getMinX() - scaledDataArea.getMinX()) / scaledDataArea.getWidth();
        double hUpper = (selection.getMaxX() - scaledDataArea.getMinX()) / scaledDataArea.getWidth();
        double vLower = (scaledDataArea.getMaxY() - selection.getMaxY()) / scaledDataArea.getHeight();
        double vUpper = (scaledDataArea.getMaxY() - selection.getMinY()) / scaledDataArea.getHeight();

        Plot p = this.chart.getPlot();
        if (p instanceof Zoomable) {
            // save previous ranges for use later when zooming out
            if (p instanceof XYPlot && rangeHistory.empty()) {
                XYPlot xyPlot = (XYPlot) p;
                rangeHistory.push(xyPlot.getDomainAxis().getRange());
                rangeHistory.push(xyPlot.getRangeAxis().getRange());
            }

            Zoomable z = (Zoomable) p;
            if (z.getOrientation() == PlotOrientation.HORIZONTAL) {
                z.zoomDomainAxes(vLower, vUpper, plotInfo, selectOrigin);
                z.zoomRangeAxes(hLower, hUpper, plotInfo, selectOrigin);
            } else {
                z.zoomDomainAxes(hLower, hUpper, plotInfo, selectOrigin);
                z.zoomRangeAxes(vLower, vUpper, plotInfo, selectOrigin);
            }

            // save current ranges for use later when zooming out
            if (p instanceof XYPlot) {
                XYPlot xyPlot = (XYPlot) p;
                rangeHistory.push(xyPlot.getDomainAxis().getRange());
                rangeHistory.push(xyPlot.getRangeAxis().getRange());
            }
        }

    }

}

From source file:com.rapidminer.gui.plotter.charts.AbstractChartPanel.java

/**
 * Handles a 'mouse released' event. On Windows, we need to check if this is a popup trigger,
 * but only if we haven't already been tracking a zoom rectangle.
 * /*ww  w . ja va  2 s.  c  o  m*/
 * @param e
 *            information about the event.
 */

@Override
public void mouseReleased(MouseEvent e) {
    // if we've been panning, we need to reset now that the mouse is
    // released...
    if (this.panLast != null) {
        this.panLast = null;
        setCursor(Cursor.getDefaultCursor());
    } else if (this.selectionRectangle != null) {
        boolean hZoom = false;
        boolean vZoom = false;
        if (this.orientation == PlotOrientation.HORIZONTAL) {
            hZoom = this.rangeZoomable;
            vZoom = this.domainZoomable;
        } else {
            hZoom = this.domainZoomable;
            vZoom = this.rangeZoomable;
        }

        boolean zoomTrigger1 = hZoom && Math.abs(e.getX() - this.zoomPoint.getX()) >= this.zoomTriggerDistance;
        boolean zoomTrigger2 = vZoom && Math.abs(e.getY() - this.zoomPoint.getY()) >= this.zoomTriggerDistance;
        if (zoomTrigger1 || zoomTrigger2) {
            if (hZoom && e.getX() < this.zoomPoint.getX() || vZoom && e.getY() < this.zoomPoint.getY()) {
                restoreAutoBounds();
            } else {
                double x, y, w, h;
                Rectangle2D screenDataArea = getScreenDataArea((int) this.zoomPoint.getX(),
                        (int) this.zoomPoint.getY());
                double maxX = screenDataArea.getMaxX();
                double maxY = screenDataArea.getMaxY();
                // for mouseReleased event, (horizontalZoom || verticalZoom)
                // will be true, so we can just test for either being false;
                // otherwise both are true
                if (!vZoom) {
                    x = this.zoomPoint.getX();
                    y = screenDataArea.getMinY();
                    w = Math.min(this.selectionRectangle.getWidth(), maxX - this.zoomPoint.getX());
                    h = screenDataArea.getHeight();
                } else if (!hZoom) {
                    x = screenDataArea.getMinX();
                    y = this.zoomPoint.getY();
                    w = screenDataArea.getWidth();
                    h = Math.min(this.selectionRectangle.getHeight(), maxY - this.zoomPoint.getY());
                } else {
                    x = this.zoomPoint.getX();
                    y = this.zoomPoint.getY();
                    w = Math.min(this.selectionRectangle.getWidth(), maxX - this.zoomPoint.getX());
                    h = Math.min(this.selectionRectangle.getHeight(), maxY - this.zoomPoint.getY());
                }
                Rectangle2D zoomArea = new Rectangle2D.Double(x, y, w, h);
                selectRectangle(zoomArea, e);
            }
            this.zoomPoint = null;
            this.selectionRectangle = null;
        } else {
            this.zoomPoint = null;
            this.selectionRectangle = null;
        }

    }

    else if (e.isPopupTrigger()) {
        if (this.popup != null) {
            displayPopupMenu(e.getX(), e.getY());
        }
    }

}