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:Hexagon.java

public void align(Rectangle2D bounds, Direction direction) {
    // these are defined here INSTEAD of in the switch, or it won't compile
    Point2D newTopRight, newTopLeft, newBottomRight, newBottomLeft;
    Point2D oldTopRight, oldTopLeft, oldBottomRight, oldBottomLeft;

    switch (direction) {
    case NorthEast:
        newTopRight = new Point2D.Double(bounds.getMaxX(), bounds.getMinY());
        oldTopRight = boundingCorners.get(BoundingCorner.TopRight);
        translate(newTopRight.getX() - oldTopRight.getX(), // deltaX
                newTopRight.getY() - oldTopRight.getY() // deltaY
        );/*  w ww  . j  av a 2  s  .  co  m*/
        break;
    case East:
        newTopRight = new Point2D.Double(bounds.getMaxX(), bounds.getMinY());
        oldTopRight = boundingCorners.get(BoundingCorner.TopRight);
        translate(newTopRight.getX() - oldTopRight.getX(), // deltaX
                0 // deltaY
        );
        break;
    case SouthEast:
        newBottomRight = new Point2D.Double(bounds.getMaxX(), bounds.getMaxY());
        oldBottomRight = boundingCorners.get(BoundingCorner.BottomRight);
        translate(newBottomRight.getX() - oldBottomRight.getX(), // deltaX
                newBottomRight.getY() - oldBottomRight.getY() // deltaY
        );
        break;
    case SouthWest:
        newBottomLeft = new Point2D.Double(bounds.getMinX(), bounds.getMaxY());
        oldBottomLeft = boundingCorners.get(BoundingCorner.BottomLeft);
        translate(newBottomLeft.getX() - oldBottomLeft.getX(), // deltaX
                newBottomLeft.getY() - oldBottomLeft.getY() // deltaY
        );
        break;
    case West:
        newTopLeft = new Point2D.Double(bounds.getMinX(), bounds.getMinY());
        oldTopLeft = boundingCorners.get(BoundingCorner.TopLeft);
        translate(newTopLeft.getX() - oldTopLeft.getX(), // deltaX
                0 // deltaY
        );
        break;
    case NorthWest:
        newTopLeft = new Point2D.Double(bounds.getMinX(), bounds.getMinY());
        oldTopLeft = boundingCorners.get(BoundingCorner.TopLeft);
        translate(newTopLeft.getX() - oldTopLeft.getX(), // deltaX
                newTopLeft.getY() - oldTopLeft.getY() // deltaY
        );
        break;
    }
}

From source file:net.sf.maltcms.chromaui.charts.FastHeatMapPlot.java

private void renderCrosshairs(Rectangle2D dataArea, Graphics2D g2) {
    int r = 5;//from   w  w  w . ja v  a 2s  .  c om
    Color fill = new Color(255, 255, 255, 192);
    Color outline = new Color(0, 0, 0, 128);
    double rx = this.domainAxis.valueToJava2D(this.getDomainCrosshairValue(), dataArea, RectangleEdge.BOTTOM);
    double minY = this.rangeAxis.valueToJava2D(dataArea.getMinY(), dataArea, RectangleEdge.LEFT);
    double maxY = this.rangeAxis.valueToJava2D(dataArea.getMaxY(), dataArea, RectangleEdge.RIGHT);
    double ry = this.rangeAxis.valueToJava2D(this.getRangeCrosshairValue(), dataArea, RectangleEdge.LEFT);
    double minX = this.domainAxis.valueToJava2D(dataArea.getMinX(), dataArea, RectangleEdge.BOTTOM);
    double maxX = this.domainAxis.valueToJava2D(dataArea.getMaxX(), dataArea, RectangleEdge.TOP);
    g2.setColor(fill);
    //        Rectangle2D.Double domainCrossHair = new Rectangle2D.Double(rx - 1, minY, 3, maxY - minY);
    //        Rectangle2D.Double rangeCrossHair = new Rectangle2D.Double(minX, ry - 1, maxX - minX, 3);
    //        g2.fill(domainCrossHair);
    //        g2.fill(rangeCrossHair);
    g2.setColor(outline);
    //        g2.draw(domainCrossHair);
    //        g2.draw(rangeCrossHair);
    //System.out.println("CH: " + rx + "," + ry);
    Ellipse2D.Double el2 = new Ellipse2D.Double(rx - r, ry - r, 2 * r, 2 * r);
    //            g2.drawOval(rx - r, ry - r, 2 * r, 2 * r);
    g2.fill(el2);
    g2.draw(el2);
}

