After playing around with Scenegraph I have felt the need for a more visual way of creating Scenegraph applications. I know that are able to do exactly that using the JavaFXPad, but I haven't had the time to learn JavaFX script. What I wanted to do was creating a visual display of a Scenegraph while you edit the Java code.
Inspired by Scott Violet's Interactive Graphics Editor, I decided to create a similar Java editor for Scenegraph.
(Please note that the Webstart is signed, since the project cannot run in the normal sandbox, due to the heavy use of reflections used by BeanShell)
Download source code
Architecture
Actually it was surprisingly easy to create the Scenegraph Shell. A JTextArea displays the current source code.
A thread is fetching the source code every second and if the source has changed, the source is compiled using BeanShell.
If the BeanShell compilation is successful, the result is displayed in the JSGPanel.
The main compilation is done by creating some 'shared' objects to editor; A root instance of SGGroup, so that you can attach SGNodes to the Scenegraph, and a instance of Timeline, so the programmer can create a start animation.
public void evaluate(String exception) throws EvalError {
Interpreter bsh = new Interpreter();
bsh.eval("import com.sun.scenario.scenegraph.*;"); // import statements
bsh.eval("import com.sun.scenario.animation.*;"); // import statements
bsh.eval("final SGGroup root = new SGGroup();"); // create root
bsh.eval("final Timeline timeline = new Timeline();"); // create timeline
bsh.eval("setStrictJava(true);");
bsh.eval( exception);
group = (SGGroup)bsh.eval("return root;");
timeline = (Timeline) bsh.eval("return timeline;");
}
After a successful evaluation, the root-group is added to the JSGPanel and the timeline is started.
Jar versions
Scenegraph (revision #279) - this should be quite close to version 0.6. The editor should work with any version of Scenegraph (however, the example applications will not work).
Bean
Shell uses the latest build 2.0b4.
Writing Scenegraph code in Scenegraph Shell
Before I started the project, I assumed that BeanShell was able to interpret all Java code. I found out, that there are a few limitations.
- Generics are not supported, so you must do old-fashioned typecasting.
- Anonymous inner classes are not supported, however you can implement interfaces. In fact you are able to implement a interface without defining all methods (as long as the unimplemented methods are never called).
I have created two example applications, that can be found in the file menu.
- Text demo - A fairly simple demo of how to create a animated text in scenegraph
- Pie chart demo - A more advanced use of Scenegraph, that displays a pie chart, that responds to mouse over events. (one of my first Scenegraph hobby projects, I original made in version 0.4)

Posted by lqd on juni 17, 2008 at 02:41 PM CEST #
Posted by Morten Nobel-Jørgensen on juni 17, 2008 at 10:47 PM CEST #
Posted by lqd on juni 18, 2008 at 12:48 AM CEST #
Posted by Morten Nobel-Jørgensen on juni 18, 2008 at 06:41 PM CEST #