Gfx doodle #2 - No Fluff Just Stuff

Gfx doodle #2

Posted by: Andres Almiray on February 19, 2008

Joshua has posted his second doodle (he noticed the first Groodle :-D thanks for the kind words!) so here goes my attempt for Groodle #2.

Reducing doodle #2 to its basic concepts reveals it is a custom shape (actually a rounded rectangle and a triangle mixed together) and some animations on its properties. Joshua uses a red rectangle to trigger animations over and over again. A couple of screenshots of groodle #2 first, for your viewing pleasure



I tweaked my version a bit to display a star instead of a rectangle, it also changes color when the mouse hovers on it and when you click it; the same TabRect shape is used to display the balloon popup.

Let's browse to the code step by step. First we will create a custom shape (as explained before here), let's recap:

In order to create a custom shape you may extend AbstractShapeGraphicsOperation, you'll get many things for free.


Following that advice yields this snippet

The previous custom shape example used Area operations directly, this time I chose to use GraphicsBuilder's nodes to build the mixed shape. This means that tabRect requires a GraphicsBuilder instance, which can be set as a property (non-observable). The other properties are (hopefully) self-explanatory if you follow Doodle #2 and previous postings on GraphicsBuilder. The next section of code will deal with registering the custom shape with GraphicsBuilder and registering aliases for some properties

Unfortunately as the commented code states, aliases are rather new, there is no metadata support (yet) to register them automatically. I hope to fill that gap soon. As you can see it is quite easy to register a new shape with GraphicsBuilder. Now on to the animation code it is, first I'll show you the definition of the animated shape. As Joshua noted, the animation syntax in JavaFX is shorter than the one found in GraphicsBuilder, perhaps it can be improved...
Here you can see the first improvement over Doodle #2, as instead of going with a flat color fill I chose to use a multiPaint composed of a base blue color and a nice white based gradient that fades away. Notice that colors can be derived and that the derive operation supports aliases too (a stands for alpha). The id property of each animation is needed to later reference them in the code that will trigger them. Next is the white balloon with blue text

Both text operations share the same font because it was set at the group level. I set the opacity (aliased to o) of the whole group to zero, so that it will popup when you hover on the star. The following snippet shows the popup and animation trigger

It is really quite simple, but one thing I do not like is having to restart each animation by itself when in this case all of them are bound to the same shape, perhaps this can also be improved somehow. To get groodle #2 running you will need to wrap the 3 snippets in a single group and set it into a GraphicsPanel, something like

Sweet!. Groodle #2 serves as a good example of what you can do to create your own shapes and also points out some areas for improvement.

Keep on Groovying!

Update: be aware that Groodle #1 & Groodle #2 require GraphicsBuilder 0.5-SNAPSHOT due to some new features and bug fixes.
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 »