Branch libreoffice-5-0-4
[LibreOffice.git] / odk / examples / java / Inspector / HideableMutableTreeNode.java
blob4148b879ae28212af094d708b206a13e45b7c6d6
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 import javax.swing.tree.*;
21 /**
22 * <code>HideableMutableTreeNode</code> is a <code>DefaultMutableTreeNode</code>
23 * implementation that works with <code>HideableTreeModel</code>.
25 public class HideableMutableTreeNode extends DefaultMutableTreeNode {
26 /**
27 * The node is visible flag.
29 private boolean bIsvisible = true;
30 private static final String SDUMMY = "Dummy";
33 /**
34 * Creates a tree node that has no parent and no children, but which
35 * allows children.
37 public HideableMutableTreeNode() {
38 super();
41 /**
42 * Creates a tree node with no parent, no children, but which allows
43 * children, and initializes it with the specified user object.
45 * @param _userObject - an Object provided by the user that
46 * constitutes the node's data
48 public HideableMutableTreeNode(Object _userObject) {
49 super(_userObject);
52 /**
53 * Creates a tree node with no parent, no children, initialized with the
54 * specified user object, and that allows children only if specified.
56 * @param _userObject - an Object provided by the user that describes the node's data
57 * @param _ballowsChildren - if true, the node is allowed to have childnodes -- otherwise, it is always a leaf node
59 public HideableMutableTreeNode(Object _userObject, boolean _ballowsChildren) {
60 super(_userObject, _ballowsChildren);
63 /**
64 * Checks if the node is visible.
66 * @return true if the node is visible, else false
68 public boolean isVisible() {
69 return this.bIsvisible;
72 /**
73 * Sets if the node is visible.
75 * @param _bIsVisible true if the node is visible, else false
77 public void setVisible(boolean _bIsVisible) {
78 this.bIsvisible = _bIsVisible;
82 public void addDummyNode(){
83 removeDummyNode();
84 DefaultMutableTreeNode oDefaultMutableTreeNode = new DefaultMutableTreeNode(SDUMMY);
85 add(oDefaultMutableTreeNode);
90 public boolean removeDummyNode(){
91 boolean breturn = false;
92 if (getChildCount() == 1){
93 DefaultMutableTreeNode oDefaultMutableTreeNode = (DefaultMutableTreeNode) getChildAt(0);
94 if (oDefaultMutableTreeNode != null){
95 if (oDefaultMutableTreeNode.getUserObject().equals(SDUMMY)){
96 remove(0);
97 breturn = true;
101 return breturn;