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(Point2D p) 

Source Link

Usage

From source file:MouseTest.java

/**
 * Finds the first square containing a point.
 * @param p a point//w  ww .  ja va 2s  . c o  m
 * @return the first square that contains p
 */
public Rectangle2D find(Point2D p) {
    for (Rectangle2D r : squares) {
        if (r.contains(p))
            return r;
    }
    return null;
}

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

/**
 * Handles a mouse pressed event by recording the initial mouse pointer
 * location.//from  w w w. ja v  a2s.  com
 * 
 * @param canvas  the JavaFX canvas (<code>null</code> not permitted).
 * @param e  the mouse event (<code>null</code> not permitted).
 */
@Override
public void handleMousePressed(ChartCanvas canvas, MouseEvent e) {
    Plot plot = canvas.getChart().getPlot();
    if (!(plot instanceof Pannable)) {
        canvas.clearLiveHandler();
        return;
    }
    Pannable pannable = (Pannable) plot;
    if (pannable.isDomainPannable() || pannable.isRangePannable()) {
        Point2D point = new Point2D.Double(e.getX(), e.getY());
        Rectangle2D dataArea = canvas.findDataArea(point);
        if (dataArea != null && dataArea.contains(point)) {
            this.panW = dataArea.getWidth();
            this.panH = dataArea.getHeight();
            this.panLast = point;
            canvas.setCursor(javafx.scene.Cursor.MOVE);
        }
    }
    // the actual panning occurs later in the mouseDragged() method
}

From source file:StrokeTest.java

public StrokeComponent() {
    addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent event) {
            Point p = event.getPoint();
            for (int i = 0; i < points.length; i++) {
                double x = points[i].getX() - SIZE / 2;
                double y = points[i].getY() - SIZE / 2;
                Rectangle2D r = new Rectangle2D.Double(x, y, SIZE, SIZE);
                if (r.contains(p)) {
                    current = i;//from w  w  w  . ja v  a 2 s  .co  m
                    return;
                }
            }
        }

        public void mouseReleased(MouseEvent event) {
            current = -1;
        }
    });

    addMouseMotionListener(new MouseMotionAdapter() {
        public void mouseDragged(MouseEvent event) {
            if (current == -1)
                return;
            points[current] = event.getPoint();
            repaint();
        }
    });

    points = new Point2D[3];
    points[0] = new Point2D.Double(200, 100);
    points[1] = new Point2D.Double(100, 200);
    points[2] = new Point2D.Double(200, 200);
    current = -1;
    width = 8.0F;
}

From source file:ShapeTest.java

public ShapeComponent() {
    addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent event) {
            Point p = event.getPoint();
            for (int i = 0; i < points.length; i++) {
                double x = points[i].getX() - SIZE / 2;
                double y = points[i].getY() - SIZE / 2;
                Rectangle2D r = new Rectangle2D.Double(x, y, SIZE, SIZE);
                if (r.contains(p)) {
                    current = i;/* ww w  .j a va  2  s. c  o m*/
                    return;
                }
            }
        }

        public void mouseReleased(MouseEvent event) {
            current = -1;
        }
    });
    addMouseMotionListener(new MouseMotionAdapter() {
        public void mouseDragged(MouseEvent event) {
            if (current == -1)
                return;
            points[current] = event.getPoint();
            repaint();
        }
    });
    current = -1;
}

From source file:com.zilbo.flamingSailor.TE.model.Component.java

/**
 * Is 'l2' inside of 'l1'// w w w .j  ava2 s .c  om
 *
 * @param l1 box1
 * @return true if this component is inside the box
 */
public boolean isContainedBy(Rectangle2D l1) {

    return l1.contains(geom);
    /*
    if (l1.getX1() <= geom.getX1() && l1.getX2() >= geom.getX2()) {
    if (l1.getY1() <= geom.getY1() && l1.getY2() >= geom.getY2()) {
        return true;
    }
    }
    return false;
    */

}

From source file:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelChart.java

