Griffon: making animations with Gfx+Trident - No Fluff Just Stuff

Griffon: making animations with Gfx+Trident

Posted by: Andres Almiray on July 29, 2009

The following video demonstrates SwingPad's basic animation capabilities with GfxBuilder + TridentBuilder



This is the code that produces the animation
Let's review the code step by step.
  1. A Model class is defined with two observable properties (s & ra). Creating observable beans with @Bindable is so easy I cannot do it in a different manner now ;-)
  2. A timeline is set to interpolate the model's properties. It will last for 4 seconds and will loop forever in a 'reverse' cycle. This means once the s property reaches 2.0 it will be animated back to 0.5 then back to 2.0, and so on.
  3. A closure named mouseHandler is defined, it will be used to pause/resume the animation. This will be triggered by clicking on the animated shape.
  4. The main content of the script follows. It is a JPanel that contains a GfxCanvas (GfxPanel was renamed to GfxCanvas) and a JLabel. The canvas contains all gfx nodes. Notice that the group's scaleX, scaleY and rotateAngle (sx, sy, and ra) properties are bound to the model's properties, using the short binding syntax. The mouseHandler closure is assigned to the group's mouseClicked property.
  5. Lastly, a repaint timeline is set on the canvas widget.
I don't know about you, but I'm excited to be able to mix & match Swing, Gfx and Trident nodes seamlessly in the same script. This script is far from optimized though, an alternative way to define the timeline that updates the model's properties could be
However, this is not yet possible with TridentBuilder 0.1, but I'd love to have that syntax finished before its next release.

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 »