1 7 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 ; 41 import java.util.List ; 42 43 import com.sun.jdi.*; 44 import com.sun.tools.example.debug.bdi.*; 45 46 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(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 classes = new Vector (); 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 expr = (String )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 monitors = env.getMonitorListModel().monitors(); 162 String expr = (String )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 toolTip, String labelText, 183 String command) { 184 JMenuItem mi = new JMenuItem(labelText); 185 mi.setToolTipText(toolTip); 186 final String 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 |