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.logisticPlanning.utils.graphics.chart.impl.jfree._JFCLineChart2D.java

/**
 * Creates a rectangle that is aligned to the frame.
 *
 * @param dimensions// w w w  .  ja  va2  s .  c o  m
 *          the dimensions for the rectangle.
 * @param frame
 *          the frame to align to.
 * @param hAlign
 *          the horizontal alignment.
 * @param vAlign
 *          the vertical alignment.
 * @return A rectangle.
 */
private static final Rectangle2D __createAlignedRectangle2D(final Size2D dimensions, final Rectangle2D frame,
        final HorizontalAlignment hAlign, final VerticalAlignment vAlign) {
    double x, y;

    x = y = Double.NaN;

    if (hAlign == HorizontalAlignment.LEFT) {
        x = frame.getX();
    } else if (hAlign == HorizontalAlignment.CENTER) {
        x = frame.getCenterX() - (dimensions.width / 2.0);
    } else if (hAlign == HorizontalAlignment.RIGHT) {
        x = frame.getMaxX() - dimensions.width;
    }
    if (vAlign == VerticalAlignment.TOP) {
        y = frame.getY();
    } else if (vAlign == VerticalAlignment.CENTER) {
        y = frame.getCenterY() - (dimensions.height / 2.0);
    } else if (vAlign == VerticalAlignment.BOTTOM) {
        y = frame.getMaxY() - dimensions.height;
    }

    return new Rectangle2D.Double(x, y, dimensions.width, dimensions.height);
}

From source file:org.gumtree.vis.mask.ChartMaskingUtilities.java

