KickJava   Java API By Example, From Geeks To Geeks.

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


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.debugger.ide.*;
27 import org.aspectj.util.gui.*;
28
29 import com.sun.jdi.*;
30 import java.awt.*;
31 import java.awt.event.*;
32 import java.io.*;
33 import java.util.*;
34 import javax.swing.*;
35
36 public class ComponentRepository {
37
38     private static StackTablePane stackTablePane = null;
39     private static CommandLine commandLine = null;
40     private static OutputTextArea outputTextArea = null;
41     private static EnvTextArea envTextArea = null;
42     private static AbstractSourcePane sourcePane = null;
43 // private static SourceTreePane sourceTreePane = null;
44
private static AJThreadGroupTreePane threadGroupTreePane = null;
45     private static BreakpointTreePane breakpointTreePane = null;
46     private static ComponentDirector gui = null;
47     private static AJToolBar toolbar = null;
48 // private static ClassTreePane classTreePane = null;
49
private static AJMenuBar menuBar = null;
50     private static ColorChangingLabel statusLabel = null;
51     private static GUIDebugger guiDebugger = null;
52     private static AJDebugger debugger = null;
53     private static WatchpointTreePane watchpointTreePane = null;
54     private static VariablesTreePane variablesTreePane = null;
55
56     static boolean debug = false;
57     static void db(Object JavaDoc o) {
58         if (debug) {
59             System.err.println("<DEBUG> " +o);
60         }
61     }
62
63     private static String JavaDoc[] tasks = null;
64     private static void initTasks() {
65         tasks = new String JavaDoc[] {
66             AJIcons.d(),
67             GUIDebugger.d(),
68             AJDebugger.d(),
69             OutputTextArea.d(),
70             StackTablePane.d(),
71             CommandLine.d(),
72             EnvTextArea.d(),
73             SourcePane.d(),
74 // SourceTreePane.d(),
75
AJThreadGroupTreePane.d(),
76             BreakpointTreePane.d(),
77             WatchpointTreePane.d(),
78             VariablesTreePane.d(),
79             AJToolBar.d(),
80 // ClassTreePane.d(),
81
AJMenuBar.d(),
82             ComponentDirector.d(),
83         };
84     }
85     static {
86         initTasks();
87     }
88
89     /* Logging */
90     private final static int LAGER_WIDTH = 300;
91     private final static int LAGER_HEIGHT = 30;
92     private static class Lager { //extends CenteredJFrame {
93
private JLabel[] labels;
94         private int times[];
95         private int task = 0;
96         private final static Color defaultColor = new JLabel().getForeground();
97         public Lager(String JavaDoc[] tasks) {
98 // super("AJDB");
99
// setResizable(false);
100
// JPanel p = panel();
101
// p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
102

103 // p.add(titlePanel());
104
// labels = new JLabel[tasks.length];
105
// times = new int[labels.length];
106
// for (int i = 0; i < tasks.length; i++) {
107
// p.add(labels[i] = center(tasks[i]));
108
// }
109
// addWindowListener(new WindowAdapter() {
110
// public void windowClosing(WindowEvent e) {
111
// debugger.quit();
112
// }
113
// });
114
// getContentPane().add(p, BorderLayout.CENTER);
115
}
116 // private JLabel center(String s) {
117
// JLabel label = new JLabel(s);
118
// label.setAlignmentX(CENTER_ALIGNMENT);
119
// label.setAlignmentY(CENTER_ALIGNMENT);
120
// return label;
121
// }
122
private JPanel panel() {
123             JPanel p = new JPanel();
124             p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
125             p.setBorder(BorderFactory.createEtchedBorder());
126             return p;
127         }
128 // private JPanel titlePanel() {
129
// JPanel p = panel();
130
// JLabel title = center(" While you're waiting...visit ");
131
// Font f = title.getFont();
132
// f = new Font(f.getName(), f.getStyle(), 14);
133
// title.setForeground(Color.black);
134
// title.setFont(f);
135
// JLabel link = center(" http://aspectj.org ");
136
// link.setForeground(Color.blue);
137
// link.setFont(f);
138
// p.add(title);
139
// p.add(link);
140
// return p;
141
// }
142
public void log(Object JavaDoc str) {
143 // if (checkTask(task-1)) unhighlight(labels[task-1]);
144
// if (checkTask(task)) highlight(labels[task]);
145
task++;
146         }
147         private void unhighlight(JLabel label) {
148             Font f = label.getFont();
149             f = new Font(f.getName(), Font.BOLD, f.getSize());
150             label.setFont(f);
151             label.setForeground(defaultColor.darker());
152         }
153         private void highlight(JLabel label) {
154             Font f = label.getFont();
155             f = new Font(f.getName(), Font.BOLD | Font.ITALIC, f.getSize());
156             label.setFont(f);
157             label.setForeground(defaultColor.darker().darker().darker());
158         }
159         private boolean checkTask(int t) {
160             return t > -1 && t < tasks.length;
161         }
162         public void start() {
163             if (!Modes.isJBuilder() && !Modes.isForte()) {
164 // pack();
165
// setVisible(true);
166
}
167         }
168         public void done() {
169 // setVisible(false);
170
// dispose();
171
}
172     }
173     private static Lager lager = new Lager(tasks);
174     private static void startLogging() {
175         lager.start();
176     }
177     private static void doneLogging() {
178         lager.done();
179     }
180     private static void task() {
181         lager.log(null);
182     }
183
184     private static boolean ide() {
185         return Modes.isIde();
186         //return false;
187
}
188
189     public final static void init(ComponentDirector gui,
190                                   GUIDebugger _guiDebugger,
191                                   AbstractSourcePane _sourcePane,
192                                   boolean _debug) {
193         startLogging();
194         debug = _debug;
195         task(); AJIcons.init();
196         task(); guiDebugger = _guiDebugger;
197         guiDebugger.setGui(gui);
198         task(); debugger = guiDebugger.getDebugger();
199         task(); outputTextArea = new OutputTextArea(guiDebugger);
200         gui.setPrintStream(outputTextArea.getPrintStream());
201         task(); stackTablePane = new StackTablePane(guiDebugger);
202         task(); commandLine = new CommandLine(gui);
203         task(); envTextArea = new EnvTextArea(guiDebugger);
204         task(); sourcePane = _sourcePane;
205 // task(); if (!ide()) { sourceTreePane = new SourceTreePane(guiDebugger, sourcePane); }
206
task(); threadGroupTreePane = new AJThreadGroupTreePane(guiDebugger);
207         task(); breakpointTreePane = new BreakpointTreePane(gui, guiDebugger);
208         task(); watchpointTreePane = new WatchpointTreePane(gui, guiDebugger);
209         task(); variablesTreePane = new VariablesTreePane(gui, guiDebugger);
210         task(); toolbar = new AJToolBar(guiDebugger);
211 // task(); classTreePane = new ClassTreePane(guiDebugger);
212
task(); if (!ide()) { menuBar = new AJMenuBar(guiDebugger); }
213         statusLabel = commandLine.getStatusLabel();
214         task(); ComponentRepository.gui = gui;
215         doneLogging();
216     }
217
218     public static void init(ComponentDirector gui, GUIDebugger _guiDebugger,
219                             AbstractSourcePane _sourcePane) {
220         init(gui, _guiDebugger, _sourcePane, false);
221     }
222
223     public static void init(ComponentDirector gui, String JavaDoc[] args) {
224         GUIDebugger guid = new GUIDebugger(gui, args);
225         init(gui, guid, new SourcePane(guid));
226     }
227
228     public static void execute(String JavaDoc cmd) {
229         getGUIDebugger().executeCommand(cmd);
230     }
231
232     public static StackTablePane getStackTablePane() { return stackTablePane; }
233     public static CommandLine getCommandLine() { return commandLine; }
234     public static OutputTextArea getOutputTextArea() { return outputTextArea; }
235     public static EnvTextArea getEnvTextArea() { return envTextArea; }
236     public static AbstractSourcePane getSourcePane() { return sourcePane; }
237 // public static SourceTreePane getSourceTreePane() { return sourceTreePane; }
238
public static AJThreadGroupTreePane getThreadGroupTreePane() { return threadGroupTreePane; }
239     public static BreakpointTreePane getBreakpointTreePane() { return breakpointTreePane; }
240     public static Frame getFrame() { return gui; }
241     public static ComponentDirector getComponentDirector() { return gui; }
242     public static AJToolBar getToolBar() { return toolbar; }
243 // public static ClassTreePane getClassTreePane() { return classTreePane; }
244
public static AJMenuBar getMenuBar() { return menuBar; }
245     public static ColorChangingLabel getStatusLabel() { return statusLabel; }
246     public static GUIDebugger getGUIDebugger() { return guiDebugger; }
247     public static AJDebugger getAJDebugger() { return debugger; }
248     public static VirtualMachine vm() throws NoVMException { return getAJDebugger().getVM(); }
249     public static WatchpointTreePane getWatchpointTreePane() { return watchpointTreePane; }
250     public static VariablesTreePane getVariablesTreePane() { return variablesTreePane; }
251
252 // public static void setRoot(String newSourcePath) {
253
// if (getSourceTreePane() == null) return;
254
// getSourceTreePane().setRoot(newSourcePath);
255
// }
256
}
257
Popular Tags