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.knime.knip.core.ui.imgviewer.panels.HistogramBC.java

private XYAnnotation slopeLine() {
    return new XYAnnotation() {

        private double x1, y1, x2, y2;

        @Override// w w  w. j a v a  2  s  . co  m
        public void removeChangeListener(final AnnotationChangeListener listener) {
            // ignore
        }

        @Override
        public void addChangeListener(final AnnotationChangeListener listener) {
            // ignore
        }

        @Override
        public void draw(final Graphics2D g2, final XYPlot plot, final Rectangle2D dataArea,
                final ValueAxis domainAxis, final ValueAxis rangeAxis, final int rendererIndex,
                final PlotRenderingInfo info) {
            calcLineCoords(dataArea);
            drawLine(g2);
        }

        private void drawLine(final Graphics2D g2) {
            final Color origColor = g2.getColor();
            g2.setColor(Color.black);
            g2.drawLine((int) x1, (int) y1, (int) x2, (int) y2);
            g2.setColor(Color.lightGray);
            g2.drawLine((int) x1, 0, (int) x1, 192);
            g2.drawLine((int) x2, 0, (int) x2, 192);
            g2.setColor(origColor);
        }

        @SuppressWarnings("synthetic-access")
        private void calcLineCoords(final Rectangle2D rect) {
            // offset necessary since chart is not drawn on whole rectangle
            int offset = 12;
            final double x = rect.getMinX() + offset;
            final double y = rect.getMinY();
            final double w = rect.getWidth() - 2 * offset;
            final double h = rect.getHeight();
            final double min = bundle.getTheoreticalMin();
            final double max = bundle.getTheoreticalMax();
            final double defaultMin = bundle.getDataMin();
            final double defaultMax = bundle.getDataMax();
            final double scale = w / (defaultMax - defaultMin);
            double slope = 0.0;
            if (max != min) {
                slope = h / (max - min);
            }
            if (min >= defaultMin) {
                x1 = scale * (min - defaultMin);
                y1 = h;
            } else {
                x1 = 0;
                if (max > min) {
                    y1 = h - ((defaultMin - min) * slope);
                } else {
                    y1 = h;
                }
            }
            if (max <= defaultMax) {
                x2 = (scale * (max - defaultMin));
                y2 = 0;
            } else {
                x2 = w;
                if (max > min) {
                    y2 = h - ((defaultMax - min) * slope);
                } else {
                    y2 = 0;
                }
            }
            x1 += x;
            x2 += x;
            y1 += y;
            y2 += y;
        }
    };
}

From source file:ro.cs.products.landsat.LandsatSearch.java

@Override
public void setAreaOfInterest(Polygon2D polygon) {
    super.setAreaOfInterest(polygon);
    final Rectangle2D bounds2D = polygon.getBounds2D();
    this.keyValues.add(new BasicNameValuePair("upperLeftCornerLatitude", String.valueOf(bounds2D.getMaxY())));
    this.keyValues.add(new BasicNameValuePair("lowerRightCornerLatitude", String.valueOf(bounds2D.getMinY())));
    this.keyValues.add(new BasicNameValuePair("lowerLeftCornerLongitude", String.valueOf(bounds2D.getMinX())));
    this.keyValues.add(new BasicNameValuePair("upperRightCornerLongitude", String.valueOf(bounds2D.getMaxX())));
}

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

/**
 *
 * @param arg0//w  w  w . ja v  a2 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);
}

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

/**
 * Draws the background for the plot./*from   w  w w . j a  va  2 s  .co m*/
 *
 * @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:org.jax.maanova.plot.MaanovaChartPanel.java

/**
 * Convert the given rectangle in java2d coordinates to chart coordinates.
 * @param java2DRectangle the rectangle to convert
 * @return the converted rectangle//from ww w. j  a  v  a 2s .com
 * @throws ClassCastException the plot isn't an XYPlot
 */
