Example usage for java.awt.geom Rectangle2D getMinY

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

Introduction

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

Prototype

public double getMinY() 

Source Link

Document

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

Usage

From source file:org.esa.snap.rcp.statistics.DensityPlotPanel.java

@Override
protected String getDataAsText() {
    final BufferedImage image = plot.getImage();
    final Rectangle2D bounds = plot.getImageDataBounds();

    final byte[] data = getValidData(image);
    if (data == null) {
        return null;
    }//  w w  w  .  j a  v a2 s. c om

    final StringBuilder sb = new StringBuilder(64000);
    final int w = image.getWidth();
    final int h = image.getHeight();

    final RasterDataNode rasterX = getRaster(X_VAR);
    assert rasterX != null;
    final String nameX = rasterX.getName();
    final double sampleMinX = bounds.getMinX();
    final double sampleMaxX = bounds.getMaxX();

    final RasterDataNode rasterY = getRaster(Y_VAR);
    assert rasterY != null;
    final String nameY = rasterY.getName();
    final double sampleMinY = bounds.getMinY();
    final double sampleMaxY = bounds.getMaxY();

    sb.append("Product name:\t").append(rasterX.getProduct().getName()).append("\n");
    sb.append("Dataset X name:\t").append(nameX).append("\n");
    sb.append("Dataset Y name:\t").append(nameY).append("\n");
    sb.append('\n');
    sb.append(nameX).append(" minimum:\t").append(sampleMinX).append("\t").append(rasterX.getUnit())
            .append("\n");
    sb.append(nameX).append(" maximum:\t").append(sampleMaxX).append("\t").append(rasterX.getUnit())
            .append("\n");
    sb.append(nameX).append(" bin size:\t").append((sampleMaxX - sampleMinX) / w).append("\t")
            .append(rasterX.getUnit()).append("\n");
    sb.append(nameX).append(" #bins:\t").append(w).append("\n");
    sb.append('\n');
    sb.append(nameY).append(" minimum:\t").append(sampleMinY).append("\t").append(rasterY.getUnit())
            .append("\n");
    sb.append(nameY).append(" maximum:\t").append(sampleMaxY).append("\t").append(rasterY.getUnit())
            .append("\n");
    sb.append(nameY).append(" bin size:\t").append((sampleMaxY - sampleMinY) / h).append("\t")
            .append(rasterY.getUnit()).append("\n");
    sb.append(nameY).append(" #bins:\t").append(h).append("\n");
    sb.append('\n');

    sb.append(nameX);
    sb.append('\t');
    sb.append(nameY);
    sb.append('\t');
    sb.append("Bin counts\t(cropped at 255)");
    sb.append('\n');

    int x, y, z;
    double v1, v2;
    for (int i = 0; i < data.length; i++) {
        z = data[i] & 0xff;
        if (z != 0) {

            x = i % w;
            y = h - i / w - 1;

            v1 = sampleMinX + ((x + 0.5) * (sampleMaxX - sampleMinX)) / w;
            v2 = sampleMinY + ((y + 0.5) * (sampleMaxY - sampleMinY)) / h;

            sb.append(v1);
            sb.append('\t');
            sb.append(v2);
            sb.append('\t');
            sb.append(z);
            sb.append('\n');
        }
    }

    return sb.toString();
}

From source file:org.proteosuite.FastScatterPlot.java

/**
 * Draws the gridlines for the plot, if they are visible.
 *
 * @param g2  the graphics device.//w  w  w .j ava 2  s .  com
 * @param dataArea  the data area.
 * @param ticks  the ticks.
 */
