History

My first initial commit with all of mine experimental changes.

Dmitry Kabak (userdima committed 13 years ago

Commit d37b88d1 parent 3f5b46618352 files · +2598093 −-8690Browse files

Showing the changes to java/pkg/com/sun/tools/example/debug/gui/JDBMenuBar.java (1 of 18352 files). Show all

Unified · Split

java/pkg/com/sun/tools/example/debug/gui/JDBMenuBar.java+190−0
@@ -0,0 +1,190 @@
1+/*
2+ * Copyright (c) 1998, 1999, Oracle and/or its affiliates. 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. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+ * or visit www.oracle.com if you need additional information or have any
23+ * questions.
24+ */
25+
26+package com.sun.tools.example.debug.gui;
27+
28+import javax.swing.*;
29+import java.awt.*;
30+import java.awt.event.*;
31+import java.util.Vector;
32+import java.util.List;
33+
34+import com.sun.tools.example.debug.bdi.*;
35+
36+//### This is currently just a placeholder!
37+
38+class JDBMenuBar extends JMenuBar {
39+
40+ Environment env;
41+
42+ ExecutionManager runtime;
43+ ClassManager classManager;
44+ SourceManager sourceManager;
45+
46+ CommandInterpreter interpreter;
47+
48+ JDBMenuBar(Environment env) {
49+ this.env = env;
50+ this.runtime = env.getExecutionManager();
51+ this.classManager = env.getClassManager();
52+ this.sourceManager = env.getSourceManager();
53+ this.interpreter = new CommandInterpreter(env, true);
54+
55+ JMenu fileMenu = new JMenu("File");
56+
57+ JMenuItem openItem = new JMenuItem("Open...", 'O');
58+ openItem.addActionListener(new ActionListener() {
59+ @Override
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+ @Override
97+ public void actionPerformed(ActionEvent e) {
98+ monitorCommand();
99+ }
100+ });
101+ cmdMenu.add(monitorItem);
102+
103+ JMenuItem unmonitorItem = new JMenuItem("Unmonitor Expression...");
104+ unmonitorItem.addActionListener(new ActionListener() {
105+ @Override
106+ public void actionPerformed(ActionEvent e) {
107+ unmonitorCommand();
108+ }
109+ });
110+ cmdMenu.add(unmonitorItem);
111+
112+ JMenu breakpointMenu = new JMenu("Breakpoint");
113+ JMenuItem stopItem = new JMenuItem("Stop in...", 'S');
114+ stopItem.addActionListener(new ActionListener() {
115+ @Override
116+ public void actionPerformed(ActionEvent e) {
117+ buildBreakpoint();
118+ }
119+ });
120+ breakpointMenu.add(stopItem);
121+
122+ JMenu helpMenu = new JMenu("Help");
123+ addTool(helpMenu, "Display command list", "Help", "help");
124+
125+ this.add(fileMenu);
126+ this.add(cmdMenu);
127+// this.add(breakpointMenu);
128+ this.add(helpMenu);
129+ }
130+
131+ private void buildBreakpoint() {
132+ Frame frame = JOptionPane.getRootFrame();
133+ JDialog dialog = new JDialog(frame, "Specify Breakpoint");
134+ Container contents = dialog.getContentPane();
135+ Vector<String> classes = new Vector<String>();
136+ classes.add("Foo");
137+ classes.add("Bar");
138+ JList list = new JList(classes);
139+ JScrollPane scrollPane = new JScrollPane(list);
140+ contents.add(scrollPane);
141+ dialog.show();
142+
143+ }
144+
145+ private void monitorCommand() {
146+ String expr = (String)JOptionPane.showInputDialog(null,
147+ "Expression to monitor:", "Add Monitor",
148+ JOptionPane.QUESTION_MESSAGE, null, null, null);
149+ if (expr != null) {
150+ interpreter.executeCommand("monitor " + expr);
151+ }
152+ }
153+
154+ private void unmonitorCommand() {
155+ List monitors = env.getMonitorListModel().monitors();
156+ String expr = (String)JOptionPane.showInputDialog(null,
157+ "Expression to unmonitor:", "Remove Monitor",
158+ JOptionPane.QUESTION_MESSAGE, null,
159+ monitors.toArray(),
160+ monitors.get(monitors.size()-1));
161+ if (expr != null) {
162+ interpreter.executeCommand("unmonitor " + expr);
163+ }
164+ }
165+
166+ private void openCommand() {
167+ JFileChooser chooser = new JFileChooser();
168+ JDBFileFilter filter = new JDBFileFilter("java", "Java source code");
169+ chooser.setFileFilter(filter);
170+ int result = chooser.showOpenDialog(this);
171+ if (result == JFileChooser.APPROVE_OPTION) {
172+ System.out.println("Chose file: " + chooser.getSelectedFile().getName());
173+ }
174+ }
175+
176+ private void addTool(JMenu menu, String toolTip, String labelText,
177+ String command) {
178+ JMenuItem mi = new JMenuItem(labelText);
179+ mi.setToolTipText(toolTip);
180+ final String cmd = command;
181+ mi.addActionListener(new ActionListener() {
182+ @Override
183+ public void actionPerformed(ActionEvent e) {
184+ interpreter.executeCommand(cmd);
185+ }
186+ });
187+ menu.add(mi);
188+ }
189+
190+}