/** * Lays out a Moen in the left-right orientation * * @param node * the current node being laid out * @param off_x * x-axis offset * @param off_y * y-axis offset */ protected void leftRightNodeLayout(CompactTreeNode node, double off_x, double off_y) { CompactTreeNode child, s; double siblingOffset; node.x += off_x + node.offsetX; node.y += off_y + node.offsetY; child = node.child; // topmost child if (child != null) { leftRightNodeLayout(child, node.x, node.y); s = child.sibling; siblingOffset = node.y + child.offsetY; while (s != null) { leftRightNodeLayout(s, node.x + child.offsetX, siblingOffset); siblingOffset += s.offsetY; s = s.sibling; } } }
/** * Top-level layout method for Moen * * @param root * the root node of the tree */ protected void layoutTree(CompactTreeNode root) { // kick off Moen's algorithm layout(root); Rectangle2D rect = graph.getBounds(root.getCell()); double rootPositionX = rect.getX(); double rootPositionY = rect.getY(); switch (orientation) { case SwingConstants.WEST: leftRightNodeLayout(root, rootPositionX, rootPositionY); break; case SwingConstants.NORTH: upDownNodeLayout(root, null, rootPositionX, rootPositionY); break; default: leftRightNodeLayout(root, rootPositionX, rootPositionY); } }