protected void drawDomainGridlines(Graphics2D g2, Rectangle2D dataArea, List<ValueTick> ticks) {

    // draw the domain grid lines, if any...
    if (isDomainGridlinesVisible()) {
        Stroke gridStroke = getDomainGridlineStroke();
        Paint gridPaint = getDomainGridlinePaint();
        if ((gridStroke != null) && (gridPaint != null)) {
            Iterator<ValueTick> iterator = ticks.iterator();
            while (iterator.hasNext()) {
                ValueTick tick = (ValueTick) iterator.next();
                double v = this.domainAxis.valueToJava2D(tick.getValue(), dataArea, RectangleEdge.BOTTOM);
                Line2D line = new Line2D.Double(v, dataArea.getMinY(), v, dataArea.getMaxY());
                g2.setPaint(gridPaint);
                g2.setStroke(gridStroke);
                g2.draw(line);
            }
        }
    }
}

From source file:net.sf.maltcms.chromaui.chromatogram2Dviewer.ui.panel.Chromatogram2DViewerPanel.java

public void setViewport(Rectangle2D rect) {
    //ignore viewport changes if we have the focus
    if (hasFocus()) {
        Logger.getLogger(getClass().getName()).info("Ignoring viewport update since we have the focus!");
    } else {/*from  w w w.  ja  v a 2 s.c o  m*/
        //otherwise, clear our own viewport and set to new value
        if (this.viewport != null) {
            this.content.remove(this.viewport);
        }
        this.viewport = new Chromatogram2DViewViewport(rect);
        Logger.getLogger(getClass().getName()).info("Setting viewport!");
        removeAxisListener();
        this.chartPanel.getChart().getXYPlot().getDomainAxis().setLowerBound(rect.getMinX());
        this.chartPanel.getChart().getXYPlot().getDomainAxis().setUpperBound(rect.getMaxX());
        this.chartPanel.getChart().getXYPlot().getRangeAxis().setLowerBound(rect.getMinY());
        this.chartPanel.getChart().getXYPlot().getRangeAxis().setUpperBound(rect.getMaxY());
        addAxisListener();
    }
}

From source file:org.gumtree.vis.awt.CompositePanel.java

@Override
public void draw(Graphics2D g2, Rectangle2D area, double shiftX, double shiftY) {
    Rectangle2D compositeBounds = getBounds();
    double xRatio = area.getWidth() / compositeBounds.getWidth();
    double yRatio = area.getHeight() / compositeBounds.getHeight();
    for (IPlot plot : plotList) {
        if (plot instanceof JPanel) {
            Rectangle2D plotBounds = ((JPanel) plot).getBounds();
            Rectangle2D newArea = new Rectangle2D.Double(area.getMinX() + plotBounds.getMinX() * xRatio,
                    area.getMinY() + plotBounds.getMinY() * yRatio, plotBounds.getWidth() * xRatio,
                    plotBounds.getHeight() * yRatio);
            plot.draw(g2, newArea, shiftX, shiftY);
        }/*from w w w  .j a  v  a2  s.co m*/
    }
}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.link_and_brush.LinkAndBrushChartPanel.java

