/** * Obtains the tree node corresponding to the specified cell * * @param cell * the cell whose tree node is to be found * @return the matching tree node, if any */ protected StandardTreeNode getTreeNode(Object cell) { if (cell != null) { StandardTreeNode node = (StandardTreeNode) nodes.get(cell); if (node == null) { node = new StandardTreeNode(cell); nodes.put(cell, node); } return node; } return null; }
/** * Obtains the right most point on the sub-tree under the specified tree * node * * @param node * the start of the sub-tree to be analysed * @return the right-most tree node in the sub-tree */ protected StandardTreeNode getRightMostX(StandardTreeNode node) { double tmp = Double.MIN_VALUE; boolean hasChildren = false; StandardTreeNode mostRight = null; Iterator iter = node.getChildren(); while (iter.hasNext()) { StandardTreeNode child = (StandardTreeNode) iter.next(); double rightPos = child.x + child.getRightWidth(); if (rightPos > tmp) { mostRight = child; tmp = rightPos; } hasChildren = true; } if (mostRight != null) { return mostRight; } return (hasChildren) ? (StandardTreeNode) node.children.get(0) : node; }
/** * @return the height of this node */ public double getHeight() { if (children.isEmpty()) { return levelheight; } double height = 0; for (Iterator it = children.iterator(); it.hasNext();) { height = Math.max(height, ((StandardTreeNode) it.next()).getHeight()); } return height + levelDistance + levelheight; }
((StandardTreeNode) it.next()).setPosition(parent, nextLevelHeight); ((StandardTreeNode) it.next()).setPosition(new Point2D.Double(x + parent.getX(), y), nextLevelHeight); routeEdges(parent);
int leftMostX = root.getLeftWidth(); double leftMostTreeX = rootX - leftMostX; if (leftMostTreeX < treeBoundary + treeDistance) { int rightMostX = root.getRightWidth(); treeBoundary = rootX + rightMostX; int rightMostX = root.getRightWidth(); double rightMostTreeX = rootX - rightMostX; if (rightMostTreeX < treeBoundary + treeDistance) { int leftMostX = root.getLeftWidth(); treeBoundary = rootX + leftMostX; int topMostY = root.getLeftWidth(); double topMostTreeY = rootY - topMostY; if (topMostTreeY < treeBoundary + treeDistance) { int bottomMostY = root.getRightWidth(); treeBoundary = rootY + bottomMostY; int topMostY = root.getRightWidth(); double topMostTreeY = rootY - topMostY; if (topMostTreeY < treeBoundary + treeDistance) { int bottomMostY = root.getLeftWidth(); treeBoundary = rootY + bottomMostY + getRightMostX(root).height;
index++; StandardTreeNode n = (StandardTreeNode) it.next(); n.setDepth(node.getDepth() + 1); double childWidth = n.width; if (childWidth > widestAmount) { sub.setDepth(node.getDepth() + 1); layout(sub); for (Iterator it = node.children.iterator(); it.hasNext();) { StandardTreeNode n = (StandardTreeNode) it.next(); n.setDepth(node.getDepth() + 1); layout(n);
/** * Top-level method that performs actual layout of tree for a specific node. * Note this acts upon the internal tree node structure * * @param node * the tree node to be laid out */ protected void layout(StandardTreeNode node) { if (node.children.size() == 0) { // do nothing } else if (node.children.size() == 1) { StandardTreeNode sub = (StandardTreeNode) node.children.get(0); sub.setDepth(node.getDepth() + 1); layout(sub); sub.leftContour.dx = (sub.width - node.width) / 2; sub.rightContour.dx = (sub.width - node.width) / 2; node.leftContour.next = sub.leftContour; node.rightContour.next = sub.rightContour; } else { for (Iterator it = node.children.iterator(); it.hasNext();) { StandardTreeNode n = (StandardTreeNode) it.next(); n.setDepth(node.getDepth() + 1); layout(n); } join(node); } }
/** * Obtains the left most point on the sub-tree under the specified tree node * * @param node * the start of the sub-tree to be analysed * @return the left-most tree node in the sub-tree */ protected StandardTreeNode getLeftMostX(StandardTreeNode node) { double tmp = Double.MAX_VALUE; boolean hasChildren = false; StandardTreeNode mostLeft = null; Iterator iter = node.getChildren(); while (iter.hasNext()) { StandardTreeNode child = (StandardTreeNode) iter.next(); double leftPos = child.x - child.getLeftWidth(); if (leftPos < tmp) { mostLeft = child; tmp = leftPos; } hasChildren = true; } if (mostLeft != null) { return mostLeft; } return (hasChildren) ? (StandardTreeNode) node.children.get(0) : node; }
/** * Return the nodes of the level of this node * * @return collection of nodes of same level */ public List getNodesByLevel() { List level = new ArrayList(); for (Iterator it = children.iterator(); it.hasNext();) { List l2 = ((StandardTreeNode) it.next()).getNodesByLevel(); if (level.size() < l2.size()) { List tmp = level; level = l2; l2 = tmp; } for (int i = 0; i < l2.size(); i++) { ((List) level.get(i)).addAll((List) l2.get(i)); } } ArrayList node = new ArrayList(); node.add(this); level.add(0, node); return level; }
/** * Sets the heights of the level under the specified node * * @param root * the node under which level heights will be set */ protected void setLevelHeights(StandardTreeNode root) { List level = root.getNodesByLevel(); double max = 0.0; for (int i = 0; i < level.size(); i++) { List l = (List) level.get(i); for (int j = 0; j < l.size(); j++) { max = Math.max(max, ((StandardTreeNode) l.get(j)).height); } for (int j = 0; j < l.size(); j++) { ((StandardTreeNode) l.get(j)).levelheight = max; } max = 0; } }
/** * @param depth the depth to set */ public void setDepth(int depth) { super.setDepth(depth); if (depth >= vertexDepthOrientationSwitch) { verticalStyleChildren = true; } }