Example usage for java.awt.geom Rectangle2D getMaxY

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

Introduction

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

Prototype

public double getMaxY() 

Source Link

Document

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

Usage

From source file:net.sf.maltcms.chromaui.annotations.PeakAnnotationRenderer.java

private VisualPeakAnnotation generateTriangle(double startX, double startY, double apexX, double apexY,
        double stopX, double stopY) {
    GeneralPath path = new GeneralPath();
    path.moveTo(startX, startY);//www .  ja  v a 2  s .  c  o  m
    path.lineTo(apexX, apexY);
    path.lineTo(stopX, stopY);
    path.closePath();
    Rectangle2D r = path.getBounds2D();
    return new VisualPeakAnnotation(path, new Point2D.Double(r.getCenterX(), r.getMaxY()),
            PeakAnnotationType.POINTER);
}

From source file:Bounce.java

/**
 * Moves the ball to the next position, reversing direction if it hits one of
 * the edges/*from  w  w  w.  j  a  va 2  s .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:peakml.util.jfreechart.FastTimePlot.java

@Override
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState,
        PlotRenderingInfo info) {/*w  w w  .ja  v  a2s . co m*/
    // add the plot area to the info (used amongst other by the axis for zooming)
    if (info != null)
        info.setPlotArea(area);

    // add the insets (if any)
    RectangleInsets insets = getInsets();
    insets.trim(area);

    // draw the axis and add the dataArea to the info (used amongst other by the axis for zooming)
    AxisSpace space = new AxisSpace();
    space = xaxis.reserveSpace(g2, this, area, RectangleEdge.BOTTOM, space);
    space = yaxis.reserveSpace(g2, this, area, RectangleEdge.LEFT, space);

    Rectangle2D dataArea = space.shrink(area, null);
    if (info != null)
        info.setDataArea(dataArea);

    // flood fill the whole area with the background color
    drawBackground(g2, dataArea);

    // draw the axis
    xaxis.draw(g2, dataArea.getMaxY(), area, dataArea, RectangleEdge.BOTTOM, info);
    yaxis.draw(g2, dataArea.getMinX(), area, dataArea, RectangleEdge.LEFT, info);

    // sanity check
    if (dataseries.size() == 0)
        return;

    // clip the draw area
    Shape originalclip = g2.getClip();
    g2.clip(dataArea);

    // draw all the values
    int index = 0;
    for (Data data : dataseries.values()) {
        g2.setColor(new Color(data.color == -1 ? colormap.getColor(index++) : data.color));
        for (int i = 0; i < data.size - 1; ++i) {
            g2.drawLine((int) xaxis.valueToJava2D(data.time[i], dataArea, RectangleEdge.BOTTOM),
                    (int) yaxis.valueToJava2D(data.values[i], dataArea, RectangleEdge.LEFT),
                    (int) xaxis.valueToJava2D(data.time[i + 1], dataArea, RectangleEdge.BOTTOM),
                    (int) yaxis.valueToJava2D(data.values[i + 1], dataArea, RectangleEdge.LEFT));
        }
    }

    // reset
    g2.setClip(originalclip);
}

From source file:peakml.util.jfreechart.FastErrorBarPlot.java

