debugger reworking

This commit is contained in:
Ben Fry
2015-05-18 11:09:07 -04:00
parent 702785eb0a
commit ecee836ad1
4 changed files with 122 additions and 76 deletions

View File

@@ -317,49 +317,49 @@ public class Debugger implements VMEventListener {
}
/** Print the current stack trace. */
public synchronized void printStackTrace() {
if (isStarted()) {
printStackTrace(currentThread);
}
}
/**
* Print local variables. Outputs type, name and value of each variable.
*/
public synchronized void printLocals() {
if (isStarted()) {
printLocalVariables(currentThread);
}
}
/**
* Print fields of current {@code this}-object.
* Outputs type, name and value of each field.
*/
public synchronized void printThis() {
if (isStarted()) {
printThis(currentThread);
}
}
/**
* Print a source code snippet of the current location.
*/
public synchronized void printSource() {
if (isStarted()) {
printSourceLocation(currentThread);
}
}
// /** Print the current stack trace. */
// public synchronized void printStackTrace() {
// if (isStarted()) {
// printStackTrace(currentThread);
// }
// }
//
//
// /**
// * Print local variables. Outputs type, name and value of each variable.
// */
// public synchronized void printLocals() {
// if (isStarted()) {
// printLocalVariables(currentThread);
// }
// }
//
//
// /**
// * Print fields of current {@code this}-object.
// * Outputs type, name and value of each field.
// */
// public synchronized void printThis() {
// if (isStarted()) {
// printThis(currentThread);
// }
// }
//
//
// /**
// * Print a source code snippet of the current location.
// */
// public synchronized void printSource() {
// if (isStarted()) {
// printSourceLocation(currentThread);
// }
// }
/**
* Set a breakpoint on the current line.
*/
public synchronized void setBreakpoint() {
synchronized void setBreakpoint() {
setBreakpoint(editor.getCurrentLineID());
}
@@ -369,12 +369,12 @@ public class Debugger implements VMEventListener {
* @param lineIdx the line index (0-based) of the current tab to set the
* breakpoint on
*/
public synchronized void setBreakpoint(int lineIdx) {
synchronized void setBreakpoint(int lineIdx) {
setBreakpoint(editor.getLineIDInCurrentTab(lineIdx));
}
public synchronized void setBreakpoint(LineID line) {
synchronized void setBreakpoint(LineID line) {
// do nothing if we are kinda busy
if (isStarted() && !isPaused()) {
return;
@@ -391,7 +391,7 @@ public class Debugger implements VMEventListener {
/**
* Remove a breakpoint from the current line (if set).
*/
public synchronized void removeBreakpoint() {
synchronized void removeBreakpoint() {
removeBreakpoint(editor.getCurrentLineID().lineIdx());
}
@@ -402,7 +402,7 @@ public class Debugger implements VMEventListener {
* @param lineIdx the line index (0-based) in the current tab to remove the
* breakpoint from
*/
protected void removeBreakpoint(int lineIdx) {
void removeBreakpoint(int lineIdx) {
// do nothing if we are kinda busy
if (isBusy()) {
return;
@@ -418,7 +418,7 @@ public class Debugger implements VMEventListener {
/** Remove all breakpoints. */
public synchronized void clearBreakpoints() {
synchronized void clearBreakpoints() {
//TODO: handle busy-ness correctly
if (isBusy()) {
log(Level.WARNING, "busy");
@@ -436,7 +436,7 @@ public class Debugger implements VMEventListener {
* Clear breakpoints in a specific tab.
* @param tabFilename the tab's file name
*/
public synchronized void clearBreakpoints(String tabFilename) {
synchronized void clearBreakpoints(String tabFilename) {
//TODO: handle busy-ness correctly
if (isBusy()) {
log(Level.WARNING, "busy");
@@ -460,7 +460,7 @@ public class Debugger implements VMEventListener {
* @return the breakpoint, or null if no breakpoint is set on the specified
* line.
*/
protected LineBreakpoint breakpointOnLine(LineID line) {
LineBreakpoint breakpointOnLine(LineID line) {
for (LineBreakpoint bp : breakpoints) {
if (bp.isOnLine(line)) {
return bp;
@@ -471,7 +471,7 @@ public class Debugger implements VMEventListener {
/** Toggle a breakpoint on the current line. */
public synchronized void toggleBreakpoint() {
synchronized void toggleBreakpoint() {
toggleBreakpoint(editor.getCurrentLineID().lineIdx());
}
@@ -480,7 +480,7 @@ public class Debugger implements VMEventListener {
* Toggle a breakpoint on a line in the current tab.
* @param lineIdx the line index (0-based) in the current tab
*/
public synchronized void toggleBreakpoint(int lineIdx) {
synchronized void toggleBreakpoint(int lineIdx) {
LineID line = editor.getLineIDInCurrentTab(lineIdx);
if (!hasBreakpoint(line)) {
setBreakpoint(line.lineIdx());
@@ -501,17 +501,17 @@ public class Debugger implements VMEventListener {
}
/** Print a list of currently set breakpoints. */
public synchronized void listBreakpoints() {
if (breakpoints.isEmpty()) {
System.out.println("no breakpoints");
} else {
System.out.println("line breakpoints:");
for (LineBreakpoint bp : breakpoints) {
System.out.println(bp);
}
}
}
// /** Print a list of currently set breakpoints. */
// public synchronized void listBreakpoints() {
// if (breakpoints.isEmpty()) {
// System.out.println("no breakpoints");
// } else {
// System.out.println("line breakpoints:");
// for (LineBreakpoint bp : breakpoints) {
// System.out.println(bp);
// }
// }
// }
/**
@@ -519,7 +519,7 @@ public class Debugger implements VMEventListener {
* @param tabFilename the tab's file name
* @return the list of breakpoints in the given tab
*/
public synchronized List<LineBreakpoint> getBreakpoints(String tabFilename) {
synchronized List<LineBreakpoint> getBreakpoints(String tabFilename) {
List<LineBreakpoint> list = new ArrayList<LineBreakpoint>();
for (LineBreakpoint bp : breakpoints) {
if (bp.lineID().fileName().equals(tabFilename)) {

View File

@@ -1450,6 +1450,7 @@ public class JavaEditor extends Editor {
}
});
debugMenu.add(item);
item.setEnabled(false);
// item = new JMenuItem(Language.text("menu.debug.stop"));
// item.addActionListener(new ActionListener() {
@@ -1467,6 +1468,7 @@ public class JavaEditor extends Editor {
}
});
debugMenu.add(item);
item.setEnabled(false);
item = Toolkit.newJMenuItemShift(Language.text("menu.debug.step_into"), KeyEvent.VK_J);
item.addActionListener(new ActionListener() {
@@ -1475,6 +1477,7 @@ public class JavaEditor extends Editor {
}
});
debugMenu.add(item);
item.setEnabled(false);
item = Toolkit.newJMenuItemAlt(Language.text("menu.debug.step_out"), KeyEvent.VK_J);
item.addActionListener(new ActionListener() {
@@ -1483,11 +1486,12 @@ public class JavaEditor extends Editor {
}
});
debugMenu.add(item);
item.setEnabled(false);
debugMenu.addSeparator();
item =
Toolkit.newJMenuItem(Language.text("menu.debug.toggle_breakpoint"), KeyEvent.VK_B);
Toolkit.newJMenuItem(Language.text("menu.debug.toggle_breakpoint"), 'B');
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Logger.getLogger(JavaEditor.class.getName()).log(Level.INFO, "Invoked 'Toggle Breakpoint' menu item");
@@ -1495,7 +1499,18 @@ public class JavaEditor extends Editor {
}
});
debugMenu.add(item);
item.setEnabled(false);
item = Toolkit.newJMenuItem(Language.text("menu.debug.variable_inspector"), 'Y');
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
toggleVariableInspector();
}
});
debugMenu.add(item);
item.setEnabled(false);
/*
item = new JMenuItem(Language.text("menu.debug.list_breakpoints"));
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
@@ -1506,7 +1521,9 @@ public class JavaEditor extends Editor {
debugMenu.add(item);
debugMenu.addSeparator();
*/
/*
item = new JMenuItem(Language.text("menu.debug.print_stack_trace"));
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
@@ -1553,6 +1570,7 @@ public class JavaEditor extends Editor {
debugMenu.add(item);
debugMenu.addSeparator();
*/
// item = Toolkit.newJMenuItem(Language.text("menu.debug.toggle_variable_inspector"), KeyEvent.VK_I);
// item.addActionListener(new ActionListener() {
@@ -1563,6 +1581,7 @@ public class JavaEditor extends Editor {
// });
// debugMenu.add(item);
/*
item = Toolkit.newJMenuItem(Language.text("menu.debug.show_sketch_outline"), KeyEvent.VK_L);
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
@@ -1580,6 +1599,7 @@ public class JavaEditor extends Editor {
}
});
debugMenu.add(item);
*/
return debugMenu;
}
@@ -2133,6 +2153,10 @@ public class JavaEditor extends Editor {
public void updateDebugToggle() {
final boolean enabled = isDebuggerEnabled();
rebuildToolbar();
if (!enabled && inspector.isVisible()) {
toggleVariableInspector();
}
/*
if (enabled) {
inspector.setFocusableWindowState(false); // to not get focus when set visible
@@ -2150,11 +2174,22 @@ public class JavaEditor extends Editor {
}
public void toggleVariableInspector() {
if (inspector.isVisible()) {
inspector.setVisible(false);
} else {
// inspector.setFocusableWindowState(false); // to not get focus when set visible
inspector.setVisible(true);
// inspector.setFocusableWindowState(true); // allow to get focus again
}
}
// public void showVariableInspector() {
// tray.setVisible(true);
// }
//
//
// /**
// * Set visibility of the variable inspector window.
// * @param visible true to set the variable inspector visible,

View File

@@ -47,7 +47,7 @@ import processing.app.Mode;
import processing.mode.java.debug.VariableNode;
public class VariableInspector extends JFrame {
public class VariableInspector extends JDialog {
static public final int GAP = 13;
EditorButton continueButton;
@@ -95,8 +95,17 @@ public class VariableInspector extends JFrame {
public VariableInspector(final JavaEditor editor) {
super("Inspector");
// As a JDialog, the menu bar comes from the Editor
super(editor, "Inspector");
this.editor = editor;
// Use the small toolbar style (at least on OS X)
// https://developer.apple.com/library/mac/technotes/tn2007/tn2196.html#WINDOWS
getRootPane().putClientProperty("Window.style", "small");
// When clicking this window, keep the focus on the Editor window
setFocusableWindowState(false);
//setUndecorated(true);
//editor.addComponentListener(new EditorFollower());
@@ -111,7 +120,6 @@ public class VariableInspector extends JFrame {
// editor.getY() + VERTICAL_OFFSET);
setLocationRelativeTo(editor);
/*
bgColor = mode.getColor("buttons.bgcolor");
statusFont = mode.getFont("buttons.status.font");