An excellent session on the following JSRs:-
JSR-296 Swing Application Framework
JSR 295 Beans Binding
Put together, these address some of the issues in quickly building Swing applications. In reality, the desktop api is very big and what was given to developers was a whole bunch of components, without structure, lifecycle or wiring. What needed to follow was tool support and a framework – both of these have been patchy at best.
Anyway the goal was to create a framework as small as possible that could be explained in 1 hour, and would work well for small to medium sized apps, and provide the following key services:
Lifecycle
Actions
Resources
Tasks
Session state
Getting started is straight forward, you subclass Application, create and show the UI in the startup method i.e. @override protected void startup(), then use the Application Context to manage the services.
From the GUI builder, there is a nice encapsulation of behaviour, a default GUI, and the ability to recall or set enabled or selected states of components.
Managing actions for Swing has always been difficult, now you use the @Action annotation for your method, then to use an action, it’s something like
Action myAction = getAction(“sayHello”) which gets the registered action from the context.
One other thing you’ve always needed to do (though we’ve all done it wrong sometimes!), is use a background thread for event dispatching. The framework includes SwingWorker, which allows you to monitor progress, handle messages, and do start/stop. This has been extended with Task which gives additional support.
To create from the GUI, there’s a simple task editor, with a select box to enable as a background task. You can even allow them to block too if you like, so you can do things like freeze the UI until your search results come back.
Then very cool, right-click the app and select enable webstart. That’s it nothing else.
JSR- 295 really is about keeping two sets of objects in sync.From source through a converter to the target, then back through a converter and validator to the source (a property on a bean).
The editor allows you to specify a source using simple EL e.g. ${customer.salary}, or a whole object e.g. customer. The beauty here, is that it doesn’t need any special object types to do this, it uses a standard property change listener, and it deals with collections too, by using observable variants of Map and List. There is also support for various update strategies: read once, only from source and keep in sync. Finally, you can validation and transformation to convert a String to a Color.
To manage all the bindings, you use a binding context.
The binding stuff is still work in progress, but in good shape already. You can get more at
beans binding and on Shannon’s blog at Shannon’s blog
Then a very cool demo showing creating a flickr photo search app, built from scratch in about 4 mins.
Wait, more demos! A mashup – Maps and a database.
When you create a new Swing Application Framework project, you have the option of the basic one with built-in menus and progress bar, or creating a Database app, which connects to your database, and uses JPA, to build a form for you. Then they showed changing the cell renderer for the part that had a URI in from string, so it would go and show a picture of a real estate property, then they added the JXMapkit to display on a map the location.
Very nice. A lot of hard work has gone into this, check it out, I know I’ll be downloading it for a play.