Example usage for java.awt.geom Rectangle2D contains

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

Introduction

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

Prototype

public boolean contains(double x, double y) 

Source Link

Usage

From source file:com.gargoylesoftware.htmlunit.html.HtmlArea.java

/**
 * Indicates if this area contains the specified point.
 * @param x the x coordinate of the point
 * @param y the y coordinate of the point
 * @return {@code true} if the point is contained in this area
 *//*from   w  w  w .j av  a2 s.  c om*/
boolean containsPoint(final int x, final int y) {
    final String shape = StringUtils.defaultIfEmpty(getShapeAttribute(), "rect").toLowerCase(Locale.ROOT);

    if ("default".equals(shape) && getCoordsAttribute() != null) {
        return true;
    }

    if ("rect".equals(shape) && getCoordsAttribute() != null) {
        final Rectangle2D rectangle = parseRect();
        return rectangle.contains(x, y);
    }

    if ("circle".equals(shape) && getCoordsAttribute() != null) {
        final Ellipse2D ellipse = parseCircle();
        return ellipse.contains(x, y);
    }

    if ("poly".equals(shape) && getCoordsAttribute() != null) {
        final GeneralPath path = parsePoly();
        return path.contains(x, y);
    }

    return false;
}

From source file:org.griphyn.vdl.karajan.monitor.monitors.swing.GraphPanel.java

private boolean isPointWithinChartArea(int x, int y) {
    Rectangle2D chartArea = cp.getScreenDataArea();
    return chartArea.contains(x, y);
}

From source file:org.jax.maanova.test.gui.VolcanoPlotPanel.java

/**
 * Getter for the indices that fall in the given area
 * @param area  the area (using chart coordinates)
 * @return  the indices/*from www  .java  2 s.c  om*/
 */
private int[] getIndicesInArea(Rectangle2D area) {
    XYProbeData xyData = this.getXYData();
    double[] xData = xyData.getXData();
    double[] yData = xyData.getYData();
    int[] probeIndices = xyData.getProbeIndices();

    int selectedCount = 0;
    int[] mySelectedIndices = new int[xData.length];
    for (int i = 0; i < xData.length; i++) {
        if (area.contains(xData[i], yData[i])) {
            mySelectedIndices[selectedCount] = probeIndices[i];
            selectedCount++;
        }
    }

    // trim the array to size
    if (selectedCount == mySelectedIndices.length) {
        return mySelectedIndices;
    } else {
        int[] trimmedArray = new int[selectedCount];
        for (int i = 0; i < trimmedArray.length; i++) {
            trimmedArray[i] = mySelectedIndices[i];
        }
        return trimmedArray;
    }
}

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

/**
 * Implementation of the MouseMotionListener's method
 *
 * @param e  the event.//  w  w  w  .j a  va2 s  . co  m
 */
public void mouseMoved(MouseEvent e) {

    //crosshair
    if (this.horizontalAxisTrace && this.verticalAxisTrace && this.crosshairNotBlocked) {
        Rectangle2D rect = this.getScaledDataArea();
        double ux = userX(e);
        double uy = userY(e);

        if (!(rect.contains(e.getX(), e.getY()) && disableCrosshairTillLeavesDisplay)) {
            if (disableCrosshairTillLeavesDisplay) {
                disableCrosshairTillLeavesDisplay = false;
                drawHorizontalAxisTrace(e.getX());
                drawVerticalAxisTrace(e.getY());
            } else {
                drawHorizontalAxisTrace(e.getX());
                drawVerticalAxisTrace(e.getY());
                if (rect.contains(e.getX(), e.getY())) {
                    float uxf = (float) ux;
                    float uyf = (float) uy;
                    this.writeToStatusBar("( " + uxf + " , " + uyf + " )");

                } else {
                    this.writeToStatusBar("");
                }
            }
        }

    }

    if (this.chartMouseListeners.isEmpty()) {
        return;
    }

    Insets insets = getInsets();
    int x = e.getX() - insets.left;
    int y = e.getY() - insets.top;

    ChartEntity entity = null;
    if (this.info != null) {
        EntityCollection entities = this.info.getEntityCollection();
        if (entities != null) {
            entity = entities.getEntity(x, y);
        }
    }

    ChartMouseEvent event = new ChartMouseEvent(getChart(), e, entity);

    Iterator iterator = chartMouseListeners.iterator();
    while (iterator.hasNext()) {
        ChartMouseListener listener = (ChartMouseListener) iterator.next();
        listener.chartMouseMoved(event);
    }
}

