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.jfree.chart.demo.CircleDrawer.java

/**
 * Draws the circle.//from  w ww . j av a2 s  .  c  o m
 * 
 * @param g2  the graphics device.
 * @param area  the area in which to draw.
 */
public void draw(final Graphics2D g2, final Rectangle2D area) {
    final Ellipse2D ellipse = new Ellipse2D.Double(area.getX(), area.getY(), area.getWidth(), area.getHeight());
    if (this.fillPaint != null) {
        g2.setPaint(this.fillPaint);
        g2.fill(ellipse);
    }
    if (this.outlinePaint != null && this.outlineStroke != null) {
        g2.setPaint(this.outlinePaint);
        g2.setStroke(this.outlineStroke);
        g2.draw(ellipse);
    }

    g2.setPaint(Color.black);
    g2.setStroke(new BasicStroke(1.0f));
    final Line2D line1 = new Line2D.Double(area.getCenterX(), area.getMinY(), area.getCenterX(),
            area.getMaxY());
    final Line2D line2 = new Line2D.Double(area.getMinX(), area.getCenterY(), area.getMaxX(),
            area.getCenterY());
    g2.draw(line1);
    g2.draw(line2);
}

From source file:de.hs.mannheim.modUro.controller.diagram.fx.interaction.ZoomHandlerFX.java

@Override
public void handleMouseReleased(ChartCanvas canvas, MouseEvent e) {
    Plot p = canvas.getChart().getPlot();
    if (!(p instanceof Zoomable)) {
        return;/*from  w w w .j  a v  a  2  s .  c  om*/
    }
    boolean hZoom, vZoom;
    Zoomable z = (Zoomable) p;
    if (z.getOrientation().isHorizontal()) {
        hZoom = z.isRangeZoomable();
        vZoom = z.isDomainZoomable();
    } else {
        hZoom = z.isDomainZoomable();
        vZoom = z.isRangeZoomable();
    }

    boolean zoomTrigger1 = hZoom && Math.abs(e.getX() - this.startPoint.getX()) >= 10;
    boolean zoomTrigger2 = vZoom && Math.abs(e.getY() - this.startPoint.getY()) >= 10;
    if (zoomTrigger1 || zoomTrigger2) {
        Point2D endPoint = new Point2D.Double(e.getX(), e.getY());
        PlotRenderingInfo pri = canvas.getRenderingInfo().getPlotInfo();
        if ((hZoom && (e.getX() < this.startPoint.getX())) || (vZoom && (e.getY() < this.startPoint.getY()))) {
            boolean saved = p.isNotify();
            p.setNotify(false);
            z.zoomDomainAxes(0, pri, endPoint);
            z.zoomRangeAxes(0, pri, endPoint);
            p.setNotify(saved);
        } else {
            double x = this.startPoint.getX();
            double y = this.startPoint.getY();
            double w = e.getX() - x;
            double h = e.getY() - y;
            Rectangle2D dataArea = canvas.findDataArea(this.startPoint);
            double maxX = dataArea.getMaxX();
            double maxY = dataArea.getMaxY();
            // for mouseReleased event, (horizontalZoom || verticalZoom)
            // will be true, so we can just test for either being false;
            // otherwise both are true
            if (!vZoom) {
                y = dataArea.getMinY();
                w = Math.min(w, maxX - this.startPoint.getX());
                h = dataArea.getHeight();
            } else if (!hZoom) {
                x = dataArea.getMinX();
                w = dataArea.getWidth();
                h = Math.min(h, maxY - this.startPoint.getY());
            } else {
                w = Math.min(w, maxX - this.startPoint.getX());
                h = Math.min(h, maxY - this.startPoint.getY());
            }
            Rectangle2D zoomArea = new Rectangle2D.Double(x, y, w, h);

            boolean saved = p.isNotify();
            p.setNotify(false);
            double pw0 = percentW(x, dataArea);
            double pw1 = percentW(x + w, dataArea);
            double ph0 = percentH(y, dataArea);
            double ph1 = percentH(y + h, dataArea);
            PlotRenderingInfo info = this.viewer.getRenderingInfo().getPlotInfo();
            if (z.getOrientation().isVertical()) {
                z.zoomDomainAxes(pw0, pw1, info, endPoint);
                z.zoomRangeAxes(1 - ph1, 1 - ph0, info, endPoint);
            } else {
                z.zoomRangeAxes(pw0, pw1, info, endPoint);
                z.zoomDomainAxes(1 - ph1, 1 - ph0, info, endPoint);
            }
            p.setNotify(saved);

        }
    }
    viewer.hideZoomRectangle();
    this.startPoint = null;
    canvas.clearLiveHandler();
}

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 2  s.c  o m
 * @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:org.esa.snap.rcp.statistics.ProfilePlotPanel.java

