Skip to content

Commit daed904

Browse files
committed
debugger reworking
1 parent ae6f599 commit daed904

File tree

4 files changed

+122
-76
lines changed

4 files changed

+122
-76
lines changed

java/src/processing/mode/java/Debugger.java

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -317,49 +317,49 @@ public synchronized void stepOut() {
317317
}
318318

319319

320-
/** Print the current stack trace. */
321-
public synchronized void printStackTrace() {
322-
if (isStarted()) {
323-
printStackTrace(currentThread);
324-
}
325-
}
326-
327-
328-
/**
329-
* Print local variables. Outputs type, name and value of each variable.
330-
*/
331-
public synchronized void printLocals() {
332-
if (isStarted()) {
333-
printLocalVariables(currentThread);
334-
}
335-
}
336-
337-
338-
/**
339-
* Print fields of current {@code this}-object.
340-
* Outputs type, name and value of each field.
341-
*/
342-
public synchronized void printThis() {
343-
if (isStarted()) {
344-
printThis(currentThread);
345-
}
346-
}
347-
348-
349-
/**
350-
* Print a source code snippet of the current location.
351-
*/
352-
public synchronized void printSource() {
353-
if (isStarted()) {
354-
printSourceLocation(currentThread);
355-
}
356-
}
320+
// /** Print the current stack trace. */
321+
// public synchronized void printStackTrace() {
322+
// if (isStarted()) {
323+
// printStackTrace(currentThread);
324+
// }
325+
// }
326+
//
327+
//
328+
// /**
329+
// * Print local variables. Outputs type, name and value of each variable.
330+
// */
331+
// public synchronized void printLocals() {
332+
// if (isStarted()) {
333+
// printLocalVariables(currentThread);
334+
// }
335+
// }
336+
//
337+
//
338+
// /**
339+
// * Print fields of current {@code this}-object.
340+
// * Outputs type, name and value of each field.
341+
// */
342+
// public synchronized void printThis() {
343+
// if (isStarted()) {
344+
// printThis(currentThread);
345+
// }
346+
// }
347+
//
348+
//
349+
// /**
350+
// * Print a source code snippet of the current location.
351+
// */
352+
// public synchronized void printSource() {
353+
// if (isStarted()) {
354+
// printSourceLocation(currentThread);
355+
// }
356+
// }
357357

358358

