/** * Creates a collection of cells using the visitor pattern. */ public static Collection<Object> filterDescendants(mxIGraphModel model, Filter filter, Object parent) { List<Object> result = new ArrayList<Object>(); if (filter == null || filter.filter(parent)) { result.add(parent); } int childCount = model.getChildCount(parent); for (int i = 0; i < childCount; i++) { Object child = model.getChildAt(parent, i); result.addAll(filterDescendants(model, filter, child)); } return result; }
/** * Creates a collection of cells using the visitor pattern. */ public static Collection<Object> filterDescendants(mxIGraphModel model, Filter filter, Object parent) { List<Object> result = new ArrayList<Object>(); if (filter == null || filter.filter(parent)) { result.add(parent); } int childCount = model.getChildCount(parent); for (int i = 0; i < childCount; i++) { Object child = model.getChildAt(parent, i); result.addAll(filterDescendants(model, filter, child)); } return result; }
/** * Draws the child edges and/or all other children in the given cell * depending on the boolean arguments. */ protected void drawChildren(Object cell, boolean edges, boolean others) { mxIGraphModel model = graph.getModel(); int childCount = model.getChildCount(cell); for (int i = 0; i < childCount; i++) { Object child = model.getChildAt(cell, i); boolean isEdge = model.isEdge(child); if ((others && !isEdge) || (edges && isEdge)) { drawCell(canvas, model.getChildAt(cell, i)); } } }
/** * Draws the child edges and/or all other children in the given cell * depending on the boolean arguments. */ protected void drawChildren(Object cell, boolean edges, boolean others) { mxIGraphModel model = graph.getModel(); int childCount = model.getChildCount(cell); for (int i = 0; i < childCount; i++) { Object child = model.getChildAt(cell, i); boolean isEdge = model.isEdge(child); if ((others && !isEdge) || (edges && isEdge)) { drawCell(canvas, model.getChildAt(cell, i)); } } }
/** * Returns the first child of the root in the model, that is, the first or * default layer of the diagram. * * @return Returns the default parent for new cells. */ public Object getDefaultParent() { Object parent = defaultParent; if (parent == null) { parent = view.getCurrentRoot(); if (parent == null) { Object root = model.getRoot(); parent = model.getChildAt(root, 0); } } return parent; }
/** * Returns the first child of the root in the model, that is, the first or * default layer of the diagram. * * @return Returns the default parent for new cells. */ public Object getDefaultParent() { Object parent = defaultParent; if (parent == null) { parent = view.getCurrentRoot(); if (parent == null) { Object root = model.getRoot(); parent = model.getChildAt(root, 0); } } return parent; }
/** * */ protected Map<String, List<Object>> findParallels(Object parent) { Map<String, List<Object>> lookup = new Hashtable<String, List<Object>>(); mxIGraphModel model = graph.getModel(); int childCount = model.getChildCount(parent); for (int i = 0; i < childCount; i++) { Object child = model.getChildAt(parent, i); if (!isEdgeIgnored(child)) { String id = getEdgeId(child); if (id != null) { if (!lookup.containsKey(id)) { lookup.put(id, new ArrayList<Object>()); } lookup.get(id).add(child); } } } return lookup; }
public void execute(Object parent) { mxGraphView view = graph.getView(); mxIGraphModel model = graph.getModel(); // Gets all vertices and edges inside the parent List<Object> edges = new ArrayList<Object>(); List<Object> vertices = new ArrayList<Object>(); int childCount = model.getChildCount(parent); for (int i = 0; i < childCount; i++) { Object cell = model.getChildAt(parent, i); mxCellState state = view.getState(cell); if (state != null) { if (!isVertexIgnored(cell)) { vertices.add(state); } else if (!isEdgeIgnored(cell)) { edges.add(state); } } } placeLabels(vertices.toArray(), edges.toArray()); }
public void execute(Object parent) { mxGraphView view = graph.getView(); mxIGraphModel model = graph.getModel(); // Gets all vertices and edges inside the parent List<Object> edges = new ArrayList<Object>(); List<Object> vertices = new ArrayList<Object>(); int childCount = model.getChildCount(parent); for (int i = 0; i < childCount; i++) { Object cell = model.getChildAt(parent, i); mxCellState state = view.getState(cell); if (state != null) { if (!isVertexIgnored(cell)) { vertices.add(state); } else if (!isEdgeIgnored(cell)) { edges.add(state); } } } placeLabels(vertices.toArray(), edges.toArray()); }
/** * Creates a set of descendant cells * @param cell The cell whose descendants are to be calculated * @return the descendants of the cell (not the cell) */ public Set<Object> filterDescendants(Object cell) { mxIGraphModel model = graph.getModel(); Set<Object> result = new LinkedHashSet<Object>(); if (model.isVertex(cell) && cell != this.parent && graph.isCellVisible(cell)) { result.add(cell); } if (this.traverseAncestors || cell == this.parent && graph.isCellVisible(cell)) { int childCount = model.getChildCount(cell); for (int i = 0; i < childCount; i++) { Object child = model.getChildAt(cell, i); result.addAll(filterDescendants(child)); } } return result; }
/** * Creates a set of descendant cells * @param cell The cell whose descendants are to be calculated * @return the descendants of the cell (not the cell) */ public Set<Object> filterDescendants(Object cell) { mxIGraphModel model = graph.getModel(); Set<Object> result = new LinkedHashSet<Object>(); if (model.isVertex(cell) && cell != this.parent && graph.isCellVisible(cell)) { result.add(cell); } if (this.traverseAncestors || cell == this.parent && graph.isCellVisible(cell)) { int childCount = model.getChildCount(cell); for (int i = 0; i < childCount; i++) { Object child = model.getChildAt(cell, i); result.addAll(filterDescendants(child)); } } return result; }
/** * Removes all cached information for the given cell and its descendants. * This is called when a cell was removed from the model. * * @param cell Cell that was removed from the model. */ protected void removeStateForCell(Object cell) { int childCount = model.getChildCount(cell); for (int i = 0; i < childCount; i++) { removeStateForCell(model.getChildAt(cell, i)); } view.invalidate(cell); view.removeState(cell); }
/** * Removes all cached information for the given cell and its descendants. * This is called when a cell was removed from the model. * * @param cell Cell that was removed from the model. */ protected void removeStateForCell(Object cell) { int childCount = model.getChildCount(cell); for (int i = 0; i < childCount; i++) { removeStateForCell(model.getChildAt(cell, i)); } view.invalidate(cell); view.removeState(cell); }
/** * */ public List<mxCellState> snapshot(mxCellState state) { List<mxCellState> result = new LinkedList<mxCellState>(); if (state != null) { result.add((mxCellState) state.clone()); mxGraph graph = graphComponent.getGraph(); mxIGraphModel model = graph.getModel(); Object cell = state.getCell(); int childCount = model.getChildCount(cell); for (int i = 0; i < childCount; i++) { result.addAll(snapshot(graph.getView().getState( model.getChildAt(cell, i)))); } } return result; }
/** * */ public List<mxCellState> snapshot(mxCellState state) { List<mxCellState> result = new LinkedList<mxCellState>(); if (state != null) { result.add((mxCellState) state.clone()); mxGraph graph = graphComponent.getGraph(); mxIGraphModel model = graph.getModel(); Object cell = state.getCell(); int childCount = model.getChildCount(cell); for (int i = 0; i < childCount; i++) { result.addAll(snapshot(graph.getView().getState( model.getChildAt(cell, i)))); } } return result; }
/** * Draws the given cell and its descendants onto the specified canvas. * * @param canvas Canvas onto which the cell should be drawn. * @param cell Cell that should be drawn onto the canvas. */ public void drawCell(mxICanvas canvas, Object cell) { drawState(canvas, getView().getState(cell), true); // Draws the children on top of their parent int childCount = model.getChildCount(cell); for (int i = 0; i < childCount; i++) { Object child = model.getChildAt(cell, i); drawCell(canvas, child); } }
/** * Draws the given cell and its descendants onto the specified canvas. * * @param canvas Canvas onto which the cell should be drawn. * @param cell Cell that should be drawn onto the canvas. */ public void drawCell(mxICanvas canvas, Object cell) { drawState(canvas, getView().getState(cell), true); // Draws the children on top of their parent int childCount = model.getChildCount(cell); for (int i = 0; i < childCount; i++) { Object child = model.getChildAt(cell, i); drawCell(canvas, child); } }
/** * Removes the state of the given cell and all descendants if the given cell * is not the current root. * * @param cell * @param force * @param recurse */ public void clear(Object cell, boolean force, boolean recurse) { removeState(cell); if (recurse && (force || cell != currentRoot)) { mxIGraphModel model = graph.getModel(); int childCount = model.getChildCount(cell); for (int i = 0; i < childCount; i++) { clear(model.getChildAt(cell, i), force, recurse); } } else { invalidate(cell); } }
/** * Removes all overlays in the graph for the given cell and all its * descendants. If no cell is specified then all overlays are removed from * the graph. This implementation uses removeOverlays to remove the overlays * from the individual cells. * * @param cell * Optional cell that represents the root of the subtree to * remove the overlays from. Default is the root in the model. */ public void clearCellOverlays(Object cell) { mxIGraphModel model = graph.getModel(); if (cell == null) { cell = model.getRoot(); } removeCellOverlays(cell); // Recursively removes all overlays from the children int childCount = model.getChildCount(cell); for (int i = 0; i < childCount; i++) { Object child = model.getChildAt(cell, i); clearCellOverlays(child); // recurse } }
/** * Removes the state of the given cell and all descendants if the given cell * is not the current root. * * @param cell * @param force * @param recurse */ public void clear(Object cell, boolean force, boolean recurse) { removeState(cell); if (recurse && (force || cell != currentRoot)) { mxIGraphModel model = graph.getModel(); int childCount = model.getChildCount(cell); for (int i = 0; i < childCount; i++) { clear(model.getChildAt(cell, i), force, recurse); } } else { invalidate(cell); } }