Groovy Coffee Cup - No Fluff Just Stuff

Groovy Coffee Cup

Posted by: Andres Almiray on December 14, 2008

Following a recent tutorial about drawing a Coffee Cup with JavaFX I present you with the Groovy version



Transforming the JavaFX version into Groovy was, for most of it, pretty straight forward though some issues were found along the way, first let me show you the code as it currently looks
In case you're seeing GraphicsBuilder code for the first time know that I made use of property aliases, which means that fill can be set as f, color as c an so on. Alright, let's visit those gotchas
  • line 13: radialGradient requires a radius as it doesn't infer it from its host, it also does not follows the shape of its host (as it is the case on JavaFX), this means that it will always have a circular profile.
  • lines 35-44: decided to improve the way the cup shape is created by using an intersect operation, problem is that the resulting shape didn't accept a nested paint node, that is why I had to save it as shape an then draw it again. When a shape is drawn this way it looses all local transformations, that is why a keepTrans property had to be set to true. While powerful the usage of draw is not intuitive.
  • line 57-60: this is not exactly a problem but a plus, as the innerRim shape is reused to create a composite shape based on an intersect operation.
  • lines 62-66: a local transformation is applied to the cup group, negative translation coordinates had to be specified given the relationship with the scale transformations, in other words, scaling is done at world coordinates, not local coordinates.
I'll take care of these issues with the next version of GraphicsBuilder, stay tuned!
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 »