@Override
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState,
        PlotRenderingInfo info) {/*from w w w . j  a  v a 2s  .  c  o m*/
    // add the plot area to the info (used amongst other by the axis for zooming)
    if (info != null)
        info.setPlotArea(area);

    // add the insets (if any)
    RectangleInsets insets = getInsets();
    insets.trim(area);

    // draw the axis and add the dataArea to the info (used amongst other by the axis for zooming)
    AxisSpace space = new AxisSpace();
    space = xaxis.reserveSpace(g2, this, area, RectangleEdge.BOTTOM, space);
    space = yaxis.reserveSpace(g2, this, area, RectangleEdge.LEFT, space);

    Rectangle2D dataArea = space.shrink(area, null);
    if (info != null)
        info.setDataArea(dataArea);

    // flood fill the whole area with the background color
    drawBackground(g2, dataArea);

    // draw the axis
    xaxis.draw(g2, dataArea.getMaxY(), area, dataArea, RectangleEdge.BOTTOM, info);
    yaxis.draw(g2, dataArea.getMinX(), area, dataArea, RectangleEdge.LEFT, info);

    // sanity check
    if (dataseries.size() == 0)
        return;

    // clip the draw area
    Shape originalclip = g2.getClip();
    g2.clip(dataArea);

    // create the strokes
    BasicStroke stroke_solid = new BasicStroke(1.f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 1.f);
    BasicStroke stroke_dashed = new BasicStroke(1.f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 1.f,
            new float[] { 2, 4 }, 0);

    g2.setStroke(stroke_solid);

    // count the number of labels
    int categoryCount = 0;
    if (showall) {
        for (Data data : dataseries)
            categoryCount += data.yvalues.length;
    } else
        categoryCount = dataseries.size();

    // draw all the values
    int pos = 0;
    boolean dashed = false;
    double prevx = -1, prevy = -1;
    for (Data data : dataseries) {
        if (data.yvalues.length == 0) {
            dashed = true;
            pos++;
            continue;
        }

        double mean[] = showall ? data.yvalues : new double[] { data.getMeanY() };
        double min[] = showall ? data.yvalues : new double[] { data.getMinY() };
        double max[] = showall ? data.yvalues : new double[] { data.getMaxY() };
        for (int i = 0; i < mean.length; ++i) {
            double ypos, xpos = xaxis.getCategoryJava2DCoordinate(CategoryAnchor.MIDDLE, pos++, categoryCount,
                    dataArea, RectangleEdge.BOTTOM);

            // draw the mean value
            g2.setColor(Color.RED);
            ypos = yaxis.valueToJava2D(mean[i], dataArea, RectangleEdge.LEFT);
            g2.drawLine((int) xpos - 2, (int) ypos, (int) xpos + 2, (int) ypos);

            // conect the dots
            if (prevx != -1 && prevy != -1) {
                g2.setColor(Color.BLACK);
                if (dashed)
                    g2.setStroke(stroke_dashed);
                g2.drawLine((int) prevx, (int) prevy, (int) xpos, (int) ypos);
                if (dashed) {
                    dashed = false;
                    g2.setStroke(stroke_solid);
                }

            }
            prevy = ypos;
            prevx = xpos;

            // draw the outer values
            g2.setColor(Color.LIGHT_GRAY);
            double ypos_min = yaxis.valueToJava2D(min[i], dataArea, RectangleEdge.LEFT);
            g2.drawLine((int) xpos - 2, (int) ypos_min, (int) xpos + 2, (int) ypos_min);
            double ypos_max = yaxis.valueToJava2D(max[i], dataArea, RectangleEdge.LEFT);
            g2.drawLine((int) xpos - 2, (int) ypos_max, (int) xpos + 2, (int) ypos_max);
            g2.drawLine((int) xpos, (int) ypos_min, (int) xpos, (int) ypos_max);
        }
    }

    // reset
    g2.setClip(originalclip);
}

From source file:com.controlj.addon.gwttree.server.OpaqueBarRenderer3D.java

@Override
public void drawBackground(Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea) {

    float x0 = (float) dataArea.getX();
    float x1 = x0 + (float) Math.abs(getXOffset());
    float x3 = (float) dataArea.getMaxX();
    float x2 = x3 - (float) Math.abs(getXOffset());

    float y0 = (float) dataArea.getMaxY();
    float y1 = y0 - (float) Math.abs(getYOffset());
    float y3 = (float) dataArea.getMinY();
    float y2 = y3 + (float) Math.abs(getYOffset());

    GeneralPath clip = new GeneralPath();
    clip.moveTo(x0, y0);/*from  w w  w. j  a  v a2s.c  om*/
    clip.lineTo(x0, y2);
    clip.lineTo(x1, y3);
    clip.lineTo(x3, y3);
    clip.lineTo(x3, y1);
    clip.lineTo(x2, y0);
    clip.closePath();

    Composite originalComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, plot.getBackgroundAlpha()));

    // fill background...
    Paint backgroundPaint = plot.getBackgroundPaint();
    if (backgroundPaint != null) {
        g2.setPaint(backgroundPaint);
        g2.fill(clip);
    }

    GeneralPath bottomWall = new GeneralPath();
    bottomWall.moveTo(x0, y0);
    bottomWall.lineTo(x1, y1);
    bottomWall.lineTo(x3, y1);
    bottomWall.lineTo(x2, y0);
    bottomWall.closePath();
    g2.setPaint(getWallPaint());
    g2.fill(bottomWall);

    // draw background image, if there is one...
    Image backgroundImage = plot.getBackgroundImage();
    if (backgroundImage != null) {
        Rectangle2D adjusted = new Rectangle2D.Double(dataArea.getX() + getXOffset(), dataArea.getY(),
                dataArea.getWidth() - getXOffset(), dataArea.getHeight() - getYOffset());
        plot.drawBackgroundImage(g2, adjusted);
    }

    g2.setComposite(originalComposite);

}

From source file:org.jfree.eastwood.GXYPlot.java

/**
 * Draws the background for the plot./*from w  w  w .  jav  a  2  s.  c  om*/
 *
 * @param g2  the graphics device.
 * @param area  the area.
 */
