/** * Returns all root cells (cells that have no parent) that the model * contains. */ public Object[] getRoots() { return DefaultGraphModel.getRoots(graphModel); }
/** * Returns all cells including all descendants. */ protected List getAll() { return DefaultGraphModel.getDescendants(model, DefaultGraphModel .getRoots(model)); }
/** * 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(); }
/** * @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; }
/** * Returns the roots of the specified model as a collection. This implementation * uses the GraphModel interface in the general case, but if the model is a * <code>DefaultGraphModel</code> the performance can be improved to * linear time. */ public static Collection getRootsAsCollection(GraphModel model) { Collection cells = null; if (model != null) { // If model is DefaultGraphModel, we can do a linear time getRoots if (model instanceof DefaultGraphModel) { cells = ((DefaultGraphModel) model).getRoots(); } else { cells = new LinkedHashSet(model.getRootCount()); for (int i = 0; i < cells.size(); i++) { cells.add(model.getRootAt(i)); } } } return cells; }
/** * Divides the graph into groups of sibling vertices, vertices that * share the same parent. This is mostly used for layouting of cell * relative to their group context. * */ protected void determineLayoutHierarchies() { if (model != null) { groupHierarchies = new ArrayList(); Set rootsSet = null; Object[] modelRoots = DefaultGraphModel.getRoots(model); for (int i = 0; i < modelRoots.length; i++) { if (DefaultGraphModel.isVertex(model, modelRoots[i])) { populateGroupHierarchies(modelRoots[i]); if (rootsSet == null) { rootsSet = new LinkedHashSet(); } rootsSet.add(modelRoots[i]); } } if (rootsSet != null) { groupHierarchies.add(rootsSet); } } }
public void hideOrShowChildrenAndDrawExtraEdges() { Vector<Runnable> graphicmodificationactions = new Vector<Runnable>(); for (Object root : DefaultGraphModel.getRoots(dgm)) { Object nedge; final DefaultGraphCell vertex = (DefaultGraphCell) root; if (parentHasVisibleContainers(vertex).isEmpty()) { // hide children hideAllChildren(graphicmodificationactions, vertex); } else { showAllChildren(vertex); } } for (Runnable run : graphicmodificationactions) { run.run(); // insert pending edges, if there is any } }
/** * Returns the roots of the specified model as an array. This implementation * uses the GraphModel interface in the general case, but if the model is a * <code>DefaultGraphModel</code> the performance can be improved to * linear time. */ public static Object[] getRoots(GraphModel model) { Object[] cells = null; if (model != null) { // If model is DefaultGraphModel, we can do a linear time getRoots if (model instanceof DefaultGraphModel) { cells = ((DefaultGraphModel) model).getRoots().toArray(); } else { cells = new Object[model.getRootCount()]; for (int i = 0; i < cells.length; i++) { cells[i] = model.getRootAt(i); } } } return cells; }
/** * 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); } }
private Vector getCells(org.jgraph.JGraph graph){ List roots=new Vector(((DefaultGraphModel)graph.getModel()).getRoots()); Vector v=new Vector(); boolean found=false; int k=0; Vector dgcs=new Vector(); org.jgraph.graph.DefaultGraphCell dgc=null; while (k<roots.size()){ Object o=roots.get(k); if (o instanceof org.jgraph.graph.DefaultGraphCell){ dgc=(org.jgraph.graph.DefaultGraphCell)o; if (dgc.getUserObject()!=null) found=((ingenias.editor.entities.Entity)dgc.getUserObject()).getId().equals(ent.getId()); if (found) dgcs.add(dgc); } k++; } return dgcs; }
/** * Sets the current model. */ public void setModel(GraphModel model) { roots.clear(); mapping.clear(); hiddenMapping.clear(); visibleSet.clear(); graphModel = model; if (!isPartial()) { Object[] cells = DefaultGraphModel.getRoots(getModel()); CellView[] cellViews = getMapping(cells, true); insertViews(cellViews); } // Update PortView Cache and Notify Observers update(); }
private DefaultGraphCell getCell(org.jgraph.JGraph graph){ List roots=new Vector(((DefaultGraphModel)graph.getModel()).getRoots()); Vector v=new Vector(); boolean found=false; int k=0; Vector dgcs=getCells(graph); org.jgraph.graph.DefaultGraphCell dgc=null; while (k<roots.size() &&!found){ Object o=roots.get(k); if (o instanceof org.jgraph.graph.DefaultGraphCell){ dgc=(org.jgraph.graph.DefaultGraphCell)o; if (dgc.getUserObject()!=null) found=((ingenias.editor.entities.Entity)dgc.getUserObject()).getId().equals(ent.getId()); } k++; } return dgc; }
private void initializeOccupiedPositions() { occupiedpositions.clear(); for (Object obj : dgm.getRoots()) { if (obj instanceof DefaultGraphCell) { // if (getChildren(obj).isEmpty()){ if (dgm.getAttributes(obj) != null && GraphConstants.getBounds(dgm.getAttributes(obj)) != null) occupiedpositions.put((DefaultGraphCell) obj, GraphConstants.getBounds(dgm.getAttributes(obj))); // } } } }
Object[] cells = DefaultGraphModel.getRoots(model); if (cells != null && cells.length > 0) { Rectangle2D ret = null;
Object[] roots = DefaultGraphModel.getRoots(model); if (roots.length == 0) { return null;
public void graphLayoutCacheChanged(GraphLayoutCacheEvent e) { Object[] changed = e.getChange().getChanged(); if (changed != null && changed.length > 0) { for (int i = 0; i < changed.length; i++) { graph.updateAutoSize(graphLayoutCache.getMapping( changed[i], false)); } } Rectangle2D oldDirtyRegion = e.getChange().getDirtyRegion(); graph.addOffscreenDirty(oldDirtyRegion); Rectangle2D newDirtyRegion = graph.getClipRectangle(e.getChange()); graph.addOffscreenDirty(newDirtyRegion); Object[] inserted = e.getChange().getInserted(); if (inserted != null && inserted.length > 0 && graphLayoutCache.isSelectsLocalInsertedCells() && !(graphLayoutCache.isSelectsAllInsertedCells() && !graphLayoutCache .isPartial()) && graph.isEnabled()) { Object[] roots = DefaultGraphModel.getRoots(graphModel, inserted); if (roots != null && roots.length > 0) { lastFocus = focus; focus = graphLayoutCache.getMapping(roots[0], false); graph.setSelectionCells(roots); } } updateSize(); }
&& graphLayoutCache.isSelectsAllInsertedCells() && graph.isEnabled()) { Object[] roots = DefaultGraphModel.getRoots(graphModel, inserted); if (roots != null && roots.length > 0) {