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:peakml.util.jfreechart.LognAxis.java

@Override
public double java2DToValue(double java2DValue, Rectangle2D plotArea, RectangleEdge edge) {
    Range range = getRange();//  w ww  .j a v a2 s .  c  o  m
    double axisMin = log(range.getLowerBound());
    double axisMax = log(range.getUpperBound());

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

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

From source file:it.unibo.alchemist.model.implementations.linkingrules.ConnectionBeam.java

@Override
public Neighborhood<T> computeNeighborhood(final Node<T> center, final Environment<T> env) {
    final Neighborhood<T> normal = super.computeNeighborhood(center, env);
    if (oenv == null) {
        if (!(env instanceof Environment2DWithObstacles<?, ?>)) {
            return normal;
        }// w  w w  .  ja  v a2  s .c o  m
        oenv = (Environment2DWithObstacles<?, ?>) env;
        obstacles.reset();
        oenv.getObstacles().forEach((obs) -> {
            /*
             * Doubles are prone to approximation errors. Use nextAfter to get rid of them
             */
            final Rectangle2D bounds = obs.getBounds2D();
            final double mx = nextAfter(bounds.getMinX(), java.lang.Double.NEGATIVE_INFINITY);
            final double my = nextAfter(bounds.getMinY(), java.lang.Double.NEGATIVE_INFINITY);
            final double ex = nextUp(bounds.getMaxX());
            final double ey = nextUp(bounds.getMaxY());
            obstacles.add(new Area(new Rectangle2D.Double(mx, my, ex - mx, ey - my)));
        });
    }
    if (!normal.isEmpty()) {
        final Position cp = env.getPosition(center);
        final List<Node<T>> neighs = normal.getNeighbors().stream().filter((neigh) -> {
            final Position np = env.getPosition(neigh);
            return !oenv.intersectsObstacle(cp, np) || projectedBeamOvercomesObstacle(cp, np);
        }).collect(ArrayList::new, (l, el) -> l.add(el), (l1, l2) -> l1.addAll(l2));
        return Neighborhoods.make(env, center, neighs);
    }
    return normal;
}

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

@Override
public double valueToJava2D(double value, Rectangle2D plotArea, RectangleEdge edge) {
    Range range = getRange();/*from   ww  w.  ja  va 2  s .co  m*/
    double axisMin = log(range.getLowerBound());
    double axisMax = log(range.getUpperBound());

    double min = 0.0, 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 = log(value);
    if (isInverted())
        return max - (((value - axisMin) / (axisMax - axisMin)) * (max - min));
    else
        return min + (((value - axisMin) / (axisMax - axisMin)) * (max - min));
}

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   ww w.  j  a  v a 2s.  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);
}

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

@Override
public boolean render(Graphics2D g2, Rectangle2D dataArea, int index, PlotRenderingInfo info,
        CrosshairState crosshairState) {
    final boolean foundData = super.render(g2, dataArea, index, info, crosshairState);
    if (image != null) {
        final int dx1 = (int) dataArea.getMinX();
        final int dy1 = (int) dataArea.getMinY();
        final int dx2 = (int) dataArea.getMaxX();
        final int dy2 = (int) dataArea.getMaxY();

        synchronized (imageLock) {
            final Rectangle rectangle = getImageSourceArea();
            final int sx1 = rectangle.x;
            final int sy1 = rectangle.y;
            final int sx2 = sx1 + rectangle.width - 1;
            final int sy2 = sy1 + rectangle.height - 1;
            g2.drawImage(image, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, null);
        }/*  w  w w  . j a v a 2  s.  c  o m*/
    }
    return foundData;
}

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);//w  ww.  jav a2  s .  com
    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:Clip.java

/**
 * @see java.lang.Object#equals(java.lang.Object)
 *///from  w  w w  .  j a va 2 s  . c  om
