GfxBuilder 0.2 released - No Fluff Just Stuff

GfxBuilder 0.2 released

Posted by: Andres Almiray on August 5, 2009

It is with great pleasure that I announce the release of GfxBuilder 0.2 and its companion griffon plugin. These are the relevant changes in this release
  • Renamed GfxPanel to GfxCanvas. this class no longer extends JPanel, it is now a regular JComponent subclass.
  • Caching of shape information was too aggressive, it hindered animations. This problem has been fixed.
  • Added missing HSL properties to griffon.builder.gfx.Colors.
  • Added a new node: rawNode. It grants you direct access to underlying graphics context.
I believe a demonstration of rawNode is in order. Let's revisit the Gfx+Trident animation, this time we would like to highlight the contour of the animated shape, along with its bounds. The following video shows the animation running:



As you can see (pause at 00:12 for a better look) there is a red rectangle that changes size as the shape scales and rotates itself. There is also a visible white border, which of course moves along with the shape. However there are two static outlines. The cyan outline matching the shape and the yellow rectangle that matches the former's bounds. Now let's look at the code
Decided to show the code as a regular standalone Groovy script, you can run it via the Groovy shell or the Groovy console, if all required libs and dependencies have been previously placed at ~/.groovy/lib. These are the main differences from the previous version:
  • The main group sets 'none' as the border color, this means not outlines will be drawn unless explicitly told so.
  • The background is set to black rather than white.
  • The secondary group (the one that holds the actual shape) now has an id, it will become useful in the next step.
  • A rawNode is used to draw the static and dynamic shapes related to the secondary group.
Notice that the static shape information can be accessed directly from the g1 group itself, while the dynamic (or runtime) shape information is accessed via a runtime property. All DrawableNodes have a runtime property, it's responsibility is to compute and cache runtime values related to their corresponding node. At the moment, rawNode is the only way to effectively peek at a node's runtime values and do something with them in the same rendering sequence.

Another advantage of rawNode is that you may be able to insert any Graphics related code directly into the rendering pipeline, say, like those Clojure powered fractals ;-) There is a catch however, rawNode is not a DrawableNode so it won't be able to contribute shape information to its surrounding parent (typically a group).

Feedback is always appreciated.

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 »