1
/* *******************************************************************
2
* Copyright (c) 1999-2001 Xerox Corporation,
3
* 2002 Palo Alto Research Center, Incorporated (PARC).
5
* This program and the accompanying materials are made available
6
* under the terms of the Eclipse Public License v1.0
7
* which accompanies this distribution and is available at
8
* http://www.eclipse.org/legal/epl-v10.html
11
* Xerox/PARC initial implementation
12
* ******************************************************************/
14
package org.aspectj.tools.ajbrowser.ui.swing;
16
import java.awt.BorderLayout;
17
import java.awt.Color;
18
import java.awt.Dimension;
19
import java.awt.FlowLayout;
20
import java.awt.event.ActionEvent;
21
import java.awt.event.KeyEvent;
22
import java.awt.event.WindowEvent;
25
import javax.swing.AbstractAction;
26
import javax.swing.BorderFactory;
27
import javax.swing.ImageIcon;
28
import javax.swing.JButton;
29
import javax.swing.JFileChooser;
30
import javax.swing.JFrame;
31
import javax.swing.JLabel;
32
import javax.swing.JMenu;
33
import javax.swing.JMenuBar;
34
import javax.swing.JMenuItem;
35
import javax.swing.JPanel;
36
import javax.swing.JPopupMenu;
37
import javax.swing.JSplitPane;
38
import javax.swing.JToolBar;
39
import javax.swing.KeyStroke;
40
import javax.swing.border.Border;
41
import javax.swing.filechooser.FileFilter;
43
import org.aspectj.ajde.Ajde;
44
import org.aspectj.ajde.ui.swing.AJButtonMenuCombo;
45
import org.aspectj.ajde.ui.swing.BuildConfigPopupMenu;
46
import org.aspectj.ajde.ui.swing.MultiStructureViewPanel;
47
import org.aspectj.asm.IProgramElement;
48
import org.aspectj.tools.ajbrowser.BrowserManager;
49
import org.aspectj.tools.ajbrowser.ui.BrowserMessageHandler;
50
import org.aspectj.tools.ajbrowser.ui.EditorManager;
53
* UI for standalone operation.
57
public class TopFrame extends JFrame {
59
private static final long serialVersionUID = 1007473581156451702L;
61
private static final File CURRENT_DIR = new File(".");
63
public JLabel statusText_label = new JLabel();
65
private JPanel editor_panel = null;
66
private JPanel sourceEditor_panel = null;
68
private JMenuBar menuBar = new JMenuBar();
69
private JMenu jMenu1 = new JMenu();
70
private JMenu jMenu2 = new JMenu();
71
private JMenuItem projectBuild_menuItem = new JMenuItem();
72
private FlowLayout left_flowLayout = new FlowLayout();
73
private JMenuItem jMenuItem1 = new JMenuItem();
74
private JMenuItem exit_menuItem = new JMenuItem();
75
private JSplitPane top_splitPane = new JSplitPane();
76
private BorderLayout borderLayout3 = new BorderLayout();
77
private JMenuItem projectRun_menuItem = new JMenuItem();
78
private JMenuItem projectRunOther_menuItem = new JMenuItem();
79
private JPanel status_panel = new JPanel();
80
private BorderLayout borderLayout4 = new BorderLayout();
81
private Border emptyBorder = BorderFactory.createEmptyBorder();
82
private JPanel toolbar_panel = new JPanel();
83
private JSplitPane right_splitPane = new JSplitPane();
84
private MessageHandlerPanel messages_panel = null;
85
private JMenu tools_menu = new JMenu();
86
private JMenuItem joinpointProbe_menuItem = new JMenuItem();
87
private JMenuItem projectDebug_menuItem = new JMenuItem();
88
private JMenuItem svProperties_menuItem = new JMenuItem();
89
private File lastChosenDir = CURRENT_DIR;
91
JPanel toolBar_panel = new JPanel();
92
JToolBar build_toolBar = new JToolBar();
93
JButton closeConfig_button = new JButton();
94
JButton openConfig_button = new JButton();
95
JButton run_button = new JButton();
96
JToolBar project_toolBar = new JToolBar();
97
JButton save_button = new JButton();
98
JButton options_button = new JButton();
99
JButton editConfig_button = new JButton();
100
JToolBar file_toolBar = new JToolBar();
101
JPanel filler_panel = new JPanel();
102
BorderLayout borderLayout5 = new BorderLayout();
103
BorderLayout borderLayout6 = new BorderLayout();
105
JLabel jLabel1 = new JLabel();
106
JLabel jLabel2 = new JLabel();
107
JPanel multiView_panel;
109
private AJButtonMenuCombo buildCombo;
111
public void init(MultiStructureViewPanel multiViewPanel,
112
MessageHandlerPanel compilerMessagesPanel, JPanel editorPanel) {
114
this.multiView_panel = multiViewPanel;
115
this.messages_panel = compilerMessagesPanel;
116
this.editor_panel = editorPanel;
117
this.sourceEditor_panel = editorPanel;
120
svProperties_menuItem.setIcon(Ajde.getDefault()
121
.getIconRegistry().getBrowserOptionsIcon());
122
projectBuild_menuItem.setIcon(Ajde.getDefault()
123
.getIconRegistry().getBuildIcon());
124
projectRun_menuItem.setIcon(Ajde.getDefault()
125
.getIconRegistry().getExecuteIcon());
126
projectRunOther_menuItem.setIcon(Ajde.getDefault()
127
.getIconRegistry().getExecuteIcon());
128
projectDebug_menuItem.setIcon(Ajde.getDefault()
129
.getIconRegistry().getDebugIcon());
131
this.setJMenuBar(menuBar);
132
this.setIconImage(((ImageIcon) Ajde.getDefault()
133
.getIconRegistry().getStructureSwingIcon(
134
IProgramElement.Kind.ADVICE)).getImage());
135
this.setLocation(75, 10);
136
this.setSize(900, 650);
137
this.setTitle(BrowserManager.TITLE);
140
messages_panel.setVisible(false);
142
JPopupMenu orderMenu = new BuildConfigPopupMenu(
143
new AbstractAction() {
145
private static final long serialVersionUID = 1L;
147
public void actionPerformed(ActionEvent arg0) {
148
BrowserManager.getDefault().saveAll();
152
buildCombo = new AJButtonMenuCombo("Build", "Build", Ajde
153
.getDefault().getIconRegistry().getBuildIcon(), orderMenu,
156
build_toolBar.add(buildCombo, 1);
158
} catch (Exception e) {
163
private void refreshBuildMenu() {
164
JPopupMenu orderMenu = new BuildConfigPopupMenu(new AbstractAction() {
165
private static final long serialVersionUID = -3204840278758386318L;
167
public void actionPerformed(ActionEvent arg0) {
168
BrowserManager.getDefault().saveAll();
172
buildCombo.setMenu(orderMenu);
175
public void setEditorPanel(JPanel panel) {
176
editor_panel = panel;
177
right_splitPane.remove(editor_panel);
178
right_splitPane.add(panel, JSplitPane.TOP);
179
panel.setVisible(true);
183
* @todo get rid of this method and make jbinit() work properly
185
private void fixButtonBorders() {
186
run_button.setBorder(null);
187
options_button.setBorder(null);
188
openConfig_button.setBorder(null);
189
closeConfig_button.setBorder(null);
190
save_button.setBorder(null);
191
editConfig_button.setBorder(null);
194
private void jbInit() throws Exception {
195
border8 = BorderFactory.createCompoundBorder(BorderFactory
196
.createEtchedBorder(Color.white, new Color(156, 156, 158)),
197
BorderFactory.createEmptyBorder(2, 2, 2, 2));
198
emptyBorder = BorderFactory.createEmptyBorder(2, 2, 2, 2);
199
jMenu1.setFont(new java.awt.Font("Dialog", 0, 11));
200
jMenu1.setText("File");
201
jMenu1.setMnemonic(KeyEvent.VK_F);
202
jMenu2.setFont(new java.awt.Font("Dialog", 0, 11));
203
jMenu2.setText("Project");
204
jMenu2.setMnemonic(KeyEvent.VK_P);
205
projectBuild_menuItem.setFont(new java.awt.Font("Dialog", 0, 11));
206
projectBuild_menuItem.setText("Build");
207
projectBuild_menuItem.setMnemonic(KeyEvent.VK_B);
208
projectBuild_menuItem.setAccelerator(KeyStroke.getKeyStroke(
209
KeyEvent.VK_B, ActionEvent.ALT_MASK));
211
projectBuild_menuItem
212
.addActionListener(new java.awt.event.ActionListener() {
213
public void actionPerformed(ActionEvent e) {
214
projectBuild_menuItem_actionPerformed(e);
217
left_flowLayout.setAlignment(FlowLayout.LEFT);
218
jMenuItem1.setFont(new java.awt.Font("Dialog", 0, 11));
219
jMenuItem1.setText("Save");
220
jMenuItem1.setMnemonic(KeyEvent.VK_S);
221
jMenuItem1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
222
ActionEvent.ALT_MASK));
223
jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
224
public void actionPerformed(ActionEvent e) {
225
jMenuItem1_actionPerformed(e);
228
exit_menuItem.setFont(new java.awt.Font("Dialog", 0, 11));
229
exit_menuItem.setText("Exit");
230
exit_menuItem.addActionListener(new java.awt.event.ActionListener() {
231
public void actionPerformed(ActionEvent e) {
232
exit_menuItem_actionPerformed(e);
235
top_splitPane.setPreferredSize(new Dimension(706, 800));
236
top_splitPane.setDividerSize(4);
237
this.getContentPane().setLayout(borderLayout3);
238
projectRun_menuItem.setEnabled(true);
239
projectRun_menuItem.setFont(new java.awt.Font("Dialog", 0, 11));
240
projectRun_menuItem.setText("Run in same VM");
242
.setToolTipText("Run in same VM (hold shift down to run in separate process)");
243
projectRun_menuItem.setMnemonic(KeyEvent.VK_R);
244
projectRun_menuItem.setAccelerator(KeyStroke.getKeyStroke(
245
KeyEvent.VK_R, ActionEvent.ALT_MASK));
247
.addActionListener(new java.awt.event.ActionListener() {
248
public void actionPerformed(ActionEvent e) {
249
projectRun_menuItem_actionPerformed(e);
252
projectRunOther_menuItem.setEnabled(true);
253
projectRunOther_menuItem.setFont(new java.awt.Font("Dialog", 0, 11));
254
projectRunOther_menuItem.setText("Run in separate process");
255
projectRunOther_menuItem.setMnemonic(KeyEvent.VK_P);
256
projectRunOther_menuItem.setAccelerator(KeyStroke.getKeyStroke(
257
KeyEvent.VK_P, ActionEvent.ALT_MASK));
258
projectRunOther_menuItem
259
.addActionListener(new java.awt.event.ActionListener() {
260
public void actionPerformed(ActionEvent e) {
261
projectRunOther_menuItem_actionPerformed(e);
264
statusText_label.setFont(new java.awt.Font("Dialog", 0, 11));
265
statusText_label.setBorder(BorderFactory.createLoweredBevelBorder());
266
statusText_label.setMaximumSize(new Dimension(2000, 20));
267
statusText_label.setPreferredSize(new Dimension(300, 20));
268
status_panel.setLayout(borderLayout4);
269
this.addWindowListener(new java.awt.event.WindowAdapter() {
270
public void windowClosed(WindowEvent e) {
271
this_windowClosed(e);
274
public void windowClosing(WindowEvent e) {
275
this_windowClosing(e);
278
toolbar_panel.setLayout(borderLayout5);
279
right_splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
280
right_splitPane.setBorder(null);
281
right_splitPane.setDividerSize(4);
282
tools_menu.setFont(new java.awt.Font("Dialog", 0, 11));
283
tools_menu.setText("Tools");
284
tools_menu.setMnemonic(KeyEvent.VK_T);
285
projectDebug_menuItem.setEnabled(false);
286
projectDebug_menuItem.setFont(new java.awt.Font("Dialog", 0, 11));
287
projectDebug_menuItem.setText("Debug");
288
svProperties_menuItem
289
.addActionListener(new java.awt.event.ActionListener() {
290
public void actionPerformed(ActionEvent e) {
291
svProperties_menuItem_actionPerformed(e);
294
svProperties_menuItem.setText("Options...");
295
svProperties_menuItem.setActionCommand("AJDE Console...");
296
svProperties_menuItem.setFont(new java.awt.Font("Dialog", 0, 11));
297
svProperties_menuItem.setMnemonic(KeyEvent.VK_O);
298
svProperties_menuItem.setAccelerator(KeyStroke.getKeyStroke(
299
KeyEvent.VK_O, ActionEvent.ALT_MASK));
300
build_toolBar.setBorder(emptyBorder);
301
build_toolBar.setFloatable(false);
302
closeConfig_button.setMaximumSize(new Dimension(100, 20));
303
closeConfig_button.setEnabled(true);
304
closeConfig_button.setFont(new java.awt.Font("Dialog", 0, 11));
305
closeConfig_button.setBorder(null);
306
closeConfig_button.setMinimumSize(new Dimension(24, 20));
307
closeConfig_button.setPreferredSize(new Dimension(20, 20));
308
closeConfig_button.setToolTipText("Close build configuration");
309
closeConfig_button.setIcon(Ajde.getDefault().getIconRegistry()
310
.getCloseConfigIcon());
312
.addActionListener(new java.awt.event.ActionListener() {
313
public void actionPerformed(ActionEvent e) {
314
closeConfig_button_actionPerformed(e);
317
openConfig_button.setMaximumSize(new Dimension(100, 20));
318
openConfig_button.setEnabled(true);
319
openConfig_button.setFont(new java.awt.Font("Dialog", 0, 11));
320
openConfig_button.setBorder(null);
321
openConfig_button.setMinimumSize(new Dimension(24, 20));
322
openConfig_button.setPreferredSize(new Dimension(20, 20));
323
openConfig_button.setToolTipText("Select build configuration...");
324
openConfig_button.setIcon(Ajde.getDefault().getIconRegistry()
325
.getOpenConfigIcon());
327
.addActionListener(new java.awt.event.ActionListener() {
328
public void actionPerformed(ActionEvent e) {
329
openConfig_button_actionPerformed(e);
332
run_button.setMaximumSize(new Dimension(60, 20));
333
run_button.setEnabled(true);
334
run_button.setFont(new java.awt.Font("Dialog", 0, 11));
335
run_button.setBorder(null);
336
run_button.setMinimumSize(new Dimension(24, 20));
337
run_button.setPreferredSize(new Dimension(20, 20));
339
.setToolTipText("Run in same VM (hold shift down to run in separate process)");
340
run_button.setIcon(Ajde.getDefault().getIconRegistry()
342
run_button.addActionListener(new java.awt.event.ActionListener() {
343
public void actionPerformed(ActionEvent e) {
344
run_button_actionPerformed(e);
347
project_toolBar.setBorder(emptyBorder);
348
save_button.addActionListener(new java.awt.event.ActionListener() {
349
public void actionPerformed(ActionEvent e) {
350
save_button_actionPerformed(e);
353
save_button.setIcon(Ajde.getDefault().getIconRegistry()
355
save_button.setText("Save");
356
save_button.setToolTipText("Save");
357
save_button.setPreferredSize(new Dimension(55, 20));
358
save_button.setMinimumSize(new Dimension(24, 20));
359
save_button.setFont(new java.awt.Font("Dialog", 0, 11));
360
save_button.setBorder(null);
361
save_button.setMaximumSize(new Dimension(60, 20));
362
options_button.addActionListener(new java.awt.event.ActionListener() {
363
public void actionPerformed(ActionEvent e) {
364
options_button_actionPerformed(e);
367
options_button.setIcon(Ajde.getDefault().getIconRegistry()
368
.getBrowserOptionsIcon());
369
options_button.setText("Options");
370
options_button.setToolTipText("Options...");
371
options_button.setPreferredSize(new Dimension(60, 20));
372
options_button.setMinimumSize(new Dimension(24, 20));
373
options_button.setFont(new java.awt.Font("Dialog", 0, 11));
374
options_button.setBorder(null);
375
options_button.setMaximumSize(new Dimension(80, 20));
377
.addActionListener(new java.awt.event.ActionListener() {
378
public void actionPerformed(ActionEvent e) {
379
editConfig_button_actionPerformed(e);
382
editConfig_button.setIcon(Ajde.getDefault().getIconRegistry()
383
.getStructureSwingIcon(IProgramElement.Kind.FILE_LST));
384
editConfig_button.setText("Edit Config");
385
editConfig_button.setToolTipText("Edit Config...");
386
editConfig_button.setPreferredSize(new Dimension(80, 20));
387
editConfig_button.setMinimumSize(new Dimension(24, 20));
388
editConfig_button.setFont(new java.awt.Font("Dialog", 0, 11));
389
editConfig_button.setBorder(null);
390
editConfig_button.setMaximumSize(new Dimension(80, 20));
391
file_toolBar.setBorder(emptyBorder);
392
toolBar_panel.setLayout(borderLayout6);
393
jLabel1.setFont(new java.awt.Font("Dialog", 0, 11));
394
jLabel1.setText(" Build: ");
395
jLabel2.setText(" Run: ");
396
jLabel2.setFont(new java.awt.Font("Dialog", 0, 11));
397
// fileStructure_panel.setFont(new java.awt.Font("Dialog", 0, 11));
398
// browser_panel.setFont(new java.awt.Font("Dialog", 0, 11));
399
this.getContentPane().add(top_splitPane, BorderLayout.CENTER);
400
top_splitPane.add(right_splitPane, JSplitPane.RIGHT);
401
top_splitPane.add(multiView_panel, JSplitPane.LEFT);
402
right_splitPane.add(messages_panel, JSplitPane.BOTTOM);
403
right_splitPane.add(editor_panel, JSplitPane.TOP);
404
// structureView_pane.add(fileStructure_panel, JSplitPane.RIGHT);
405
// structureView_pane.add(browser_panel, JSplitPane.LEFT);
406
this.getContentPane().add(status_panel, BorderLayout.SOUTH);
407
status_panel.add(statusText_label, BorderLayout.CENTER);
408
this.getContentPane().add(toolbar_panel, BorderLayout.NORTH);
409
toolbar_panel.add(filler_panel, BorderLayout.CENTER);
410
toolbar_panel.add(toolBar_panel, BorderLayout.WEST);
411
// file_toolBar.add(editConfig_button, null);
412
file_toolBar.add(save_button, null);
413
file_toolBar.add(options_button, null);
414
toolBar_panel.add(build_toolBar, BorderLayout.WEST);
415
toolBar_panel.add(project_toolBar, BorderLayout.CENTER);
416
project_toolBar.add(jLabel2, null);
417
project_toolBar.add(run_button, null);
418
build_toolBar.add(jLabel1, null);
419
build_toolBar.add(openConfig_button, null);
420
build_toolBar.add(closeConfig_button, null);
421
toolBar_panel.add(file_toolBar, BorderLayout.EAST);
424
menuBar.add(tools_menu);
425
jMenu1.add(jMenuItem1);
426
jMenu1.addSeparator();
427
jMenu1.add(exit_menuItem);
428
jMenu2.add(projectBuild_menuItem);
429
jMenu2.add(projectRun_menuItem);
430
jMenu2.add(projectRunOther_menuItem);
431
// jMenu2.add(projectDebug_menuItem);
432
tools_menu.add(joinpointProbe_menuItem);
433
tools_menu.add(svProperties_menuItem);
434
top_splitPane.setDividerLocation(380);
435
right_splitPane.setDividerLocation(500);
436
project_toolBar.addSeparator();
437
project_toolBar.addSeparator();
440
private void exit_menuItem_actionPerformed(ActionEvent e) {
444
private void this_windowClosing(WindowEvent e) {
448
private void quit() {
453
void treeMode_comboBox_actionPerformed(ActionEvent e) {
456
void save_button_actionPerformed(ActionEvent e) {
457
BrowserManager.getDefault().getEditorManager().saveContents();
460
void this_windowClosed(WindowEvent e) {
464
public void showMessagesPanel(BrowserMessageHandler handler) {
465
right_splitPane.setDividerLocation(right_splitPane.getHeight() - 100);
466
messages_panel.showMessageHandlerPanel(handler, true);
469
public void hideMessagesPanel(BrowserMessageHandler handler) {
470
right_splitPane.setDividerLocation(right_splitPane.getHeight());
471
messages_panel.showMessageHandlerPanel(handler, false);
474
void jMenuItem1_actionPerformed(ActionEvent e) {
475
BrowserManager.getDefault().getEditorManager().saveContents();
478
void projectBuild_menuItem_actionPerformed(ActionEvent e) {
479
BrowserManager.getDefault().saveAll();
480
if (EditorManager.isShiftDown(e.getModifiers())) {
487
void run_button_actionPerformed(ActionEvent e) {
488
if (EditorManager.isShiftDown(e.getModifiers())) {
495
void projectRunOther_menuItem_actionPerformed(ActionEvent e) {
499
void projectRun_menuItem_actionPerformed(ActionEvent e) {
500
if (EditorManager.isShiftDown(e.getModifiers())) {
507
void build_button_actionPerformed(ActionEvent e) {
508
BrowserManager.getDefault().saveAll();
509
if (EditorManager.isShiftDown(e.getModifiers())) {
516
void options_button_actionPerformed(ActionEvent e) {
517
Ajde.getDefault().showOptionsFrame();
520
void editConfig_button_actionPerformed(ActionEvent e) {
521
BrowserManager.getDefault().openFile(
522
Ajde.getDefault().getBuildConfigManager()
523
.getActiveConfigFile());
527
public void resetSourceEditorPanel() {
528
right_splitPane.removeAll();
529
right_splitPane.add(sourceEditor_panel, JSplitPane.TOP);
532
private void svProperties_menuItem_actionPerformed(ActionEvent e) {
533
Ajde.getDefault().showOptionsFrame();
536
private void openConfig_button_actionPerformed(ActionEvent e) {
537
JFileChooser fileChooser = new JFileChooser();
538
fileChooser.setCurrentDirectory(lastChosenDir);
539
fileChooser.setFileFilter(new FileFilter() {
540
public boolean accept(File f) {
541
return (f.getPath().endsWith(".lst") || f.isDirectory());
544
public String getDescription() {
545
return "AspectJ Build Configuration (*.lst)";
548
int returnVal = fileChooser.showOpenDialog(this);
549
if (returnVal == JFileChooser.APPROVE_OPTION) {
550
File result = fileChooser.getSelectedFile();
551
String path = result.getAbsolutePath();// .replace('\\', '/');
552
if (!Ajde.getDefault().getBuildConfigManager()
553
.getAllBuildConfigFiles().contains(path)) {
554
Ajde.getDefault().getBuildConfigManager()
555
.getAllBuildConfigFiles().add(0, path);
557
Ajde.getDefault().getBuildConfigManager().setActiveConfigFile(
559
lastChosenDir = result.getParentFile();
560
if (null == lastChosenDir) {
561
lastChosenDir = CURRENT_DIR;
567
private void closeConfig_button_actionPerformed(ActionEvent e) {
568
Ajde.getDefault().getBuildConfigManager()
569
.getAllBuildConfigFiles().remove(
570
Ajde.getDefault().getBuildConfigManager()
571
.getActiveConfigFile());
572
if (!Ajde.getDefault().getBuildConfigManager()
573
.getAllBuildConfigFiles().isEmpty()) {
574
Ajde.getDefault().getBuildConfigManager().setActiveConfigFile(
575
(String) Ajde.getDefault().getBuildConfigManager()
576
.getAllBuildConfigFiles().get(0));
581
private void buildFresh() {
582
Ajde.getDefault().runBuildInDifferentThread(Ajde.getDefault()
583
.getBuildConfigManager().getActiveConfigFile(), true);
586
private void build() {
587
Ajde.getDefault().runBuildInDifferentThread(Ajde.getDefault()
588
.getBuildConfigManager().getActiveConfigFile(), false);
591
private void runInSameVM() {
592
Ajde.getDefault().runInSameVM();
595
private void runInNewVM() {
596
Ajde.getDefault().runInNewVM();