1 // *** HideableMutableTreeNode *** 2 import javax.swing.*; 3 import javax.swing.tree.*; 4 5 /** 6 * <code>HideableMutableTreeNode</code> is a <code>DefaultMutableTreeNode</code> 7 * implementation that works with <code>HideableTreeModel</code>. 8 */ 9 public class HideableMutableTreeNode extends DefaultMutableTreeNode { 10 /** 11 * The node is visible flag. 12 */ 13 public boolean bIsvisible = true; 14 private static final String SDUMMY = "Dummy"; 15 16 17 /** 18 * Creates a tree node that has no parent and no children, but which 19 * allows children. 20 */ 21 public HideableMutableTreeNode() { 22 super(); 23 } 24 25 /** 26 * Creates a tree node with no parent, no children, but which allows 27 * children, and initializes it with the specified user object. 28 * 29 * @param userObject - an Object provided by the user that 30 * constitutes the node's data 31 */ 32 public HideableMutableTreeNode(Object _userObject) { 33 super(_userObject); 34 } 35 36 /** 37 * Creates a tree node with no parent, no children, initialized with the 38 * specified user object, and that allows children only if specified. 39 * 40 * @param _userObject - an Object provided by the user that describes the node's data 41 * @param _ballowsChildren - if true, the node is allowed to have childnodes -- otherwise, it is always a leaf node 42 */ 43 public HideableMutableTreeNode(Object _userObject, boolean _ballowsChildren) { 44 super(_userObject, _ballowsChildren); 45 } 46 47 /** 48 * Checks if the node is visible. 49 * 50 * @return true if the node is visible, else false 51 */ 52 public boolean isVisible() { 53 return this.bIsvisible; 54 } 55 56 /** 57 * Sets if the node is visible. 58 * 59 * @param returns true if the node is visible, else false 60 */ 61 public void setVisible(boolean _bIsVisible) { 62 this.bIsvisible = _bIsVisible; 63 } 64 65 66 public void addDummyNode(){ 67 removeDummyNode(); 68 DefaultMutableTreeNode oDefaultMutableTreeNode = new DefaultMutableTreeNode(SDUMMY); 69 add(oDefaultMutableTreeNode); 70 71 } 72 73 74 public boolean removeDummyNode(){ 75 boolean breturn = false; 76 if (getChildCount() == 1){ 77 DefaultMutableTreeNode oDefaultMutableTreeNode = (DefaultMutableTreeNode) getChildAt(0); 78 if (oDefaultMutableTreeNode != null){ 79 if (oDefaultMutableTreeNode.getUserObject().equals(SDUMMY)){ 80 remove(0); 81 breturn = true; 82 } 83 } 84 } 85 return breturn; 86 } 87 88 }