1 15 16 package com.jdon.strutsutil.treeview; 17 18 import java.io.Serializable ; 19 import java.util.*; 20 21 32 33 public class TreeControl implements Serializable { 34 35 public static boolean init = true; private ViewNode selected = null; 38 private ViewNode root = null; 39 private HashMap registry = new HashMap(); 40 41 42 public TreeControl(ViewNode root) { 43 this.root = root; 44 root.setTree(this); 45 root.setLast(true); 46 } 47 48 public ViewNode getRoot() { 49 return (this.root); 50 } 51 52 53 public ViewNode findNode(String key) { 54 return ( (ViewNode) registry.get(key)); 55 } 56 57 public void selectNode(String key) { 58 if (selected != null) { 59 selected.setSelected(false); 60 selected = null; 61 } 62 selected = findNode(key); 63 if (selected != null) 64 selected.setSelected(true); 65 66 } 67 68 public void addNode(ViewNode node) throws 69 IllegalArgumentException { 70 node.setTree(this); 71 registry.put(node.getKey(), node); 72 } 73 74 public int getTreeWidth() { 75 if (root == null) 76 return (0); 77 else 78 return (getWidth(root)); 79 80 } 81 82 89 public int getWidth(ViewNode node) { 90 int width = node.getDepth(); 91 ViewNode children[] = node.findChildren(); 92 for (int i = 0; i < children.length; i++) { 93 int current = getWidth(children[i]); 94 if (current > width) 95 width = current; 96 } 97 return (width); 98 } 99 100 101 } 102 | Popular Tags |