KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.aspectj.util.gui.*;
27
28 import java.awt.*;
29 import java.awt.event.*;
30 import java.io.*;
31 import java.util.*;
32 import java.util.List JavaDoc;
33 import javax.swing.*;
34 import com.sun.jdi.*;
35 import com.sun.jdi.event.*;
36 import com.sun.jdi.event.Event;
37
38 public class ComponentDirector extends AJCenteredJFrame {
39
40     PrintStream out = System.out;
41
42     static final int THREAD_GROUP_TREE_PANE_HEIGHT = 550;
43     static final int STACK_TABLE_PANE_HEIGHT = 150;
44
45     static final int RIGHT_UPPER_HEIGHT = 380;
46     static final int OUTPUT_TEXT_AREA_HEIGHT = 150;
47     static final int ENV_TEXT_AREA_HEIGHT = 150;
48     static final int COMMAND_LINE_HEIGHT = 20;
49     static final int RIGHT_LOWER_HEIGHT = OUTPUT_TEXT_AREA_HEIGHT +
50                                                           ENV_TEXT_AREA_HEIGHT +
51                                                           COMMAND_LINE_HEIGHT;
52
53     static final int SOURCE_TREE_PANE_WIDTH = 200;
54     static final int TREE_TABBED_PANE_WIDTH = 200;
55     static final int SOURCE_PANE_WIDTH = 400;
56
57     static final int LEFT_PANEL_WIDTH = 400;
58     static final int RIGHT_PANEL_WIDTH = SOURCE_TREE_PANE_WIDTH +
59                                                           SOURCE_PANE_WIDTH;
60
61     static final int COMMAND_LINE_WIDTH = RIGHT_PANEL_WIDTH;
62
63     static final int DIVIDER_SIZE = 5;
64
65     static final Dimension THREAD_GROUP_TREE_PANE_DIM
66         = new Dimension(LEFT_PANEL_WIDTH, THREAD_GROUP_TREE_PANE_HEIGHT);
67     static final Dimension STACK_TABLE_PANE_DIM
68         = new Dimension(LEFT_PANEL_WIDTH, STACK_TABLE_PANE_HEIGHT);
69     static final Dimension SOURCE_TREE_PANE_DIM
70         = new Dimension(SOURCE_TREE_PANE_WIDTH, RIGHT_UPPER_HEIGHT);
71     static final Dimension TREE_TABBED_PANE_DIM
72         = new Dimension(TREE_TABBED_PANE_WIDTH, RIGHT_UPPER_HEIGHT);
73     static final Dimension SOURCE_PANE_DIM
74         = new Dimension(SOURCE_PANE_WIDTH, RIGHT_UPPER_HEIGHT);
75     static final Dimension OUTPUT_TEXT_AREA_DIM
76         = new Dimension(RIGHT_PANEL_WIDTH, OUTPUT_TEXT_AREA_HEIGHT);
77     static final Dimension ENV_TEXT_AREA_DIM
78         = new Dimension(RIGHT_PANEL_WIDTH, ENV_TEXT_AREA_HEIGHT);
79     static final Dimension COMMAND_LINE_DIM
80         = new Dimension(COMMAND_LINE_WIDTH, COMMAND_LINE_HEIGHT);
81     static final Dimension COMMAND_OUTPUT_PANEL_DIM
82         = new Dimension(RIGHT_PANEL_WIDTH, RIGHT_LOWER_HEIGHT);
83
84
85     protected ComponentDirector() {
86         super();
87     }
88
89     protected ComponentDirector(String JavaDoc title, String JavaDoc mode) {
90         super(title);
91         Modes.setMode(mode);
92     }
93
94     public ComponentDirector(String JavaDoc[] args) {
95         this(args, null);
96     }
97
98         protected OutputTextArea outputTextArea = null;
99         protected EnvTextArea envTextArea = null;
100         public AbstractTextArea getOutputTextArea() { return outputTextArea; }
101         public AbstractTextArea getEnvTextArea() { return envTextArea; }
102
103     public ComponentDirector(String JavaDoc[] args, WindowListener windowListener) {
104         super("AspectJ Debugger");
105         Modes.setMode(Modes.GUI);
106         ComponentRepository.init(this, args);
107
108         AJMenuBar menuBar = ComponentRepository.getMenuBar();
109         setJMenuBar(menuBar);
110
111         StackTablePane stackTablePane = ComponentRepository.getStackTablePane();
112         stackTablePane.setPreferredSize(STACK_TABLE_PANE_DIM);
113
114         JPanel commandLine = new CommandLinePanel(true);
115         commandLine.setPreferredSize(COMMAND_LINE_DIM);
116
117         OutputTextArea outputTextArea = ComponentRepository.getOutputTextArea();
118         outputTextArea.setPreferredSize(OUTPUT_TEXT_AREA_DIM);
119
120         EnvTextArea envTextArea = ComponentRepository.getEnvTextArea();
121         envTextArea.setPreferredSize(ENV_TEXT_AREA_DIM);
122
123         //SourceTreePane sourceTreePane = ComponentRepository.getSourceTreePane();
124
BreakpointTreePane breakpointTreePane = ComponentRepository.getBreakpointTreePane();
125         //ClassTreePane classTreePane = ComponentRepository.getClassTreePane();
126
VariablesTreePane variablesTreePane = ComponentRepository.getVariablesTreePane();
127         JTabbedPane treeTabbedPane = new JTabbedPane(JTabbedPane.BOTTOM);
128         //treeTabbedPane.addTab("Sources", null, sourceTreePane);
129
//treeTabbedPane.addTab("Classes", null, classTreePane);
130
treeTabbedPane.addTab("Breaks", null, breakpointTreePane);
131         treeTabbedPane.addTab("Variables", null, variablesTreePane);
132         treeTabbedPane.setPreferredSize(TREE_TABBED_PANE_DIM);
133
134         AbstractSourcePane sourcePane = ComponentRepository.getSourcePane();
135         sourcePane.setPreferredSize(SOURCE_PANE_DIM);
136
137         AJThreadGroupTreePane threadGroupTreePane = ComponentRepository.getThreadGroupTreePane();
138         threadGroupTreePane.setPreferredSize(THREAD_GROUP_TREE_PANE_DIM);
139
140         AJToolBar toolbar = ComponentRepository.getToolBar();
141
142         JSplitPane splitMain = null;
143         JSplitPane splitLeft = null;
144         JSplitPane splitRight = null;
145         JSplitPane splitUpperRight = null;
146         JSplitPane splitLowerRight = null;
147         JPanel commandOutputPanel = null;
148
149         splitUpperRight = makeSplit(JSplitPane.HORIZONTAL_SPLIT,
150                                     treeTabbedPane,
151                                     sourcePane);
152
153         commandOutputPanel = new JPanel();
154         commandOutputPanel.setLayout(new BorderLayout());
155         commandOutputPanel.add(envTextArea, BorderLayout.CENTER);
156         commandOutputPanel.add(commandLine, BorderLayout.SOUTH);
157         commandOutputPanel.setPreferredSize(COMMAND_OUTPUT_PANEL_DIM);
158
159
160         splitRight = makeSplit(JSplitPane.VERTICAL_SPLIT,
161                                splitUpperRight,
162                                commandOutputPanel);
163         splitLeft = makeSplit(JSplitPane.VERTICAL_SPLIT,
164                               threadGroupTreePane,
165                               stackTablePane);
166         splitMain = makeSplit(JSplitPane.HORIZONTAL_SPLIT,
167                               splitLeft,
168                               splitRight);
169
170         getContentPane().add(splitMain, BorderLayout.CENTER);
171         JPanel bottomFiller = new JPanel();
172         bottomFiller.setLayout(new BoxLayout(bottomFiller, BoxLayout.X_AXIS));
173         bottomFiller.add(Box.createHorizontalGlue());
174         bottomFiller.add(toolbar);
175         getContentPane().add(toolbar, BorderLayout.SOUTH);
176
177         if (windowListener != null) {
178             addWindowListener(windowListener);
179         } else {
180             addWindowListener(getDefaultWindowListener());
181         }
182         pack();
183         setVisible(wantsToBeVisible());
184     }
185
186     /** Override this to provide your own window closing stuff. */
187         protected WindowListener getDefaultWindowListener() {
188             return new WindowAdapter() {
189                     public void windowClosing(WindowEvent e) {
190                         //XXX
191
try {
192                             new org.aspectj.debugger.request.QuitRequest(getDebugger()).go();
193                         } catch (Throwable JavaDoc t) {
194                             getDebugger().quit();
195                         }
196                         System.exit(0);
197                     }
198                 };
199         }
200
201     protected boolean wantsToBeVisible() { return true; }
202
203     private JSplitPane makeSplit(int placement, Component one, Component two) {
204         JSplitPane sp = new JSplitPane(placement, one, two);
205         sp.setDividerSize(DIVIDER_SIZE);
206         return sp;
207     }
208
209
210         public GUIDebugger getGUIDebugger() {
211             return ComponentRepository.getGUIDebugger();
212         }
213
214         public Debugger getDebugger() {
215             return getGUIDebugger().getDebugger();
216         }
217
218
219     public void go() {
220         getGUIDebugger().go();
221     }
222
223     public void setPrintStream(PrintStream out) {
224         this.out = out;
225     }
226
227         public void restoreStreams() {
228             if (outputTextArea != null) outputTextArea.shutDown();
229             if (envTextArea != null) envTextArea.shutDown();
230         }
231
232     public void shutDown() {
233         restoreStreams();
234     }
235
236     public PrintStream getPrintStream() {
237         return out;
238     }
239
240     public String JavaDoc toString() { return d(); }
241         public static String JavaDoc d() { return "Component Director"; }
242
243     /**
244      * Implement this to show the thread pane.
245      * It's called before the super.whereCommand().
246      */

247      public /*abstract*/ void showThreadPane() {}
248
249         public void makeTopLevel() {
250             requestFocus();
251         }
252 }
253
Popular Tags