public void drawBackground(Graphics2D g2, Rectangle2D area) {
    Paint p = getBackgroundPaint();
    if (p instanceof GradientPaint) {
        // do the transformation directly
        GradientPaint gp = (GradientPaint) p;
        double r = (this.f1 - this.f0) * area.getWidth();
        Point2D p0 = new Point2D.Double(area.getMinX() + this.f0 * area.getWidth(), area.getMaxY());
        Point2D p1 = new Point2D.Double(p0.getX() + r * Math.cos(this.angle),
                p0.getY() - r * Math.sin(this.angle));
        p = new GradientPaint(p0, gp.getColor1(), p1, gp.getColor2());
    }
    g2.setPaint(p);
    g2.fill(area);
}

From source file:Clip.java

/**
 * Union this clip with another region. As a result, this clip
 * will become a bounding box around the two original regions.
 * @param r the rectangle to union with/*  www.  j  a v a 2  s .  c o m*/
 */
public void union(Rectangle2D r) {
    if (status == INVALID)
        return;

    double minx = r.getMinX();
    double miny = r.getMinY();
    double maxx = r.getMaxX();
    double maxy = r.getMaxY();

    if (Double.isNaN(minx) || Double.isNaN(miny) || Double.isNaN(maxx) || Double.isNaN(maxy)) {
        Logger.getLogger(getClass().getName()).warning("Union with invalid clip region: " + r);
        return;
    }

    if (status == EMPTY) {
        setClip(r);
        status = INUSE;
        return;
    }
    clip[0] = Math.min(clip[0], minx);
    clip[1] = Math.min(clip[1], miny);
    clip[6] = Math.max(clip[6], maxx);
    clip[7] = Math.max(clip[7], maxy);
}

From source file:org.fhcrc.cpl.viewer.mrm.utilities.MRMerMouseListener.java

public void mouseDragged(MouseEvent e) {
    if ((e.isShiftDown() || e.getButton() == MouseEvent.BUTTON3) || shifted) {
        if (this.coElutionStart == null) {
            return;
        }/*ww w.ja v  a  2  s.  c  o  m*/
        Graphics2D g2 = (Graphics2D) _cp.getGraphics();
        if (this.coElutionRegion != null)
            drawCoElutionRegion(g2);
        if (e.getX() < this.coElutionStart.getX())
            return;
        // Erase the previous zoom rectangle (if any)...
        Rectangle2D scaledDataArea = _cp.getScreenDataArea((int) this.coElutionStart.getX(),
                (int) this.coElutionStart.getY());

        // 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.coElutionRegion = new Rectangle2D.Double(
                this.coElutionStart.getX(), this.coElutionStart.getY(),
                xmax - this.coElutionStart.getX(), ymax - this.coElutionStart.getY());
        */
        this.coElutionRegion = new Rectangle2D.Double(this.coElutionStart.getX(), scaledDataArea.getMinY(),
                Math.abs(e.getX() - coElutionStart.getX()), scaledDataArea.getHeight());

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

        g2.dispose();

    } else {
        _cp.mouseDragged(e);
    }
}

From source file:net.sourceforge.processdash.ui.lib.chart.DiscLegendAxis.java

/**
 * Converts a disc area to a coordinate in Java2D space on the legend axis.
 *//*w ww .j av a  2 s. c  o m*/
@Override
public double valueToJava2D(double value, Rectangle2D area, RectangleEdge edge) {

    if (discItemDistributor == null) {
        // This should not happen since prior to using a legend axis, a DiscPlot
        //  should set a DiscItemDistributor.
        return 0.0;
    }

    double discRadius = Math.sqrt(Math.abs(value) / Math.PI);
    double discDiameter = 2 * discRadius;
    double scaledDiameter = discDiameter * discItemDistributor.getScale();
    double java2DValue = area.getMaxY() - scaledDiameter;

    return java2DValue;
}

From source file:edu.jhuapl.graphs.jfreechart.utils.SparselyLabeledCategoryAxis.java

private void drawDomainGridline(Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea, double value) {
    Line2D line = null;//from  w  w w. ja  v  a2s. c  om
    PlotOrientation orientation = plot.getOrientation();

    if (orientation == PlotOrientation.HORIZONTAL) {
        line = new Line2D.Double(dataArea.getMinX(), value, dataArea.getMaxX(), value);
    } else if (orientation == PlotOrientation.VERTICAL) {
        line = new Line2D.Double(value, dataArea.getMinY(), value, dataArea.getMaxY());
    }

    g2.setPaint(domainGridlinePaint);
    Stroke stroke = plot.getDomainGridlineStroke();

    if (stroke == null) {
        stroke = CategoryPlot.DEFAULT_GRIDLINE_STROKE;
    }

    g2.setStroke(stroke);
    g2.draw(line);
}