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