359359
/**
360360
* Set a breakpoint on the current line.
361361
*/
362-
public synchronized void setBreakpoint() {
362+
synchronized void setBreakpoint() {
363363
setBreakpoint(editor.getCurrentLineID());
364364
}
365365

@@ -369,12 +369,12 @@ public synchronized void setBreakpoint() {
369369
* @param lineIdx the line index (0-based) of the current tab to set the
370370
* breakpoint on
371371
*/
372-
public synchronized void setBreakpoint(int lineIdx) {
372+
synchronized void setBreakpoint(int lineIdx) {
373373
setBreakpoint(editor.getLineIDInCurrentTab(lineIdx));
374374
}
375375

376376

377-
public synchronized void setBreakpoint(LineID line) {
377+
synchronized void setBreakpoint(LineID line) {
378378
// do nothing if we are kinda busy
379379
if (isStarted() && !isPaused()) {
380380
return;
@@ -391,7 +391,7 @@ public synchronized void setBreakpoint(LineID line) {
391391
/**
392392
* Remove a breakpoint from the current line (if set).
393393
*/
394-
public synchronized void removeBreakpoint() {
394+
synchronized void removeBreakpoint() {
395395
removeBreakpoint(editor.getCurrentLineID().lineIdx());
396396
}
397397

@@ -402,7 +402,7 @@ public synchronized void removeBreakpoint() {
402402
* @param lineIdx the line index (0-based) in the current tab to remove the
403403
* breakpoint from
404404
*/
405-
protected void removeBreakpoint(int lineIdx) {
405+
void removeBreakpoint(int lineIdx) {
406406
// do nothing if we are kinda busy
407407
if (isBusy()) {
408408
return;
@@ -418,7 +418,7 @@ protected void removeBreakpoint(int lineIdx) {
418418

419419

420420
/** Remove all breakpoints. */
421-
public synchronized void clearBreakpoints() {
421+
synchronized void clearBreakpoints() {
422422
//TODO: handle busy-ness correctly
423423
if (isBusy()) {
424424
log(Level.WARNING, "busy");
@@ -436,7 +436,7 @@ public synchronized void clearBreakpoints() {
436436
* Clear breakpoints in a specific tab.
437437
* @param tabFilename the tab's file name
438438
*/
439-
public synchronized void clearBreakpoints(String tabFilename) {
439+
synchronized void clearBreakpoints(String tabFilename) {
440440
//TODO: handle busy-ness correctly
441441
if (isBusy()) {
442442
log(Level.WARNING, "busy");
@@ -460,7 +460,7 @@ public synchronized void clearBreakpoints(String tabFilename) {
460460
* @return the breakpoint, or null if no breakpoint is set on the specified
461461
* line.
462462
*/
463-
protected LineBreakpoint breakpointOnLine(LineID line) {
463+
LineBreakpoint breakpointOnLine(LineID line) {
464464
for (LineBreakpoint bp : breakpoints) {
465465
if (bp.isOnLine(line)) {
466466
return bp;
@@ -471,7 +471,7 @@ protected LineBreakpoint breakpointOnLine(LineID line) {
471471

472472

473473
/** Toggle a breakpoint on the current line. */
474-
public synchronized void toggleBreakpoint() {
474+
synchronized void toggleBreakpoint() {
475475
toggleBreakpoint(editor.getCurrentLineID().lineIdx());
476476
}
477477

@@ -480,7 +480,7 @@ public synchronized void toggleBreakpoint() {
480480
* Toggle a breakpoint on a line in the current tab.
481481
* @param lineIdx the line index (0-based) in the current tab
482482
*/
483-
public synchronized void toggleBreakpoint(int lineIdx) {
483+
synchronized void toggleBreakpoint(int lineIdx) {
484484
LineID line = editor.getLineIDInCurrentTab(lineIdx);
485485
if (!hasBreakpoint(line)) {
486486
setBreakpoint(line.lineIdx());
@@ -501,25 +501,25 @@ protected boolean hasBreakpoint(LineID line) {
501501
}
502502

503503

504-
/** Print a list of currently set breakpoints. */
505-
public synchronized void listBreakpoints() {
506-
if (breakpoints.isEmpty()) {
507-
System.out.println("no breakpoints");
508-
} else {
509-
System.out.println("line breakpoints:");
510-
for (LineBreakpoint bp : breakpoints) {
511-
System.out.println(bp);
512-
}
513-
}
514-
}
504+
// /** Print a list of currently set breakpoints. */
505+
// public synchronized void listBreakpoints() {
506+
// if (breakpoints.isEmpty()) {
507+
// System.out.println("no breakpoints");
508+
// } else {
509+
// System.out.println("line breakpoints:");
510+
// for (LineBreakpoint bp : breakpoints) {
511+
// System.out.println(bp);
512+
// }
513+
// }
514+
// }
515515

516516

517517
/**
518518
* Retrieve a list of breakpoint in a particular tab.
519519
* @param tabFilename the tab's file name
520520
* @return the list of breakpoints in the given tab
521521
*/
522-
public synchronized List<LineBreakpoint> getBreakpoints(String tabFilename) {
522+
synchronized List<LineBreakpoint> getBreakpoints(String tabFilename) {
523523
List<LineBreakpoint> list = new ArrayList<LineBreakpoint>();
524524
for (LineBreakpoint bp : breakpoints) {
525525
if (bp.lineID().fileName().equals(tabFilename)) {

java/src/processing/mode/java/JavaEditor.java

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,6 +1450,7 @@ public void actionPerformed(ActionEvent e) {
14501450
}
14511451
});
14521452
debugMenu.add(item);
1453+
item.setEnabled(false);
14531454

14541455
// item = new JMenuItem(Language.text("menu.debug.stop"));
14551456
// item.addActionListener(new ActionListener() {
@@ -1467,6 +1468,7 @@ public void actionPerformed(ActionEvent e) {
14671468
}
14681469
});
14691470
debugMenu.add(item);
1471+
item.setEnabled(false);
14701472

14711473
item = Toolkit.newJMenuItemShift(Language.text("menu.debug.step_into"), KeyEvent.VK_J);
14721474
item.addActionListener(new ActionListener() {
@@ -1475,6 +1477,7 @@ public void actionPerformed(ActionEvent e) {
14751477
}
14761478
});
14771479
debugMenu.add(item);
1480+
item.setEnabled(false);
14781481

14791482
item = Toolkit.newJMenuItemAlt(Language.text("menu.debug.step_out"), KeyEvent.VK_J);
14801483
item.addActionListener(new ActionListener() {
@@ -1483,19 +1486,31 @@ public void actionPerformed(ActionEvent e) {
14831486
}
14841487
});
14851488
debugMenu.add(item);
1489+
item.setEnabled(false);
14861490

14871491
debugMenu.addSeparator();
14881492

14891493
item =
1490-
Toolkit.newJMenuItem(Language.text("menu.debug.toggle_breakpoint"), KeyEvent.VK_B);
1494+
Toolkit.newJMenuItem(Language.text("menu.debug.toggle_breakpoint"), 'B');
14911495
item.addActionListener(new ActionListener() {
14921496
public void actionPerformed(ActionEvent e) {
14931497
Logger.getLogger(JavaEditor.class.getName()).log(Level.INFO, "Invoked 'Toggle Breakpoint' menu item");
14941498
debugger.toggleBreakpoint();
14951499
}
14961500
});
14971501
debugMenu.add(item);
1502+
item.setEnabled(false);
1503+
1504+
item = Toolkit.newJMenuItem(Language.text("menu.debug.variable_inspector"), 'Y');
1505+
item.addActionListener(new ActionListener() {
1506+
public void actionPerformed(ActionEvent e) {
1507+
toggleVariableInspector();
1508+
}
1509+
});
1510+
debugMenu.add(item);
1511+
item.setEnabled(false);
14981512

1513+
/*
14991514
item = new JMenuItem(Language.text("menu.debug.list_breakpoints"));
15001515
item.addActionListener(new ActionListener() {
15011516
public void actionPerformed(ActionEvent e) {
@@ -1506,7 +1521,9 @@ public void actionPerformed(ActionEvent e) {
15061521
debugMenu.add(item);
15071522
15081523
debugMenu.addSeparator();
1524+
*/
15091525

1526+
/*
15101527
item = new JMenuItem(Language.text("menu.debug.print_stack_trace"));
15111528
item.addActionListener(new ActionListener() {
15121529
public void actionPerformed(ActionEvent e) {
@@ -1553,6 +1570,7 @@ public void actionPerformed(ActionEvent e) {
15531570
debugMenu.add(item);
15541571
15551572
debugMenu.addSeparator();
1573+
*/
15561574

15571575
// item = Toolkit.newJMenuItem(Language.text("menu.debug.toggle_variable_inspector"), KeyEvent.VK_I);
15581576
// item.addActionListener(new ActionListener() {
@@ -1563,6 +1581,7 @@ public void actionPerformed(ActionEvent e) {
15631581
// });
15641582
// debugMenu.add(item);
15651583

1584+
/*
15661585
item = Toolkit.newJMenuItem(Language.text("menu.debug.show_sketch_outline"), KeyEvent.VK_L);
15671586
item.addActionListener(new ActionListener() {
15681587
public void actionPerformed(ActionEvent e) {
@@ -1580,6 +1599,7 @@ public void actionPerformed(ActionEvent e) {
15801599
}
15811600
});
15821601
debugMenu.add(item);
1602+
*/
15831603

15841604
return debugMenu;
15851605
}
@@ -2133,6 +2153,10 @@ public void toggleDebug() {
21332153
public void updateDebugToggle() {
21342154
final boolean enabled = isDebuggerEnabled();
21352155
rebuildToolbar();
2156+
2157+
if (!enabled && inspector.isVisible()) {
2158+
toggleVariableInspector();
2159+
}
21362160
/*
21372161
if (enabled) {
21382162
inspector.setFocusableWindowState(false); // to not get focus when set visible
@@ -2150,11 +2174,22 @@ public void updateDebugToggle() {
21502174
}
21512175

21522176

2177+
public void toggleVariableInspector() {
2178+
if (inspector.isVisible()) {
2179+
inspector.setVisible(false);
2180+
} else {
2181+
// inspector.setFocusableWindowState(false); // to not get focus when set visible
2182+
inspector.setVisible(true);
2183+
// inspector.setFocusableWindowState(true); // allow to get focus again
2184+
}
2185+
}
2186+
2187+
21532188
// public void showVariableInspector() {
21542189
// tray.setVisible(true);
21552190
// }
2156-
//
2157-
//
2191+
2192+
21582193
// /**
21592194
// * Set visibility of the variable inspector window.
21602195
// * @param visible true to set the variable inspector visible,

java/src/processing/mode/java/VariableInspector.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
import processing.mode.java.debug.VariableNode;
4848

4949

50-
public class VariableInspector extends JFrame {
50+
public class VariableInspector extends JDialog {
5151
static public final int GAP = 13;
5252

5353
EditorButton continueButton;
@@ -95,8 +95,17 @@ public class VariableInspector extends JFrame {
9595

9696

9797
public VariableInspector(final JavaEditor editor) {
98-
super("Inspector");
98+
// As a JDialog, the menu bar comes from the Editor
99+
super(editor, "Inspector");
99100
this.editor = editor;
101+
102+
// Use the small toolbar style (at least on OS X)
103+
// https://developer.apple.com/library/mac/technotes/tn2007/tn2196.html#WINDOWS
104+
getRootPane().putClientProperty("Window.style", "small");
105+
106+
// When clicking this window, keep the focus on the Editor window
107+
setFocusableWindowState(false);
108+
100109
//setUndecorated(true);
101110
//editor.addComponentListener(new EditorFollower());
102111

@@ -111,7 +120,6 @@ public VariableInspector(final JavaEditor editor) {
111120
// editor.getY() + VERTICAL_OFFSET);
112121
setLocationRelativeTo(editor);
113122

114-
115123
/*
116124
bgColor = mode.getColor("buttons.bgcolor");
117125
statusFont = mode.getFont("buttons.status.font");

0 commit comments

Comments
 (0)