KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > tools > example > debug > gui > JDBMenuBar


1 /*
2  * @(#)JDBMenuBar.java 1.12 05/11/17
3  *
4  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 /*
8  * Copyright (c) 1997-1999 by Sun Microsystems, Inc. All Rights Reserved.
9  *
10  * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
11  * modify and redistribute this software in source and binary code form,
12  * provided that i) this copyright notice and license appear on all copies of
13  * the software; and ii) Licensee does not utilize the software in a manner
14  * which is disparaging to Sun.
15  *
16  * This software is provided "AS IS," without a warranty of any kind. ALL
17  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
18  * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
19  * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
20  * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
21  * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
22  * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
23  * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
24  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
25  * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGES.
27  *
28  * This software is not designed or intended for use in on-line control of
29  * aircraft, air traffic, aircraft navigation or aircraft communications; or in
30  * the design, construction, operation or maintenance of any nuclear
31  * facility. Licensee represents and warrants that it will not use or
32  * redistribute the Software for such purposes.
33  */

34
35 package com.sun.tools.example.debug.gui;
36
37 import javax.swing.*;
38 import java.awt.*;
39 import java.awt.event.*;
40 import java.util.Vector JavaDoc;
41 import java.util.List JavaDoc;
42
43 import com.sun.jdi.*;
44 import com.sun.tools.example.debug.bdi.*;
45
46 //### This is currently just a placeholder!
47

48 class JDBMenuBar extends JMenuBar {
49
50     Environment env;
51
52     ExecutionManager runtime;
53     ClassManager classManager;
54     SourceManager sourceManager;
55
56     CommandInterpreter interpreter;
57
58     JDBMenuBar(Environment env) {
59     this.env = env;
60     this.runtime = env.getExecutionManager();
61     this.classManager = env.getClassManager();
62     this.sourceManager = env.getSourceManager();
63     this.interpreter = new CommandInterpreter(env, true);
64
65     JMenu fileMenu = new JMenu("File");
66
67     JMenuItem openItem = new JMenuItem("Open...", 'O');
68     openItem.addActionListener(new ActionListener() {
69         public void actionPerformed(ActionEvent e) {
70         openCommand();
71         }
72     });
73     fileMenu.add(openItem);
74     addTool(fileMenu, "Exit debugger", "Exit", "exit");
75
76     JMenu cmdMenu = new JMenu("Commands");
77
78     addTool(cmdMenu, "Step into next line", "Step", "step");
79     addTool(cmdMenu, "Step over next line", "Next", "next");
80     cmdMenu.addSeparator();
81
82     addTool(cmdMenu, "Step into next instruction",
83                 "Step Instruction", "stepi");
84     addTool(cmdMenu, "Step over next instruction",
85                 "Next Instruction", "nexti");
86     cmdMenu.addSeparator();
87
88     addTool(cmdMenu, "Step out of current method call",
89                 "Step Up", "step up");
90     cmdMenu.addSeparator();
91
92     addTool(cmdMenu, "Suspend execution", "Interrupt", "interrupt");
93     addTool(cmdMenu, "Continue execution", "Continue", "cont");
94     cmdMenu.addSeparator();
95
96     addTool(cmdMenu, "Display current stack", "Where", "where");
97     cmdMenu.addSeparator();
98
99     addTool(cmdMenu, "Move up one stack frame", "Up", "up");
100     addTool(cmdMenu, "Move down one stack frame", "Down", "down");
101     cmdMenu.addSeparator();
102
103     JMenuItem monitorItem = new JMenuItem("Monitor Expression...", 'M');
104     monitorItem.addActionListener(new ActionListener() {
105         public void actionPerformed(ActionEvent e) {
106         monitorCommand();
107         }
108     });
109         cmdMenu.add(monitorItem);
110
111     JMenuItem unmonitorItem = new JMenuItem("Unmonitor Expression...");
112     unmonitorItem.addActionListener(new ActionListener() {
113         public void actionPerformed(ActionEvent e) {
114         unmonitorCommand();
115         }
116     });
117         cmdMenu.add(unmonitorItem);
118
119     JMenu breakpointMenu = new JMenu("Breakpoint");
120     JMenuItem stopItem = new JMenuItem("Stop in...", 'S');
121     stopItem.addActionListener(new ActionListener() {
122         public void actionPerformed(ActionEvent e) {
123         buildBreakpoint();
124         }
125     });
126     breakpointMenu.add(stopItem);
127        
128     JMenu helpMenu = new JMenu("Help");
129     addTool(helpMenu, "Display command list", "Help", "help");
130        
131         this.add(fileMenu);
132         this.add(cmdMenu);
133 // this.add(breakpointMenu);
134
this.add(helpMenu);
135     }
136
137     private void buildBreakpoint() {
138         Frame frame = JOptionPane.getRootFrame();
139         JDialog dialog = new JDialog(frame, "Specify Breakpoint");
140         Container contents = dialog.getContentPane();
141         Vector JavaDoc classes = new Vector JavaDoc();
142         classes.add("Foo");
143         classes.add("Bar");
144         JList list = new JList(classes);
145         JScrollPane scrollPane = new JScrollPane(list);
146         contents.add(scrollPane);
147         dialog.show();
148         
149     }
150
151     private void monitorCommand() {
152         String JavaDoc expr = (String JavaDoc)JOptionPane.showInputDialog(null,
153                            "Expression to monitor:", "Add Monitor",
154                            JOptionPane.QUESTION_MESSAGE, null, null, null);
155         if (expr != null) {
156             interpreter.executeCommand("monitor " + expr);
157         }
158     }
159
160     private void unmonitorCommand() {
161         List JavaDoc monitors = env.getMonitorListModel().monitors();
162         String JavaDoc expr = (String JavaDoc)JOptionPane.showInputDialog(null,
163                            "Expression to unmonitor:", "Remove Monitor",
164                            JOptionPane.QUESTION_MESSAGE, null,
165                            monitors.toArray(),
166                            monitors.get(monitors.size()-1));
167         if (expr != null) {
168             interpreter.executeCommand("unmonitor " + expr);
169         }
170     }
171
172     private void openCommand() {
173     JFileChooser chooser = new JFileChooser();
174     JDBFileFilter filter = new JDBFileFilter("java", "Java source code");
175     chooser.setFileFilter(filter);
176     int result = chooser.showOpenDialog(this);
177     if (result == JFileChooser.APPROVE_OPTION) {
178         System.out.println("Chose file: " + chooser.getSelectedFile().getName());
179     }
180     }
181     
182     private void addTool(JMenu menu, String JavaDoc toolTip, String JavaDoc labelText,
183                          String JavaDoc command) {
184     JMenuItem mi = new JMenuItem(labelText);
185     mi.setToolTipText(toolTip);
186     final String JavaDoc cmd = command;
187     mi.addActionListener(new ActionListener() {
188         public void actionPerformed(ActionEvent e) {
189         interpreter.executeCommand(cmd);
190         }
191     });
192     menu.add(mi);
193     }
194
195 }
196
Popular Tags