int widestIndex = -1;
int index = -1;
double widestAmount = 0;
for (Iterator it = node.children.iterator(); it.hasNext();) {
index++;
StandardTreeNode n = (StandardTreeNode) it.next();
n.setDepth(node.getDepth() + 1);
double childWidth = n.width;
if (childWidth > widestAmount) {
widestAmount = childWidth;
widestIndex = index;
}
}
if (widestIndex >= 0) {
StandardTreeNode sub = (StandardTreeNode) node.children.get(widestIndex);
sub.leftContour.dx = 0;
sub.rightContour.dx = (sub.width - node.width) / 2 + verticalEdgeLeftInset + verticalEdgeRightInset;
node.leftContour.next = sub.leftContour;
node.rightContour.next = sub.rightContour;
} else {
StandardTreeNode sub = (StandardTreeNode) node.children.get(0);
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 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);
}