KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > debugger > gui > AJTree


1 /* -*- Mode: JDE; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * This file is part of the debugger and core tools for the AspectJ(tm)
4  * programming language; see http://aspectj.org
5  *
6  * The contents of this file are subject to the Mozilla Public License
7  * Version 1.1 (the "License"); you may not use this file except in
8  * compliance with the License. You may obtain a copy of the License at
9  * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is AspectJ.
17  *
18  * The Initial Developer of the Original Code is Xerox Corporation. Portions
19  * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
20  * All Rights Reserved.
21  */

22
23 package org.aspectj.debugger.gui;
24
25 import org.aspectj.debugger.base.*;
26
27 import com.sun.jdi.*;
28 import java.awt.Dimension JavaDoc;
29 import java.util.List JavaDoc;
30 import java.util.*;
31 import javax.swing.*;
32 import javax.swing.tree.*;
33
34 /**
35  * An extension of JTree providing very little else.
36  */

37 public abstract class AJTree extends JTree {
38
39     public AJTree(TreeModel model) {
40         super(model);
41         init();
42     }
43
44     /**
45      * Calls init to construct an empty tree.
46      */

47     public AJTree() {
48         init();
49     }
50
51     /**
52      * Constructs a new tree with AJRootNode <code>root<\code>.
53      *
54      * @param root new root.
55      */

56     public AJTree(AJRootNode root) {
57         super(root);
58         init();
59     }
60
61     /**
62      * Returns the root.
63      *
64      * @return the root.
65      */

66     public AJRootNode getRoot() {
67         return (AJRootNode) getModel().getRoot();
68     }
69
70     /**
71      * Sets the root. The node <code>root<\code> must be an instance of
72      * AJDBRootNode so that it keeps with the look of all the roots.
73      *
74      * @param root the new root.
75      */

76     public void setRoot(AJRootNode root) {
77         ((DefaultTreeModel) getModel()).setRoot(root);
78     }
79
80     //XXX Need a better way
81
/**
82      * Expands the tree fully.
83      */

84     protected void expand() {
85         int row = 0;
86         while (row < this.getRowCount()) {
87             expandRow(row++);
88         }
89     }
90
91 // public void expandPath(TreePath path) {
92
// System.out.println("expandPath");
93
// super.expandPath(path);
94
// System.out.println("expandPath DONE");
95
// }
96
//
97
// public void treeDidChange() {
98
// System.out.println("treeDidChange");
99
// super.treeDidChange();
100
// System.out.println("treeDidChange DONE");
101
// }
102
//
103
// public void revalidate() {
104
// System.out.println("revalidate");
105
// super.revalidate();
106
// System.out.println("revalidate DONE");
107
// }
108
//
109
// public void repaint() {
110
// System.out.println("repaint");
111
// super.repaint();
112
// System.out.println("repaint DONE");
113
// }
114

115
116     /**
117      * Override this method to clear this tree to the extent desired.
118      */

119     public abstract void clear();
120
121     public void reloadAll() {
122         //XXX Hack, reload all the leaf nodes
123
DefaultTreeModel model = (DefaultTreeModel) getModel();
124         Enumeration nodes = ((DefaultMutableTreeNode) model.getRoot()).breadthFirstEnumeration();
125         while (nodes.hasMoreElements()) {
126             DefaultMutableTreeNode node = (DefaultMutableTreeNode) nodes.nextElement();
127             if (node.isLeaf() || ((AJTreeNode) node).isString()) {
128                 model.reload(node);
129             }
130         }
131     }
132
133     /**
134      * A threaded upateUI.
135      */

136     public final void modernize() {
137         Runnable JavaDoc update = new Runnable JavaDoc() {
138                 public void run() {
139                     try {
140                         doModernize();
141                     } catch (VMDisconnectedException vmde) {
142                     }
143                 }
144             };
145         if (SwingUtilities.isEventDispatchThread()) {
146             update.run();
147         } else {
148             SwingUtilities.invokeLater(update);
149         }
150         //((DefaultTreeModel) getModel()).reload(getRoot());
151
}
152
153     public void doModernize() {
154         AJTree.super.updateUI();
155     }
156
157     /**
158      * Called by the constructor the initialize the tree. This contains common
159      * characteristics used by many trees, and was, for convenience, put in
160      * this class. If other trees look much different we'll take it out of
161      * here and let all the trees configure themselves completely.
162      */

163     protected final void init() {
164         putClientProperty("JTree.lineStyle", "Angled");
165         setEditable(false);
166         //setShowsRootHandles(true);
167
setMinimumSize(new Dimension JavaDoc(100,200));
168         getSelectionModel().setSelectionMode
169             (TreeSelectionModel.SINGLE_TREE_SELECTION);
170         addTreeWillExpandListener(new AJTreeWillExpandListener(this));
171         addTreeExpansionListener(new AJTreeExpansionListener(this));
172         //this.setCellRenderer(new AJTreeCellRenderer());
173
}
174 }
175
Popular Tags