Example usage for java.awt.geom Rectangle2D createIntersection

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

Introduction

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

Prototype

public abstract Rectangle2D createIntersection(Rectangle2D r);

Source Link

Document

Returns a new Rectangle2D object representing the intersection of this Rectangle2D with the specified Rectangle2D .

Usage

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

protected int findCursorOnSelectedItem(int x, int y) {
    if (getSelectedMask() != null && !getSelectedMask().getRectangleFrame().isEmpty()) {
        Rectangle2D screenArea = getScreenDataArea();
        Rectangle2D maskArea = ChartMaskingUtilities
                .translateChartRectangle(getSelectedMask(), getScreenDataArea(), getChart())
                .getRectangleFrame();/*w w  w .  jav a 2s.c o m*/
        Rectangle2D intersect = screenArea.createIntersection(maskArea);
        Point2D point = new Point2D.Double(x, y);
        double minX = maskArea.getMinX();
        double maxX = maskArea.getMaxX();
        double minY = maskArea.getMinY();
        double maxY = maskArea.getMaxY();
        double width = maskArea.getWidth();
        double height = maskArea.getHeight();
        if (!intersect.isEmpty() && screenArea.contains(point)) {
            //              if (y > minY && y < maxY) {
            //                 if (minX > screenArea.getMinX() + 1 
            //                       && minX < screenArea.getMaxX() - 1) {
            //                       if (x > minX - 4 && x < minX + (width < 8 ? width / 2 : 4)) {
            //                          return Cursor.W_RESIZE_CURSOR;
            //                       } 
            //                 }
            //                 if (maxX > screenArea.getMinX() + 1 
            //                       && maxX < screenArea.getMaxX() - 1) {
            //                       if (x > maxX - (width < 8 ? width / 2 : 4) && x < maxX + 4) {
            //                          return Cursor.E_RESIZE_CURSOR;
            //                       } 
            //                 }
            //              }
            if (height > 8 && width > 8) {
                Rectangle2D center = new Rectangle2D.Double(minX + 4, minY + 4, width - 8, height - 8);
                if (screenArea.createIntersection(center).contains(point)) {
                    return Cursor.MOVE_CURSOR;
                }
            }
            if (height > 8) {
                Rectangle2D west = new Rectangle2D.Double(minX - 4, minY + 4, width < 8 ? width / 2 + 4 : 8,
                        height - 8);
                if (screenArea.createIntersection(west).contains(point)) {
                    return Cursor.W_RESIZE_CURSOR;
                }
                Rectangle2D east = new Rectangle2D.Double(maxX - (width < 8 ? width / 2 : 4), minY + 4,
                        width < 8 ? width / 2 + 4 : 8, height - 8);
                if (screenArea.createIntersection(east).contains(point)) {
                    return Cursor.E_RESIZE_CURSOR;
                }
            }
            if (width > 8) {
                Rectangle2D north = new Rectangle2D.Double(minX + 4, minY - 4, width - 8,
                        height < 8 ? height / 2 + 4 : 8);
                if (screenArea.createIntersection(north).contains(point)) {
                    return Cursor.N_RESIZE_CURSOR;
                }
                Rectangle2D south = new Rectangle2D.Double(minX + 4, maxY - (height < 8 ? height / 2 : 4),
                        width - 8, height < 8 ? height / 2 + 4 : 8);
                if (screenArea.createIntersection(south).contains(point)) {
                    return Cursor.S_RESIZE_CURSOR;
                }
            }
            Rectangle2D northwest = new Rectangle2D.Double(minX - 4, minY - 4, width < 8 ? width / 2 + 4 : 8,
                    height < 8 ? height / 2 + 4 : 8);
            if (screenArea.createIntersection(northwest).contains(point)) {
                return Cursor.NW_RESIZE_CURSOR;
            }
            Rectangle2D northeast = new Rectangle2D.Double(maxX - (width < 8 ? width / 2 : 4), minY - 4,
                    width < 8 ? width / 2 + 4 : 8, height < 8 ? height / 2 + 4 : 8);
            if (screenArea.createIntersection(northeast).contains(point)) {
                return Cursor.NE_RESIZE_CURSOR;
            }
            Rectangle2D southwest = new Rectangle2D.Double(minX - 4, maxY - (height < 8 ? height / 2 : 4),
                    width < 8 ? width / 2 + 4 : 8, height < 8 ? height / 2 + 4 : 8);
            if (screenArea.createIntersection(southwest).contains(point)) {
                return Cursor.SW_RESIZE_CURSOR;
            }
            Rectangle2D southeast = new Rectangle2D.Double(maxX - (width < 8 ? width / 2 : 4),
                    maxY - (height < 8 ? height / 2 : 4), width < 8 ? width / 2 + 4 : 8,
                    height < 8 ? height / 2 + 4 : 8);
            if (screenArea.createIntersection(southeast).contains(point)) {
                return Cursor.SE_RESIZE_CURSOR;
            }
        }
        //           System.out.println("intersect X:[" + intersect.getMinX() + ", " + 
        //                 (intersect.getMinX() + intersect.getWidth()) + 
        //                 "], Y:[" + intersect.getMinY() + ", " + 
        //                 (intersect.getMinY() + intersect.getHeight()) +
        //                 "], x=" + point.getX() + ", y=" + point.getY() + 
        //                 " " + intersect.contains(point));
    }
    return Cursor.DEFAULT_CURSOR;
}

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

