Gfx doodle #3 - No Fluff Just Stuff

Gfx doodle #3

Posted by: Andres Almiray on March 14, 2008

Back to Joshy's latest doodle, I managed to get something out after meddling with GraphicsBuilder's recent updates. So here goes



There were some minor problems along the way, like shadow filter not working as expected (this filter is not based on the one provided by Swingx), that is why I choose to use shapes instead of images, updating the border while dragging instead of applying a shadow filter.

Let's step into each element of this groodle, first we will look at each shape, starting with the frog face. If it looks familiar is because it is based on the multipaint sphere example
Well, that was easy, now for each draggable piece of clothing. They are simple shapes, some area operations, and the hat has a pair of filters to give it a little depth (these pieces of clothing are not as nice as Joshy's hand drawn ones)

One last touch before ending the build closure is attaching a Swing button (not shown in the image) that will reset the position of all pieces of clothing. Thanks to Groovy's closures and having ids associated with each piece the code is pretty straight forward.

We reuse the each/closure trick outside the building closure to assign the mouse event handlers to each piece

Alright, so now we must define 3 closures to handle each event and then we are done, right? well almost. It turns out it is not so easy to do drag&,drop with gfx, at least not in as many lines as its jfx counterpart, because as of today d&d support is not automatically included. If you look closely at the jfx example you will notice that it is just a matter of binding e.dragTransition.[x,y], hopefully it will be too in gfx during the next days. For now let me show you how it is done, there is definitely room for improvement so if anyone notices something please let me know! :-)

As you can see the code is a bit verbose right now but it gets the job done, looks similar to the revisited dragging example previously posted. I have posted the code for this and the other groodles here, you can take them for a spin as soon as GraphicsBuilder 0.5 is released.

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 »