Still Alive 

In early 2008, I wrote my only blog entry of the year, on the subject of the filter effects framework that serves as part of the foundation of JavaFX. It has been a fun project to work on, and I'm fairly proud of the result. There was so much more I wanted to write about on the subject, but I wanted to wait until we first had a stable API and delivered an actual product.

It was a long road to JavaFX 1.0, but now that it has shipped, I can finally talk more about using filter effects in JavaFX and what's going on behind the scenes. Since it's a big subject, I'll try to break things up into smaller, more focused blog entries instead of my usual monolithic tomes. (At minimum, it will provide the illusion that I'm more prolific in 2009 than I was in 2008.)

Like any good graphics API, the filter effects framework in JavaFX is easy to use, provides high-quality visual results, and offers top-notch performance. In this entry, I'll just focus on the ease-of-use angle.


Bunny Jump, Bunny Jump 

The best place to start is to look at the javafx.scene.effectpackage API. All of the core filter effect classes extend the abstract javafx.scene.effect.Effect base class. AnyEffect instance can be applied to a scene graphNode by setting the Node.effect variable. Each Effect subclass exposes a small number of variables that control the visual appearance of theNode. In addition, most Effect subclasses provide one or more input variables that can be used to "chain" effects (more on that in a future blog entry).

To take a specific example, the DropShadow class provides 5 variables, analogous to knobs on a control panel:color, offsetX, offsetY,radius, and spread. Each "knob" is generally documented with default, minimum, maximum, and identity values, which makes it easy to see the acceptable range of values. Here's a really simple example that shows how to apply aDropShadow effect to a rounded Rectangleand control its appearance through the magic of thebind operator.

    

And here's the relevant code (or download the complete sourceshere):

            Rectangle {
                effect: DropShadow {
                    radius: bind radius
                }
                x: 50 y: 30 width: 150 height: 100
                arcWidth: 40 arcHeight: 40
                fill: Color.RED
            }

That's it! Pretty easy, isn't it? You, the developer, only need to concern yourself with turning these simple knobs. The effects framework does all the heavy lifting for you, such as painting theNode into an offscreen image at the appropriate resolution, manipulating the pixels in one of the CPU and/or GPU accelerated backends, and automatically repainting the affected portion of the scene.

For more interactive examples of the built-inEffect subclasses, check out the EffectsPlaygroundapplet featured in the JavaFX Samples Gallery. Stay tuned for entries on quality, performance, and more...


In my ears: No Age, Nouns
In my eyes: Woody Allen, Mere Anarchy