public Rectangle2D toChartRectangle(Rectangle2D java2DRectangle) throws ClassCastException {
    XYPlot plot = this.getChart().getXYPlot();
    Rectangle2D dataArea = this.chartRenderingInfo.getPlotInfo().getDataArea();

    double x1 = plot.getDomainAxis().java2DToValue(java2DRectangle.getMinX(), dataArea,
            plot.getDomainAxisEdge());
    double y1 = plot.getRangeAxis().java2DToValue(java2DRectangle.getMinY(), dataArea, plot.getRangeAxisEdge());
    double x2 = plot.getDomainAxis().java2DToValue(java2DRectangle.getMaxX(), dataArea,
            plot.getDomainAxisEdge());
    double y2 = plot.getRangeAxis().java2DToValue(java2DRectangle.getMaxY(), dataArea, plot.getRangeAxisEdge());

    return toNonNegativeWidthHeightRectangle(new Rectangle2D.Double(x1, y1, x2 - x1, y2 - y1));
}

From source file:Clip.java

/**
 * Intersect this clip with another region. As a result, this
 * clip will become the intersecting area of the two regions.
 * @param r the rectangle to intersect with
 *///  w  w w .j  a  va 2s  .co  m
public void intersection(Rectangle2D r) {
    if (status == INVALID)
        return;
    if (status == EMPTY) {
        setClip(r);
        status = INUSE;
        return;
    }
    clip[0] = Math.max(clip[0], r.getMinX());
    clip[1] = Math.max(clip[1], r.getMinY());
    clip[6] = Math.min(clip[6], r.getMaxX());
    clip[7] = Math.min(clip[7], r.getMaxY());
}

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

@Override
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState,
        PlotRenderingInfo info) {/*ww w.  ja  va 2s .com*/
    // 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
    for (Data data : dataseries) {
        int xpos = (int) xaxis.valueToJava2D(data.mass, dataArea, RectangleEdge.BOTTOM);
        int ypos = (int) yaxis.valueToJava2D(data.intensity, dataArea, RectangleEdge.LEFT);
        g2.drawLine(xpos, (int) yaxis.valueToJava2D(0, dataArea, RectangleEdge.LEFT), xpos, ypos);

        // draw the label
        if (data.description != null && data.description.length() != 0) {
            g2.setColor(Color.RED);
            g2.drawLine(xpos + 2, ypos - 2, xpos + 15, ypos - 15);
            g2.setColor(Color.BLACK);
            g2.drawString(data.description, xpos + 17, ypos - 17);
        }
    }

    // reset
    g2.setClip(originalclip);
}

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

@Override
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState,
        PlotRenderingInfo info) {//from  www .  jav a 2 s  .com
    // 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  ww .ja v a  2  s.  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:gda.plots.DataMagnifierWindow.java

/**
 * The SimplePlot will call this method when the Rectangle to be magnified has changed.
 * /* ww  w . ja  v a  2  s.  co  m*/
 * @param magnifyRectangle
 *            the Rectangle to be magnified
 */
@Override
public void update(Rectangle2D magnifyRectangle) {

    // The magnifyRectangle will be in Java coordinates, need to calculate
    // the axis limits required. This mechanism was copied from the zooming
    // methods within JFreeChart.

    double hLower = 0.0;
    double hUpper = 0.0;
    double vLower = 0.0;
    double vUpper = 0.0;
    double a;
    double b;
    Rectangle2D scaledDataArea;
    if (magnifyRectangle != null) {
        scaledDataArea = simplePlot.getScreenDataArea();
        hLower = (magnifyRectangle.getMinX() - scaledDataArea.getMinX()) / scaledDataArea.getWidth();
        hUpper = (magnifyRectangle.getMaxX() - scaledDataArea.getMinX()) / scaledDataArea.getWidth();
        vLower = (scaledDataArea.getMaxY() - magnifyRectangle.getMaxY()) / scaledDataArea.getHeight();
        vUpper = (scaledDataArea.getMaxY() - magnifyRectangle.getMinY()) / scaledDataArea.getHeight();

        Range r = simplePlot.getChart().getXYPlot().getDomainAxis().getRange();
        a = r.getLowerBound() + hLower * r.getLength();
        b = r.getLowerBound() + hUpper * r.getLength();
        Range newR = new Range(Math.min(a, b), Math.max(a, b));
        magnifiedPlot.getDomainAxis().setRange(newR);

        r = simplePlot.getChart().getXYPlot().getRangeAxis().getRange();
        a = r.getLowerBound() + vLower * r.getLength();
        b = r.getLowerBound() + vUpper * r.getLength();
        newR = new Range(Math.min(a, b), Math.max(a, b));
        magnifiedPlot.getRangeAxis().setRange(newR);

        repaint();
    }
}