[home]   [me]   [my gallery]   [my blog]   [my articles]   [my code and projects]   [my links]
 

Scenegraph Shell


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.


Preview:
Preview
Launch

(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)
Now it's your turn. Try to alter some of the code in the projects or create your own. If you create something cool, please share the source code in a comment to this blog.
 
 
 
 
Comments:

maybe you could have full java support if you embedded eclipse's compiler ?

Posted by lqd on juni 17, 2008 at 02:41 PM CEST #

Great idea - I'll create a 'full java version' using eclipse's compiler later this week :-)

Posted by Morten Nobel-Jørgensen on juni 17, 2008 at 10:47 PM CEST #

i guess you could also compile with the javac tool interface (forgot the exact api, easy to find out) but i can't remember if you need to have a jdk (instead of just a jre as with eclipse's compiler) or not for that to work, and i think you do need a jdk Which might not seem a big deal since your tool seems targeted at developers, and they should have a jdk and javac.

Posted by lqd on juni 18, 2008 at 12:48 AM CEST #

Actually both the eclipse compiler and sun's jdk compiler share the java 1.6 interface javax.tools.JavaCompiler. So I actually could make it compiler independent. But I want to keep it simple, and I don't think webstart will work with sun's jdk compiler, since webstart would normally use the jre version (even when the jdk is installed). I have already made the eclipse work with some simple test-cases, so hopefully you should soon see a updated Scenegraph Shell (actually I think I'll change the name - Shell refers to BeanShell) :-)

Posted by Morten Nobel-Jørgensen on juni 18, 2008 at 06:41 PM CEST #

Post a Comment:
  • HTML Syntax: NOT allowed
 

« januar 2009
mationtofr
   
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 
       
Today

AddThis Feed Button

 
© Morten Nobel