Scene graph API available under open source

; Date: Tue Dec 11 2007

Tags: Java

Joshua Marinacci has discussed how ( Our new Java Scene Graph is open sourced .. and I decided to take a look.

The project is at ( and it is available under GPL (v2) right now. It's very early, labeled as v0.4, it has basically zero javadoc comments (hopefully they'll fix that shortly as it's a glaring hole), but it's pretty straightforward. Even someone like me who barely knows how to draw graphics can see my way to using this. Josh also has a link to a presentation at Javapolis by Chet Haase giving the high level.

My first thought, though, was to look into testability. Can one drive UI interactions against an animation driven by this scenegraph thingymajob.

My years of building, looking at or using GUI automation tools has shown me one key issue. Where does the tester point the mouse? In AWT/Swing components we have this nice method, Component.getLocationOnScreen, which tells us the screen coordinates. Then by retrieving the width/height you can calculate the midpoint of the component and click there and for most components that's good enough. For some specific components you will have to do special calculations to figure out where to click, but for the most part this is doable.

I had been afraid the scenegraph engine would not have any support for this. But it appears it's there.

JSGPanel is a JComponent and is where you add a scenegraph, thus JSGPanel.getLocationOnScreen tells you its screen coordinates. You set up your scenegraph using a variety of SGNode's doing whatever it is you wish.

While SGNode does not have a direct equivalent to getLocationOnScreen it does have a method localToGlobal. This tells you the corresponding coordinate, within the parent JSGPanel, of a coordinate within the SGNode. I hope (and haven't verified) that it accounts for any transformations applied to the SGNode. For the simple test I just wrote adding the x,y from getLocationOnScreen to the x,y from SGNode.getBounds does result in the correct coordinate to click on the SGNode.

It would be nice, for testability, if there were a convenience method to help with this.

Source: (

About the Author(s)

David Herron : David Herron is a writer and software engineer focusing on the wise use of technology. He is especially interested in clean energy technologies like solar power, wind power, and electric cars. David worked for nearly 30 years in Silicon Valley on software ranging from electronic mail systems, to video streaming, to the Java programming language, and has published several books on Node.js programming and electric vehicles.