From source file:org.gumtree.vis.awt.JChartPanel.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.
 *
 * @param x  the x-coordinate.//  w w  w  .  ja  v  a2  s . com
 * @param y  the y-coordinate.
 * @param area  the rectangle (<code>null</code> not permitted).
 *
 * @return A point within the rectangle.
 */
protected 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:org.gumtree.vis.plot1d.LogarithmizableAxis.java

/**
 * Converts a data value to a coordinate in Java2D space, assuming that
 * the axis runs along one edge of the specified plotArea.
 * Note that it is possible for the coordinate to fall outside the
 * plotArea./*from  w w  w  .  j  a va2  s .  co  m*/
 *
 * @param value  the data value.
 * @param plotArea  the area for plotting the data.
 * @param edge  the axis location.
 *
 * @return The Java2D coordinate.
 */
public double logValueToJava2D(double value, Rectangle2D plotArea, RectangleEdge edge) {

    Range range = getRange();
    double axisMin = switchedLog10(range.getLowerBound());
    double axisMax = switchedLog10(range.getUpperBound());

    double min = 0.0;
    double max = 0.0;
    if (RectangleEdge.isTopOrBottom(edge)) {
        min = plotArea.getMinX();
        max = plotArea.getMaxX();
    } else if (RectangleEdge.isLeftOrRight(edge)) {
        min = plotArea.getMaxY();
        max = plotArea.getMinY();
    }

    value = switchedLog10(value);

    if (isInverted()) {
        return max - (((value - axisMin) / (axisMax - axisMin)) * (max - min));
    } else {
        return min + (((value - axisMin) / (axisMax - axisMin)) * (max - min));
    }

}

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

/**
  * Draws a vertical line used to trace the mouse position to the horizontal
  * axis.//from  w  ww  .  jav a 2  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();
    if (((int) dataArea.getMinX() < x) && (x < (int) dataArea.getMaxX())) {
        g2.setPaint(getAxisTraceColor());
        g2.setStroke(new BasicStroke(0.25f));
        g2.draw(new Line2D.Float(x, (int) dataArea.getMinY(), x, (int) dataArea.getMaxY()));
    }
}

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

protected int findCursorOnSelectedItem(int x, int y) {
    if (isInternalLegendEnabled && isInternalLegendSelected) {
        Rectangle2D screenArea = getScreenDataArea();
        Rectangle2D legendArea = new Rectangle2D.Double(screenArea.getMaxX() - internalLegendSetup.getMinX(),
                screenArea.getMinY() + internalLegendSetup.getMinY(), internalLegendSetup.getWidth(),
                internalLegendSetup.getHeight());
        Rectangle2D intersect = screenArea.createIntersection(legendArea);
        Point2D point = new Point2D.Double(x, y);
        double minX = legendArea.getMinX();
        double maxX = legendArea.getMaxX();
        double minY = legendArea.getMinY();
        double width = legendArea.getWidth();
        double height = legendArea.getHeight();
        if (!intersect.isEmpty() && screenArea.contains(point)) {
            if (width > 8) {
                Rectangle2D center = new Rectangle2D.Double(minX + 4, minY, width - 8, height);
                if (screenArea.createIntersection(center).contains(point)) {
                    return Cursor.MOVE_CURSOR;
                }/*ww  w .  j  ava 2s  . c o  m*/
            }
            Rectangle2D west = new Rectangle2D.Double(minX - 4, minY, width < 8 ? width / 2 + 4 : 8, height);
            if (screenArea.createIntersection(west).contains(point)) {
                return Cursor.W_RESIZE_CURSOR;
            }
            Rectangle2D east = new Rectangle2D.Double(maxX - (width < 8 ? width / 2 : 4), minY,
                    width < 8 ? width / 2 + 4 : 8, height);
            if (screenArea.createIntersection(east).contains(point)) {
                return Cursor.E_RESIZE_CURSOR;
            }
        }
    } else if (getSelectedMask() != null && !getSelectedMask().isEmpty()) {
        Rectangle2D screenArea = getScreenDataArea();
        Rectangle2D maskArea = ChartMaskingUtilities.getDomainMaskFrame(getSelectedMask(), getScreenDataArea(),
                getChart());
        Rectangle2D intersect = screenArea.createIntersection(maskArea);
        Point2D point = new Point2D.Double(x, y);
        double minX = maskArea.getMinX();
        double maxX = maskArea.getMaxX();
        double minY = maskArea.getMinY();
        double width = maskArea.getWidth();
        double height = maskArea.getHeight();
        if (!intersect.isEmpty() && screenArea.contains(point)) {
            if (width > 8) {
                Rectangle2D center = new Rectangle2D.Double(minX + 4, minY, width - 8, height);
                if (screenArea.createIntersection(center).contains(point)) {
                    return Cursor.MOVE_CURSOR;
                }
            }
            Rectangle2D west = new Rectangle2D.Double(minX - 4, minY, width < 8 ? width / 2 + 4 : 8, height);
            if (screenArea.createIntersection(west).contains(point)) {
                return Cursor.W_RESIZE_CURSOR;
            }
            Rectangle2D east = new Rectangle2D.Double(maxX - (width < 8 ? width / 2 : 4), minY,
                    width < 8 ? width / 2 + 4 : 8, height);
            if (screenArea.createIntersection(east).contains(point)) {
                return Cursor.E_RESIZE_CURSOR;
            }
        }
    }
    return Cursor.DEFAULT_CURSOR;
}

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 www. j a v  a  2 s  . c o m
        }
    }
    if (selectedTextWrapper != null) {
        selectedTextWrapper = null;
    }
}

