Example usage for java.awt.geom Rectangle2D getMaxX

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

Introduction

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

Prototype

public double getMaxX() 

Source Link

Document

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

Usage

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

/**
  * Draws a vertical line used to trace the mouse position to the horizontal
  * axis.//  ww w .jav  a  2s .  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:net.sf.maltcms.chromaui.charts.FastHeatMapPlot.java

private void renderCrosshairs(Rectangle2D dataArea, Graphics2D g2) {
    int r = 5;/*from w w w. ja va  2  s  .c o  m*/
    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

/**
  * Draws a horizontal line used to trace the mouse position to the vertical
  * axis./*from  w w  w.  j a v a  2  s .  co  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:com.isti.traceview.common.TraceViewChartPanel.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.
 * /* ww w  . j a  v a  2s .  c  o  m*/
 * @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 Point getPointInRectangle(int x, int y, Rectangle2D area) {
    x = (int) Math.max(Math.ceil(area.getMinX()), Math.min(x, Math.floor(area.getMaxX())));
    y = (int) Math.max(Math.ceil(area.getMinY()), Math.min(y, Math.floor(area.getMaxY())));
    return new Point(x, y);
}

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

/**
 * Draws a vertical line used to trace the mouse position to the horizontal axis.
 * //from   w  ww  .  j a v  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();

    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.gumtree.vis.plot1d.Plot1DPanel.java

private void makeNewMask(MouseEvent e) {
    Point2D screenPoint = translateScreenToJava2D(e.getPoint());
    if (Double.isNaN(maskPoint) || Math.abs(screenPoint.getX() - maskPoint) < minMaskWidth) {
        return;//from w  w  w  . jav a  2s .  co m
    }
    Graphics2D g2 = (Graphics2D) getGraphics();

    // erase the previous zoom rectangle (if any).  We only need to do
    // this is we are using XOR mode, which we do when we're not using
    // the buffer (if there is a buffer, then at the end of this method we
    // just trigger a repaint)
    if (!isDoubleBuffered()) {
        //          drawZoomRectangle(g2, true);
        ChartMaskingUtilities.drawMasks(g2, getScreenDataArea(), getMaskMap(), getSelectedMask(), getChart());
    }

    //       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.maskPoint.getX(), (int) this.maskPoint.getY());
    // Working on the current mask. Only create one new mask per drag-drawing.
    if (currentMaskRectangle == null) {
        boolean isInclusive = (e.getModifiers() & maskingExclusiveMask) == 0;
        currentMaskRectangle = new RangeMask(isInclusive);
        //           currentMaskRectangle.setFillColor(getNextMaskColor(isInclusive));
        //           getMasks().add(currentMaskRectangle);
        addMask(currentMaskRectangle);
    }
    // selected rectangle shouldn't extend outside the data area...
    double xmax = Math.min(e.getX(), scaledDataArea.getMaxX());
    // Update the current mask.
    Insets insets = getInsets();
    double startX = ChartMaskingUtilities.translateScreenX((maskPoint - insets.left) / getScaleX(),
            getScreenDataArea(), getChart());
    double endX = ChartMaskingUtilities.translateScreenX((xmax - insets.left) / getScaleX(),
            getScreenDataArea(), getChart());
    updateCurrentDomainMask(startX, endX);
    // Draw the new zoom rectangle...
    if (isDoubleBuffered()) {
        repaint();
    } else {
        // with no buffer, we use XOR to draw the rectangle "over" the
        // chart...
        ChartMaskingUtilities.drawMasks(g2, getScreenDataArea(), getMaskMap(), getSelectedMask(), getChart());
    }
    g2.dispose();
}

From source file:org.gumtree.vis.hist2d.Hist2DPanel.java

private void makeNewMask(MouseEvent e, EntityCollection entities) {
    if (this.maskPoint == null) {
        return;//from w  ww.j  a va 2s.  c om
    }
    Graphics2D g2 = (Graphics2D) getGraphics();

    // erase the previous zoom rectangle (if any).  We only need to do
    // this is we are using XOR mode, which we do when we're not using
    // the buffer (if there is a buffer, then at the end of this method we
    // just trigger a repaint)
    if (!isDoubleBuffered()) {
        //          drawZoomRectangle(g2, true);
        ChartMaskingUtilities.drawMasks(g2, getScreenDataArea(), getMaskMap(), getSelectedMask(), getChart());
    }

    //       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.maskPoint.getX(), (int) this.maskPoint.getY());
    // Working on the current mask. Only create one new mask per drag-drawing.
    if (currentMaskRectangle == null) {
        boolean isInclusive = (e.getModifiers() & maskingExclusiveMask) == 0;
        boolean isEllipse = (e.getModifiers() & MouseEvent.BUTTON3_MASK) != 0;
        if (isEllipse) {
            currentMaskRectangle = new EllipseMask(isInclusive);
        } else {
            currentMaskRectangle = new RectangleMask(isInclusive);
        }
        //           currentMaskRectangle.setFillColor(getNextMaskColor(isInclusive));
        //           getMasks().add(currentMaskRectangle);
        addMask(currentMaskRectangle);
    }
    // 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());
    // Update the current mask.
    ChartEntity startEntity = null;
    ChartEntity endEntity = null;
    boolean isMaskUpdated = false;
    if (entities != null) {
        //            EntityCollection entities = this.info.getEntityCollection();
        //            if (entities != null) {
        Insets insets = getInsets();
        double screenX = (maskPoint.getX() - insets.left) / getScaleX();
        double screenY = (maskPoint.getY() - insets.top) / getScaleY();
        startEntity = entities.getEntity(screenX, screenY);

        screenX = (xmax - insets.left) / getScaleX();
        screenY = (ymax - insets.top) / getScaleY();
        if (screenX >= scaledDataArea.getMaxX()) {
            screenX = scaledDataArea.getMaxX() - 0.001;
        }
        if (screenY >= scaledDataArea.getMaxY()) {
            screenY = scaledDataArea.getMaxY() - 0.001;
        }
        endEntity = entities.getEntity(screenX, screenY);
        //           System.out.println("Try to update mask");
        if (startEntity instanceof XYItemEntity && endEntity instanceof XYItemEntity) {
            isMaskUpdated = updateCurrentMaskRectangle((XYItemEntity) startEntity, (XYItemEntity) endEntity);
        }
        //            }
    }
    if (!isMaskUpdated) {
        currentMaskRectangle.setRectangleFrame(new Rectangle2D.Double(maskPoint.getX(), this.maskPoint.getY(),
                xmax - this.maskPoint.getX(), ymax - this.maskPoint.getY()));
    }
    // Draw the new zoom rectangle...
    if (isDoubleBuffered()) {
        repaint();
    } else {
        // with no buffer, we use XOR to draw the rectangle "over" the
        // chart...
        ChartMaskingUtilities.drawMasks(g2, getScreenDataArea(), getMaskMap(), getSelectedMask(), getChart());
    }
    g2.dispose();
}

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

/**
 * Handles a 'mouse dragged' event./*www  . j  a  v  a  2 s . com*/
 * 
 * @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

/**
 * Draws a vertical line used to trace the mouse position to the horizontal
 * axis./* w w w .  ja  va2s .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:com.isti.traceview.common.TraceViewChartPanel.java

/**
 * Draws a horizontal line used to trace the mouse position to the vertical axis.
 * /* 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();
}