Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Rediscovering the Caricature Demo for Beans Binding

DZone's Guide to

Rediscovering the Caricature Demo for Beans Binding

· Java Zone
Free Resource

What every Java engineer should know about microservices: Reactive Microservices Architecture.  Brought to you in partnership with Lightbend.

I came across Scott Violet's caricature demo sometime ago and also found the sources somewhere, probably in his blog. The demo is used to demonstrate, in a humorous way, what the Beans Binding Framework is all about. It shows a caricature, as the application object, with Swing controls that bind to its properties. However, the sample didn't work anymore with the current version of the APIs. On top of which, the Timing API and Animations API have also undergone change in the meantime. So, I had a bit of work to do...

However, today I figured it out! Or, at least, everything except the animation part. The code that I needed to work on, because it had changed since Scott wrote the demo, is the following part, which shows exactly the part that is relevant to the Beans Binding Framework:

public BindingCaricatureController() {
bindingGroup = new BindingGroup();
Binding eyeBinding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE,
caricature, BeanProperty.create("eyeStyle"), eyesSlider, BeanProperty.create("value"));
Binding faceBinding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE,
caricature, BeanProperty.create("faceStyle"), faceSlider, BeanProperty.create("value"));
Binding mouthBinding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE,
caricature, BeanProperty.create("mouthStyle"), mouthSlider, BeanProperty.create("value"));
Binding hairBinding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE,
caricature, BeanProperty.create("hairStyle"), hairSlider, BeanProperty.create("value"));
Binding noseBinding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE,
caricature, BeanProperty.create("noseStyle"), noseSlider, BeanProperty.create("value"));
Binding rotationBinding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE,
caricature, BeanProperty.create("rotation"), rotationSlider, BeanProperty.create("value"));
bindingGroup.addBinding(eyeBinding);
bindingGroup.addBinding(faceBinding);
bindingGroup.addBinding(mouthBinding);
bindingGroup.addBinding(hairBinding);
bindingGroup.addBinding(noseBinding);
bindingGroup.addBinding(rotationBinding);
bindingGroup.bind();
}

When I ran the application, I could use the Swing controls to change the application object's properties:

On top of that, I found that I could take Scott's cool application object and add it to the palette in NetBeans IDE. From there, I can drag it onto Swing containers. The Properties window displays all the properties that I can bind to my Swing controls:

And, while in design mode, I can also use the Properties window to try out the properties defined in the application object:

This is going make one cool demo for Beans Binding Framework presentations, also because it shows how snugly application objects integrate with NetBeans IDE!

Microservices for Java, explained. Revitalize your legacy systems (and your career) with Reactive Microservices Architecture, a free O'Reilly book. Brought to you in partnership with Lightbend.

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}