/** * Constructs a graph layout cache. */ public GraphLayoutCache() { this(new DefaultGraphModel(), new DefaultCellViewFactory()); }
Set ctx = getEdges(DefaultGraphModel.this, changed); context = ctx.toArray(); remove = handleInsert(inserted); previousParentMap = parentMap; parentMap = handleParentMap(parentMap); connectionSet = handleConnectionSet(connectionSet); insert = handleRemove(removed); previousAttributes = attributes; attributes = handleAttributes(attributes); changed = tmp.toArray(); fireGraphChanged(DefaultGraphModel.this, this);
/** * Returns all cells including all descendants. */ protected List getAll() { return DefaultGraphModel.getDescendants(model, DefaultGraphModel .getRoots(model)); }
/** * 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; }
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[] fanout = (directed) ? DefaultGraphModel.getOutgoingEdges( model, cell) : DefaultGraphModel.getEdges(model, new Object[] { cell }).toArray(); List connectedCells = new ArrayList(fanout.length); Set localExclude = new HashSet(fanout.length + 8, (float) 0.75); for (int i = 0; i < fanout.length; i++) { Object neighbour = DefaultGraphModel.getOpposite(model, fanout[i], cell); if (neighbour != null
/** * Returns the incoming edges for cell. Cell should be a port or a vertex. */ public static Object[] getIncomingEdges(GraphModel model, Object cell) { return getEdges(model, cell, true); }
Object[] roots = DefaultGraphModel.getRoots(model); if (roots.length == 0) { return null; cells = DefaultGraphModel.order(model, cells); if (cells == null || cells.length < 2) { return null; List cell1Children = DefaultGraphModel.getDescendants(model, new Object[] { cell1 }); List cells1 = new ArrayList(); while (iter.hasNext()) { Object childCell = iter.next(); if (DefaultGraphModel.isVertex(model, childCell) && (!cache.isVisible(childCell))) { cells1.add(childCell); List cell2Children = DefaultGraphModel.getDescendants(model, new Object[] { cell2 }); List cells2 = new ArrayList(); while (iter.hasNext()) { Object childCell = iter.next(); if (DefaultGraphModel.isVertex(model, childCell) && (!cache.isVisible(childCell))) { cells2.add(childCell); .getEdgesBetween(model, cell1, cell2, false);
/** * Returns all root cells (cells that have no parent) that the model * contains. */ public Object[] getRoots() { return DefaultGraphModel.getRoots(graphModel); }
/** * @param model * @param node * @return all the edges entering the given <code>node</code> */ public static Set getIncomingEdges(GraphModel model, Object node) { Set result = new HashSet(); Set edges = DefaultGraphModel.getEdges(model, new Object[] { node }); Iterator it = edges.iterator(); while (it.hasNext()) { Object edge = it.next(); if (!DefaultGraphModel.isGroup(model, edge)) { Object target = model.getTarget(edge); if (target == node || isParentOf(model, node, target)) result.add(edge); } } return result; }
/** * 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 the edges between two specified ports or two specified vertices. * If directed is true then <code>cell1</code> must be the source of the * returned edges. This method never returns null. If there are no edges * between the specified cells, then an array of length 0 is returned. */ public static Object[] getEdgesBetween(GraphModel model, Object cell1, Object cell2, boolean directed) { boolean isPort1 = model.isPort(cell1); boolean isPort2 = model.isPort(cell2); ArrayList result = new ArrayList(); Set edges = DefaultGraphModel.getEdges(model, new Object[] { cell1 }); Iterator it = edges.iterator(); while (it.hasNext()) { Object edge = it.next(); // TODO: Handle edge groups Object source = (isPort1) ? model.getSource(edge) : getSourceVertex(model, edge); Object target = (isPort2) ? model.getTarget(edge) : getTargetVertex(model, edge); if ((source == cell1 && target == cell2) || (!directed && source == cell2 && target == cell1)) result.add(edge); } return result.toArray(); }
/** * Inserts the specified connection into the model. */ protected void handleConnection(ConnectionSet.Connection c, boolean establish) { Object edge = c.getEdge(); Object port = (establish) ? c.getPort() : (c.isSource()) ? getSource(edge) : getTarget(edge); connect(edge, port, c.isSource(), establish); }
/** * 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); } }
/** * 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); } } }
/** * Returns the graph model's attribute. Shortcut to <code> * getAttributes(null)</code>. * * @return attributes of <code>node</code> as a <code>Map</code> */ public Map getAttributes() { return getAttributes(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; }
AttributeMap attr = getAttributes(cell); if (attr != null) { deltaOld = attr.applyMap(deltaNew); Object oldValue = valueForCellChanged(cell, newValue); if (oldValue != null) GraphConstants.setValue(deltaOld, oldValue); for (int i = 0; i < remove.length; i++) { if (remove[i] == GraphConstants.VALUE) { Object oldValue = valueForCellChanged(cell, null); if (oldValue != null) {
Paint oldPaint = g2d.getPaint(); if (!DefaultGraphModel.isGroup(getScuflGraphModel(), view .getCell())) { g2d.setPaint(new GradientPaint(0, 0, getBackground(),
/** * A shortcut method to create a connection set that represents the * connections in this model. Useful for encoding to avoid writing redundant * connection data stored in the cells. */ public ConnectionSet getConnectionSet() { return ConnectionSet .create(this, DefaultGraphModel.getAll(this), false); }