Example usage for java.awt.geom Rectangle2D getMaxY

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

Introduction

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

Prototype

public double getMaxY() 

Source Link

Document

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

Usage

From source file:org.gvsig.remotesensing.scatterplot.chart.ScatterPlotDiagram.java

/**
 * Handles a 'mouse dragged' event.//from  w w  w  .ja va2 s .  c  o m
 *
 * @param e  the mouse event.
 */
public void mouseDragged(MouseEvent e) {

    // if the popup menu has already been triggered, then ignore dragging...
    if (this.popup != null && this.popup.isShowing()) {
        return;
    }
    // if no initial zoom point was set, ignore dragging...
    if (this.zoomPoint == null) {
        return;
    }
    Graphics2D g2 = (Graphics2D) getGraphics();

    // Erase the previous zoom rectangle (if any)...
    drawRectangle(g2);

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

    // Draw the new zoom rectangle...
    drawRectangle(g2);
    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.// www .j ava  2  s  . c om
 * 
 * @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.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 {// w w w. ja v  a2s .  c om
        //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.gvsig.remotesensing.scatterplot.chart.ScatterPlotDiagram.java

/**
 * @param selection .//from w  ww . j av  a  2 s  . c  om
 * @return range[] rangos del rectangulo
 */
public Range[] getRange(Rectangle2D selection) {

    Range[] rangos = new Range[2];

    // get the origin of the zoom selection in the Java2D space used for
    // drawing the chart (that is, before any scaling to fit the panel)
    Point2D selectOrigin = translateScreenToJava2D(
            new Point((int) Math.ceil(selection.getX()), (int) Math.ceil(selection.getY())));
    PlotRenderingInfo plotInfo = this.info.getPlotInfo();
    Rectangle2D scaledDataArea = getScreenDataArea((int) selection.getCenterX(), (int) selection.getCenterY());
    if ((selection.getHeight() > 0) && (selection.getWidth() > 0)) {

        double hLower = (selection.getMinX() - scaledDataArea.getMinX()) / scaledDataArea.getWidth();
        double hUpper = (selection.getMaxX() - scaledDataArea.getMinX()) / scaledDataArea.getWidth();
        double vLower = (scaledDataArea.getMaxY() - selection.getMaxY()) / scaledDataArea.getHeight();
        double vUpper = (scaledDataArea.getMaxY() - selection.getMinY()) / scaledDataArea.getHeight();

        Plot p = this.chart.getPlot();
        if (p instanceof ScatterPlotChart) {
            ScatterPlotChart z = (ScatterPlotChart) p;
            if (z.getOrientation() == PlotOrientation.HORIZONTAL) {
                rangos[0] = z.getRangeX(vLower, vUpper, plotInfo, selectOrigin);
                rangos[1] = z.getRangeY(hLower, hUpper, plotInfo, selectOrigin);
            } else {
                // devolver las coordenadas del rectangulo.
                rangos[0] = z.getRangeX(hLower, hUpper, plotInfo, selectOrigin);
                rangos[1] = z.getRangeY(vLower, vUpper, plotInfo, selectOrigin);
            }
        }

    }

    return rangos;
}

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 {//from   www .  ja v  a  2 s  .  co 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.gumtree.vis.hist2d.Hist2DPanel.java

private void changeMaskYMin(double y) {
    Rectangle2D frame = getSelectedMask().getRectangleFrame();
    getSelectedMask().setRectangleFrame(new Rectangle2D.Double(frame.getMinX(), Math.min(frame.getMaxY(), y),
            frame.getWidth(), Math.abs(frame.getMaxY() - y)));
}

From source file:Hexagon.java

public void align(Rectangle2D bounds, Direction direction) {
    // these are defined here INSTEAD of in the switch, or it won't compile
    Point2D newTopRight, newTopLeft, newBottomRight, newBottomLeft;
    Point2D oldTopRight, oldTopLeft, oldBottomRight, oldBottomLeft;

    switch (direction) {
    case NorthEast:
        newTopRight = new Point2D.Double(bounds.getMaxX(), bounds.getMinY());
        oldTopRight = boundingCorners.get(BoundingCorner.TopRight);
        translate(newTopRight.getX() - oldTopRight.getX(), // deltaX
                newTopRight.getY() - oldTopRight.getY() // deltaY
        );//from ww  w  . j  a  v a 2  s .co m
        break;
    case East:
        newTopRight = new Point2D.Double(bounds.getMaxX(), bounds.getMinY());
        oldTopRight = boundingCorners.get(BoundingCorner.TopRight);
        translate(newTopRight.getX() - oldTopRight.getX(), // deltaX
                0 // deltaY
        );
        break;
    case SouthEast:
        newBottomRight = new Point2D.Double(bounds.getMaxX(), bounds.getMaxY());
        oldBottomRight = boundingCorners.get(BoundingCorner.BottomRight);
        translate(newBottomRight.getX() - oldBottomRight.getX(), // deltaX
                newBottomRight.getY() - oldBottomRight.getY() // deltaY
        );
        break;
    case SouthWest:
        newBottomLeft = new Point2D.Double(bounds.getMinX(), bounds.getMaxY());
        oldBottomLeft = boundingCorners.get(BoundingCorner.BottomLeft);
        translate(newBottomLeft.getX() - oldBottomLeft.getX(), // deltaX
                newBottomLeft.getY() - oldBottomLeft.getY() // deltaY
        );
        break;
    case West:
        newTopLeft = new Point2D.Double(bounds.getMinX(), bounds.getMinY());
        oldTopLeft = boundingCorners.get(BoundingCorner.TopLeft);
        translate(newTopLeft.getX() - oldTopLeft.getX(), // deltaX
                0 // deltaY
        );
        break;
    case NorthWest:
        newTopLeft = new Point2D.Double(bounds.getMinX(), bounds.getMinY());
        oldTopLeft = boundingCorners.get(BoundingCorner.TopLeft);
        translate(newTopLeft.getX() - oldTopLeft.getX(), // deltaX
                newTopLeft.getY() - oldTopLeft.getY() // deltaY
        );
        break;
    }
}

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  . j  a  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:net.sf.maltcms.chromaui.charts.FastHeatMapPlot.java

/**
 * Draws the fast scatter plot on a Java 2D graphics device (such as the
 * screen or a printer).//from  ww  w. ja  va2s .c o  m
 *
 * @param g2 the graphics device.
 * @param area the area within which the plot (including axis labels) should
 * be drawn.
 * @param anchor the anchor point (<code>null</code> permitted).
 * @param parentState the state from the parent plot (ignored).
 * @param info collects chart drawing information (<code>null</code>
 * permitted).
 */
@Override
public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState,
        PlotRenderingInfo info) {

    // set up info collection...
    if (info != null) {
        info.setPlotArea(area);
    }

    // adjust the drawing area for plot insets (if any)...
    RectangleInsets insets = getInsets();
    insets.trim(area);

    AxisSpace space = new AxisSpace();
    space = this.domainAxis.reserveSpace(g2, this, area, RectangleEdge.BOTTOM, space);
    space = this.rangeAxis.reserveSpace(g2, this, area, RectangleEdge.LEFT, space);
    Rectangle2D dataArea = space.shrink(area, null);

    if (info != null) {
        info.setDataArea(dataArea);
    }

    // draw the plot background and axes...
    drawBackground(g2, dataArea);

    AxisState domainAxisState = this.domainAxis.draw(g2, dataArea.getMaxY(), area, dataArea,
            RectangleEdge.BOTTOM, info);
    AxisState rangeAxisState = this.rangeAxis.draw(g2, dataArea.getMinX(), area, dataArea, RectangleEdge.LEFT,
            info);
    drawDomainGridlines(g2, dataArea, domainAxisState.getTicks());
    drawRangeGridlines(g2, dataArea, rangeAxisState.getTicks());

    Shape originalClip = g2.getClip();
    Composite originalComposite = g2.getComposite();

    g2.clip(dataArea);
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha()));
    render(g2, dataArea, info, null);

    g2.setClip(originalClip);
    g2.setComposite(originalComposite);
    drawOutline(g2, dataArea);

}

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  a  va2s.  c  om*/
        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);
    }
}