@Override
public void mouseDragged(MouseEvent e) {
    // when not allowed to zoom / select, return
    if (blockSelectionOrZoom) {
        return;//from  ww  w.  j  av a2 s.  c  om
    }
    // if the popup menu has already been triggered, then ignore dragging...
    if (getChartFieldValueByName("popup") != null
            && ((JPopupMenu) getChartFieldValueByName("popup")).isShowing()) {
        return;
    }

    // handle panning if we have a start point
    if (getChartFieldValueByName("panLast") != null) {
        double dx = e.getX() - ((Point) getChartFieldValueByName("panLast")).getX();
        double dy = e.getY() - ((Point) getChartFieldValueByName("panLast")).getY();
        if (dx == 0.0 && dy == 0.0) {
            return;
        }
        double wPercent = -dx / ((Double) getChartFieldValueByName("panW"));
        double hPercent = dy / ((Double) getChartFieldValueByName("panH"));
        boolean old = getChart().getPlot().isNotify();
        getChart().getPlot().setNotify(false);
        Pannable p = (Pannable) getChart().getPlot();
        if (p.getOrientation() == PlotOrientation.VERTICAL) {
            p.panDomainAxes(wPercent, getChartRenderingInfo().getPlotInfo(),
                    (Point) getChartFieldValueByName("panLast"));
            p.panRangeAxes(hPercent, getChartRenderingInfo().getPlotInfo(),
                    (Point) getChartFieldValueByName("panLast"));
        } else {
            p.panDomainAxes(hPercent, getChartRenderingInfo().getPlotInfo(),
                    (Point) getChartFieldValueByName("panLast"));
            p.panRangeAxes(wPercent, getChartRenderingInfo().getPlotInfo(),
                    (Point) getChartFieldValueByName("panLast"));
        }
        setChartFieldValue((getChartFieldByName("panLast")), e.getPoint());
        getChart().getPlot().setNotify(old);
        return;
    }

    // if no initial zoom point was set, ignore dragging...
    if (getChartFieldValueByName("zoomPoint") == null) {
        return;
    }
    Graphics2D g2 = (Graphics2D) getGraphics();

    // erase the previous zoom rectangle (if any). We only need to do
    // this is we are using XOR mode, which we do when we're not using
    // the buffer (if there is a buffer, then at the end of this method we
    // just trigger a repaint)
    if (!(Boolean) getChartFieldValueByName("useBuffer")) {
        drawZoomRectangle(g2, true);
    }

    boolean hZoom = false;
    boolean vZoom = false;
    if ((PlotOrientation) getChartFieldValueByName("orientation") == PlotOrientation.HORIZONTAL) {
        hZoom = (Boolean) getChartFieldValueByName("rangeZoomable");
        vZoom = (Boolean) getChartFieldValueByName("domainZoomable");
    } else {
        hZoom = (Boolean) getChartFieldValueByName("domainZoomable");
        vZoom = (Boolean) getChartFieldValueByName("rangeZoomable");
    }
    Point2D zoomPoint = (Point2D) getChartFieldValueByName("zoomPoint");
    Rectangle2D scaledDataArea = getScreenDataArea((int) zoomPoint.getX(), (int) zoomPoint.getY());
    if (hZoom && vZoom) {
        // 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());
        setChartFieldValue(getChartFieldByName("zoomRectangle"), new Rectangle2D.Double(zoomPoint.getX(),
                zoomPoint.getY(), xmax - zoomPoint.getX(), ymax - zoomPoint.getY()));
    } else if (hZoom) {
        double xmax = Math.min(e.getX(), scaledDataArea.getMaxX());
        setChartFieldValue(getChartFieldByName("zoomRectangle"), new Rectangle2D.Double(zoomPoint.getX(),
                scaledDataArea.getMinY(), xmax - zoomPoint.getX(), scaledDataArea.getHeight()));
    } else if (vZoom) {
        double ymax = Math.min(e.getY(), scaledDataArea.getMaxY());
        setChartFieldValue(getChartFieldByName("zoomRectangle"),
                new Rectangle2D.Double(scaledDataArea.getMinX(), zoomPoint.getY(), scaledDataArea.getWidth(),
                        ymax - zoomPoint.getY()));
    }

    // Draw the new zoom rectangle...
    if ((Boolean) getChartFieldValueByName("useBuffer")) {
        repaint();
    } else {
        // with no buffer, we use XOR to draw the rectangle "over" the
        // chart...
        drawZoomRectangle(g2, true);
    }
    g2.dispose();

}

From source file:gda.plots.TurboXYItemRenderer.java

