blob: b60471bd39711c834b9cbaa471d321c4ac10fe9a [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 1998-1999 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26package com.sun.tools.example.debug.gui;
27
28import javax.swing.*;
29import java.awt.*;
30import java.awt.event.*;
31import java.util.Vector;
32import java.util.List;
33
34import com.sun.jdi.*;
35import com.sun.tools.example.debug.bdi.*;
36
37//### This is currently just a placeholder!
38
39class JDBMenuBar extends JMenuBar {
40
41 Environment env;
42
43 ExecutionManager runtime;
44 ClassManager classManager;
45 SourceManager sourceManager;
46
47 CommandInterpreter interpreter;
48
49 JDBMenuBar(Environment env) {
50 this.env = env;
51 this.runtime = env.getExecutionManager();
52 this.classManager = env.getClassManager();
53 this.sourceManager = env.getSourceManager();
54 this.interpreter = new CommandInterpreter(env, true);
55
56 JMenu fileMenu = new JMenu("File");
57
58 JMenuItem openItem = new JMenuItem("Open...", 'O');
59 openItem.addActionListener(new ActionListener() {
60 public void actionPerformed(ActionEvent e) {
61 openCommand();
62 }
63 });
64 fileMenu.add(openItem);
65 addTool(fileMenu, "Exit debugger", "Exit", "exit");
66
67 JMenu cmdMenu = new JMenu("Commands");
68
69 addTool(cmdMenu, "Step into next line", "Step", "step");
70 addTool(cmdMenu, "Step over next line", "Next", "next");
71 cmdMenu.addSeparator();
72
73 addTool(cmdMenu, "Step into next instruction",
74 "Step Instruction", "stepi");
75 addTool(cmdMenu, "Step over next instruction",
76 "Next Instruction", "nexti");
77 cmdMenu.addSeparator();
78
79 addTool(cmdMenu, "Step out of current method call",
80 "Step Up", "step up");
81 cmdMenu.addSeparator();
82
83 addTool(cmdMenu, "Suspend execution", "Interrupt", "interrupt");
84 addTool(cmdMenu, "Continue execution", "Continue", "cont");
85 cmdMenu.addSeparator();
86
87 addTool(cmdMenu, "Display current stack", "Where", "where");
88 cmdMenu.addSeparator();
89
90 addTool(cmdMenu, "Move up one stack frame", "Up", "up");
91 addTool(cmdMenu, "Move down one stack frame", "Down", "down");
92 cmdMenu.addSeparator();
93
94 JMenuItem monitorItem = new JMenuItem("Monitor Expression...", 'M');
95 monitorItem.addActionListener(new ActionListener() {
96 public void actionPerformed(ActionEvent e) {
97 monitorCommand();
98 }
99 });
100 cmdMenu.add(monitorItem);
101
102 JMenuItem unmonitorItem = new JMenuItem("Unmonitor Expression...");
103 unmonitorItem.addActionListener(new ActionListener() {
104 public void actionPerformed(ActionEvent e) {
105 unmonitorCommand();
106 }
107 });
108 cmdMenu.add(unmonitorItem);
109
110 JMenu breakpointMenu = new JMenu("Breakpoint");
111 JMenuItem stopItem = new JMenuItem("Stop in...", 'S');
112 stopItem.addActionListener(new ActionListener() {
113 public void actionPerformed(ActionEvent e) {
114 buildBreakpoint();
115 }
116 });
117 breakpointMenu.add(stopItem);
118
119 JMenu helpMenu = new JMenu("Help");
120 addTool(helpMenu, "Display command list", "Help", "help");
121
122 this.add(fileMenu);
123 this.add(cmdMenu);
124// this.add(breakpointMenu);
125 this.add(helpMenu);
126 }
127
128 private void buildBreakpoint() {
129 Frame frame = JOptionPane.getRootFrame();
130 JDialog dialog = new JDialog(frame, "Specify Breakpoint");
131 Container contents = dialog.getContentPane();
132 Vector<String> classes = new Vector<String>();
133 classes.add("Foo");
134 classes.add("Bar");
135 JList list = new JList(classes);
136 JScrollPane scrollPane = new JScrollPane(list);
137 contents.add(scrollPane);
138 dialog.show();
139
140 }
141
142 private void monitorCommand() {
143 String expr = (String)JOptionPane.showInputDialog(null,
144 "Expression to monitor:", "Add Monitor",
145 JOptionPane.QUESTION_MESSAGE, null, null, null);
146 if (expr != null) {
147 interpreter.executeCommand("monitor " + expr);
148 }
149 }
150
151 private void unmonitorCommand() {
152 List monitors = env.getMonitorListModel().monitors();
153 String expr = (String)JOptionPane.showInputDialog(null,
154 "Expression to unmonitor:", "Remove Monitor",
155 JOptionPane.QUESTION_MESSAGE, null,
156 monitors.toArray(),
157 monitors.get(monitors.size()-1));
158 if (expr != null) {
159 interpreter.executeCommand("unmonitor " + expr);
160 }
161 }
162
163 private void openCommand() {
164 JFileChooser chooser = new JFileChooser();
165 JDBFileFilter filter = new JDBFileFilter("java", "Java source code");
166 chooser.setFileFilter(filter);
167 int result = chooser.showOpenDialog(this);
168 if (result == JFileChooser.APPROVE_OPTION) {
169 System.out.println("Chose file: " + chooser.getSelectedFile().getName());
170 }
171 }
172
173 private void addTool(JMenu menu, String toolTip, String labelText,
174 String command) {
175 JMenuItem mi = new JMenuItem(labelText);
176 mi.setToolTipText(toolTip);
177 final String cmd = command;
178 mi.addActionListener(new ActionListener() {
179 public void actionPerformed(ActionEvent e) {
180 interpreter.executeCommand(cmd);
181 }
182 });
183 menu.add(mi);
184 }
185
186}