public void mousePressed(MouseEvent event) {
    try {/*from ww  w .  j  a  va 2 s . co  m*/
        if (chartPanButton.isSelected()
                || chartPanButton.isEnabled() && SwingUtilities.isRightMouseButton(event)) {
            Rectangle2D dataArea = this.chartPanel.getScaledDataArea();
            Point2D point = event.getPoint();
            if (dataArea.contains(point)) {
                setPanMode(true);
                panStartPoint = point;
            }
        }
    } catch (Exception e) {
        MsgBox.error(e.getMessage());
    }
}

From source file:org.yccheok.jstock.gui.charting.ChartLayerUI.java

private void updateTraceInfosIfPossible(int dataOffset) {
    // Do we have a valid mainTraceInfo?
    if (this.mainTraceInfo.point == null) {
        // Nope. Returns early.
        return;// w ww.  j  a v  a  2s.  c o  m
    }
    final int newDataIndex = dataOffset + this.mainTraceInfo.dataIndex;
    if (newDataIndex < 0) {
        // We try to offset beyond chart boundary. Returns early.
    }

    /* Try to get correct main chart area. */
    final ChartPanel chartPanel = this.chartJDialog.getChartPanel();
    final Rectangle2D _plotArea = chartPanel.getChartRenderingInfo().getPlotInfo().getSubplotInfo(0)
            .getDataArea();

    final Point2D tmpPoint = this.getPoint(0, 0, newDataIndex);
    if (tmpPoint == null || _plotArea.contains(tmpPoint) == false) {
        return;
    }

    this.mainTraceInfo = TraceInfo.newInstance(tmpPoint, 0, 0, newDataIndex);
    this.updateTraceInfos();
}

From source file:org.yccheok.jstock.gui.charting.ChartLayerUI.java

private void updateIndicatorTraceInfos(int mainPointIndex) {
    this.indicatorTraceInfos.clear();
    if (this.mainTraceInfo == null) {
        return;/*  ww  w  .  jav  a  2  s . co  m*/
    }

    final ChartPanel chartPanel = this.chartJDialog.getChartPanel();

    Day day = null;

    final XYDataset xyDataset = this.chartJDialog.getPlot().getDataset();
    if (xyDataset instanceof TimeSeriesCollection) {
        // Get the date.
        day = (Day) ((TimeSeriesCollection) xyDataset).getSeries(0).getDataItem(mainPointIndex).getPeriod();

        // 0 means main plot.
        final XYPlot plot = this.chartJDialog.getPlot();
        final TimeSeriesCollection timeSeriesCollection = (TimeSeriesCollection) plot.getDataset();
        // Start with 1. We are not interested in main series.
        for (int j = 1, size = timeSeriesCollection.getSeriesCount(); j < size; j++) {
            final TimeSeries timeSeries = timeSeriesCollection.getSeries(j);
            /* Time consuming. */
            final int dataIndex = getDataIndex(timeSeries, day);

            if (dataIndex < 0) {
                continue;
            }

            final Point2D point = this.getPoint(0, j, dataIndex);
            final String name = this.getLegendName(0, j);
            final Number value = this.getValue(0, j, dataIndex);

            if (point == null || name == null || value == null) {
                continue;
            }

            // We will never draw ball for SMA, EMA...
            this.indicatorTraceInfos.add(TraceInfo.newInstance(null, 0, j, dataIndex));
        }
    } else {
        final Date date = ((org.jfree.data.xy.DefaultHighLowDataset) xyDataset).getXDate(0, mainPointIndex);
        // OK to do so? Is "day" only used to compare day, excluding time information?
        // Will day 13th September 2009, 1:00pm same as another day 13th September 2009, 3:00pm?
        day = new Day(date);

        // 0 means main plot.
        final XYPlot plot = this.chartJDialog.getPlot();
        final int count = plot.getDatasetCount();
        for (int i = 1; i < count; i++) {
            final TimeSeriesCollection timeSeriesCollection = (TimeSeriesCollection) plot.getDataset(i);

            /* Not ready. */
            if (timeSeriesCollection == null) {
                continue;
            }

            final TimeSeries timeSeries = timeSeriesCollection.getSeries(0);
            /* Time consuming. */
            final int dataIndex = getDataIndex(timeSeries, day);

            if (dataIndex < 0) {
                continue;
            }

            final Point2D point = this.getPoint(0, i, dataIndex);
            final String name = this.getLegendName(0, i);
            final Number value = this.getValue(0, i, dataIndex);

            if (point == null || name == null || value == null) {
                continue;
            }

            // We will never draw ball for SMA, EMA...
            this.indicatorTraceInfos.add(TraceInfo.newInstance(null, 0, i, dataIndex));
        }
    }

    // Begin with 1. 0 is main plot.
    for (int i = 1, size = this.chartJDialog.getPlotSize(); i < size; i++) {
        final XYPlot plot = this.chartJDialog.getPlot(i);
        final TimeSeriesCollection timeSeriesCollection = (TimeSeriesCollection) plot.getDataset();
        // So far, for subplot, each of them only have 1 series.
        assert (1 == timeSeriesCollection.getSeriesCount());
        for (int j = 0, size2 = timeSeriesCollection.getSeriesCount(); j < size2; j++) {
            final TimeSeries timeSeries = timeSeriesCollection.getSeries(j);
            /* Time consuming. */
            final int dataIndex = getDataIndex(timeSeries, day);

            if (dataIndex < 0) {
                continue;
            }

            final Point2D point = this.getPoint(i, j, dataIndex);
            final String name = this.getLegendName(i, j);
            final Number value = this.getValue(i, j, dataIndex);

            if (point == null || name == null || value == null) {
                continue;
            }

            final Rectangle2D plotArea = chartPanel.getChartRenderingInfo().getPlotInfo().getSubplotInfo(i)
                    .getDataArea();
            if (plotArea.contains(point)) {
                this.indicatorTraceInfos.add(TraceInfo.newInstance(point, i, j, dataIndex));
            } else {
                this.indicatorTraceInfos.add(TraceInfo.newInstance(null, i, j, dataIndex));
            }
        }
    }
}