From source file:org.gvsig.remotesensing.scatterplot.chart.ScatterPlotDiagram.java

/**
 * Handles a 'mouse dragged' event.//ww w. j  a v  a 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)...
    drawRectangle(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...
    drawRectangle(g2);
    g2.dispose();
}

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

/**
  * Draws a horizontal line used to trace the mouse position to the vertical
  * axis.//w ww  .  ja  va2 s .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();
    if (((int) dataArea.getMinY() < y) && (y < (int) dataArea.getMaxY())) {
        g2.setPaint(getAxisTraceColor());
        g2.setStroke(new BasicStroke(0.25f));
        g2.draw(new Line2D.Float((int) dataArea.getMinX(), y, (int) dataArea.getMaxX(), y));
    }
}

From source file:org.tsho.dmc2.core.chart.jfree.DmcChartPanel.java

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

    if (zoomRectangle != null) {

        //            if (Math.abs(e.getX() - zoomPoint.getX()) >= MINIMUM_DRAG_ZOOM_SIZE) {
        if (Math.abs(e.getX() - zoomPoint.getX()) >= 7) {
            if (e.getX() < zoomPoint.getX() || e.getY() < zoomPoint.getY()) {
                autoRangeBoth();
            } else {
                double x, y, w, h;
                Rectangle2D scaledDataArea = getScaledDataArea();
                //for a mouseReleased event, (horizontalZoom || verticalZoom)
                //will be true, so we can just test for either being false;
                //otherwise both are true
                if (!verticalZoom) {
                    x = zoomPoint.getX();
                    y = scaledDataArea.getMinY();
                    w = Math.min(zoomRectangle.getWidth(), scaledDataArea.getMaxX() - zoomPoint.getX());
                    h = scaledDataArea.getHeight();
                } else if (!horizontalZoom) {
                    x = scaledDataArea.getMinX();
                    y = zoomPoint.getY();
                    w = scaledDataArea.getWidth();
                    h = Math.min(zoomRectangle.getHeight(), scaledDataArea.getMaxY() - zoomPoint.getY());
                } else {
                    x = zoomPoint.getX();
                    y = zoomPoint.getY();
                    w = Math.min(zoomRectangle.getWidth(), scaledDataArea.getMaxX() - zoomPoint.getX());
                    h = Math.min(zoomRectangle.getHeight(), scaledDataArea.getMaxY() - zoomPoint.getY());
                }
                Rectangle2D zoomArea = new Rectangle2D.Double(x, y, w, h);
                zoom(zoomArea);

            }
            this.zoomPoint = null;
            this.zoomRectangle = null;
        } else {
            Graphics2D g2 = (Graphics2D) getGraphics();
            g2.setXORMode(java.awt.Color.gray);
            if (fillZoomRectangle) {
                g2.fill(zoomRectangle);
            } else {
                g2.draw(zoomRectangle);
            }
            g2.dispose();
            this.zoomRectangle = null;
        }

        // notify a redraw event
        CoreStatusEvent ev = new CoreStatusEvent(this);
        ev.setType(CoreStatusEvent.REDRAW);
        ((AbstractDmcPlot) chart.getPlot()).notifyCoreStatusListeners(ev);
    }

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