public boolean equals(Object o) {
    if (o instanceof Rectangle2D) {
        Rectangle2D r = (Rectangle2D) o;
        return (r.getMinX() == clip[0] && r.getMinY() == clip[1] && r.getMaxX() == clip[6]
                && r.getMaxY() == clip[7]);
    } else if (o instanceof Clip) {
        Clip r = (Clip) o;
        if (r.status == status) {
            if (status == Clip.INUSE)
                return (r.clip[0] == clip[0] && r.clip[1] == clip[1] && r.clip[6] == clip[6]
                        && r.clip[7] == clip[7]);
            else
                return true;
        } else {
            return false;
        }
    } else {
        return false;
    }
}

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;
        }// w  w w. j  av a  2s .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: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/*from w ww .  ja va2 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:net.sf.maltcms.chromaui.annotations.XYSelectableShapeAnnotation.java

/**
 *
 * @param arg0//w w w .j  av a  2  s  . c o  m
 * @param arg1
 * @param arg2
 * @param arg3
 * @param arg4
 * @param arg5
 * @param arg6
 */
@Override
public void draw(Graphics2D arg0, XYPlot arg1, Rectangle2D arg2, ValueAxis arg3, ValueAxis arg4, int arg5,
        PlotRenderingInfo arg6) {
    //System.out.println("Annotation "+toString()+" is active: "+isActive());
    PlotOrientation orientation = arg1.getOrientation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(arg1.getDomainAxisLocation(), orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(arg1.getRangeAxisLocation(), orientation);

    // compute transform matrix elements via sample points. Assume no
    // rotation or shear.
    Rectangle2D bounds = this.s.getBounds2D();
    double x0 = bounds.getMinX();
    double x1 = bounds.getMaxX();
    double xx0 = arg3.valueToJava2D(x0, arg2, domainEdge);
    double xx1 = arg3.valueToJava2D(x1, arg2, domainEdge);
    double m00 = (xx1 - xx0) / (x1 - x0);
    double m02 = xx0 - x0 * m00;

    double y0 = bounds.getMaxY();
    double y1 = bounds.getMinY();
    double yy0 = arg4.valueToJava2D(y0, arg2, rangeEdge);
    double yy1 = arg4.valueToJava2D(y1, arg2, rangeEdge);
    double m11 = (yy1 - yy0) / (y1 - y0);
    double m12 = yy0 - m11 * y0;

    //  create transform & transform shape
    Shape s = null, ch = null;
    if (orientation == PlotOrientation.HORIZONTAL) {
        AffineTransform t1 = new AffineTransform(0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f);
        AffineTransform t2 = new AffineTransform(m11, 0.0f, 0.0f, m00, m12, m02);
        s = t1.createTransformedShape(this.s);
        s = t2.createTransformedShape(s);
        //            ch = t1.createTransformedShape(this.ch);
        //            ch = t2.createTransformedShape(ch);
    } else if (orientation == PlotOrientation.VERTICAL) {
        AffineTransform t = new AffineTransform(m00, 0, 0, m11, m02, m12);
        s = t.createTransformedShape(this.s);
        //            ch = t.createTransformedShape(this.ch);
    }

    if (this.active) {
        arg0.setPaint(this.highlight);
        //            double x = s.getBounds2D().getX();
        //            double y = s.getBounds2D().getY();
        //            double w = s.getBounds2D().getWidth();
        //            double h = s.getBounds2D().getHeight();
        //            Shape e = new Ellipse2D.Double(x, y, w, h);
        arg0.fill(s);
        arg0.setPaint(this.outline);
        arg0.draw(s);
        //            arg0.setStroke(this.stroke);
        //            arg0.draw(ch);
    } else {
        arg0.setPaint(this.fill);
        arg0.fill(s);
        arg0.setPaint(this.outline);
        arg0.draw(s);
    }
    addEntity(arg6, s, arg5, getToolTipText(), getURL());
    this.xyta.draw(arg0, arg1, arg2, arg3, arg4, arg5, arg6);
}