private ChartPanel createChartPanel(JFreeChart chart) {
    profilePlotDisplay = new ChartPanel(chart);

    MaskSelectionToolSupport maskSelectionToolSupport = new MaskSelectionToolSupport(this, profilePlotDisplay,
            "profile_plot_area", "Mask generated from selected profile plot area", Color.RED,
            PlotAreaSelectionTool.AreaType.Y_RANGE) {

        @Override/*  w ww  . j  a va  2s .  c  om*/
        protected String createMaskExpression(PlotAreaSelectionTool.AreaType areaType, Shape shape) {
            Rectangle2D bounds = shape.getBounds2D();
            return createMaskExpression(bounds.getMinY(), bounds.getMaxY());
        }

        protected String createMaskExpression(double x1, double x2) {
            String bandName = BandArithmetic.createExternalName(getRaster().getName());
            return String.format("%s >= %s && %s <= %s", bandName, x1, bandName, x2);
        }
    };

    profilePlotDisplay.addChartMouseListener(new XYPlotMarker(profilePlotDisplay, new XYPlotMarker.Listener() {
        @Override
        public void pointSelected(XYDataset xyDataset, int seriesIndex, Point2D dataPoint) {
            if (profileData != null) {
                GeoPos[] geoPositions = profileData.getGeoPositions();
                int index = (int) dataPoint.getX();
                if (index >= 0 && index < geoPositions.length) {
                    if (cursorSynchronizer == null) {
                        cursorSynchronizer = new DefaultCursorSynchronizer();
                    }
                    if (!cursorSynchronizer.isEnabled()) {
                        cursorSynchronizer.setEnabled(true);
                    }
                    cursorSynchronizer.updateCursorOverlays(geoPositions[index]);
                }
            }
        }

        @Override
        public void pointDeselected() {
            cursorSynchronizer.setEnabled(false);
        }
    }));
    profilePlotDisplay.setInitialDelay(200);
    profilePlotDisplay.setDismissDelay(1500);
    profilePlotDisplay.setReshowDelay(200);
    profilePlotDisplay.setZoomTriggerDistance(5);
    profilePlotDisplay.getPopupMenu().addSeparator();
    profilePlotDisplay.getPopupMenu().add(maskSelectionToolSupport.createMaskSelectionModeMenuItem());
    profilePlotDisplay.getPopupMenu().add(maskSelectionToolSupport.createDeleteMaskMenuItem());
    profilePlotDisplay.getPopupMenu().addSeparator();
    profilePlotDisplay.getPopupMenu().add(createCopyDataToClipboardMenuItem());

    return profilePlotDisplay;
}

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

private ChartPanel createChartPanel(JFreeChart chart) {
    profilePlotDisplay = new ChartPanel(chart);

    MaskSelectionToolSupport maskSelectionToolSupport = new MaskSelectionToolSupport(this, profilePlotDisplay,
            "profile_plot_area", "Mask generated from selected profile plot area", Color.RED,
            PlotAreaSelectionTool.AreaType.Y_RANGE) {

        @Override//from  ww  w . j  a  v a2  s. c o  m
        protected String createMaskExpression(PlotAreaSelectionTool.AreaType areaType, Shape shape) {
            Rectangle2D bounds = shape.getBounds2D();
            return createMaskExpression(bounds.getMinY(), bounds.getMaxY());
        }

        protected String createMaskExpression(double x1, double x2) {
            String bandName = BandArithmetic.createExternalName(getRaster().getName());
            return String.format("%s >= %s && %s <= %s", bandName, x1, bandName, x2);
        }
    };

    profilePlotDisplay.addChartMouseListener(new XYPlotMarker(profilePlotDisplay, new XYPlotMarker.Listener() {
        @Override
        public void pointSelected(XYDataset xyDataset, int seriesIndex, Point2D dataPoint) {
            if (profileData != null) {
                GeoPos[] geoPositions = profileData.getGeoPositions();
                int index = (int) dataPoint.getX();
                if (index >= 0 && index < geoPositions.length) {
                    if (cursorSynchronizer == null) {
                        cursorSynchronizer = new CursorSynchronizer(VisatApp.getApp());
                    }
                    if (!cursorSynchronizer.isEnabled()) {
                        cursorSynchronizer.setEnabled(true);
                    }
                    cursorSynchronizer.updateCursorOverlays(geoPositions[index]);
                }
            }
        }

        @Override
        public void pointDeselected() {
            cursorSynchronizer.setEnabled(false);
        }
    }));
    profilePlotDisplay.setInitialDelay(200);
    profilePlotDisplay.setDismissDelay(1500);
    profilePlotDisplay.setReshowDelay(200);
    profilePlotDisplay.setZoomTriggerDistance(5);
    profilePlotDisplay.getPopupMenu().addSeparator();
    profilePlotDisplay.getPopupMenu().add(maskSelectionToolSupport.createMaskSelectionModeMenuItem());
    profilePlotDisplay.getPopupMenu().add(maskSelectionToolSupport.createDeleteMaskMenuItem());
    profilePlotDisplay.getPopupMenu().addSeparator();
    profilePlotDisplay.getPopupMenu().add(createCopyDataToClipboardMenuItem());

    return profilePlotDisplay;
}

