1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 // *** HideableMutableTreeNode *** 23 import javax.swing.*; 24 import javax.swing.tree.*; 25 26 /** 27 * <code>HideableMutableTreeNode</code> is a <code>DefaultMutableTreeNode</code> 28 * implementation that works with <code>HideableTreeModel</code>. 29 */ 30 public class HideableMutableTreeNode extends DefaultMutableTreeNode { 31 /** 32 * The node is visible flag. 33 */ 34 public boolean bIsvisible = true; 35 private static final String SDUMMY = "Dummy"; 36 37 38 /** 39 * Creates a tree node that has no parent and no children, but which 40 * allows children. 41 */ HideableMutableTreeNode()42 public HideableMutableTreeNode() { 43 super(); 44 } 45 46 /** 47 * Creates a tree node with no parent, no children, but which allows 48 * children, and initializes it with the specified user object. 49 * 50 * @param userObject - an Object provided by the user that 51 * constitutes the node's data 52 */ HideableMutableTreeNode(Object _userObject)53 public HideableMutableTreeNode(Object _userObject) { 54 super(_userObject); 55 } 56 57 /** 58 * Creates a tree node with no parent, no children, initialized with the 59 * specified user object, and that allows children only if specified. 60 * 61 * @param _userObject - an Object provided by the user that describes the node's data 62 * @param _ballowsChildren - if true, the node is allowed to have childnodes -- otherwise, it is always a leaf node 63 */ HideableMutableTreeNode(Object _userObject, boolean _ballowsChildren)64 public HideableMutableTreeNode(Object _userObject, boolean _ballowsChildren) { 65 super(_userObject, _ballowsChildren); 66 } 67 68 /** 69 * Checks if the node is visible. 70 * 71 * @return true if the node is visible, else false 72 */ isVisible()73 public boolean isVisible() { 74 return this.bIsvisible; 75 } 76 77 /** 78 * Sets if the node is visible. 79 * 80 * @param returns true if the node is visible, else false 81 */ setVisible(boolean _bIsVisible)82 public void setVisible(boolean _bIsVisible) { 83 this.bIsvisible = _bIsVisible; 84 } 85 86 addDummyNode()87 public void addDummyNode(){ 88 removeDummyNode(); 89 DefaultMutableTreeNode oDefaultMutableTreeNode = new DefaultMutableTreeNode(SDUMMY); 90 add(oDefaultMutableTreeNode); 91 92 } 93 94 removeDummyNode()95 public boolean removeDummyNode(){ 96 boolean breturn = false; 97 if (getChildCount() == 1){ 98 DefaultMutableTreeNode oDefaultMutableTreeNode = (DefaultMutableTreeNode) getChildAt(0); 99 if (oDefaultMutableTreeNode != null){ 100 if (oDefaultMutableTreeNode.getUserObject().equals(SDUMMY)){ 101 remove(0); 102 breturn = true; 103 } 104 } 105 } 106 return breturn; 107 } 108 109 }