From source file:ucar.unidata.idv.control.chart.MyTimeSeriesPlot.java

/**
 * draw//ww  w . java 2s  .  c o m
 *
 * @param g2 the graphics
 * @param dataArea where the data area is
 * @param index which data set
 * @param info info
 * @param crosshairState crosshairState
 *
 * @return any drawn
 */
public boolean render(Graphics2D g2, Rectangle2D dataArea, int index, PlotRenderingInfo info,
        CrosshairState crosshairState) {

    XYDataset dataset = getDataset(index);
    if (DatasetUtilities.isEmptyOrNull(dataset)) {
        return false;
    }

    ValueAxis rangeAxis = getRangeAxisForDataset(index);
    ValueAxis domainAxis = getDomainAxisForDataset(index);
    AxisLocation rangeAxisLocation = getRangeAxisLocation(index);
    AxisLocation domainAxisLocation = getDomainAxisLocation(index);
    RectangleEdge rangeEdge = getRangeAxisEdge();
    RectangleEdge domainEdge = getDomainAxisEdge();
    int seriesCount = dataset.getSeriesCount();
    //        System.out.println ("********************************");
    for (int series = seriesCount - 1; series >= 0; series--) {
        int itemCount = dataset.getItemCount(series);
        int[] xs = new int[itemCount];
        int[] ys = new int[itemCount];
        g2.setStroke(getRendererForDataset(dataset).getSeriesStroke(series));
        g2.setPaint(getRendererForDataset(dataset).getSeriesPaint(series));
        int pointCnt = 0;
        for (int item = 0; item < itemCount; item++) {
            double x1 = dataset.getXValue(series, item);
            double y1 = dataset.getYValue(series, item);
            if (!timeseries.valuesOk(index, x1, y1)) {
                if (pointCnt > 0) {
                    g2.drawPolyline(xs, ys, pointCnt);
                    pointCnt = 0;
                }
                continue;
            }
            double transX = domainAxis.valueToJava2D(x1, dataArea, domainEdge);
            double transY = rangeAxis.valueToJava2D(y1, dataArea, rangeEdge);
            if (!dataArea.contains(transX, transY)) {
                continue;
            }

            xs[pointCnt] = (int) (transX + 0.5);
            ys[pointCnt] = (int) (transY + 0.5);
            pointCnt++;
            if (pointCnt > 10) {
                g2.drawPolyline(xs, ys, pointCnt);
                xs[0] = xs[pointCnt - 1];
                ys[0] = ys[pointCnt - 1];
                pointCnt = 1;
            }

        }
        if (pointCnt > 1) {
            g2.drawPolyline(xs, ys, pointCnt);
        }
        long t2 = System.currentTimeMillis();
        //            System.err.println("time:" + (t2 - t1) + "ms #" + itemCount);
    }
    return true;
}

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

private void selectText(double xNew, double yNew) {
    for (Entry<Rectangle2D, String> item : textContentMap.entrySet()) {
        Rectangle2D rect = item.getKey();
        Point2D screenPoint = ChartMaskingUtilities.translateChartPoint(
                new Point2D.Double(rect.getMinX(), rect.getMinY()), getScreenDataArea(), getChart());
        Rectangle2D screenRect = new Rectangle2D.Double(screenPoint.getX(), screenPoint.getY() - 15,
                rect.getWidth(), rect.getHeight());
        if (screenRect.contains(xNew, yNew)) {
            if (selectedTextWrapper == rect) {
                selectedTextWrapper = null;
            } else {
                selectedTextWrapper = rect;
                setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
                return;
            }//  w  ww  .j  av a  2 s  .  co m
        }
    }
    if (selectedTextWrapper != null) {
        selectedTextWrapper = null;
    }
}

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

