diff --git a/pdex/src/processing/mode/experimental/DebugEditor.java b/pdex/src/processing/mode/experimental/DebugEditor.java index 6506b6e8f..fc3d8ee6b 100755 --- a/pdex/src/processing/mode/experimental/DebugEditor.java +++ b/pdex/src/processing/mode/experimental/DebugEditor.java @@ -373,7 +373,7 @@ public class DebugEditor extends JavaEditor implements ActionListener { * * @return the sketch menu */ - @Override + /*@Override public JMenu buildSketchMenu() { JMenuItem runItem = Toolkit.newJMenuItemShift(DebugToolbar.getTitle(DebugToolbar.RUN, false), KeyEvent.VK_R); runItem.addActionListener(new ActionListener() { @@ -399,6 +399,19 @@ public class DebugEditor extends JavaEditor implements ActionListener { } }); return buildSketchMenu(new JMenuItem[]{runItem, presentItem, stopItem}); + }*/ + + boolean debugToolbarShown = false; + protected EditorToolbar javaToolbar, debugToolbar; + protected void switchToolbars(){ + if(debugToolbarShown){ + // switch to java + } + else{ + // switch to debug + if(debugToolbar == null) + debugToolbar = new DebugToolbar(this, getBase()); + } } /** @@ -410,7 +423,16 @@ public class DebugEditor extends JavaEditor implements ActionListener { protected JMenu buildDebugMenu() { debugMenu = new JMenu("Debug"); - debugMenuItem = Toolkit.newJMenuItem("Debug", KeyEvent.VK_R); + JCheckBoxMenuItem toggleDebugger = new JCheckBoxMenuItem("Show Debug Toolbar"); + toggleDebugger.setSelected(false); + toggleDebugger.addActionListener(new ActionListener() { + + public void actionPerformed(ActionEvent e) { + + } + }); + debugMenu.add(toggleDebugger); + debugMenuItem = Toolkit.newJMenuItemAlt("Debug", KeyEvent.VK_R); debugMenuItem.addActionListener(this); continueMenuItem = Toolkit.newJMenuItem("Continue", KeyEvent.VK_U); continueMenuItem.addActionListener(this); @@ -921,7 +943,9 @@ public class DebugEditor extends JavaEditor implements ActionListener { } public DebugToolbar toolbar() { + if(toolbar instanceof DebugToolbar) return (DebugToolbar) toolbar; + return null; } /** @@ -1191,10 +1215,10 @@ public class DebugEditor extends JavaEditor implements ActionListener { * * @return the toolbar */ - @Override + /*@Override public EditorToolbar createToolbar() { return new DebugToolbar(this, base); - } + }*/ /** * Event Handler for double clicking in the left hand gutter area. diff --git a/pdex/src/processing/mode/experimental/DebugToolbar.java b/pdex/src/processing/mode/experimental/DebugToolbar.java index 3738b9db9..67af28774 100755 --- a/pdex/src/processing/mode/experimental/DebugToolbar.java +++ b/pdex/src/processing/mode/experimental/DebugToolbar.java @@ -17,12 +17,16 @@ */ package processing.mode.experimental; +import java.awt.Graphics; import java.awt.Image; import java.awt.event.MouseEvent; +import java.awt.image.BufferedImage; import java.util.logging.Level; import java.util.logging.Logger; import processing.app.Base; import processing.app.Editor; +import processing.app.Preferences; +import processing.app.Toolkit; import processing.mode.java.JavaToolbar; /** @@ -64,7 +68,55 @@ public class DebugToolbar extends JavaToolbar { public DebugToolbar(Editor editor, Base base) { super(editor, base); } - + public Image[][] loadImages() { + int res = Toolkit.highResDisplay() ? 2 : 1; + + String suffix = null; + Image allButtons = null; + // Some modes may not have a 2x version. If a mode doesn't have a 1x + // version, this will cause an error... they should always have 1x. + if (res == 2) { + suffix = "-2x.png"; + allButtons = mode.loadImage("theme/buttons-debug" + suffix); + if (allButtons == null) { + res = 1; // take him down a notch + } + } + if (res == 1) { + suffix = ".png"; + allButtons = mode.loadImage("theme/buttons-debug" + suffix); + if (allButtons == null) { + // use the old (pre-2.0b9) file name + suffix = ".gif"; + allButtons = mode.loadImage("theme/buttons-debug" + suffix); + } + } + /** Width of each toolbar button. */ + final int BUTTON_WIDTH = 27; + /** Height of each toolbar button. */ +// static final int BUTTON_HEIGHT = 32; + /** The amount of space between groups of buttons on the toolbar. */ + final int BUTTON_GAP = 5; + /** Size (both width and height) of the buttons in the source image. */ + final int BUTTON_IMAGE_SIZE = 33; + int count = allButtons.getWidth(this) / BUTTON_WIDTH*res; + final int GRID_SIZE = 32; + Image[][] buttonImages = new Image[count][3]; + + for (int i = 0; i < count; i++) { + for (int state = 0; state < 3; state++) { + Image image = new BufferedImage(BUTTON_WIDTH*res, GRID_SIZE*res, BufferedImage.TYPE_INT_ARGB); + Graphics g = image.getGraphics(); + g.drawImage(allButtons, + -(i*BUTTON_IMAGE_SIZE*res) - 3, + (state-2)*BUTTON_IMAGE_SIZE*res, null); + g.dispose(); + buttonImages[i][state] = image; + } + } + + return buttonImages; + } /** * Initialize buttons. Loads images and adds the buttons to the toolbar. diff --git a/pdex/src/processing/mode/experimental/Debugger.java b/pdex/src/processing/mode/experimental/Debugger.java index 758f6cfae..50b5d9846 100755 --- a/pdex/src/processing/mode/experimental/Debugger.java +++ b/pdex/src/processing/mode/experimental/Debugger.java @@ -168,7 +168,7 @@ public class Debugger implements VMEventListener { // load edits into sketch obj, etc... editor.prepareRun(); - + if(editor.toolbar() != null) editor.toolbar().activate(DebugToolbar.DEBUG); // after prepareRun, since this removes highlights try { @@ -236,9 +236,11 @@ public class Debugger implements VMEventListener { } stopTrackingLineChanges(); started = false; - editor.toolbar().deactivate(DebugToolbar.DEBUG); - editor.toolbar().deactivate(DebugToolbar.CONTINUE); - editor.toolbar().deactivate(DebugToolbar.STEP); + if(editor.toolbar() != null){ + editor.toolbar().deactivate(DebugToolbar.DEBUG); + editor.toolbar().deactivate(DebugToolbar.CONTINUE); + editor.toolbar().deactivate(DebugToolbar.STEP); + } editor.statusEmpty(); } @@ -246,7 +248,8 @@ public class Debugger implements VMEventListener { * Resume paused debugging session. Resumes VM. */ public synchronized void continueDebug() { - editor.toolbar().activate(DebugToolbar.CONTINUE); + if(editor.toolbar() != null) + editor.toolbar().activate(DebugToolbar.CONTINUE); editor.variableInspector().lock(); //editor.clearSelection(); //clearHighlight(); @@ -271,7 +274,8 @@ public class Debugger implements VMEventListener { startDebug(); } else if (isPaused()) { editor.variableInspector().lock(); - editor.toolbar().activate(DebugToolbar.STEP); + if(editor.toolbar() != null) + editor.toolbar().activate(DebugToolbar.STEP); // use global to mark that there is a step request pending requestedStep = runtime.vm().eventRequestManager().createStepRequest(currentThread, StepRequest.STEP_LINE, stepDepth); @@ -588,8 +592,10 @@ public class Debugger implements VMEventListener { @Override public void run() { editor.setCurrentLine(newCurrentLine); - editor.toolbar().deactivate(DebugToolbar.STEP); - editor.toolbar().deactivate(DebugToolbar.CONTINUE); + if(editor.toolbar() != null){ + editor.toolbar().deactivate(DebugToolbar.STEP); + editor.toolbar().deactivate(DebugToolbar.CONTINUE); + } } }); @@ -616,8 +622,10 @@ public class Debugger implements VMEventListener { @Override public void run() { editor.setCurrentLine(newCurrentLine); - editor.toolbar().deactivate(DebugToolbar.STEP); - editor.toolbar().deactivate(DebugToolbar.CONTINUE); + if(editor.toolbar() != null){ + editor.toolbar().deactivate(DebugToolbar.STEP); + editor.toolbar().deactivate(DebugToolbar.CONTINUE); + } } });