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; }
/** * Flattens the given array of root cells by adding the roots and their * descandants. The resulting set contains all cells, which means it * contains branches <strong>and </strong> leafs. Note: This is an iterative * implementation. No recursion used. <br> * Note: This returns a linked list, for frequent read operations you should * turn this into an array, or at least an array list. */ public static List getDescendants(GraphModel model, Object[] cells) { if (cells != null) { Stack stack = new Stack(); for (int i = cells.length - 1; i >= 0; i--) stack.add(cells[i]); LinkedList result = new LinkedList(); while (!stack.isEmpty()) { Object tmp = stack.pop(); for (int i = model.getChildCount(tmp) - 1; i >= 0; i--) stack.add(model.getChild(tmp, i)); if (tmp != null) result.add(tmp); } return result; } return null; }
/** * Orders cells so that they reflect the model order. */ public static Object[] order(GraphModel model, Object[] cells) { if (cells != null) { Set cellSet = new HashSet(); for (int i = 0; i < cells.length; i++) cellSet.add(cells[i]); Stack stack = new Stack(); for (int i = model.getRootCount() - 1; i >= 0; i--) stack.add(model.getRootAt(i)); LinkedList result = new LinkedList(); while (!stack.isEmpty()) { Object tmp = stack.pop(); for (int i = model.getChildCount(tmp) - 1; i >= 0; i--) stack.add(model.getChild(tmp, i)); if (cellSet.remove(tmp)) result.add(tmp); } return result.toArray(); } return null; }
/** * 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; }
/** * Creates a set of sibling vertices and adds them to the group * hierarchy collection. The list of hierarchies will naturally * form in an order * @param vertex The parent vertex to the returned vertices */ protected void populateGroupHierarchies(Object vertex) { LinkedHashSet result = null; if (vertex != null) { for (int i = 0; i < model.getChildCount(vertex); i++) { Object child = model.getChild(vertex, i); if (DefaultGraphModel.isVertex(model, child)) { if (result == null) { result = new LinkedHashSet(); } result.add(child); populateGroupHierarchies(child); } } } if (groupHierarchies == null) { groupHierarchies = new ArrayList(); } if (result != null) { groupHierarchies.add(result); } }
public static Port[] getPorts(Object[] vertexList, ModelJGraph graph) { // Ports of argument vertexs. Port[] ports = new Port[vertexList.length]; // Obtain the model. GraphModel model = graph.getModel(); // Iterate over all Objects. for (int i = 0; i < vertexList.length; i++) { Port objectPort = null; // Iterate over all Children for (int j = 0; j < model.getChildCount(vertexList[i]); j++) { // Fetch the Child of Vertex at Index i Object child = model.getChild(vertexList[i], j); // Check if Child is a Port if (child instanceof Port) { // Return the Child as a Port objectPort = (Port) child; } } ports[i] = objectPort; } return ports; }
private Port[] getPorts(ModelJGraph graph, Object[] vertexList) { // Ports of argument vertexs. Port[] ports = new Port[vertexList.length]; // Obtain the model. GraphModel model = graph.getModel(); // Iterate over all Objects. for (int i = 0; i < vertexList.length; i++) { Port objectPort = null; // Iterate over all Children for (int j = 0; j < model.getChildCount(vertexList[i]); j++) { // Fetch the Child of Vertex at Index i Object child = model.getChild(vertexList[i], j); // Check if Child is a Port if (child instanceof Port) { // Return the Child as a Port objectPort = (Port) child; } } ports[i] = objectPort; } return ports; }
private Port[] getPorts(ModelJGraph graph, Object[] vertexList) { // Ports of argument vertexs. Port[] ports = new Port[vertexList.length]; // Obtain the model. GraphModel model = graph.getModel(); // Iterate over all Objects. for (int i = 0; i < vertexList.length; i++) { Port objectPort = null; // Iterate over all Children for (int j = 0; j < model.getChildCount(vertexList[i]); j++) { // Fetch the Child of Vertex at Index i Object child = model.getChild(vertexList[i], j); // Check if Child is a Port if (child instanceof Port) { // Return the Child as a Port objectPort = (Port) child; } } ports[i] = objectPort; } return ports; }
private Port[] getPorts(Object[] vertexList, ModelJGraph graph) { // Ports of argument vertexs. Port[] ports = new Port[vertexList.length]; // Obtain the model. GraphModel model = graph.getModel(); // Iterate over all Objects. for (int i = 0; i < vertexList.length; i++) { Port objectPort = null; // Iterate over all Children for (int j = 0; j < model.getChildCount(vertexList[i]); j++) { // Fetch the Child of Vertex at Index i Object child = model.getChild(vertexList[i], j); // Check if Child is a Port if (child instanceof Port) { // Return the Child as a Port objectPort = (Port) child; } } ports[i] = objectPort; } return ports; }
/** * Gets the port attribute of the Editor object * *@param vertexNode Description of Parameter *@return The port value */ public static Port getPort(Object vertexNode, ModelJGraph graph) { GraphModel model = graph.getModel(); // Iterate over all Children for (int i = 0; i < model.getChildCount(vertexNode); i++) { // Fetch the Child of Vertex at Index i Object child = model.getChild(vertexNode, i); // Check if Child is a Port if (child instanceof Port) { // Return the Child as a Port return (Port) child; } } // No Ports Found return null; }
for (int j = 0; j < model.getChildCount(vertexList[i]); j++) {
result.add(tmp); for (int i = 0; i < graphModel.getChildCount(tmp.getCell()); i++) { Object child = graphModel.getChild(tmp.getCell(), i); if (graphModel.isPort(child)) {
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; }
private static boolean evaluateCurrentNAryEdge(Rectangle rect1, ModelJGraph graph, boolean intersectsline, NAryEdge currentNary) { for (int k=0;k<graph.getModel().getChildCount(currentNary) && !intersectsline;k++){ Object port = graph.getModel().getChild(currentNary,k); intersectsline = intersectsline||detectEdgeIntersections(rect1, graph, intersectsline, port); } return intersectsline; }
/** * Returns the cells that are currently selectable. The array is ordered so * that the top-most cell appears first. <br> */ public Object[] getSelectables() { if (isChildrenSelectable()) { List result = new ArrayList(); // Roots Are Always Selectable Stack s = new Stack(); GraphModel model = graph.getModel(); for (int i = 0; i < model.getRootCount(); i++) s.add(model.getRootAt(i)); while (!s.isEmpty()) { Object cell = s.pop(); AttributeMap attrs = graph.getAttributes(cell); if (!model.isPort(cell) && (attrs == null || GraphConstants.isSelectable(attrs))) result.add(cell); if (isChildrenSelectable(cell)) { for (int i = 0; i < model.getChildCount(cell); i++) s.add(model.getChild(cell, i)); } } return result.toArray(); } return graph.getRoots(); }
/** * 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; }
for (int i = 0; i < model.getChildCount(cell); i++) { Object child = model.getChild(cell, i); CellView view = mapper.getMapping(child, createDependentViews);
/** * Hook for subclassers to return the first or last visible port to replace * the current source or target port of the edge. This is called when groups * are collapsed for the edges that cross the group, ie. go from a child * cell to a cell which is outside the group. This implementation returns * the first port of the parent group if source is true, otherwise it * returns the last port of the parent group. */ protected Object getParentPort(Object edge, boolean source) { // Contains the parent of the parent vertex, eg. the group Object parent = getModel().getParent( (source) ? DefaultGraphModel.getSourceVertex(getModel(), edge) : DefaultGraphModel.getTargetVertex(getModel(), edge)); // Finds a port in the group int c = getModel().getChildCount(parent); for (int i = (source) ? c - 1 : 0; i < getModel().getChildCount(parent) && i >= 0; i += (source) ? -1 : +1) { Object child = getModel().getChild(parent, i); if (getModel().isPort(child)) { return child; } } return null; }
/** * Returns the default portview for the specified cell. The default * implementation returns the first floating port (ie. the first port that * does not define an offset) or <b>the </b> port, if there is only one * port. * * @param cell * the cell whose port is to be obtained * @return the port view of the specified cell */ public PortView getDefaultPortForCell(Object cell) { if (cell != null && !getModel().isEdge(cell)) { int childCount = getModel().getChildCount(cell); for (int i = 0; i < childCount; i++) { Object childCell = getModel().getChild(cell, i); CellView child = getGraphLayoutCache().getMapping(childCell, false); if (child instanceof PortView) { Point2D offset = GraphConstants.getOffset(child .getAllAttributes()); if (offset == null || childCount == 1) return (PortView) child; } } } return null; }
/** * Gets the targetPortAt attribute of the MarqueeHandler object * *@param point Description of Parameter *@return The targetPortAt value */ protected PortView getTargetPortAt(Point point) { // Find Cell at point (No scaling needed here) Object cell = getGraph().getFirstCellForLocation(point.x, point.y); // Loop Children to find PortView for (int i = 0; i < getGraph().getModel().getChildCount(cell); i++) { // Get Child from Model Object tmp = getGraph().getModel().getChild(cell, i); // Get View for Child using the Graph's View as a Cell Mapper tmp = getGraph().getGraphLayoutCache().getMapping(tmp, false); // If Child View is a Port View and not equal to First Port if (tmp instanceof PortView && tmp != firstPort) { // Return as PortView return (PortView) tmp; } } // No Port View found return getSourcePortAt(point); }