/** * Obtains the mapped node from the internal tree representation used from * the cell specified * * @param cell * the cell whose <code>TreeLayoutNode</code> is to be found * @param createIfNotPresent * whether or not to create the internal node if it doesn't * already exist * @return the internal node representation of the specified cell */ protected CompactTreeNode getTreeLayoutNode(Object cell, boolean createIfNotPresent) { CompactTreeNode node = (CompactTreeNode) nodes.get(cell); if (node == null && createIfNotPresent) { node = new CompactTreeNode(cell); nodes.put(cell, node); } return node; }
/** * Sets the new positions of the cells in the graph based on the information * from the interal tree nodes. Note this doesn't apply the position to the * actual graph, only stores the bounds values to be applied later * * @param treeLayoutNodes * the nodes of the internal tree structure that describe the new * tree layout */ protected void dispatchResult(Collection treeLayoutNodes) { Iterator it = treeLayoutNodes.iterator(); while (it.hasNext()) { CompactTreeNode node = (CompactTreeNode) it.next(); graph.setLocation(node.getCell(), node.x, node.y); } }
/** * 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); } }