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