KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > gui > AbstractNode


1 /*
2   Copyright (C) 2002 Renaud Pawlak, Laurent Martelli
3   
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful, but
10   WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public
15   License along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17   USA */

18
19 package org.objectweb.jac.aspects.gui;
20
21 import javax.swing.tree.DefaultMutableTreeNode JavaDoc;
22
23 /**
24  * This tree node caches the text and the icon to display so that
25  * calls to the wrappee are not needed every time tree is painted
26  */

27 public abstract class AbstractNode extends DefaultMutableTreeNode JavaDoc {
28     String JavaDoc icon;
29     String JavaDoc text;
30     String JavaDoc tooltip;
31     TreeView model;
32     boolean showRelations = false;
33     boolean isLeaf = true;
34     boolean areChildrenUptodate = false;
35
36     public AbstractNode() {
37     }
38
39     public AbstractNode(TreeView model, Object JavaDoc object, boolean showRelations) {
40         super(object);
41         this.model = model;
42         this.showRelations = showRelations;
43     }
44
45     /**
46      * Returns true if this node is a leaf of the tree that holds
47      * it. */

48     public boolean isLeaf() {
49         return super.isLeaf() && isLeaf;
50     }
51    
52     /**
53      * Sets this node to be a leaf or not of the tree.
54      *
55      * @param isLeaf true => leaf
56      * @see #isLeaf() */

57     public void setLeaf(boolean isLeaf) {
58         this.isLeaf = isLeaf;
59     }
60
61     /**
62      * Returns true if the children of this node are to be updated. */

63
64     public boolean areChildrenUptodate() {
65         return areChildrenUptodate;
66     }
67
68     /**
69      * Sets the uptodate state of this node's children.
70      *
71      * @param value true => uptodate
72      * @see #areChildrenUptodate */

73
74     public void setChildrenUptodate(boolean value) {
75         this.areChildrenUptodate = value;
76     }
77
78     /**
79      * Sets the model (abstract tree representation) of this node. */

80
81     public void setModel(TreeView model) {
82         this.model = model;
83     }
84
85     /**
86      * Gets the icon of this node (null if none). */

87
88     public String JavaDoc getIcon() {
89         return icon;
90     }
91
92     /**
93      * Gets the text of this node (null is none). */

94
95     public String JavaDoc getText() {
96         return text;
97     }
98
99     public String JavaDoc getToolTip() {
100         return tooltip;
101     }
102
103     /**
104      * Unregister from all update events
105      */

106     public abstract void unregisterEvents();
107
108     /**
109      * Redefines the DefaultMutableTreeNode.setParent in order to
110      * unregister the update events.
111      *
112      * @param parent the parent node
113      * @see #unregisterEvents() */

114
115     public void setParent(DefaultMutableTreeNode JavaDoc parent) {
116         super.setParent(parent);
117         if (parent==null) {
118             unregisterEvents();
119         }
120     }
121 }
122
Popular Tags