Project Links
Home Source Code Build Instructions Rhino Integration Implementation Checklist
Parser Documentation
JavaDoc API (http://www.rj.pcblaze.com/downloads/xulparser/javadoc/) Casting Reference
| Table of contents |
Rhino Integration
So why did we decide to integrate XUL Parser with Rhino? The same reason that Mozilla uses JavaScript instead of pure C++. It makes some simple GUI tasks easier and allows for quicker extension and skins support. Instead of having to make 50 ActionListeners for each GUI event, you can now make a simple JavaScript function to perform the same tasks.
Currently the onclick value of a tag should equal the name of the JavaScript function (excluding the () for compatibility). You cannot put JavaScript expressions inside of the onclick values. Hopefully this will change soon.
Functionality
JavaScript support is provided to xulFrame's through the JavascriptEngine class. To retrieve a class instance for your xulFrame, run frame.getJavascriptEngine(). Once the engine has been retrieved, you can define certain objects for use in your JavaScript code by running the defineObject() function.
For most xulFrames, you should set the "document" object equal to your GUI class (whether or not it inherits xulFrame) and have your "window" object set to the xulFrame instance (unless your class inherits xulFrame, which it'll then be the same as "document").
XPCOM
Rhino integration will not include a Java port of Mozilla's XPCOM library mainly because it's not worth the time and effort. As great as XPCOM is, porting such a large library, especially when you can access the Java library from Rhino, seems a waste of time. It only adds code bloat and increases the learning curve when using XulParser. If someone wanted some extensive library features, they could use the Java library (since Rhino does provide access to it from JavaScript).
Making Java objects from JavaScript
The JavascriptEngine class adds some definitions to JavaScript for use in your application. If you want to create a new Java class instance from within JavaScript, just run:
var fileChooser = jsEngine.makeObject("javax.swing.JFileChooser");
Once you have your Java object created, you can access its functions just as if it were a Java object.
Performance
Using JavaScript over the old event system of accessing Java does result in a performance hit. In order to regain the performance, Rhino does provide a JavaScript "compiler" that will compile JavaScript to Java class files. Once the scripts are compiled, you offer little performance hit (and sometimes a performance gain) over the old Java system.
Rhino resources
Some links to areas where you can find more information about the Rhino JavaScript implementation:
- Rhino Overview (http://www.mozilla.org/rhino/overview.html)
- Rhino Debugger (http://www.mozilla.org/rhino/debugger.html)
- Performance Hints (http://www.mozilla.org/rhino/perf.html)
- Scripting Java (http://www.mozilla.org/rhino/ScriptingJava.html)
Navigation
Copyright © 2005-2006 Keller Technologies Inc.
All Rights Reserved
Contact Information | Privacy Policy
