/** * Returns <code>true</code> if <code>vertex</code> is a valid vertex. * * @return <code>true</code> if <code>vertex</code> is a valid vertex. */ public static boolean isVertex(GraphModel model, Object vertex) { return (vertex != null && !model.isEdge(vertex) && !model.isPort(vertex)); }
protected Collection getPorts(Object cell) { LinkedList list = new LinkedList(); for (int i = 0; i < graphModel.getChildCount(cell); i++) { Object child = graphModel.getChild(cell, i); if (graphModel.isPort(child)) list.add(child); } return list; }
/** * Returns an new consistent array of views for the ports. */ public CellView[] createTemporaryPortViews() { GraphModel model = graph.getModel(); ArrayList result = new ArrayList(); Iterator it = allCells.iterator(); while (it.hasNext()) { Object cand = it.next(); if (model.isPort(cand) && graph.getGraphLayoutCache().isVisible(cand)) result.add(getMapping(cand, true)); } // List -> CellView[] Conversion CellView[] array = new CellView[result.size()]; result.toArray(array); return array; }
/** * Checks whether the cell has at least one child which is not a port. This * implementation operates on the model, not taking into account visibility * of cells. It returns true for groups regardless of their folded state. * * @param cell * the cell to check for being a group * @return Returns true if the cell contains at least one cell which is not * a port */ public static boolean isGroup(GraphModel model, Object cell) { for (int i = 0; i < model.getChildCount(cell); i++) { if (!model.isPort(model.getChild(cell, i))) return true; } return false; }
private Object getPort(Object node, Object edge) { if (!model.isPort(node)) { for (int index = 0; index < model.getChildCount(node); index++) { Object result = getPort(model.getChild(node, index), edge); if (result != null) { return result; } } return null; } Iterator edges = model.edges(node); while (edges.hasNext()) { if (edge.equals(edges.next())) { return node; } } return null; }
public org.jgraph.graph.CellView createView(GraphModel model, Object cell) { org.jgraph.graph.CellView view = null; if (model.isPort(cell)) view = new PortView(cell); else if (model.isEdge(cell)) view = createEdgeView(cell); else view = createVertexView(cell); return view; }
public org.jgraph.graph.CellView createView(GraphModel model, Object cell) { org.jgraph.graph.CellView view = null; if (model.isPort(cell)) view = new PortView(cell); else if (model.isEdge(cell)) view = createEdgeView(cell); else view = createVertexView(cell); return view; }
public org.jgraph.graph.CellView createView(GraphModel model, Object cell) { org.jgraph.graph.CellView view = null; if (model.isPort(cell)) view = new PortView(cell); else if (model.isEdge(cell)) view = createEdgeView(cell); else view = createVertexView(cell); return view; }
public org.jgraph.graph.CellView createView(GraphModel model, Object cell) { org.jgraph.graph.CellView view = null; if (model.isPort(cell)) view = new PortView(cell); else if (model.isEdge(cell)) view = createEdgeView(cell); else view = createVertexView(cell); return view; }
public org.jgraph.graph.CellView createView(GraphModel model, Object cell) { org.jgraph.graph.CellView view = null; if (model.isPort(cell)) view = new PortView(cell); else if (model.isEdge(cell)) view = createEdgeView(cell); else view = createVertexView(cell); return view; }
public org.jgraph.graph.CellView createView(GraphModel model, Object cell) { org.jgraph.graph.CellView view = null; if (model.isPort(cell)) view = new PortView(cell); else if (model.isEdge(cell)) view = createEdgeView(cell); else view = createVertexView(cell); return view; }
public org.jgraph.graph.CellView createView(GraphModel model, Object cell) { org.jgraph.graph.CellView view = null; if (model.isPort(cell)) view = new PortView(cell); else if (model.isEdge(cell)) view = createEdgeView(cell); else view = createVertexView(cell); return view; }
public org.jgraph.graph.CellView createView(GraphModel model, Object cell) { org.jgraph.graph.CellView view = null; if (model.isPort(cell)) view = new PortView(cell); else if (model.isEdge(cell)) view = createEdgeView(cell); else view = createVertexView(cell); return view; }
public org.jgraph.graph.CellView createView(GraphModel model, Object cell) { org.jgraph.graph.CellView view = null; if (model.isPort(cell)) view = new PortView(cell); else if (model.isEdge(cell)) view = createEdgeView(cell); else view = createVertexView(cell); return view; }
/** * @return Returns the opposite port or vertex in <code>edge</code>. */ public static Object getOpposite(GraphModel model, Object edge, Object cell) { boolean isPort = model.isPort(cell); Object source = (isPort) ? model.getSource(edge) : getSourceVertex( model, edge); if (cell == source) return (isPort) ? model.getTarget(edge) : getTargetVertex(model, edge); else return source; }
/** * A helper method to return various arrays of cells that are visible in * this cache. For example, to get all selected vertices in a graph, do * <code>graph.getSelectionCells(graph.getGraphLayoutCache().getCells(false, true, false, false));</code> */ public Object[] getCells(boolean groups, boolean vertices, boolean ports, boolean edges) { CellView[] views = getCellViews(); List result = new ArrayList(views.length); GraphModel model = getModel(); for (int i = 0; i < views.length; i++) { Object cell = views[i].getCell(); boolean isEdge = model.isEdge(cell); if ((ports || !model.isPort(cell))) { if (((((ports || vertices) && !isEdge) || (edges && isEdge)) && views[i] .isLeaf()) || (groups && !views[i].isLeaf())) result.add(views[i].getCell()); } } return result.toArray(); }
/** * Returns the <code>CellView</code> that is mapped to <code>cell</code> * in the graph context. New views are created based on whether cell is * contained in the context. The <code>create</code>-flag is ignored. */ public CellView getMapping(Object cell, boolean create) { if (cell != null) { CellView view = (CellView) views.get(cell); if (view != null) return view; else if (contains(cell) || (graph.getModel().isPort(cell) && create && graph .getGraphLayoutCache().isVisible(cell))) return createMapping(cell); else return graphLayoutCache.getMapping(cell, false); } return null; }
/** * Constructs a view for the specified cell and associates it with the * specified object using the specified CellMapper. This calls refresh on * the created CellView to create all dependent views. * <p> * Note: The mapping needs to be available before the views of child cells * and ports are created. * <b>Note: This method must return new instances!</b> * * @param cell * reference to the object in the model */ public CellView createView(GraphModel model, Object cell) { CellView view = null; if (model.isPort(cell)) view = createPortView(cell); else if (model.isEdge(cell)) view = createEdgeView(cell); else view = createVertexView(cell); return view; }
/** * Hook for subclassers to return the port to be used for edges that have * been connected to the group. This is called from expand. This returns the * first port of the first or last vertex depending on <code>source</code>. */ protected Object getChildPort(Object edge, boolean source) { GraphModel model = getModel(); // Contains the parent of the port, eg. the group Object parent = (source) ? DefaultGraphModel.getSourceVertex(model, edge) : DefaultGraphModel.getTargetVertex(model, edge); // Finds a vertex in the group int c = model.getChildCount(parent); for (int i = (source) ? c - 1 : 0; i < c && i >= 0; i += (source) ? -1 : +1) { Object child = model.getChild(parent, i); if (!model.isEdge(child) && !model.isPort(child)) { // Finds a port in the vertex for (int j = 0; j < model.getChildCount(child); j++) { Object port = model.getChild(child, j); if (model.isPort(port)) { return port; } } } } return null; }
/** * Adds the specified model root cells to the view. Do not add a view that * is already in roots. */ public void insertViews(CellView[] views) { if (views != null) { refresh(views, true); for (int i = 0; i < views.length; i++) { if (views[i] != null && getMapping(views[i].getCell(), false) != null) { CellView parentView = views[i].getParentView(); Object parent = (parentView != null) ? parentView.getCell() : null; if (!graphModel.isPort(views[i].getCell()) && parent == null) { roots.add(views[i]); } } } } }