/**
 * Draws the visual representation of a single data item. This mostly reproduces the code of StandardXYItemRenderer
 * but using the line by line information stored in the SimpleXYSeries instead of the series indexed information
 * stored in the Renderer itself.//from w  ww  .ja v  a 2s  .c o m
 * 
 * @param g2
 *            the graphics device.
 * @param state
 *            the renderer state.
 * @param dataArea
 *            the area within which the data is being drawn.
 * @param info
 *            collects information about the drawing.
 * @param plot
 *            the plot (can be used to obtain standard color information etc).
 * @param domainAxis
 *            the domain axis.
 * @param rangeAxis
 *            the range axis.
 * @param dataset
 *            the dataset.
 * @param series
 *            the series index (zero-based).
 * @param crosshairState
 *            crosshair information for the plot ( <code>null</code> permitted).
 * @param pass
 *            the pass index.
 */
@Override
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info,
        XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int _item,
        CrosshairState crosshairState, int pass) {

    if (_item > 0)
        return;
    SimpleXYSeries sxys = (SimpleXYSeries) ((SimpleXYSeriesCollection) dataset).getSeries(series);
    if (!sxys.isVisible()) {
        return;
    }

    PlotOrientation orientation = plot.getOrientation();
    g2.setPaint(sxys.getPaint());
    g2.setStroke(sxys.getStroke());

    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();

    try {
        int x0 = -1; // the x position in pixels of the previous point
        int y0 = -1; // the y position in pixels of the previous point
        int x1 = -1; // the x position in pixels of the current point
        int y1 = -1; // the y position in pixels of the current point
        int xmin = (int) dataArea.getMinX();
        int xmax = (int) dataArea.getMaxX();
        int ymin = (int) dataArea.getMinY();
        int ymax = (int) dataArea.getMaxY();
        GeneralPath path = null;

        /*
         * To remove the time spent repeatedly calling domainAxis.valueToJava2D for linear axes use simple linear
         * maths
         */
        double xl = 0., mx = Double.NaN, cx = 0.;
        if (domainAxis instanceof SimpleNumberAxis) {
            xl = domainAxis.getRange().getLowerBound();
            mx = dataArea.getWidth() / (domainAxis.getRange().getUpperBound() - xl);
            cx = xmin;
        }
        double yl = 0., my = Double.NaN, cy = 0.;
        if (rangeAxis instanceof SimpleNumberAxis) {
            yl = rangeAxis.getRange().getLowerBound();
            my = -dataArea.getHeight() / (rangeAxis.getRange().getUpperBound() - yl);
            cy = ymax;
        }
        List<XYDataItem> list = sxys.getData();

        boolean MX_MY_NaN = Double.isNaN(mx) || Double.isNaN(my);
        Paint paint = sxys.getPaint();
        Stroke stroke = sxys.getStroke();
        Paint paint_symbol = sxys.getSymbolPaint();
        Stroke stroke_symbol = new BasicStroke();
        drawLines = sxys.isDrawLines();
        boolean filled = sxys.getFilled();
        Shape shape = sxys.getSymbol();
        boolean drawMarkers = sxys.isDrawMarkers() & shape != null;
        int tooltipThresholdCounts = -1; /* number of points to be shown below which markers are also to be drawn */
        if (drawLines && drawMarkers && shape != null && tooltipThreshold != 0) {
            Rectangle shapeBoundingBox = shape.getBounds();
            tooltipThresholdCounts = (int) dataArea.getWidth()
                    / (Math.max(1, shapeBoundingBox.width) * tooltipThreshold);
        }

        java.util.Vector<ddouble> markerPositions = null;
        Shape entityArea = null;
        EntityCollection entities = null;
        if (info != null) {
            entities = info.getOwner().getEntityCollection();
        }
        boolean prevLineAdded = false;
        // In case the iterator does not work then use the TODO comment iterator use and why not always
        // comment variables
        synchronized (list) {
            Iterator<XYDataItem> iter = list.iterator();
            /*
             * loop over all points calculating X1 and Y1. Store previous points positions into X0 and Y0 The
             * variable addThis determines if the current point is to be added to the path If previous line was
             * added that the current must be even if off the screen - but in this case the flag prevLineAdded is
             * set false so that the next does not have to be added.
             */
            for (int item = 0; iter.hasNext(); item++, x0 = x1, y0 = y1, x1 = -1, y1 = -1) {
                XYDataItem dataitem = iter.next();
                double x = dataitem.getX().doubleValue();
                double y = dataitem.getY().doubleValue();
                x = xValueTransformer.transformValue(x);

                x1 = MX_MY_NaN ? (int) domainAxis.valueToJava2D(x, dataArea, xAxisLocation)
                        : (int) ((x - xl) * mx + cx);
                y1 = MX_MY_NaN ? (int) rangeAxis.valueToJava2D(y, dataArea, yAxisLocation)
                        : (int) ((y - yl) * my + cy);

                boolean addThis = true;
                if (item == 0) {
                    x0 = x1;
                    y0 = y1;
                    if ((x1 < xmin) || (x1 > xmax) || (y1 < ymin) || (y1 > ymax)) {
                        addThis = false;
                    }
                } else {
                    if (x1 == x0 && y1 == y0) {
                        addThis = false;
                    }
                    if ((x1 < xmin && x0 < xmin) || (x1 > xmax && x0 > xmax) || (y1 < ymin && y0 < ymin)
                            || (y1 > ymax && y0 > ymax)) {
                        if (prevLineAdded) {
                            path = addPointToLine(path, orientation, x1, y1);
                        }
                        addThis = false;
                    }
                }
                if (addThis) {
                    /*
                     * If the current point is to be added then ensure previous one is as well to prevent lines
                     * not crossing the edge of the screen
                     */
                    if (!prevLineAdded) {
                        path = addPointToLine(path, orientation, x0, y0);
                    }
                    path = addPointToLine(path, orientation, x1, y1);
                    prevLineAdded = true;
                }
                prevLineAdded = addThis;
                if (addThis && drawMarkers) {
                    if (markerPositions == null) {
                        markerPositions = new java.util.Vector<ddouble>();
                    }
                    markerPositions.add(new ddouble(item, x1, y1));
                    if (tooltipThresholdCounts != -1 && markerPositions.size() > tooltipThresholdCounts) {
                        drawMarkers = false;
                        markerPositions = null;
                    }
                }
            }
            if (path != null) {
                g2.setStroke(stroke);
                g2.setPaint(paint);
                g2.draw(path);
            }
            if (markerPositions != null) {
                if (drawMarkers) {
                    g2.setPaint(paint_symbol);
                    g2.setStroke(stroke_symbol);
                    for (ddouble dd : markerPositions) {
                        Shape shape_item = ShapeUtilities.createTranslatedShape(shape, dd.x, dd.y);
                        if (filled) {
                            g2.fill(shape_item);
                        } else {
                            g2.draw(shape_item);
                        }
                        entityArea = shape_item;
                        // add an entity for the item...
                        if (entities != null) {
                            addEntity(entities, entityArea, dataset, series, dd.item, dd.x, dd.y);
                        }
                    }
                    g2.setPaint(paint);
                    g2.setStroke(stroke);
                }
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:net.sf.maltcms.chromaui.chromatogram1Dviewer.ui.panel.Chromatogram1DHeatmapViewerPanel.java

public void setViewport(Rectangle2D rect) {
    //ignore viewport changes if we have the focus
    if (hasFocus()) {
        Logger.getLogger(getClass().getName()).info("Ignoring viewport update since we have the focus!");
    } else {//  w ww  .  j  ava  2s .c  o  m
        //otherwise, clear our own viewport and set to new value
        if (this.viewport != null) {
            this.content.remove(this.viewport);
        }
        this.viewport = new ChromatogramViewViewport(rect);
        Logger.getLogger(getClass().getName()).info("Setting viewport!");
        removeAxisListener();
        this.chartPanel.getChart().getXYPlot().getDomainAxis().setLowerBound(rect.getMinX());
        this.chartPanel.getChart().getXYPlot().getDomainAxis().setUpperBound(rect.getMaxX());
        this.chartPanel.getChart().getXYPlot().getRangeAxis().setLowerBound(rect.getMinY());
        this.chartPanel.getChart().getXYPlot().getRangeAxis().setUpperBound(rect.getMaxY());
        addAxisListener();
    }
}

From source file:org.kalypso.ogc.sensor.diagview.jfreechart.ObservationPlot.java

/**
 * Draw alarmlevels (horizontal line and text annotation)
 *//*w  w  w  .  j a  v a 2  s  .  c  o  m*/
private void drawAlarmLevels(final Graphics2D g2, final Rectangle2D dataArea) {
    for (final Object element : m_yConsts.keySet()) {
        final AlarmLevelPlotElement vac = m_yConsts.get(element);

        final ValueAxis axis = m_diag2chartAxis.get(vac.getAxis());
        if (axis == null)
            continue;

        if (axis.getRange().contains(vac.getAlarm().value)) {
            final double yy = axis.valueToJava2D(vac.getAlarm().value, dataArea, RectangleEdge.LEFT);
            final Line2D line = new Line2D.Double(dataArea.getMinX(), yy, dataArea.getMaxX(), yy);
            // always set stroke, else we got the stroke from the last drawn line
            g2.setStroke(AlarmLevelPlotElement.STROKE_ALARM);
            g2.setPaint(vac.getAlarm().color);
            g2.draw(line);

            // and draw the text annotation: if annotation is outside (on top); label it below the line
            if (yy < dataArea.getMinY() + 20)
                vac.getAnnotation().setAngle(Math.toRadians(20));
            else
                vac.getAnnotation().setAngle(Math.toRadians(340));

            vac.getAnnotation().draw(g2, this, dataArea, getDomainAxis(), axis);
        }
    }
}

From source file:org.tsho.dmc2.core.chart.jfree.DmcChartPanel.java

private double userY(MouseEvent event) {
    Rectangle2D rectangle = getScaledDataArea();
    double minY = rectangle.getMinY();
    double maxY = rectangle.getMaxY();
    Plot plot = chart.getPlot();/*w  w w .  ja v a  2 s .  c o  m*/
    int yc = event.getY();

    ValueAxis ya = this.getVerticalValueAxis(plot);
    double ymin = ya.getLowerBound();
    double ymax = ya.getUpperBound();
    double v = (yc - minY) / (maxY - minY);
    v = 1 - v;
    return (v * (ymax - ymin) + ymin);
}

From source file:org.gumtree.vis.hist2d.Hist2DPanel.java

@Override
protected void drawToolTipFollower(Graphics2D g2, int x, int y) {
    Rectangle2D dataArea = getScreenDataArea();
    if (((int) dataArea.getMinX() < x) && (x < (int) dataArea.getMaxX()) && ((int) dataArea.getMinY() < y)
            && (y < (int) dataArea.getMaxY())) {
        String text = String.format("(%." + mouseFollowerXPrecision + "f, %." + mouseFollowerYPrecision
                + "f, %." + mouseFollowerZPrecision + "f)", getChartX(), getChartY(), getChartZ());
        int xLoc = x + 10;
        int yLoc = y + 20;
        double width = text.length() * 5.5;
        double height = 15;
        if (xLoc + width > dataArea.getMaxX()) {
            xLoc = (int) (x - width);
        }/*from w  w  w  . j  av a 2  s.  co m*/
        if (yLoc + height > dataArea.getMaxY()) {
            yLoc = (int) (y - height);
        }

        Rectangle2D toolTipArea = new Rectangle2D.Double(xLoc, yLoc, width, height);
        g2.setColor(Color.white);
        g2.fill(toolTipArea);
        g2.setColor(Color.black);
        g2.drawString(text, xLoc + 3, yLoc + 11);
    }
}