/** * Hook for subclassers to return a different view for a mouse click at * <code>pt</code>. For example, this can be used to return a leaf cell * instead of a group. */ protected CellView findViewForPoint(Point2D pt) { double snap = graph.getTolerance(); Rectangle2D r = new Rectangle2D.Double(pt.getX() - snap, pt.getY() - snap, 2 * snap, 2 * snap); for (int i = 0; i < views.length; i++) if (views[i].intersects(graph, r)) return views[i]; return null; }
/** * Returns true if the view intersects the given rectangle. * * @param graph * the <code>JGraph</code> instance of the view * @param rect * the rectangle within which intersection is being checked for * * @return whether or not the rectangle specified intersects the view */ public boolean intersects(JGraph graph, Rectangle2D rect) { if (isLeaf() || GraphConstants.isGroupOpaque(getAllAttributes())) { Rectangle2D bounds = getBounds(); if (bounds != null) return bounds.intersects(rect); } else { // Check If Children Intersect Iterator it = childViews.iterator(); while (it.hasNext()) if (((CellView) it.next()).intersects(graph, rect)) return true; } return false; }
for (int i = 0; i < cells.length; i++) { if (cells[i] != null && (!leafsOnly || cells[i].isLeaf()) && cells[i].intersects(this, r)) {
/** * Returns the topmost cell view at the specified location using the view's * bounds on non-leafs to check for containment. If reverse is true this * will return the innermost view. */ public CellView getTopmostViewAt(double x, double y, boolean reverse, boolean leafsOnly) { Rectangle2D r = new Rectangle2D.Double(x, y, 1, 1); Object[] cells = getDescendants(getRoots()); for (int i = (reverse) ? cells.length - 1 : 0; i >= 0 && i < cells.length; i += (reverse) ? -1 : +1) { CellView view = getGraphLayoutCache().getMapping(cells[i], false); if (view != null && (!leafsOnly || view.isLeaf()) && ((view.isLeaf() && view.intersects(this, r)) || (!view .isLeaf() && view.getBounds().contains(x, y)))) return view; } return null; }
.getX() - s, e.getY() - s, 2 * s, 2 * s)); lastFocus = focus; focus = (focus != null && focus.intersects(graph, r)) ? focus : null; cell = graph.getNextSelectableViewAt(focus, e.getX(), e.getY());