/** * Returns a deep clone of the specified cells, including all children. */ public static Object[] cloneCell(GraphModel model, Object[] cells) { Map clones = model.cloneCells(getDescendants(model, cells).toArray()); for (int i = 0; i < cells.length; i++) { cells[i] = clones.get(cells[i]); } return cells; }
/** * Returns all cells including all descendants. */ protected List getAll() { return DefaultGraphModel.getDescendants(model, DefaultGraphModel .getRoots(model)); }
/** * Returns a deep clone of the specified cell, including all children. */ public static Object cloneCell(GraphModel model, Object cell) { Map clones = model.cloneCells(getDescendants(model, new Object[] { cell }).toArray()); return clones.get(cell); }
/** * Returns all cells of the model in an array. * * @see #getDescendants(GraphModel, Object[]) * * @return Returns all cells in the model including all descandants. */ public static Object[] getAll(GraphModel model) { return getDescendants(model, getRoots(model)).toArray(); }
/** * Returns all <code>cells</code> including all descendants in the passed * in order of cells. */ public Object[] getDescendants(Object[] cells) { return DefaultGraphModel.getDescendants(getModel(), cells).toArray(); }
/** * Inserts <code>cells</code> into the model. Returns the cells that were * inserted (including descendants). */ protected Object[] handleInsert(Object[] cells) { Object[] inserted = null; if (cells != null) { for (int i = 0; i < cells.length; i++) // Add to Roots if no parent if (getParent(cells[i]) == null) roots.add(cells[i]); // Return *all* inserted cells inserted = getDescendants(this, cells).toArray(); } return inserted; }
/** * @param model * @return all edges in the model */ public static Set getAllEdges(GraphModel model) { List cells = DefaultGraphModel.getDescendants(model, (DefaultGraphModel.getRoots(model))); if (cells != null) { Set result = new HashSet(); for (int index = 0; index < cells.size(); index++) if (model.isEdge(cells.get(index))) result.add(cells.get(index)); return result; } return null; }
/** * Obtains all hidden vertices of the specified cell * @param cell the cell whose children are to be determined * @return all the child hidden vertices */ private Set getHiddenChildren(Object cell) { List cellChildren = DefaultGraphModel.getDescendants(model, new Object[] {cell}); Set cells = new HashSet(); cells.add(cell); Iterator iter = cellChildren.iterator(); while (iter.hasNext()) { Object childCell = iter.next(); if (DefaultGraphModel.isVertex(model, childCell) && !graphLayoutCache.isVisible(childCell)) { cells.add(childCell); } } return cells; }
List descendants = getDescendants(model, cells);
/** * Hides the specified cells with all children if <code>descandants</code> * is true. * NOTE: Your GraphLayoutCache must be <code>partial</code> (set * <code>partial</code> to <code>true</code> in the constructor) * in order to use the visibility functionality of expand/collapse, * setVisible, etc. */ public void hideCells(Object[] cells, boolean descandants) { if (cells != null && cells.length > 0) { if (descandants) cells = DefaultGraphModel.getDescendants(getModel(), cells) .toArray(); setVisible(cells, false); } }
/** * Shows the specified cells with all children if <code>descandants</code> * is true. * NOTE: Your GraphLayoutCache must be <code>partial</code> (set * <code>partial</code> to <code>true</code> in the constructor) * in order to use the visibility functionality of expand/collapse, * setVisible, etc. */ public void showCells(Object[] cells, boolean descandants) { if (cells != null && cells.length > 0) { if (descandants) cells = DefaultGraphModel.getDescendants(getModel(), cells) .toArray(); setVisible(cells, true); } }
/** * Updates the cached array of ports. */ protected void updatePorts() { Object[] roots = DefaultGraphModel.getRoots(graphModel); List list = DefaultGraphModel.getDescendants(graphModel, roots); if (list != null) { ArrayList result = new ArrayList(); Iterator it = list.iterator(); while (it.hasNext()) { Object cell = it.next(); if (graphModel.isPort(cell)) { CellView portView = getMapping(cell, false); if (portView != null) { result.add(portView); portView.refresh(this, this, false); } } } ports = new PortView[result.size()]; result.toArray(ports); } }
/** * Constructs a graph context for <code>cells</code> with respect to the * connections defined in the model, and the views in the view of * <code>graph</code>. */ public GraphContext(JGraph graph, Object[] cells) { GraphModel model = graph.getModel(); allCells = new HashSet(DefaultGraphModel.getDescendants(model, cells)); graphLayoutCache = graph.getGraphLayoutCache(); this.graph = graph; this.cells = cells; // Count Visible Non-Port Cells cellSet = new HashSet(); Iterator it = allCells.iterator(); while (it.hasNext()) { Object cell = it.next(); if (graphLayoutCache.isVisible(cell)) { cellSet.add(cell); if (!model.isPort(cell)) cellCount++; } } }
/** * Inserts the <code>cells</code> and connections into the model, and * absorbs the local attributes. This implementation sets the inserted cells * visible and selects the new roots depending on graph.selectNewCells. */ public void insert(Object[] roots, Map attributes, ConnectionSet cs, ParentMap pm, UndoableEdit[] e) { Object[] visible = null; if (isPartial() && showsInsertedCells) { List tmp = DefaultGraphModel.getDescendants(graphModel, roots); tmp.removeAll(visibleSet); if (!tmp.isEmpty()) visible = tmp.toArray(); } // Absorb local attributes GraphLayoutCacheEdit edit = createLocalEdit(roots, attributes, visible, null); if (edit != null) e = augment(e, edit); graphModel.insert(roots, attributes, cs, pm, e); }
/** * Removes cells from the model, including all children and connected edges * if <code>children</code> or <code>edges</code> is true, respectively. * * @param cells * The cells to remove. * @param descendants * Whether to remove all descendants as well. * @param edges * Whether to remove all connected edges as well. */ public void remove(Object[] cells, boolean descendants, boolean edges) { if (cells != null && cells.length > 0) { if (edges) { Object[] tmp = DefaultGraphModel.getEdges(getModel(), cells) .toArray(); Object[] newCells = new Object[cells.length + tmp.length]; System.arraycopy(cells, 0, newCells, 0, cells.length); System.arraycopy(tmp, 0, newCells, cells.length, tmp.length); cells = newCells; } if (descendants) cells = DefaultGraphModel.getDescendants(getModel(), cells) .toArray(); remove(cells); } }
List removed = DefaultGraphModel.getDescendants(getModel(), change.getRemoved()); Rectangle2D removedBounds = (removed != null && !removed.isEmpty()) ? getCellBounds(removed.toArray()) : null; List inserted = DefaultGraphModel.getDescendants(getModel(), change.getInserted()); Rectangle2D insertedBounds = (inserted != null && !inserted.isEmpty()) ? getCellBounds(inserted.toArray()) : null; List changed = DefaultGraphModel.getDescendants(getModel(), change.getChanged()); Rectangle2D changedBounds = (changed != null && !changed.isEmpty()) ? getCellBounds(changed.toArray()) : null; List context = DefaultGraphModel.getDescendants(getModel(), change.getContext()); Rectangle2D contextBounds = (context != null && !context.isEmpty()) ? getCellBounds(context.toArray()) : null;
List cell1Children = DefaultGraphModel.getDescendants(model, new Object[] { cell1 }); List cells1 = new ArrayList(); List cell2Children = DefaultGraphModel.getDescendants(model, new Object[] { cell2 }); List cells2 = new ArrayList();
List childs = DefaultGraphModel.getDescendants(model, tmp);
List toHide = DefaultGraphModel.getDescendants(getModel(), collapse); if (collapse != null) {
cells = DefaultGraphModel.getDescendants(getModel(), cells) .toArray();