@Override
public void mousePressed(MouseEvent e) {
    if (selectedTextWrapper != null && getCursor() == Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)) {
        Point2D screenXY = ChartMaskingUtilities.translateChartPoint(
                new Point2D.Double(selectedTextWrapper.getMinX(), selectedTextWrapper.getMinY()),
                getScreenDataArea(), getChart());
        Rectangle2D screenRect = new Rectangle2D.Double(screenXY.getX(), screenXY.getY() - 15,
                selectedTextWrapper.getWidth(), selectedTextWrapper.getHeight());
        if (screenRect.contains(e.getX(), e.getY())) {

            double screenX = ChartMaskingUtilities.translateScreenX(e.getX() / getScaleX(), getScreenDataArea(),
                    getChart());//from   w w w.  j a  v a  2s  .  co  m
            double screenY = ChartMaskingUtilities.translateScreenY(e.getY(), getScreenDataArea(), getChart(),
                    0);
            //         Point2D point = translateScreenToChart(translateScreenToJava2D(e.getPoint()));
            Point2D point = new Point2D.Double(screenX, screenY);
            if (point != null) {
                this.textMovePoint = point;
            }
        } else {
            this.textMovePoint = null;
        }
    } else {
        super.mousePressed(e);
    }
}

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

protected void addMaskMenu(int x, int y) {
    if (this.removeSelectedMaskMenuItem != null) {
        boolean isRemoveMenuEnabled = false;
        if (this.selectedMask != null) {
            Rectangle2D screenMask = ChartMaskingUtilities.getMaskFramework(selectedMask, getScreenDataArea(),
                    getChart());/* w  ww  . j av  a  2  s .  co  m*/
            if (screenMask.contains(x, y)) {
                isRemoveMenuEnabled = true;
            }
        }
        this.removeSelectedMaskMenuItem.setEnabled(isRemoveMenuEnabled);
        if (isRemoveMenuEnabled) {
            removeSelectedMaskMenuItem.setVisible(true);
            removeSelectedMaskMenuItem.setText("Remove " + selectedMask.getName());
        } else {
            //              removeSelectedMaskMenuItem.setText("Mask Management");
            removeSelectedMaskMenuItem.setVisible(false);
        }
    }
    maskManagementMenu.removeAll();
    if (maskList.size() > 0) {
        maskManagementMenu.setEnabled(true);
        JMenuItem selectNoneMaskItem = new JRadioButtonMenuItem();
        selectNoneMaskItem.setText("Select None");
        selectNoneMaskItem.setActionCommand(DESELECT_MASK_COMMAND);
        selectNoneMaskItem.addActionListener(this);
        maskManagementMenu.add(selectNoneMaskItem);
        boolean isInShade = false;
        for (AbstractMask mask : maskList.keySet()) {
            Rectangle2D screenMask = ChartMaskingUtilities.getMaskFramework(mask, getScreenDataArea(),
                    getChart());
            if (screenMask.contains(x, y)) {
                JMenuItem selectMaskItem = new JRadioButtonMenuItem();
                selectMaskItem.setText("Select " + mask.getName());
                selectMaskItem.setActionCommand(SELECT_MASK_COMMAND + "-" + mask.getName());
                if (mask == selectedMask) {
                    selectMaskItem.setSelected(true);
                }
                selectMaskItem.addActionListener(this);
                maskManagementMenu.add(selectMaskItem);
                isInShade = true;
            }
        }
        if (isInShade) {
            if (selectedMask == null) {
                selectNoneMaskItem.setSelected(true);
            }
        } else {
            for (AbstractMask mask : getMasks()) {
                JMenuItem selectMaskItem = new JRadioButtonMenuItem();
                selectMaskItem.setText("Select " + mask.getName());
                selectMaskItem.setActionCommand(SELECT_MASK_COMMAND + "-" + mask.getName());
                if (mask == selectedMask) {
                    selectMaskItem.setSelected(true);
                }
                selectMaskItem.addActionListener(this);
                maskManagementMenu.add(selectMaskItem);
            }
            selectNoneMaskItem.setSelected(selectedMask == null);
        }
    } else {
        maskManagementMenu.setEnabled(false);
    }
}

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

