KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.awt.BorderLayout JavaDoc;
28 import java.awt.Dimension JavaDoc;
29 import java.util.*;
30 import javax.swing.*;
31 import javax.swing.tree.*;
32 import com.sun.jdi.*;
33 import com.sun.jdi.event.*;
34
35 public class AJThreadGroupTreePane
36     extends JScrollPane
37     implements StopListener,
38                VMListener,
39                ThreadListener {
40
41     //TODO: Should be private, but keep it public now for testing
42
public AJThreadGroupTree tree = null;
43
44     private GUIDebugger guid;
45
46     public AJThreadGroupTreePane(AJThreadGroupTree tree) {
47         super();
48         this.tree = tree;
49         addTree();
50     }
51
52     public AJThreadGroupTreePane(GUIDebugger guid) {
53         this(new AJThreadGroupTree());
54         this.guid = guid;
55         guid.getDebugger().addStopListener(this);
56         guid.getDebugger().addVMListener(this);
57         guid.getDebugger().addThreadListener(this);
58         
59     }
60
61     public boolean add(ThreadReference ref) {
62         return tree.add(ref);
63     }
64
65     public boolean remove(ThreadReference ref) {
66         return tree.remove(ref);
67     }
68
69     public void clear() {
70         tree.clear();
71     }
72
73     public void modernizeTree() {
74         try {
75             tree.modernize();
76         } catch (Exception JavaDoc e) { AJUtil.ex(e);
77         }
78     }
79
80     public void invalidateAllThreads() {
81         tree.invalidateAllThreads();
82     }
83
84     public void expandToFrame(StackFrame frame) {
85         guid.getGui().showThreadPane();
86         tree.expandToFrame(frame);
87         centerTreeSelection();
88     }
89
90     public void expandToLocals(StackFrame frame) {
91         guid.getGui().showThreadPane();
92         tree.expandToLocals(frame);
93         centerTreeSelection();
94     }
95
96     protected void centerTreeSelection() {
97 // int visibleAmount = verticalScrollBar.getVisibleAmount();
98
// int unitIncrement = verticalScrollBar.getUnitIncrement();
99
// int min = verticalScrollBar.getMinimum();
100
// int max = verticalScrollBar.getMaximum();
101
// int rowCount = tree.getRowCount();
102
// int[] selections = tree.getSelectionRows();
103
// int selection = -1;
104
// if (selections != null && selections.length > 0) {
105
// selection = selections[0];
106
// }
107
// System.out.println("visibleAmount:" + visibleAmount);
108
// System.out.println("unitIncrement:" + unitIncrement);
109
// System.out.println("min:" + min);
110
// System.out.println("max:" + max);
111
// System.out.println("rowCount:" + rowCount);
112
// System.out.println("selection:" + selection);
113
// if (selection != -1) {
114

115 // }
116
}
117
118     public void expandToValue(Value value, String JavaDoc name) {
119         tree.expandToValue(value, name);
120         centerTreeSelection();
121     }
122
123     public AJThreadGroupTree getTree() {
124         return tree;
125     }
126
127     private void addTree() {
128         getViewport().add(tree, BorderLayout.CENTER);
129     }
130
131     /* VMListener */
132     public void vmDeathEvent(VMDeathEvent e) {
133         tree.clear();
134     }
135     public void vmDisconnectEvent(VMDisconnectEvent e) {
136         tree.clear();
137     }
138     public void vmStartEvent(VMStartEvent e) {
139         try {
140             Iterator iter = ComponentRepository.vm().allThreads().iterator();
141             while (iter.hasNext()) {
142                 tree.add((ThreadReference) iter.next());
143             }
144         } catch (Exception JavaDoc ee) {}
145         modernizeTree();
146     }
147
148     /* StopListener */
149     public void accessWatchpointEvent(AccessWatchpointEvent e) {
150         modernizeTree();
151     }
152     public void breakpointEvent(BreakpointEvent e) {
153         modernizeTree();
154     }
155     public void exceptionEvent(ExceptionEvent e) {
156         modernizeTree();
157     }
158     public void modificationWatchpointEvent(ModificationWatchpointEvent e) {
159         modernizeTree();
160     }
161     public void stepEvent(StepEvent e) {
162         modernizeTree();
163     }
164
165     /* ThreadListener */
166     public void threadDeathEvent(ThreadDeathEvent e) {
167         tree.remove(e.thread());
168     }
169     public void threadStartEvent(ThreadStartEvent e) {
170         tree.add(e.thread());
171     }
172
173     public static String JavaDoc d() { return "Thread Group Tree Pane"; }
174     public String JavaDoc toString() { return d(); }
175 }
176
Popular Tags