/** * Locates the nodes. */ private void locateNode() { int xPoint = BASE_POINT_X; int yPoint = BASE_POINT_Y; NodeList baseNodeList = getGraph().getBaseNodeList(); for (int i = 0; i < baseNodeList.size(); i++) { Node node = baseNodeList.getNode(i); NodeEx nodeEx = getNodeEx(node); Rectangle rect = nodeEx.getBlockBounds(); locateNode(nodeEx, xPoint, yPoint); if (ArrangeAngle.createInstance().getAngle() == ArrangeAngle.Direction.Vertical) { xPoint += rect.width + HORIZONTAL_SPACING; } else { yPoint += rect.height + VERTICAL_SPACING; } } }
/** * Adjusts the position of a node. * * @param nodeEx a node. * @param x x axis movement. * @param y y axis movement. */ private void adjustLocation(NodeEx nodeEx, int x, int y) { if (adjustStack.contains(nodeEx)) { return; } if (stack.contains(nodeEx)) { return; } adjustStack.push(nodeEx); nodeEx.getNode().x += x; nodeEx.getBlockBounds().x += x; nodeEx.getNode().y += y; nodeEx.getBlockBounds().y += y; NodeList childList = nodeEx.getChildren(); for (int i = 0; i < childList.size(); i++) { adjustLocation(getNodeEx(childList.getNode(i)), x, y); } adjustStack.pop(); }
/** * Returns the children those should be locate to the south. * * @return the children those should be locate to the south. */ @SuppressWarnings("unchecked") public NodeList getSouthNodes() { EdgeList edgeList = new EdgeList(); NodeList nodeList = new NodeList(); for (Object obj : node.outgoing) { if (!DcaseDirectedGraph.isEast((Node) ((Edge) obj).target)) { edgeList.add(obj); } } // sorts by the sibling order. if (edgeList.size() > 1) { Collections.sort(edgeList, new DcaseEditPartLayoutComparator()); } for (int i = 0; i < edgeList.size(); i++) { nodeList.add(((Edge) edgeList.get(i)).target); } return nodeList; }
/** * Returns the children those should be locate to the east. * * @return the children those should be locate to the east. */ @SuppressWarnings("unchecked") public NodeList getEastNodes() { EdgeList edgeList = new EdgeList(); NodeList nodeList = new NodeList(); for (Object obj : node.outgoing) { if (DcaseDirectedGraph.isEast((Node) ((Edge) obj).target)) { edgeList.add(obj); } } // sorts by the sibling order. if (edgeList.size() > 1) { Collections.sort(edgeList, new DcaseEditPartLayoutComparator()); } for (int i = 0; i < edgeList.size(); i++) { nodeList.add(((Edge) edgeList.get(i)).target); } return nodeList; }
/** * Collects the first node. * * @param node the node. */ private void collectBaseNode(Node node) { NodeEx nodeEx = getNodeEx(node); if (nodeEx != null) { if (stack.contains(nodeEx)) { nodeEx.setLooped(true); } return; } nodeEx = addNodeEx(node); stack.push(nodeEx); NodeList list = nodeEx.getChildren(); for (int i = 0; i < list.size(); i++) { Node child = list.getNode(i); collectBaseNode(child); } if (nodeEx.getParentCount() > 1) { list = nodeEx.getParent(); for (int i = 0; i < list.size(); i++) { Node parent = list.getNode(i); getRootParent(parent); } } nodeEx.setDepth(stack.size()); stack.pop(); }
/** * Calculates the preferred size of the area to show the specified node and its children. * * @param node the root node. */ private void calcBlockSize(Node node) { NodeEx nodeEx = getNodeEx(node); if (stack.contains(nodeEx)) { return; } stack.push(nodeEx); NodeList list = nodeEx.getChildren(); for (int i = 0; i < list.size(); i++) { Node child = list.getNode(i); NodeEx childEx = getNodeEx(child); if (nodeEx.getDepth() < childEx.getDepth()) { calcBlockSize(child); } } Dimension dim = nodeEx.calcBlockSize(); Rectangle rect = nodeEx.getBlockBounds(); rect.width = dim.width; rect.height = dim.height; stack.pop(); }
protected void applyResults(RelationshipPart relationshipPart) { Edge e = (Edge) partToNodesMap.get(relationshipPart); if (e == null) return; NodeList nodes = e.vNodes; PolylineConnection conn = (PolylineConnection) relationshipPart .getConnectionFigure(); if (nodes != null) { List<AbsoluteBendpoint> bends = new ArrayList<AbsoluteBendpoint>(); for (int i = 0; i < nodes.size(); i++) { Node vn = nodes.getNode(i); int x = vn.x; int y = vn.y; if (e.isFeedback()) { bends.add(new AbsoluteBendpoint(x, y + vn.height)); bends.add(new AbsoluteBendpoint(x, y)); } else { bends.add(new AbsoluteBendpoint(x, y)); bends.add(new AbsoluteBendpoint(x, y + vn.height)); } } conn.setRoutingConstraint(bends); } else { conn.setRoutingConstraint(Collections.EMPTY_LIST); } }
@SuppressWarnings("unchecked") private static void sortNodes(final NodeList nodes) { Collections.sort(nodes, new Comparator<Node>() { @Override public int compare(final Node v1, final Node v2) { final Long id1 = (Long) v1.data; final Long id2 = (Long) v2.data; final int isz1 = v1.incoming.size(); final int isz2 = v2.incoming.size(); final int osz1 = v1.outgoing.size(); final int osz2 = v2.outgoing.size(); // at least one node is a root if (isz1 == 0 || isz2 == 0) { // if both are root nodes, oldest first, otherwise, root first return isz1 == isz2 ? (int) (id1 - id2) : (isz1 - isz2); } // at least one node is a leaf if (osz1 == 0 || osz2 == 0) { // if both are leaf nodes, oldest first, otherwise, internal first return osz1 == osz2 ? (int) (id1 - id2) : (osz2 - osz1); } // both nodes are internal return (int) (id1 - id2); } }); }
private Node getNodeMap(NodeList nodes, DexClass type) { if (typeNodeMap.containsKey(type)) { return typeNodeMap.get(type); } Figure newfigure; newfigure = new ClassFigure(type); Node newnode = new Node(newfigure); typeNodeMap.put(type, newnode); nodes.add(newnode); return newnode; }
/** * Returns the first node that should be locate in south. * * @param nodeEx a node. * @return the first node that should be locate in south. */ private Node getWestOfSouth(NodeEx nodeEx) { Node node = null; NodeList list = nodeEx.getSouthNodes(); for (int i = 0; i < list.size(); i++) { Node child = (Node) list.get(i); NodeEx childEx = getNodeEx(child); if (nodeEx.getDepth() < childEx.getDepth()) { node = child; break; } } return node; }
/** * Returns the last child that should be locate in south. * * @param nodeEx a node. * @return the last child that should be locate in south. */ private Node getEastOfSouth(NodeEx nodeEx) { Node node = null; NodeList list = nodeEx.getSouthNodes(); for (int i = list.size() - 1; i >= 0; i--) { Node child = (Node) list.get(i); NodeEx childEx = getNodeEx(child); if (nodeEx.getDepth() < childEx.getDepth()) { node = child; break; } } return node; }
/** * Returns the first child that should be locate in east. * * @param nodeEx a node. * @return the first child that should be locate in east. */ private Node getNorthOfEast(NodeEx nodeEx) { Node node = null; NodeList list = nodeEx.getEastNodes(); for (int i = 0; i < list.size(); i++) { Node child = (Node) list.get(i); NodeEx childEx = getNodeEx(child); if (nodeEx.getDepth() < childEx.getDepth()) { node = child; break; } } return node; }
/** * Returns the last child that should be locate in east. * * @param nodeEx a node. * @return the last child that should be locate in east. */ private Node getSouthOfEast(NodeEx nodeEx) { Node node = null; NodeList list = nodeEx.getEastNodes(); for (int i = list.size() - 1; i >= 0; i--) { Node child = (Node) list.get(i); NodeEx childEx = getNodeEx(child); if (nodeEx.getDepth() < childEx.getDepth()) { node = child; break; } } return node; }
/** * Returns the size of the south. * * @param nodeEx a node. * @return the size of the south. */ public Dimension getSouthSize(NodeEx nodeEx) { Dimension dim = new Dimension(); NodeList list = nodeEx.getSouthNodes(); int count = 0; for (int i = 0; i < list.size(); i++) { Node child = list.getNode(i); NodeEx childEx = getNodeEx(child); if (nodeEx.getDepth() < childEx.getDepth()) { Rectangle childRect = childEx.getBlockBounds(); if (ArrangeAngle.createInstance().getAngle() == ArrangeAngle.Direction.Vertical) { dim.width += childRect.width; dim.height = Math.max(dim.height, childRect.height); } else { dim.width = Math.max(dim.width, childRect.width); dim.height += childRect.height; } count++; } } if (count > 1) { if (ArrangeAngle.createInstance().getAngle() == ArrangeAngle.Direction.Vertical) { dim.width += (HORIZONTAL_SPACING * (count - 1)); } else { dim.height += (VERTICAL_SPACING * (count - 1)); } } return dim; }
/** * Returns the size of the east. * * @param nodeEx a node. * @return the size of the east. */ public Dimension getEastSize(NodeEx nodeEx) { Dimension dim = new Dimension(); NodeList list = nodeEx.getEastNodes(); int count = 0; for (int i = 0; i < list.size(); i++) { Node child = list.getNode(i); NodeEx childEx = getNodeEx(child); if (nodeEx.getDepth() < childEx.getDepth()) { Rectangle childRect = childEx.getBlockBounds(); if (ArrangeAngle.createInstance().getAngle() == ArrangeAngle.Direction.Vertical) { dim.width = Math.max(dim.width, childRect.width); dim.height += childRect.height; } else { dim.width += childRect.width; dim.height = Math.max(dim.height, childRect.height); } count++; } } if (count > 1) { if (ArrangeAngle.createInstance().getAngle() == ArrangeAngle.Direction.Vertical) { dim.height += (VERTICAL_CONTEXT_SPACING * (count - 1)); } else { dim.width += (HORIZONTAL_CONTEXT_SPACING * (count - 1)); } } return dim; }
/** * Adds the first node. * * @param node the first node. */ @SuppressWarnings("unchecked") protected void addBaseNodeList(Node node) { NodeList list = graph.getBaseNodeList(); if (!list.contains(node)) { list.add(node); } }
/** * Returns the parents. * * @return the parents. */ @SuppressWarnings("unchecked") public NodeList getParent() { NodeList nodeList = new NodeList(); for (Object obj : node.incoming) { nodeList.add((Node) ((Edge) obj).source); } return nodeList; }
/** * Returns the children. * * @return Returns the children. */ @SuppressWarnings("unchecked") public NodeList getChildren() { NodeList nodeList = new NodeList(); for (Object obj : node.outgoing) { nodeList.add((Node) ((Edge) obj).target); } return nodeList; }
/** * Calculates the preferred size of the area to show the nodes and theirs children. */ private void calcBlockSize() { NodeList baseNodeList = getGraph().getBaseNodeList(); for (int i = 0; i < baseNodeList.size(); i++) { Node node = baseNodeList.getNode(i); calcBlockSize(node); } }
/** * Returns the list of first nodes. * * @return the first node. */ protected NodeList getBaseNodeList() { return graph.getBaseNodeList(); }
/** * Returns the all of the nodes in the graph. * * @return the all of the nodes in the graph. */ public NodeList getNodeList() { return graph.nodes; }
/** * Returns the first nodes. * * @return the first nodes. */ protected NodeList getBaseNodeList() { return baseNodeList; }