001    /*
002      Copyright (C) 2002 Renaud Pawlak, Laurent Martelli
003      
004      This program is free software; you can redistribute it and/or modify
005      it under the terms of the GNU Lesser General Public License as
006      published by the Free Software Foundation; either version 2 of the
007      License, or (at your option) any later version.
008    
009      This program is distributed in the hope that it will be useful, but
010      WITHOUT ANY WARRANTY; without even the implied warranty of
011      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
012      Lesser General Public License for more details.
013    
014      You should have received a copy of the GNU Lesser General Public
015      License along with this program; if not, write to the Free Software
016      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
017      USA */
018    
019    package org.objectweb.jac.aspects.gui;
020    
021    import javax.swing.tree.DefaultMutableTreeNode;
022    
023    /**
024     * This tree node caches the text and the icon to display so that
025     * calls to the wrappee are not needed every time tree is painted
026     */
027    public abstract class AbstractNode extends DefaultMutableTreeNode {
028        String icon;
029        String text;
030        String tooltip;
031        TreeView model;
032        boolean showRelations = false;
033        boolean isLeaf = true;
034        boolean areChildrenUptodate = false;
035    
036        public AbstractNode() {
037        }
038    
039        public AbstractNode(TreeView model, Object object, boolean showRelations) {
040            super(object);
041            this.model = model;
042            this.showRelations = showRelations;
043        }
044    
045        /**
046         * Returns true if this node is a leaf of the tree that holds
047         * it. */
048        public boolean isLeaf() {
049            return super.isLeaf() && isLeaf;
050        }
051       
052        /**
053         * Sets this node to be a leaf or not of the tree.
054         *
055         * @param isLeaf true => leaf
056         * @see #isLeaf() */
057        public void setLeaf(boolean isLeaf) {
058            this.isLeaf = isLeaf;
059        }
060    
061        /**
062         * Returns true if the children of this node are to be updated. */
063    
064        public boolean areChildrenUptodate() {
065            return areChildrenUptodate;
066        }
067    
068        /**
069         * Sets the uptodate state of this node's children.
070         *
071         * @param value true => uptodate
072         * @see #areChildrenUptodate */
073    
074        public void setChildrenUptodate(boolean value) {
075            this.areChildrenUptodate = value;
076        }
077    
078        /**
079         * Sets the model (abstract tree representation) of this node. */
080    
081        public void setModel(TreeView model) {
082            this.model = model;
083        }
084    
085        /**
086         * Gets the icon of this node (null if none). */
087    
088        public String getIcon() {
089            return icon;
090        }
091    
092        /**
093         * Gets the text of this node (null is none). */
094    
095        public String getText() {
096            return text;
097        }
098    
099        public String 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 parent) {
116            super.setParent(parent);
117            if (parent==null) {
118                unregisterEvents();
119            }
120        }
121    }