Script
interface, and create a debugger session using the SwingDebugScriptWindow.
public interface Script { public int computeResult(int value) { } }
DebuggingWrapper<Script> wrapper = new GroovyScriptWrapper<Script>() { };
SwingDebugScriptWindow
and set it as a Debug listener of the wrapper:SwingDebugScriptWindow debugWindow = new SwingDebugScriptWindow(20, 20); debugWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); wrapper.setDebugListener(debugWindow);
debugWindow.setVisible(true); JFileChooser chooser = new JFileChooser("Open Script"); chooser.setCurrentDirectory(new File(System.getProperty("user.dir"))); chooser.setDialogType(JFileChooser.OPEN_DIALOG); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); File file = null; int ret = chooser.showOpenDialog(null); if (ret == JFileChooser.APPROVE_OPTION) { file = chooser.getSelectedFile(); } wrapper.initializeDebugSession(); wrapper.installScript(file); DebugSession<Script> session = wrapper.createDebugSession(); session.setExecutionMode(ScriptWrapper.MODE_NON_BLOCKING); session.setSessionHook(new SessionHook<Script>() { public void start(Script script) { script.computeResult(10); } }); session.startSession();
public class DebugTutorial { public void startDebug() throws Exception { DebuggingWrapper<Script> wrapper = new GroovyScriptWrapper<Script>() { }; SwingDebugScriptWindow debugWindow = new SwingDebugScriptWindow(20, 20); wrapper.setDebugListener(debugWindow); debugWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); debugWindow.setVisible(true); File file = openScript(); if (file == null) { System.exit(0); } wrapper.initializeDebugSession(); wrapper.installScript(file); DebugSession<Script> session = wrapper.createDebugSession(); session.setExecutionMode(ScriptWrapper.MODE_NON_BLOCKING); session.setSessionHook(new SessionHook<Script>() { public void start(Script script) { script.computeResult(10); } }); session.startSession(); } private File openScript() { JFileChooser chooser = new JFileChooser("Open Script"); chooser.setCurrentDirectory(new File(System.getProperty("user.dir"))); chooser.setDialogType(JFileChooser.OPEN_DIALOG); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); File file = null; int ret = chooser.showOpenDialog(null); if (ret == JFileChooser.APPROVE_OPTION) { file = chooser.getSelectedFile(); } return file; } public static final void main(String[] args) throws Exception { DebugTutorial tutorial = new DebugTutorial(); tutorial.startDebug(); } }
public int computeResult(int value) { int a = 0; for (int i = 0; i < 100; i++) { a = a + value; context.echo("a = " + a); } return a; }
DebugTutorial
class and select the script. You should see the following window:Copyright 2019-2020 Herve Girod. All Rights Reserved. Documentation and source under the BSD licence