private static void drawMaskBoarder(Graphics2D g2, Abstract2DMask mask) {
    g2.setPaint(Color.orange);//from  w  ww.  j  a va 2s.  c o m
    g2.setStroke(new BasicStroke(1));
    Rectangle2D frame = mask.getRectangleFrame();
    g2.draw(frame);
    Rectangle2D dragPoint = new Rectangle2D.Double(frame.getMinX() - maskDragPointHalfWidth,
            frame.getMinY() - maskDragPointHalfWidth, maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getCenterX() - maskDragPointHalfWidth, frame.getMinY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getMaxX() - maskDragPointHalfWidth, frame.getMinY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getMaxX() - maskDragPointHalfWidth, frame.getCenterY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getMinX() - maskDragPointHalfWidth, frame.getCenterY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getMinX() - maskDragPointHalfWidth, frame.getMaxY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getCenterX() - maskDragPointHalfWidth, frame.getMaxY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getMaxX() - maskDragPointHalfWidth, frame.getMaxY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    Color fillColor = new Color(250, 250, 50, 10);
    g2.setPaint(fillColor);
    g2.fill(mask.getShape());
}

From source file:org.gumtree.vis.mask.ChartMaskingUtilities.java

public static void drawMaskBoarder(Graphics2D g2, Rectangle2D frame) {
    g2.setPaint(Color.orange);/*from   www  .  j  a va  2  s  . com*/
    g2.setStroke(new BasicStroke(1));
    g2.draw(frame);
    Rectangle2D dragPoint = new Rectangle2D.Double(frame.getMinX() - maskDragPointHalfWidth,
            frame.getMinY() - maskDragPointHalfWidth, maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getCenterX() - maskDragPointHalfWidth, frame.getMinY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getMaxX() - maskDragPointHalfWidth, frame.getMinY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getMaxX() - maskDragPointHalfWidth, frame.getCenterY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getMinX() - maskDragPointHalfWidth, frame.getCenterY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getMinX() - maskDragPointHalfWidth, frame.getMaxY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getCenterX() - maskDragPointHalfWidth, frame.getMaxY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    dragPoint.setRect(frame.getMaxX() - maskDragPointHalfWidth, frame.getMaxY() - maskDragPointHalfWidth,
            maskDragPointWidth, maskDragPointWidth);
    g2.fill(dragPoint);
    Color fillColor = new Color(250, 250, 50, 30);
    g2.setPaint(fillColor);
    g2.fill(frame);
}

From source file:ec.util.chart.swing.JTimeSeriesRendererSupport.java

private static Shape createShape(double x, double y, Rectangle2D hotspot) {
    Area result = new Area(new RoundRectangle2D.Double(hotspot.getX(), hotspot.getY(), hotspot.getWidth(),
            hotspot.getHeight(), 8, 8));

    boolean right = hotspot.getMinX() > x;

    Polygon po = new Polygon();
    po.addPoint(0, 0);/*from ww w  .  j  a  v a 2s . c o  m*/
    po.addPoint(0, 10);
    po.addPoint(10, 0);
    AffineTransform af = new AffineTransform();
    if (right) {
        af.translate(hotspot.getX() - 7, hotspot.getY() + hotspot.getHeight() / 2);
        af.rotate(-Math.PI / 4);
    } else {
        af.translate(hotspot.getMaxX() + 7, hotspot.getY() + hotspot.getHeight() / 2);
        af.rotate(Math.PI * 3 / 4);
    }

    Shape shape = af.createTransformedShape(po);
    result.add(new Area(shape));
    return result;
}

From source file:org.fhcrc.cpl.toolbox.gui.chart.ChartMouseAndMotionListener.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. j av  a  2 s .c  om
 * @param y  the y-coordinate.
 * @param area  the rectangle (<code>null</code> not permitted).
 *
 * @return A point within the rectangle.
 */
protected 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:org.fhcrc.cpl.toolbox.gui.chart.ChartMouseAndMotionListener.java

/**
 * Transform a mouse X value into a value in the units of the X axis of the chart.
 * Note: if there were multiple subplots, this would need to take a MouseEvent to determine which one
 * Note: bounds the raw value by the boundaries of the chart.  No using values off the ends, even if you're zoomed
 * @param rawValue/*from  www.j  a  v a  2  s  . c  om*/
 * @return
 */
protected double transformMouseXValue(double rawValue) {
    Rectangle2D screenDataArea = _chartPanel.getScreenDataArea();
    double boundedValue = Math.min(screenDataArea.getMaxX(), Math.max(screenDataArea.getMinX(), rawValue));

    double leftmostOnAxis = domainAxis.getLowerBound();
    double rightmostOnAxis = domainAxis.getUpperBound();
    double leftmostonscreen = screenDataArea.getX();
    double rightmostonscreen = leftmostonscreen + screenDataArea.getWidth();
    double slope = (rightmostOnAxis - leftmostOnAxis) / (rightmostonscreen - leftmostonscreen);
    return ((slope * (boundedValue - leftmostonscreen)) + leftmostOnAxis);
}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.legend.CustomLegendGraphic.java

@Override
public void draw(Graphics2D g2, Rectangle2D area) {

    area = trimMargin(area);//  www.ja  va2  s .  co  m
    drawBorder(g2, area);
    area = trimBorder(area);
    area = trimPadding(area);

    if (isLineVisible()) {
        Point2D location = RectangleAnchor.coordinates(area, getShapeLocation());
        Shape aLine = ShapeUtilities.createTranslatedShape(getLine(), getShapeAnchor(), location.getX(),
                location.getY());
        g2.setPaint(getLinePaint());
        g2.setStroke(getLineStroke());
        g2.draw(aLine);
    }

    if (isShapeVisible()) {
        Point2D location = RectangleAnchor.coordinates(area, getShapeLocation());

        Shape s = ShapeUtilities.createTranslatedShape(getShape(), getShapeAnchor(), location.getX(),
                location.getY());
        if (isShapeFilled()) {
            Paint p = getFillPaint();
            if (p instanceof GradientPaint) {
                GradientPaint gp = (GradientPaint) getFillPaint();
                p = getFillPaintTransformer().transform(gp, s);
            } else if (p instanceof LinearGradientPaint) {
                LinearGradientPaint gradient = (LinearGradientPaint) p;
                Rectangle2D bounds = s.getBounds2D();
                p = getTranslatedLinearGradientPaint(gradient,
                        new Point2D.Double(bounds.getMinX(), bounds.getMinY()),
                        new Point2D.Double(bounds.getMaxX(), bounds.getMaxY()), false);
            }
            g2.setPaint(p);
            g2.fill(s);
        }
        if (isShapeOutlineVisible()) {
            g2.setPaint(getOutlinePaint());
            g2.setStroke(getOutlineStroke());
            g2.draw(s);
        }
    }

}

From source file:Bounce.java

/**
 * Moves the ball to the next position, reversing direction if it hits one of
 * the edges/*from  www. ja  v  a2s . co m*/
 */
public void move(Rectangle2D bounds) {
    x += dx;
    y += dy;
    if (x < bounds.getMinX()) {
        x = bounds.getMinX();
        dx = -dx;
    }
    if (x + XSIZE >= bounds.getMaxX()) {
        x = bounds.getMaxX() - XSIZE;
        dx = -dx;
    }
    if (y < bounds.getMinY()) {
        y = bounds.getMinY();
        dy = -dy;
    }
    if (y + YSIZE >= bounds.getMaxY()) {
        y = bounds.getMaxY() - YSIZE;
        dy = -dy;
    }
}

From source file:de.hs.mannheim.modUro.controller.diagram.fx.interaction.ZoomHandlerFX.java

@Override
public void handleMouseReleased(ChartCanvas canvas, MouseEvent e) {
    Plot p = canvas.getChart().getPlot();
    if (!(p instanceof Zoomable)) {
        return;//from w w  w . j  a  v  a  2 s  . c  om
    }
    boolean hZoom, vZoom;
    Zoomable z = (Zoomable) p;
    if (z.getOrientation().isHorizontal()) {
        hZoom = z.isRangeZoomable();
        vZoom = z.isDomainZoomable();
    } else {
        hZoom = z.isDomainZoomable();
        vZoom = z.isRangeZoomable();
    }

    boolean zoomTrigger1 = hZoom && Math.abs(e.getX() - this.startPoint.getX()) >= 10;
    boolean zoomTrigger2 = vZoom && Math.abs(e.getY() - this.startPoint.getY()) >= 10;
    if (zoomTrigger1 || zoomTrigger2) {
        Point2D endPoint = new Point2D.Double(e.getX(), e.getY());
        PlotRenderingInfo pri = canvas.getRenderingInfo().getPlotInfo();
        if ((hZoom && (e.getX() < this.startPoint.getX())) || (vZoom && (e.getY() < this.startPoint.getY()))) {
            boolean saved = p.isNotify();
            p.setNotify(false);
            z.zoomDomainAxes(0, pri, endPoint);
            z.zoomRangeAxes(0, pri, endPoint);
            p.setNotify(saved);
        } else {
            double x = this.startPoint.getX();
            double y = this.startPoint.getY();
            double w = e.getX() - x;
            double h = e.getY() - y;
            Rectangle2D dataArea = canvas.findDataArea(this.startPoint);
            double maxX = dataArea.getMaxX();
            double maxY = dataArea.getMaxY();
            // for mouseReleased event, (horizontalZoom || verticalZoom)
            // will be true, so we can just test for either being false;
            // otherwise both are true
            if (!vZoom) {
                y = dataArea.getMinY();
                w = Math.min(w, maxX - this.startPoint.getX());
                h = dataArea.getHeight();
            } else if (!hZoom) {
                x = dataArea.getMinX();
                w = dataArea.getWidth();
                h = Math.min(h, maxY - this.startPoint.getY());
            } else {
                w = Math.min(w, maxX - this.startPoint.getX());
                h = Math.min(h, maxY - this.startPoint.getY());
            }
            Rectangle2D zoomArea = new Rectangle2D.Double(x, y, w, h);

            boolean saved = p.isNotify();
            p.setNotify(false);
            double pw0 = percentW(x, dataArea);
            double pw1 = percentW(x + w, dataArea);
            double ph0 = percentH(y, dataArea);
            double ph1 = percentH(y + h, dataArea);
            PlotRenderingInfo info = this.viewer.getRenderingInfo().getPlotInfo();
            if (z.getOrientation().isVertical()) {
                z.zoomDomainAxes(pw0, pw1, info, endPoint);
                z.zoomRangeAxes(1 - ph1, 1 - ph0, info, endPoint);
            } else {
                z.zoomRangeAxes(pw0, pw1, info, endPoint);
                z.zoomDomainAxes(1 - ph1, 1 - ph0, info, endPoint);
            }
            p.setNotify(saved);

        }
    }
    viewer.hideZoomRectangle();
    this.startPoint = null;
    canvas.clearLiveHandler();
}

From source file:org.esa.beam.visat.toolviews.stat.XYImagePlot.java

public void setImageDataBounds(Rectangle2D imageDataBounds) {
    synchronized (imageLock) {
        this.imageDataBounds = (Rectangle2D) imageDataBounds.clone();
        DefaultXYDataset xyDataset = new DefaultXYDataset();
        xyDataset.addSeries("Image Data Bounds",
                new double[][] { { imageDataBounds.getMinX(), imageDataBounds.getMaxX() },
                        { imageDataBounds.getMinY(), imageDataBounds.getMaxY() } });
        setDataset(xyDataset);/*  w w  w  .  j a  v a  2s .  c  o  m*/
        getDomainAxis().setRange(imageDataBounds.getMinX(), imageDataBounds.getMaxX());
        getRangeAxis().setRange(imageDataBounds.getMinY(), imageDataBounds.getMaxY());
    }
}