/** * Returns all cells that intersect the given rectangle. */ public Object[] getRoots(Rectangle clip) { CellView[] views = graphLayoutCache.getRoots(clip); Object[] cells = new Object[views.length]; for (int i = 0; i < views.length; i++) cells[i] = views[i].getCell(); return cells; }
/** * Returns all views, shortcut to getAllDescendants(getRoots()) */ public CellView[] getAllViews() { return getAllDescendants(getRoots()); }
/** * Return all root cells that intersect the given rectangle. */ public CellView[] getRoots(Rectangle2D clip) { java.util.List result = new ArrayList(); CellView[] views = getRoots(); for (int i = 0; i < views.length; i++) if (views[i].getBounds().intersects(clip)) result.add(views[i]); views = new CellView[result.size()]; result.toArray(views); return views; }
/** * Sets the current model. */ public void update() { updatePorts(); cellViewsChanged(getRoots()); }
public static java.awt.Point findEmptyPlacePoint(Dimension dim, org.jgraph.JGraph model){ int j=0; int y=30; boolean occupied=true; while (occupied){ Rectangle2D clip=new Rectangle(new Point(j,y), dim); occupied=model.getGraphLayoutCache().getRoots(clip)!=null && model.getGraphLayoutCache().getRoots(clip).length!=0; /*FirstCellForLocation(j, y)!=null || model.getFirstCellForLocation(j+20, y)!=null || model.getFirstCellForLocation(j, y+20)!=null || model.getFirstCellForLocation(j+20, y+20)!=null;*/ if (occupied){ j=(int) (j+dim.getWidth()); } if (j>(model.getVisibleRect().x+model.getVisibleRect().width)){ j=model.getVisibleRect().x; y=(int) (y+dim.getHeight()); } } return new java.awt.Point(j,y); }
/** * Returns the next view at the specified location wrt. <code>current</code>. * This is used to iterate overlapping cells, and cells that are grouped. * The current selection affects this method. <br> * Note: This returns the next <i>selectable </i> view. <br> * Note: Arguments are not expected to be scaled (they are scaled in here). */ public CellView getNextViewAt(CellView current, double x, double y, boolean leafsOnly) { CellView[] cells = AbstractCellView .getDescendantViews(getGraphLayoutCache().getRoots()); return getNextViewAt(cells, current, x, y, leafsOnly); }
.getRoots()); if (size == null) size = new Rectangle2D.Double();
/** * Hook for subclassers. Current implementation checks if graph selection is * enabled. This is called from mouseReleased to execute the marquee * selection. */ public void handleMarqueeEvent(MouseEvent e, JGraph graph, Rectangle2D bounds) { CellView[] views = graph.getGraphLayoutCache().getRoots(bounds); ArrayList list = new ArrayList(); for (int i = 0; i < views.length; i++) // above returns intersection, we want containment if (bounds.contains(views[i].getBounds())) list.add(views[i].getCell()); Object[] cells = list.toArray(); graph.getUI().selectCellsForEvent(graph, cells, e); }
/** * Hook method to allow subclassers to alter just the cell painting * functionality * * @param g * the graphics object to paint to * @param realClipBounds * the bounds of the region being repainted */ protected void paintCells(Graphics g, Rectangle2D realClipBounds) { CellView[] views = graphLayoutCache.getRoots(); for (int i = 0; i < views.length; i++) { Rectangle2D bounds = views[i].getBounds(); if (bounds != null) { if (realClipBounds == null) { paintCell(g, views[i], bounds, false); } else if (bounds.intersects(realClipBounds)) { paintCell(g, views[i], bounds, false); } } } }