1 21 22 package org.armedbear.j.jdb; 23 24 import java.awt.Dimension ; 25 import java.awt.Font ; 26 import java.awt.FontMetrics ; 27 import java.awt.Point ; 28 import java.awt.Rectangle ; 29 import java.awt.Toolkit ; 30 import java.awt.event.ActionEvent ; 31 import java.awt.event.ActionListener ; 32 import java.awt.event.ComponentEvent ; 33 import java.awt.event.ComponentListener ; 34 import java.awt.event.KeyEvent ; 35 import java.awt.event.KeyListener ; 36 import java.awt.event.WindowAdapter ; 37 import java.awt.event.WindowEvent ; 38 import java.net.URL ; 39 import javax.swing.BorderFactory ; 40 import javax.swing.BoxLayout ; 41 import javax.swing.ImageIcon ; 42 import javax.swing.JButton ; 43 import javax.swing.JDialog ; 44 import javax.swing.JLabel ; 45 import javax.swing.JPanel ; 46 import javax.swing.JTabbedPane ; 47 import javax.swing.JToolBar ; 48 import org.armedbear.j.Constants; 49 import org.armedbear.j.DefaultTextFieldHandler; 50 import org.armedbear.j.Editor; 51 import org.armedbear.j.EditorIterator; 52 import org.armedbear.j.Expansion; 53 import org.armedbear.j.History; 54 import org.armedbear.j.HistoryTextField; 55 import org.armedbear.j.SessionProperties; 56 import org.armedbear.j.StandardButton; 57 58 public final class JdbControlDialog extends JDialog implements JdbConstants, 59 Constants, ContextListener, ActionListener , ComponentListener , KeyListener 60 { 61 private static final String commandKey = "jdb.command"; 62 63 private static final SessionProperties sessionProperties = 64 Editor.getSessionProperties(); 65 66 private final Jdb jdb; 67 private final JToolBar toolBar; 68 private final HistoryTextField commandTextField; 69 private final History commandHistory; 70 private final StandardButton suspendButton; 71 private final StandardButton continueButton; 72 73 public JdbControlDialog(Jdb jdb) 74 { 75 super(Editor.getCurrentFrame(), "Jdb", false); 76 this.jdb = jdb; 77 toolBar = new JToolBar (); 78 toolBar.setOrientation(JToolBar.HORIZONTAL); 79 toolBar.setFloatable(false); 80 toolBar.putClientProperty("JToolBar.isRollover", Boolean.FALSE); 81 addButton("Next", null, "jdbNext"); 82 addButton("Step", null, "jdbStep"); 83 addButton("Step Out", null, "jdbFinish"); 84 addSeparator(); 85 suspendButton = addButton("Suspend", null, "jdbSuspend"); 86 continueButton = addButton("Continue", null, "jdbContinue"); 87 addSeparator(); 88 addButton("Restart", null, "jdbRestart"); 89 addButton("Quit", null, "jdbQuit"); 90 getContentPane().add(toolBar, "North"); 91 JTabbedPane tabbedPane = new JTabbedPane (); 92 StackPanel stackPanel = new StackPanel(jdb, this); 93 tabbedPane.addTab("Stack", stackPanel.getComponent()); 94 ThreadPanel threadPanel = new ThreadPanel(jdb, this); 95 tabbedPane.addTab("Threads", threadPanel.getComponent()); 96 BreakpointPanel breakpointPanel = new BreakpointPanel(jdb, this); 97 tabbedPane.addTab("Breakpoints", breakpointPanel.getComponent()); 98 getContentPane().add(tabbedPane, "Center"); 99 JPanel commandPanel = new JPanel (); 100 commandPanel.setLayout(new BoxLayout (commandPanel, BoxLayout.X_AXIS)); 101 commandPanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 4, 3)); 102 commandPanel.add(new JLabel ("Command:")); 103 commandTextField = new HistoryTextField(20); 104 commandHistory = new History(commandKey); 105 commandTextField.setHistory(commandHistory); 106 commandTextField.setHandler(new CommandTextFieldHandler(commandTextField)); 107 commandPanel.add(commandTextField); 108 getContentPane().add(commandPanel, "South"); 109 pack(); 110 jdb.addContextListener(this); 111 addComponentListener(this); 112 addWindowListener(new WindowMonitor()); 113 commandTextField.addKeyListener(this); 114 if (jdb.getStartSuspended()) 115 tabbedPane.setSelectedComponent(breakpointPanel.getComponent()); 116 contextChanged(); 117 requestDefaultFocus(); 118 } 119 120 public void requestDefaultFocus() 121 { 122 commandTextField.requestFocus(); 123 } 124 125 private StandardButton addButton(String text, String iconFile, String command) 126 { 127 StandardButton button = new StandardButton(text); 128 Font font = button.getFont(); 129 FontMetrics fm = Toolkit.getDefaultToolkit().getFontMetrics(font); 130 int width = fm.stringWidth(text); 131 Dimension dim = new Dimension (width + 14, StandardButton.DEFAULT_HEIGHT); 132 button.setMinimumSize(dim); 133 button.setMaximumSize(dim); 134 button.setPreferredSize(dim); 135 if (command != null) 136 button.setActionCommand(command); 137 button.addActionListener(this); 138 button.setRequestFocusEnabled(false); 139 toolBar.add(button); 140 return button; 141 } 142 143 private void addSeparator() 144 { 145 toolBar.addSeparator(); 146 } 147 148 public void show() 149 { 150 int width = sessionProperties.getIntegerProperty("jdb.width", 425); 151 int height = sessionProperties.getIntegerProperty("jdb.height", 250); 152 setSize(width, height); 153 int x = sessionProperties.getIntegerProperty("jdb.x", -1); 154 int y = sessionProperties.getIntegerProperty("jdb.y", -1); 155 if (x >= 0 && y >= 0) { 156 setLocation(x, y); 157 } else { 158 Editor editor = null; 160 for (EditorIterator it = new EditorIterator(); it.hasNext();) { 161 Editor ed = it.nextEditor(); 162 if (ed.getBuffer() == jdb) { 163 editor = ed; 164 break; 165 } 166 } 167 if (editor != null) { 168 Dimension parent = editor.getFrame().getSize(); 169 Dimension dialog = getSize(); 170 Point p = editor.getFrame().getLocation(); 171 p.translate(parent.width - dialog.width - 30, 172 parent.height - dialog.height - 50); 173 setLocation(p); 174 } else 175 Editor.currentEditor().centerDialog(this); 176 } 177 super.show(); 178 } 179 180 public void contextChanged() 181 { 182 if (jdb.getVM() == null) { 183 suspendButton.setEnabled(false); 184 continueButton.setEnabled(false); 185 } else if (jdb.isSuspended()) { 186 suspendButton.setEnabled(false); 187 continueButton.setEnabled(true); 188 } else { 189 suspendButton.setEnabled(true); 190 continueButton.setEnabled(false); 191 } 192 } 193 194 public void actionPerformed(ActionEvent e) 195 { 196 Editor.currentEditor().getDispatcher().actionPerformed(e); 197 } 198 199 public void keyPressed(KeyEvent e) 200 { 201 if (e.getKeyCode() == KeyEvent.VK_ENTER) { 202 if ((e.getModifiers() & 0x0f) == 0) { 204 if (commandTextField.getText().trim().length() > 0) { 205 jdb.doCommand(commandTextField.getText()); 206 commandTextField.setText(""); 207 } else { 208 int command = jdb.getLastCommand(); 209 if (command == JDB_CONTINUE || command == JDB_NEXT || 210 command == JDB_STEP) 211 jdb.doCommand(command, null); 212 } 213 } 214 } 215 } 216 217 public void keyReleased(KeyEvent e) {} 218 219 public void keyTyped(KeyEvent e) {} 220 221 public void componentResized(ComponentEvent e) 222 { 223 saveWindowPlacement(); 224 } 225 226 public void componentMoved(ComponentEvent e) 227 { 228 saveWindowPlacement(); 229 } 230 231 public void componentShown(ComponentEvent e) 232 { 233 saveWindowPlacement(); 234 } 235 236 public void componentHidden(ComponentEvent e) {} 237 238 private void saveWindowPlacement() 239 { 240 Rectangle r = getBounds(); 241 sessionProperties.setIntegerProperty("jdb.x", r.x); 242 sessionProperties.setIntegerProperty("jdb.y", r.y); 243 sessionProperties.setIntegerProperty("jdb.width", r.width); 244 sessionProperties.setIntegerProperty("jdb.height", r.height); 245 } 246 247 private class WindowMonitor extends WindowAdapter 248 { 249 public void windowClosing(WindowEvent e) 250 { 251 setVisible(false); 252 dispose(); 253 jdb.doCommand("quit"); 254 } 255 } 256 257 private class CommandTextFieldHandler extends DefaultTextFieldHandler 258 { 259 CommandTextFieldHandler(HistoryTextField textField) 260 { 261 super(textField); 262 } 263 264 public void enter() 265 { 266 commandHistory.append(textField.getText()); 267 } 268 269 public void escape() 270 { 271 textField.setText(""); 272 } 273 274 public Expansion getExpansion(String prefix) 275 { 276 Expansion expansion = new Expansion(jdb, prefix, prefix); 277 EditorIterator iter = new EditorIterator(); 278 while (iter.hasNext()) { 279 Editor ed = iter.nextEditor(); 280 if (ed.getModeId() == JAVA_MODE) { 281 Expansion exp = 282 new Expansion(ed.getBuffer(), prefix, prefix, ed.getDot()); 283 expansion.appendCandidates(exp.getCandidates()); 284 } 285 } 286 return expansion; 287 } 288 } 289 } 290 | Popular Tags |