@Override
public void mouseMoved(MouseEvent e) {
    //        if (isMaskingEnabled() && (e.getModifiers() & maskingKeyMask) != 0) {
    if (selectedTextWrapper == null && isMaskingEnabled()) {
        int cursorType = findCursorOnSelectedItem(e.getX(), e.getY());
        setCursor(Cursor.getPredefinedCursor(cursorType));
    } else {/*  www  .ja  va2 s . c  o  m*/
        Cursor newCursor = defaultCursor;
        if (selectedTextWrapper != null) {
            Point2D screenXY = ChartMaskingUtilities.translateChartPoint(
                    new Point2D.Double(selectedTextWrapper.getMinX(), selectedTextWrapper.getMinY()),
                    getScreenDataArea(), getChart());
            Rectangle2D screenRect = new Rectangle2D.Double(screenXY.getX(), screenXY.getY() - 15,
                    selectedTextWrapper.getWidth(), selectedTextWrapper.getHeight());
            if (screenRect.contains(e.getX(), e.getY())) {
                newCursor = Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR);
            }
        }
        if (newCursor != getCursor()) {
            setCursor(newCursor);
        }
    }
    Line2D oldSelection = selectedMarker;
    findSelectedMarker(e.getPoint());
    if (selectedMarker != oldSelection) {
        repaint();
    }
}

From source file:ste.travian.world.TileRenderer.java

/**
 * Draws the visual representation of a single data item.
 *
 * @param g2  the graphics device.//  w ww.j a v a 2  s . c  o m
 * @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 (horizontal) axis.
 * @param rangeAxis  the range (vertical) axis.
 * @param dataset  the dataset.
 * @param series  the series index (zero-based).
 * @param item  the item index (zero-based).
 * @param crosshairState  crosshair information for the plot 
 *                        (<code>null</code> permitted).
 * @param pass  the pass index.
 */
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) {

    // get the data point...
    double x = dataset.getXValue(series, item);
    double y = dataset.getYValue(series, item);
    double adjx = (this.dotWidth - 1) / 2.0;
    double adjy = (this.dotHeight - 1) / 2.0;
    if (Double.isNaN(y)) {
        return;
    }

    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    double transX = domainAxis.valueToJava2D(x, dataArea, xAxisLocation) - adjx;
    double transY = rangeAxis.valueToJava2D(y, dataArea, yAxisLocation) - adjy;

    g2.setPaint(getItemPaint(series, item));
    if (orientation == PlotOrientation.HORIZONTAL) {
        g2.fillRect((int) transY, (int) transX, this.dotHeight, this.dotWidth);
    } else if (orientation == PlotOrientation.VERTICAL) {
        g2.fillRect((int) transX, (int) transY, this.dotWidth, this.dotHeight);
    }

    int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
    int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
    updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY, orientation);

    // add an entity for the item, but only if it falls within the data
    // area...
    EntityCollection entities = null;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
    }
    int xx = (int) transX;
    int yy = (int) transY;
    if (orientation == PlotOrientation.HORIZONTAL) {
        xx = (int) transY;
        yy = (int) transX;
    }
    if (entities != null && dataArea.contains(xx, yy)) {
        addEntity(entities, null, dataset, series, item, (int) xx, (int) yy);
    }

}