protected int findCursorOnSelectedItem(int x, int y) {
    if (isInternalLegendEnabled && isInternalLegendSelected) {
        Rectangle2D screenArea = getScreenDataArea();
        Rectangle2D legendArea = new Rectangle2D.Double(screenArea.getMaxX() - internalLegendSetup.getMinX(),
                screenArea.getMinY() + internalLegendSetup.getMinY(), internalLegendSetup.getWidth(),
                internalLegendSetup.getHeight());
        Rectangle2D intersect = screenArea.createIntersection(legendArea);
        Point2D point = new Point2D.Double(x, y);
        double minX = legendArea.getMinX();
        double maxX = legendArea.getMaxX();
        double minY = legendArea.getMinY();
        double width = legendArea.getWidth();
        double height = legendArea.getHeight();
        if (!intersect.isEmpty() && screenArea.contains(point)) {
            if (width > 8) {
                Rectangle2D center = new Rectangle2D.Double(minX + 4, minY, width - 8, height);
                if (screenArea.createIntersection(center).contains(point)) {
                    return Cursor.MOVE_CURSOR;
                }/*  ww  w  .j av  a 2s.  c o  m*/
            }
            Rectangle2D west = new Rectangle2D.Double(minX - 4, minY, width < 8 ? width / 2 + 4 : 8, height);
            if (screenArea.createIntersection(west).contains(point)) {
                return Cursor.W_RESIZE_CURSOR;
            }
            Rectangle2D east = new Rectangle2D.Double(maxX - (width < 8 ? width / 2 : 4), minY,
                    width < 8 ? width / 2 + 4 : 8, height);
            if (screenArea.createIntersection(east).contains(point)) {
                return Cursor.E_RESIZE_CURSOR;
            }
        }
    } else if (getSelectedMask() != null && !getSelectedMask().isEmpty()) {
        Rectangle2D screenArea = getScreenDataArea();
        Rectangle2D maskArea = ChartMaskingUtilities.getDomainMaskFrame(getSelectedMask(), getScreenDataArea(),
                getChart());
        Rectangle2D intersect = screenArea.createIntersection(maskArea);
        Point2D point = new Point2D.Double(x, y);
        double minX = maskArea.getMinX();
        double maxX = maskArea.getMaxX();
        double minY = maskArea.getMinY();
        double width = maskArea.getWidth();
        double height = maskArea.getHeight();
        if (!intersect.isEmpty() && screenArea.contains(point)) {
            if (width > 8) {
                Rectangle2D center = new Rectangle2D.Double(minX + 4, minY, width - 8, height);
                if (screenArea.createIntersection(center).contains(point)) {
                    return Cursor.MOVE_CURSOR;
                }
            }
            Rectangle2D west = new Rectangle2D.Double(minX - 4, minY, width < 8 ? width / 2 + 4 : 8, height);
            if (screenArea.createIntersection(west).contains(point)) {
                return Cursor.W_RESIZE_CURSOR;
            }
            Rectangle2D east = new Rectangle2D.Double(maxX - (width < 8 ? width / 2 : 4), minY,
                    width < 8 ? width / 2 + 4 : 8, height);
            if (screenArea.createIntersection(east).contains(point)) {
                return Cursor.E_RESIZE_CURSOR;
            }
        }
    }
    return Cursor.DEFAULT_CURSOR;
}

From source file:org.kalypsodeegree_impl.model.geometry.GM_Envelope_Impl.java