From source file:org.tsho.dmc2.core.chart.AbstractDmcPlot.java

private void drawDomainGridLine(Graphics2D g2, Rectangle2D dataArea, double value) {

    Range range = domainAxis.getRange();
    if (!range.contains(value)) {
        return;/*from w w w .  ja  v  a  2 s.co  m*/
    }

    Line2D line = null;
    double v = domainAxis.valueToJava2D(value, dataArea, RectangleEdge.BOTTOM);
    line = new Line2D.Double(v, dataArea.getMinY(), v, dataArea.getMaxY());

    g2.setPaint(gridPaint);
    g2.setStroke(gridStroke);
    g2.draw(line);

}

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

private void chooseROI(Abstract2DMask mask) {
    if (mask != null) {
        roiName.setText(mask.getName());
        if (mask instanceof EllipseMask) {
            shapeLabel.setText(ELLIPSE_SHAPE_LABEL);
        } else {//from  www .j a  v a 2  s .c  o m
            shapeLabel.setText(RECTANGLE_SHAPE_LABEL);
        }
        if (mask.isInclusive()) {
            inclusiveRadio.setSelected(true);
        } else {
            exclusiveRadio.setSelected(true);
        }
        Rectangle2D bounds = mask.getRectangleFrame();
        xMin.setText(String.valueOf(bounds.getMinX()));
        xMax.setText(String.valueOf(bounds.getMaxX()));
        yMin.setText(String.valueOf(bounds.getMinY()));
        yMax.setText(String.valueOf(bounds.getMaxY()));
        //         xMin.setText(String.format("%.2f", bounds.getMinX()));
        //         xMax.setText(String.format("%.2f", bounds.getMaxX()));
        //         yMin.setText(String.format("%.2f", bounds.getMinY()));
        //         yMax.setText(String.format("%.2f", bounds.getMaxY()));
        deleteButton.setEnabled(true);
    } else {
        roiName.setText(null);
        shapeLabel.setText(null);
        inclusiveRadio.setSelected(false);
        exclusiveRadio.setSelected(false);
        xMin.setText(null);
        xMax.setText(null);
        yMin.setText(null);
        yMax.setText(null);
    }
    applyButton.setEnabled(false);
}

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

/**
 *
 * @param arg0/*  www.ja  v  a 2 s . c om*/
 * @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:de.hs.mannheim.modUro.controller.diagram.fx.interaction.ZoomHandlerFX.java

/**
 * Handles a mouse dragged event by updating the zoom rectangle displayed
 * in the ChartViewer./*  w  w  w.j a v a 2 s .c om*/
 * 
 * @param canvas  the JavaFX canvas (<code>null</code> not permitted).
 * @param e  the mouse event (<code>null</code> not permitted).
 */
@Override
public void handleMouseDragged(ChartCanvas canvas, MouseEvent e) {
    if (this.startPoint == null) {
        //no initial zoom rectangle exists but the handler is set
        //as life handler unregister
        canvas.clearLiveHandler();
        return;
    }

    boolean hZoom, vZoom;
    Plot p = canvas.getChart().getPlot();
    if (!(p instanceof Zoomable)) {
        return;
    }
    Zoomable z = (Zoomable) p;
    if (z.getOrientation().isHorizontal()) {
        hZoom = z.isRangeZoomable();
        vZoom = z.isDomainZoomable();
    } else {
        hZoom = z.isDomainZoomable();
        vZoom = z.isRangeZoomable();
    }
    Rectangle2D dataArea = canvas.findDataArea(this.startPoint);

    double x = this.startPoint.getX();
    double y = this.startPoint.getY();
    double w = 0;
    double h = 0;
    if (hZoom && vZoom) {
        // selected rectangle shouldn't extend outside the data area...
        double xmax = Math.min(e.getX(), dataArea.getMaxX());
        double ymax = Math.min(e.getY(), dataArea.getMaxY());
        w = xmax - this.startPoint.getX();
        h = ymax - this.startPoint.getY();
    } else if (hZoom) {
        double xmax = Math.min(e.getX(), dataArea.getMaxX());
        y = dataArea.getMinY();
        w = xmax - this.startPoint.getX();
        h = dataArea.getHeight();
    } else if (vZoom) {
        double ymax = Math.min(e.getY(), dataArea.getMaxY());
        x = dataArea.getMinX();
        w = dataArea.getWidth();
        h = ymax - this.startPoint.getY();
    }
    viewer.showZoomRectangle(x, y, w, h);
}

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 ww . j  a  v  a2s  . co  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);
    }
}