From 459c65e52de179df4219a90718855f3125b952c7 Mon Sep 17 00:00:00 2001 From: benfry Date: Sun, 11 Nov 2012 23:01:44 +0000 Subject: [PATCH] additional cleanup --- .../processing/mode/java2/DebugToolbar.java | 368 +++++++++--------- 1 file changed, 190 insertions(+), 178 deletions(-) diff --git a/app/src/processing/mode/java2/DebugToolbar.java b/app/src/processing/mode/java2/DebugToolbar.java index 0dbdc7892..1a168c9c8 100755 --- a/app/src/processing/mode/java2/DebugToolbar.java +++ b/app/src/processing/mode/java2/DebugToolbar.java @@ -34,209 +34,221 @@ import processing.mode.java.JavaToolbar; * * @author Martin Leopold */ -@SuppressWarnings("hiding") public class DebugToolbar extends JavaToolbar { // preserve original button id's, but re-define so they are accessible // (they are used by DebugEditor, so they want to be public) - static protected final int RUN = 100; // change this, to be able to get it's name via getTitle() - static protected final int STOP = JavaToolbar.STOP; + @SuppressWarnings("hiding") + static protected final int RUN = 100; // change this, to be able to get it's name via getTitle() + static protected final int DEBUG = JavaToolbar.RUN; - static protected final int NEW = JavaToolbar.NEW; - static protected final int OPEN = JavaToolbar.OPEN; - static protected final int SAVE = JavaToolbar.SAVE; - static protected final int EXPORT = JavaToolbar.EXPORT; + static protected final int CONTINUE = 101; + static protected final int STEP = 102; + static protected final int TOGGLE_BREAKPOINT = 103; + static protected final int TOGGLE_VAR_INSPECTOR = 104; - static protected final int DEBUG = JavaToolbar.RUN; - static protected final int CONTINUE = 101; - static protected final int STEP = 102; - static protected final int TOGGLE_BREAKPOINT = 103; - static protected final int TOGGLE_VAR_INSPECTOR = 104; - static protected final int[] buttonSequence = { - DEBUG, CONTINUE, STEP, STOP, TOGGLE_BREAKPOINT, TOGGLE_VAR_INSPECTOR, NEW, OPEN, SAVE, EXPORT - }; // the sequence of button ids. (this maps button position = index to button ids) + @SuppressWarnings("hiding") + static protected final int STOP = JavaToolbar.STOP; - public DebugToolbar(Editor editor, Base base) { - super(editor, base); + @SuppressWarnings("hiding") + static protected final int NEW = JavaToolbar.NEW; + @SuppressWarnings("hiding") + static protected final int OPEN = JavaToolbar.OPEN; + @SuppressWarnings("hiding") + static protected final int SAVE = JavaToolbar.SAVE; + @SuppressWarnings("hiding") + static protected final int EXPORT = JavaToolbar.EXPORT; + + + // the sequence of button ids. (this maps button position = index to button ids) + static protected final int[] buttonSequence = { + DEBUG, CONTINUE, STEP, STOP, TOGGLE_BREAKPOINT, TOGGLE_VAR_INSPECTOR, + NEW, OPEN, SAVE, EXPORT + }; + + + public DebugToolbar(Editor editor, Base base) { + super(editor, base); + } + + + /** + * Initialize buttons. Loads images and adds the buttons to the toolbar. + */ + @Override + public void init() { + Image[][] images = loadImages(); + for (int idx = 0; idx < buttonSequence.length; idx++) { + int id = buttonId(idx); + addButton(getTitle(id, false), getTitle(id, true), images[idx], id == NEW || id == TOGGLE_BREAKPOINT); } + } - /** - * Initialize buttons. Loads images and adds the buttons to the toolbar. - */ - @Override - public void init() { - Image[][] images = loadImages(); - for (int idx = 0; idx < buttonSequence.length; idx++) { - int id = buttonId(idx); - addButton(getTitle(id, false), getTitle(id, true), images[idx], id == NEW || id == TOGGLE_BREAKPOINT); - } + + /** + * Get the title for a toolbar button. Displayed in the toolbar when + * hovering over a button. + * @param id id of the toolbar button + * @param shift true if shift is pressed + * @return the title + */ + public static String getTitle(int id, boolean shift) { + switch (id) { + case DebugToolbar.RUN: + return JavaToolbar.getTitle(JavaToolbar.RUN, shift); + case STOP: + return JavaToolbar.getTitle(JavaToolbar.STOP, shift); + case NEW: + return JavaToolbar.getTitle(JavaToolbar.NEW, shift); + case OPEN: + return JavaToolbar.getTitle(JavaToolbar.OPEN, shift); + case SAVE: + return JavaToolbar.getTitle(JavaToolbar.SAVE, shift); + case EXPORT: + return JavaToolbar.getTitle(JavaToolbar.EXPORT, shift); + case DEBUG: + if (shift) { + return "Run"; + } else { + return "Debug"; + } + case CONTINUE: + return "Continue"; + case TOGGLE_BREAKPOINT: + return "Toggle Breakpoint"; + case STEP: + if (shift) { + return "Step Into"; + } else { + return "Step"; + } + case TOGGLE_VAR_INSPECTOR: + return "Variable Inspector"; } + return null; + } - /** - * Get the title for a toolbar button. Displayed in the toolbar when - * hovering over a button. - * - * @param id id of the toolbar button - * @param shift true if shift is pressed - * @return the title - */ - public static String getTitle(int id, boolean shift) { - switch (id) { - case DebugToolbar.RUN: - return JavaToolbar.getTitle(JavaToolbar.RUN, shift); - case STOP: - return JavaToolbar.getTitle(JavaToolbar.STOP, shift); - case NEW: - return JavaToolbar.getTitle(JavaToolbar.NEW, shift); - case OPEN: - return JavaToolbar.getTitle(JavaToolbar.OPEN, shift); - case SAVE: - return JavaToolbar.getTitle(JavaToolbar.SAVE, shift); - case EXPORT: - return JavaToolbar.getTitle(JavaToolbar.EXPORT, shift); - case DEBUG: - if (shift) { - return "Run"; - } else { - return "Debug"; - } - case CONTINUE: - return "Continue"; - case TOGGLE_BREAKPOINT: - return "Toggle Breakpoint"; - case STEP: - if (shift) { - return "Step Into"; - } else { - return "Step"; - } - case TOGGLE_VAR_INSPECTOR: - return "Variable Inspector"; - } - return null; - } + + /** + * Event handler called when a toolbar button is clicked. + * @param e the mouse event + * @param idx index (i.e. position) of the toolbar button clicked + */ + @Override + public void handlePressed(MouseEvent e, int idx) { + boolean shift = e.isShiftDown(); + DebugEditor deditor = (DebugEditor) editor; + int id = buttonId(idx); // convert index/position to button id - /** - * Event handler called when a toolbar button is clicked. - * - * @param e the mouse event - * @param idx index (i.e. position) of the toolbar button clicked - */ - @Override - public void handlePressed(MouseEvent e, int idx) { - boolean shift = e.isShiftDown(); - DebugEditor deditor = (DebugEditor) editor; - int id = buttonId(idx); // convert index/position to button id - - switch (id) { + switch (id) { // case DebugToolbar.RUN: // super.handlePressed(e, JavaToolbar.RUN); // break; - case STOP: - Logger.getLogger(DebugToolbar.class.getName()).log(Level.INFO, "Invoked 'Stop' toolbar button"); - super.handlePressed(e, JavaToolbar.STOP); - break; - case NEW: - Logger.getLogger(DebugToolbar.class.getName()).log(Level.INFO, "Invoked 'New' toolbar button"); - super.handlePressed(e, JavaToolbar.NEW); - break; - case OPEN: - Logger.getLogger(DebugToolbar.class.getName()).log(Level.INFO, "Invoked 'Open' toolbar button"); - super.handlePressed(e, JavaToolbar.OPEN); - break; - case SAVE: - Logger.getLogger(DebugToolbar.class.getName()).log(Level.INFO, "Invoked 'Save' toolbar button"); - super.handlePressed(e, JavaToolbar.SAVE); - break; - case EXPORT: - Logger.getLogger(DebugToolbar.class.getName()).log(Level.INFO, "Invoked 'Export' toolbar button"); - super.handlePressed(e, JavaToolbar.EXPORT); - break; - case DEBUG: - if (shift) { - Logger.getLogger(DebugToolbar.class.getName()).log(Level.INFO, "Invoked 'Run' toolbar button"); - deditor.handleRun(); - } else { - Logger.getLogger(DebugToolbar.class.getName()).log(Level.INFO, "Invoked 'Debug' toolbar button"); - deditor.dbg.startDebug(); - } - break; - case CONTINUE: - Logger.getLogger(DebugToolbar.class.getName()).log(Level.INFO, "Invoked 'Continue' toolbar button"); - deditor.dbg.continueDebug(); - break; - case TOGGLE_BREAKPOINT: - Logger.getLogger(DebugToolbar.class.getName()).log(Level.INFO, "Invoked 'Toggle Breakpoint' toolbar button"); - deditor.dbg.toggleBreakpoint(); - break; - case STEP: - if (shift) { - Logger.getLogger(DebugToolbar.class.getName()).log(Level.INFO, "Invoked 'Step Into' toolbar button"); - deditor.dbg.stepInto(); - } else { - Logger.getLogger(DebugToolbar.class.getName()).log(Level.INFO, "Invoked 'Step' toolbar button"); - deditor.dbg.stepOver(); - } - break; + case STOP: + Logger.getLogger(DebugToolbar.class.getName()).log(Level.INFO, "Invoked 'Stop' toolbar button"); + super.handlePressed(e, JavaToolbar.STOP); + break; + case NEW: + Logger.getLogger(DebugToolbar.class.getName()).log(Level.INFO, "Invoked 'New' toolbar button"); + super.handlePressed(e, JavaToolbar.NEW); + break; + case OPEN: + Logger.getLogger(DebugToolbar.class.getName()).log(Level.INFO, "Invoked 'Open' toolbar button"); + super.handlePressed(e, JavaToolbar.OPEN); + break; + case SAVE: + Logger.getLogger(DebugToolbar.class.getName()).log(Level.INFO, "Invoked 'Save' toolbar button"); + super.handlePressed(e, JavaToolbar.SAVE); + break; + case EXPORT: + Logger.getLogger(DebugToolbar.class.getName()).log(Level.INFO, "Invoked 'Export' toolbar button"); + super.handlePressed(e, JavaToolbar.EXPORT); + break; + case DEBUG: + if (shift) { + Logger.getLogger(DebugToolbar.class.getName()).log(Level.INFO, "Invoked 'Run' toolbar button"); + deditor.handleRun(); + } else { + Logger.getLogger(DebugToolbar.class.getName()).log(Level.INFO, "Invoked 'Debug' toolbar button"); + deditor.dbg.startDebug(); + } + break; + case CONTINUE: + Logger.getLogger(DebugToolbar.class.getName()).log(Level.INFO, "Invoked 'Continue' toolbar button"); + deditor.dbg.continueDebug(); + break; + case TOGGLE_BREAKPOINT: + Logger.getLogger(DebugToolbar.class.getName()).log(Level.INFO, "Invoked 'Toggle Breakpoint' toolbar button"); + deditor.dbg.toggleBreakpoint(); + break; + case STEP: + if (shift) { + Logger.getLogger(DebugToolbar.class.getName()).log(Level.INFO, "Invoked 'Step Into' toolbar button"); + deditor.dbg.stepInto(); + } else { + Logger.getLogger(DebugToolbar.class.getName()).log(Level.INFO, "Invoked 'Step' toolbar button"); + deditor.dbg.stepOver(); + } + break; // case STEP_INTO: // deditor.dbg.stepInto(); // break; // case STEP_OUT: // deditor.dbg.stepOut(); // break; - case TOGGLE_VAR_INSPECTOR: - Logger.getLogger(DebugToolbar.class.getName()).log(Level.INFO, "Invoked 'Variable Inspector' toolbar button"); - deditor.toggleVariableInspector(); - break; - } + case TOGGLE_VAR_INSPECTOR: + Logger.getLogger(DebugToolbar.class.getName()).log(Level.INFO, "Invoked 'Variable Inspector' toolbar button"); + deditor.toggleVariableInspector(); + break; } + } - /** - * Activate (light up) a button. - * - * @param id the button id - */ - @Override - public void activate(int id) { - //System.out.println("activate button idx: " + buttonIndex(id)); - super.activate(buttonIndex(id)); - } + + /** + * Activate (light up) a button. + * @param id the button id + */ + @Override + public void activate(int id) { + //System.out.println("activate button idx: " + buttonIndex(id)); + super.activate(buttonIndex(id)); + } - /** - * Set a button to be inactive. - * - * @param id the button id - */ - @Override - public void deactivate(int id) { - //System.out.println("deactivate button idx: " + buttonIndex(id)); - super.deactivate(buttonIndex(id)); - } + + /** + * Set a button to be inactive. + * @param id the button id + */ + @Override + public void deactivate(int id) { + //System.out.println("deactivate button idx: " + buttonIndex(id)); + super.deactivate(buttonIndex(id)); + } - /** - * Get button position (index) from it's id. - * - * @param buttonId the button id - * ({@link #RUN}, {@link #DEBUG}, {@link #CONTINUE}), {@link #STEP}, ...) - * @return the button index - */ - protected int buttonIndex(int buttonId) { - for (int i = 0; i < buttonSequence.length; i++) { - if (buttonSequence[i] == buttonId) { - return i; - } - } - return -1; + + /** + * Get button position (index) from it's id. + * @param buttonId the button id + * ({@link #RUN}, {@link #DEBUG}, {@link #CONTINUE}), {@link #STEP}, ...) + * @return the button index + */ + protected int buttonIndex(int buttonId) { + for (int i = 0; i < buttonSequence.length; i++) { + if (buttonSequence[i] == buttonId) { + return i; + } } + return -1; + } - /** - * Get the button id from its position (index). - * - * @param buttonIdx the button index - * @return the button id - * ({@link #RUN}, {@link #DEBUG}, {@link #CONTINUE}), {@link #STEP}, ...) - */ - protected int buttonId(int buttonIdx) { - return buttonSequence[buttonIdx]; - } + + /** + * Get the button id from its position (index). + * @param buttonIdx the button index + * @return the button id + * ({@link #RUN}, {@link #DEBUG}, {@link #CONTINUE}), {@link #STEP}, ...) + */ + protected int buttonId(int buttonIdx) { + return buttonSequence[buttonIdx]; + } }