Example usage for java.awt.geom Rectangle2D getMinX

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

Introduction

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

Prototype

public double getMinX() 

Source Link

Document

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

Usage

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

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

    double minX = scaledDataArea.getMinX();
    double maxX = scaledDataArea.getMaxX();
    double partToLeft = (x - minX) / (maxX - minX);

    double lowerDomain = axis.getLowerBound();
    double upperDomain = axis.getUpperBound();
    double middlePointLeft = lowerDomain + (upperDomain - lowerDomain) * partToLeft;
    double width = (upperDomain - lowerDomain) * zoomFactor;
    Range domainRange = new Range(middlePointLeft - width / 2d, middlePointLeft + width / 2d);
    for (String axisName : axisNameResolver.resolveXAxis(axisIndex)) {
        selectionObject.addDelimiter(axisName, domainRange);
    }/*from  w w  w.ja v  a2 s. c  om*/
}

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 w ww  . j  ava 2  s  . c om
 * @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:com.isti.traceview.common.TraceViewChartPanel.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.
 * //  www.j  a v a  2 s.co 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()))) {
                restoreAutoBounds();
            } else {
                double x, y, w, h;
                Rectangle2D screenDataArea = getScreenDataArea((int) this.zoomPoint.getX(),
                        (int) this.zoomPoint.getY());
                // 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(),
                            screenDataArea.getMaxX() - 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(),
                            screenDataArea.getMaxY() - this.zoomPoint.getY());
                } else {
                    x = this.zoomPoint.getX();
                    y = this.zoomPoint.getY();
                    w = Math.min(this.zoomRectangle.getWidth(),
                            screenDataArea.getMaxX() - this.zoomPoint.getX());
                    h = Math.min(this.zoomRectangle.getHeight(),
                            screenDataArea.getMaxY() - 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:org.rdv.viz.chart.ChartPanel.java

/**
 * Zooms in on a selected region./*from   w  w  w. jav a 2s  .c  o 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

public void selectRectangle(Rectangle2D selection, MouseEvent selectionEvent) {
    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 XYPlot) {
            XYPlot plot = (XYPlot) p;//  w w w  . jav  a 2  s  .  com
            Selection selectionObject = new Selection();
            for (int i = 0; i < plot.getDomainAxisCount(); i++) {
                ValueAxis domain = plot.getDomainAxis(i);
                double lowerDomain = domain.getLowerBound();
                double upperDomain = domain.getUpperBound();
                Range axisRange = new Range(lowerDomain + (upperDomain - lowerDomain) * hLower,
                        lowerDomain + (upperDomain - lowerDomain) * hUpper);
                for (String axisName : axisNameResolver.resolveXAxis(i)) {
                    selectionObject.addDelimiter(axisName, axisRange);
                }
            }
            for (int i = 0; i < plot.getRangeAxisCount(); i++) {
                ValueAxis range = plot.getRangeAxis(i);
                double lowerRange = range.getLowerBound();
                double upperRange = range.getUpperBound();
                Range axisRange = new Range(lowerRange + (upperRange - lowerRange) * vLower,
                        lowerRange + (upperRange - lowerRange) * vUpper);
                for (String axisName : axisNameResolver.resolveYAxis(i)) {
                    selectionObject.addDelimiter(axisName, axisRange);
                }
            }
            informSelectionListener(selectionObject, selectionEvent);
        }
    }

}

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 w  w .j a v  a 2 s  .c om
 * @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.isti.traceview.common.TraceViewChartPanel.java

/**
 * Handles a 'mouse dragged' event./*w w  w  . j a  v  a 2  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 w w. j  a va 2 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:org.rdv.viz.chart.ChartPanel.java

/**
 * Handles a 'mouse dragged' event.//from   ww  w  .j a  v a2 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.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.
 * //from w  w w. j  av  a  2 s  .  c om
 * @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());
        }
    }

}