From source file:org.gumtree.vis.plot1d.Plot1DPanel.java

private void changeSelectedMask(MouseEvent e) {
    // TODO Auto-generated method stub
    Point2D screenPoint = translateScreenToJava2D(e.getPoint());
    //TODO: resize the mask
    Rectangle2D screenArea = getScreenDataArea();
    if (screenArea.contains(screenPoint)) {
        //             Point2D chartPoint = translateScreenToChart(screenPoint);

        changeSelectedMask(//w w w.  j  a  v  a  2  s .c  o  m
                ChartMaskingUtilities.translateScreenX(screenPoint.getX(), getScreenDataArea(), getChart()));
        repaint();
    }
}

From source file:org.gumtree.vis.plot1d.Plot1DPanel.java

private void changeInternalLegend(MouseEvent e) {
    // TODO Auto-generated method stub
    Point2D screenPoint = translateScreenToJava2D(e.getPoint());
    //TODO: resize the mask
    Rectangle2D screenArea = getScreenDataArea();
    if (screenArea.contains(screenPoint)) {
        //             Point2D chartPoint = translateScreenToChart(screenPoint);

        //         changeSelectedMask(ChartMaskingUtilities.translateScreenX(
        //               screenPoint.getX(), getScreenDataArea(), getChart()));
        int cursorType = findCursorOnSelectedItem(e.getX(), e.getY());
        switch (cursorType) {
        case Cursor.MOVE_CURSOR:
            moveLegend(e.getPoint());/*from w  w w.  j av  a2  s .  c  o m*/
            break;
        case Cursor.W_RESIZE_CURSOR:
            changeLegendX(e.getPoint());
            break;
        case Cursor.E_RESIZE_CURSOR:
            changeLegendWidth(e.getPoint());
            break;
        default:
            break;
        }
        repaint();
    }
}