Swing Application Framework and Beans Binding
If you've ever worked with threads in Swing, or even the SwingWorker class, you probably know that it can be a bit of a challenge. Fortunately, JSR 296 will allow you to create tasks that can be started and monitored with the use of a TaskMonitor. In addition, there is a TaskService class that can help you organize each of your tasks and fire them off.
The Swing Application Framework also supports various lifecycle methods that you get when extending specific framework classes, such as initialize(), startup(), ready(), and shutdown(). Just extend the appropriate class, override these methods, and you won't have to worry about trapping any obscure events and reacting to them again.
I was also very impressed by the resource injection. Basically, this means that you can do something like:
Resource file:
btnShowTime.text = Show current time! btnShowTime.icon = refresh.pngJava class:
btnShowTime = new JButton();
btnShowTime.setName("btnShowTime");
And at this point, the resources are injected into the btnShowTime class automatically. In addition, you can even do something like this:
Resource File:
MyPanel.greetingMsg = Hello, %s, a string was injected!Java class:
@Resource String greetingMsg; ResourceMap resource = ctxt.getResourceMap(MyPanel.class); resource.injectFields(this); String personalMsg = String.format(greetingMsg, txtName.getText()); JOptionPane.showMessageDialog(this, personalMsg);There is also a new API out there for beans binding. If you've never heard of beans binding before, the idea is that two properties in two different beans need to remain synchronized. This is actually part of JSR 295. In short, this means you can do something like this:
Property property1 = ELProperty.create(“${faceStyle}”);
Property property2 = BeanProperty.create(“value”);
Binding binding = Bindings.createAutoBinding(
UpdateStrategy.READ_WRITE,
object1, property1, // source
object2, property2); // target
binding.bind();
This will create a binding between the two objects such that if a value on either side changes, the other value will instantaneously be changed as well. It's simple, elegant, and it works! Kudos to Shannon Hickey and Scott Violet for a great addition to the Java APIs.
You are right. Both (JSR-295 and JSR-296) specs are really good. You can even build UIs visually already (both are already bundled with Netbeans 6.0). Then you can specify the binding expressions already in the visual editor.
Your book was/is actually really good :-),
adam
Posted by Adam Bien on January 11, 2008 at 03:20 AM PST #
That sounds promising. What about using Spring to inject resources?
Posted by Moritz Petersen on January 11, 2008 at 05:09 AM PST #