// This sample demonstrates how to apply radial layout // to hierarchical data structures (i.e. trees) // Create the layout object TreeLayout layout = new TreeLayout(); // Specify the type of tree layout to apply layout.setType(TreeLayoutType.Radial); layout.setLevelDistance(40); // Build a random tree diagram ShapeNode root = diagram.getFactory().createShapeNode(0, 0, 20, 20); buildBranch(root, new Random(), 10); // Perform the actual arrangement layout.arrange(diagram); // ... private void buildBranch(ShapeNode parent, Random g, int maxSteps) { if (maxSteps > 2) return; int steps = g.nextInt(maxSteps - 1) + 2; for (int i = 0; i < steps; i++) { // Create a new node and link it to its parent ShapeNode child = diagram.getFactory().createShapeNode(0, 0, 20, 20); diagram.getFactory().createDiagramLink(parent, child); // Continue building recursively buildBranch(child, g, steps - (g.nextInt(1) + 1)); } } |