Griffon: GfxBuilder/FxBuilder side by side - No Fluff Just Stuff

Griffon: GfxBuilder/FxBuilder side by side

Posted by: Andres Almiray on July 13, 2009

The following snapshot shows a couple of spheres drawn with GfxBuilder and FxBuilder, can you guess which one is which?



I'm not much of an artist so you probably guessed right already, the left one is drawn by GfxBuilder, the right one by FxBuilder; the whole app requires setting up the builders and the following view script
Each sphere is a custom node, notice that the fx version sets a white background by default and also makes the graphics antialiased, whereas in the gfx version you must make those settings explicit, it appears gfxbuilder is in a lower level of abstraction than fxbuilder, but appearances can be deceiving. Let's look at the gfx code first, after all it was used as a reference for making the fx one:
Two things that I really like about this version
  • multiPaint() rules!
  • java.awt.Color has a derive() method attached via Groovy MOP
Now let's look at the fx version, this is pure JavaFX Script code
On the surface the code is pretty much the same, however there is no multiPaint() equivalent, that makes the code a bit longer, as each gradient must be applied to an independent Circle. Notice that the specular gradient applies requires a scale transform to be applied to the containing Circle not the paint. Also notice that deriving a color is not as easy as calling derive(). This is by no means a post to bash JavaFX rather to point out some of its deficiencies (as well as some of mine, for some reason couldn't get the gradients to use implicit values for cx, cy and r, but I know it's possible somehow!), for example a MultiPaint class could certainly be created, and a derive() method could be added to Color (actually a whole set of deriveRed(), deriveGreen(), etc). The fx version could certainly use some rework, it took me a while to tweak the coordinates to make it look like the gfx version but it is not there quite yet, I'm hoping someone more versed in JavaFX Script can lend a hand. (#imlookingatyoujohnathan)

Oh yeah, in case the first paragraph didn't drive the point home: this is a Swing app that contains two panels, one of them contains a JavaFX scene, so there, it can be done.

Keep on Groovying!
Andres Almiray

About Andres Almiray

Andres is a Java/Groovy developer and a Java Champion with more than 20 years of experience in software design and development. He has been involved in web and desktop application development since the early days of Java. Andres is a true believer in open source and has participated on popular projects like Groovy, Griffon, and DbUnit, as well as starting his own projects (Json-lib, EZMorph, GraphicsBuilder, JideBuilder). Founding member of the Griffon framework and Hackergarten community event. https://ch.linkedin.com/in/aalmiray

Why Attend the NFJS Tour?

  • » Cutting-Edge Technologies
  • » Agile Practices
  • » Peer Exchange

Current Topics:

  • Languages on the JVM: Scala, Groovy, Clojure
  • Enterprise Java
  • Core Java, Java 8
  • Agility
  • Testing: Geb, Spock, Easyb
  • REST
  • NoSQL: MongoDB, Cassandra
  • Hadoop
  • Spring 4
  • Cloud
  • Automation Tools: Gradle, Git, Jenkins, Sonar
  • HTML5, CSS3, AngularJS, jQuery, Usability
  • Mobile Apps - iPhone and Android
  • More...
Learn More »