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: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   ww  w. jav  a  2  s. com*/
 * @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: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  ww  . jav a 2  s .com*/
    }
    return foundData;
}

From source file:edu.uci.ics.jung.visualization.util.VertexShapeFactory.java

/**
 * Returns a regular <code>num_sides</code>-sided 
 * <code>Polygon</code> whose bounding 
 * box's width and height are defined by this instance's size and
 * aspect ratio functions for this vertex.
 * @param num_sides the number of sides of the polygon; must be >= 3.
 *//*from w  w w .j  av a 2 s.com*/
public Shape getRegularPolygon(V v, int num_sides) {
    if (num_sides < 3)
        throw new IllegalArgumentException("Number of sides must be >= 3");
    Rectangle2D frame = getRectangle(v);
    float width = (float) frame.getWidth();
    float height = (float) frame.getHeight();

    // generate coordinates
    double angle = 0;
    thePolygon.reset();
    thePolygon.moveTo(0, 0);
    thePolygon.lineTo(width, 0);
    double theta = (2 * Math.PI) / num_sides;
    for (int i = 2; i < num_sides; i++) {
        angle -= theta;
        float delta_x = (float) (width * Math.cos(angle));
        float delta_y = (float) (width * Math.sin(angle));
        Point2D prev = thePolygon.getCurrentPoint();
        thePolygon.lineTo((float) prev.getX() + delta_x, (float) prev.getY() + delta_y);
    }
    thePolygon.closePath();

    // scale polygon to be right size, translate to center at (0,0)
    Rectangle2D r = thePolygon.getBounds2D();
    double scale_x = width / r.getWidth();
    double scale_y = height / r.getHeight();
    float translationX = (float) (r.getMinX() + r.getWidth() / 2);
    float translationY = (float) (r.getMinY() + r.getHeight() / 2);

    AffineTransform at = AffineTransform.getScaleInstance(scale_x, scale_y);
    at.translate(-translationX, -translationY);

    Shape shape = at.createTransformedShape(thePolygon);
    return shape;
}

From source file:edu.uci.ics.jung.visualization.util.VertexShapeFactory.java

/**
 * Returns a regular <code>Polygon</code> of <code>num_points</code>
 * points whose bounding //www  . jav  a2s . c o  m
 * box's width and height are defined by this instance's size and
 * aspect ratio functions for this vertex.
 * @param num_points the number of points of the polygon; must be >= 5.
 */
public Shape getRegularStar(V v, int num_points) {
    if (num_points < 5)
        throw new IllegalArgumentException("Number of sides must be >= 5");
    Rectangle2D frame = getRectangle(v);
    float width = (float) frame.getWidth();
    float height = (float) frame.getHeight();

    // generate coordinates
    double theta = (2 * Math.PI) / num_points;
    double angle = -theta / 2;
    thePolygon.reset();
    thePolygon.moveTo(0, 0);
    float delta_x = width * (float) Math.cos(angle);
    float delta_y = width * (float) Math.sin(angle);
    Point2D prev = thePolygon.getCurrentPoint();
    thePolygon.lineTo((float) prev.getX() + delta_x, (float) prev.getY() + delta_y);
    for (int i = 1; i < num_points; i++) {
        angle += theta;
        delta_x = width * (float) Math.cos(angle);
        delta_y = width * (float) Math.sin(angle);
        prev = thePolygon.getCurrentPoint();
        thePolygon.lineTo((float) prev.getX() + delta_x, (float) prev.getY() + delta_y);
        angle -= theta * 2;
        delta_x = width * (float) Math.cos(angle);
        delta_y = width * (float) Math.sin(angle);
        prev = thePolygon.getCurrentPoint();
        thePolygon.lineTo((float) prev.getX() + delta_x, (float) prev.getY() + delta_y);
    }
    thePolygon.closePath();

    // scale polygon to be right size, translate to center at (0,0)
    Rectangle2D r = thePolygon.getBounds2D();
    double scale_x = width / r.getWidth();
    double scale_y = height / r.getHeight();

    float translationX = (float) (r.getMinX() + r.getWidth() / 2);
    float translationY = (float) (r.getMinY() + r.getHeight() / 2);

    AffineTransform at = AffineTransform.getScaleInstance(scale_x, scale_y);
    at.translate(-translationX, -translationY);

    Shape shape = at.createTransformedShape(thePolygon);
    return shape;
}

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);//ww  w .  j  a  v a2s .c om
        getDomainAxis().setRange(imageDataBounds.getMinX(), imageDataBounds.getMaxX());
        getRangeAxis().setRange(imageDataBounds.getMinY(), imageDataBounds.getMaxY());
    }
}

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

@Override
public double valueToJava2D(double value, Rectangle2D plotArea, RectangleEdge edge) {
    Range range = getRange();//from w ww  . ja v a  2  s .  com
    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;//  w w w . j  av  a  2  s. c  o  m
    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:Clip.java

/**
 * @see java.lang.Object#equals(java.lang.Object)
 *///w w  w .j  a v a 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:net.sourceforge.processdash.ui.lib.chart.DiscPlot.java

private void drawLegendAxis(Graphics2D g2, Rectangle2D dataArea, PlotRenderingInfo info) {
    if (legendAxis != null) {
        double cursor = dataArea.getMinX();
        legendAxis.draw(g2, cursor, dataArea, dataArea, RectangleEdge.RIGHT, info);
    }/*from w  w  w. ja v  a 2 s  . c  om*/
}

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 va 2s . 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);
}