
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:
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 textBoth 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 triggerIt 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.