1 import javax
.swing
.SwingUtilities
;
2 import java
.io
.InputStream
;
4 import org
.mozilla
.javascript
.Context
;
5 import org
.mozilla
.javascript
.Scriptable
;
6 import org
.mozilla
.javascript
.ImporterTopLevel
;
7 import org
.mozilla
.javascript
.tools
.debugger
.Main
;
8 import org
.mozilla
.javascript
.tools
.debugger
.ScopeProvider
;
10 import drafts
.com
.sun
.star
.script
.framework
.runtime
.XScriptContext
;
12 public class OORhinoDebugger
implements OOScriptDebugger
{
14 public void go(final XScriptContext xsctxt
, String filename
) {
15 Main sdb
= initUI(xsctxt
);
17 // This is the method we've added to open a file when starting
19 sdb
.openFile(filename
);
22 public void go(final XScriptContext xsctxt
, InputStream in
) {
23 Main sdb
= initUI(xsctxt
);
25 // Open a stream in the debugger
29 // This code is based on the main method of the Rhino Debugger Main class
30 // We pass in the XScriptContext in the global scope for script execution
31 private Main
initUI(final XScriptContext xsctxt
) {
33 final Main sdb
= new Main("Rhino JavaScript Debugger");
34 swingInvoke(new Runnable() {
37 sdb
.setSize(640, 640);
41 sdb
.setExitAction(new Runnable() {
46 Context
.addContextListener(sdb
);
47 sdb
.setScopeProvider(new ScopeProvider() {
48 public Scriptable
getScope() {
49 Context ctxt
= Context
.enter();
50 ImporterTopLevel scope
= new ImporterTopLevel(ctxt
);
51 Scriptable jsArgs
= Context
.toObject(xsctxt
, scope
);
52 scope
.put("XSCRIPTCONTEXT", scope
, jsArgs
);
58 } catch (Exception exc
) {
59 exc
.printStackTrace();
64 static void swingInvoke(Runnable f
) {
65 if (SwingUtilities
.isEventDispatchThread()) {
70 SwingUtilities
.invokeAndWait(f
);
71 } catch (Exception exc
) {
72 exc
.printStackTrace();