/**
 * returns a new GM_Envelope object representing the intersection of this GM_Envelope with the specified GM_Envelope.
 * * Note: If there is no intersection at all GM_Envelope will be null.
 * /*from  w  w w  .ja  v a 2 s  .  c om*/
 * @param bb
 *          the GM_Envelope to be intersected with this GM_Envelope
 * @return the largest GM_Envelope contained in both the specified GM_Envelope and in this GM_Envelope.
 */
@Override
public GM_Envelope createIntersection(final GM_Envelope bb) {
    Rectangle2D rect = new Rectangle2D.Double(bb.getMin().getX(), bb.getMin().getY(), bb.getWidth(),
            bb.getHeight());
    final Rectangle2D rect2 = new Rectangle2D.Double(getMin().getX(), getMin().getY(), getWidth(), getHeight());

    if (rect2.intersects(bb.getMin().getX(), bb.getMin().getY(), bb.getWidth(), bb.getHeight())) {
        rect = rect.createIntersection(rect2);
    } else {
        rect = null;
    }

    if (rect == null) {
        return null;
    }

    final double xmin = rect.getX();
    final double ymin = rect.getY();
    final double xmax = rect.getX() + rect.getWidth();
    final double ymax = rect.getY() + rect.getHeight();

    // TODO Check coordinate systems, if equal.
    return new GM_Envelope_Impl(xmin, ymin, xmax, ymax, m_coordinateSystem);
}

From source file:tufts.vue.LWComponent.java

protected boolean doZoomingDoubleClick(MapMouseEvent e) {
    //   System.out.println("zooming double click");

    final MapViewer viewer = e.getViewer();

    if (viewer.getFocal() == this) {
        viewer.popFocal(MapViewer.POP_TO_TOP, MapViewer.ANIMATE);
        return true;
        //return false;
    }/*from   w  w  w  .j  a va  2s .c o m*/
    VUE.getActiveMap().setTempBounds(VUE.getActiveViewer().getVisibleMapBounds());
    final Rectangle2D viewerBounds = viewer.getVisibleMapBounds();
    final Rectangle2D mapBounds = getMapBounds();
    final Rectangle2D overlap = viewerBounds.createIntersection(mapBounds);
    final double overlapArea = overlap.getWidth() * overlap.getHeight();
    //final double viewerArea = viewerBounds.getWidth() * viewerBounds.getHeight();
    final double nodeArea = mapBounds.getWidth() * mapBounds.getHeight();
    final boolean clipped = overlapArea < nodeArea;

    final double overlapWidth = mapBounds.getWidth() / viewerBounds.getWidth();
    final double overlapHeight = mapBounds.getHeight() / viewerBounds.getHeight();

    final boolean focusNode; // otherwise, re-focus map

    // Note: this code is way more complicated than we're making use of right now --
    // we always fully load objects (slides) as the focal when we zoom to them.
    // This code permitted double-clicking through a slide-icon stack, where we'd
    // zoom to the slide icon, but retain the map focal.  The overlap herustics here
    // determined how much of the current view was occupied by the current clicked
    // on zoom-to object.  If mostly in view, assume we want to "de-focus" (zoom
    // back out to the map from our "virtual focal" zoomed-to node), but if mostly
    // not in view, re-center on this object.  When last tested, this was smart
    // enough to allow you to simply cycle through a stack of slide-icons with
    // double clicking on the exposed edge of the nearby slide icons (of course,
    // this code was on LWSlide back then...)

    if (DEBUG.Enabled) {
        outf(" overlapWidth %4.1f%%", overlapWidth * 100);
        outf("overlapHeight %4.1f%%", overlapHeight * 100);
        outf("clipped=" + clipped);
    }

    if (clipped) {
        focusNode = true;
    } else if (overlapWidth > 0.8 || overlapHeight > 0.8) {
        focusNode = false;
    } else
        focusNode = true;

    if (focusNode) {
        viewer.clearRollover();

        if (SwapFocalOnSlideZoom) {
            // loadfocal animate only currently works when popping (to a parent focal)
            //viewer.loadFocal(this, true, AnimateOnZoom);
            ZoomTool.setZoomFitRegion(viewer, mapBounds, 0, AnimateOnZoom);
            viewer.loadFocal(this);
        } else {
            ZoomTool.setZoomFitRegion(viewer, mapBounds, -LWPathway.PathBorderStrokeWidth / 2, AnimateOnZoom);
        }
    } else {
        // just re-fit to the map
        viewer.fitToFocal(AnimateOnZoom);
    }

    return true;
}