S for Sierra: this little letter turns one “Java Champion” into (at least) two “Java Champions”. Now we can officially append the pluralizing ‘s’, since two of the roughly 140 Java Champions worldwide belong to Canoo. Gerrit Grunwald received the coveted award last week in the course of the Java Champions Project, sponsored by Oracle. Andres Almiray had already been nominated and selected by the committee in 2010. As leader of JUG Münster, international speaker and software engineer with many years’ Java experience, Gerrit Grunwald actively passes his expertise on to developers and members of the community. In doing so, he not only follows the guiding principles of his Java Champion fellows but also underscores Canoo’s philosophy. “Hearty congratulations” from us!
In July the Java Forum Stuttgart took place for the 16th occasion. And while Dierk König and Gerrit Grunwald filled the congress centre’s lecture rooms with their talks “OpenDolphin – Java Desktop UIs for Enterprise Applications” and “JavaFX on Raspberry Pi and BeagleBoard xM“, the Canoo exhibition stand provided the meeting point for the Java Community. Here visitors were able to find out even more about the open source project Dolphin and exchange ideas with our experts about the use of JavaFX on embedded hardware. For those of you unable to attend the congress, you can view the Open Dolphin presentation slides and the JavaFX presentation slides. A great performance which we could only have topped with a homemade Raspberry Pie!
Today I would like to show you how a pure Swing based application can benefit from using Open Dolphin even if you are not planning to migrate it to JavaFX.
Although open-dolphin comes with many JavaFX examples it is not bound to JavaFX at all. In fact it does not require any specific UI toolkit.
You can get the source code for this example ready to build from github:
- git clone https://github.com/svene/opendolphin_swing_example.git
- ./gradlew build (or ‘gradlew.bat build’ if you are on Windows)
- ./gradlew :combined:run
The included example consists of just four simple widgets: a text field, a label and two buttons.
I did not spend any effort in making it visually attractive since I want you to concentrate on the open-dolphin aspects.
This is how the GUI looks like:
and here is a video demonstrating it’s behavior:
The following picture depicts how the individual widgets of the GUI are connected to the single presentation model:
Whenever a button is pressed a new value for the color is set on the presentation model (PM for short). And whenever the PM’s value changes both the label and the textfield are updated accordingly. In addition whenever the value in the textfield is changed by the user the value will be written back into the PM which in turn will update the label and so on.
In other words: each widget only talks (is bound) to the PM and not to other widgets. This also means they are only depending on the PM but not on other widgets. You can find more information about the PM concept on open-dolphin.org.
Some things worth to mention about the code:
When we invoke
as decribed earlier the application starts up with ApplicationInMemoryStarter. If you have a look into it you find that it uses SwingUiThreadHandler so that Dolphin can make use of Swing’s thread handling using:
The GUI (see ApplicationFrame) makes use of my preferred layoutcontainer: MigLayout.
Widgets are bound using Open Dolphin’s Binder class. The label for example is bound to the PM with a convenient DSL as follows:
which means: whenever the color of pm1 changes update the label’s text accordingly. The textfield is bound in the same way. Since text fields in Swing are a little uncooperative in regards to binding I used Jean-Marc Astesana’s CoolJTextField (see http://stackoverflow.com/questions/3953208/value-change-listener-to-jtextfield for the details).
This blog post gave you a starting point on how to apply the presentation model concept with Open Dolphin to a Swing application. But we only scratched the surface. If you would like to learn more about these intersting topics visit the Open Dolphin website or get in contact with Canoo.
Sven Ehrke (@syendar)
It’s all in one page, so you can search without clicking or navigating. And all the links refer back to the Mozilla documentation. So if you’re tired of shuffling through documentation trying to remember the parameter order for Arrays.reduce, then this is the thing for you. Just click the big image and away you go!
How and when were the source text changed? This question is quickly resolved using a version control system. While the majority of people have been working with central systems such as CVS or SVN until now, more and more developer teams are switching to the distributed system Git. Last Monday Canoo offered those who are interested in the potential future deployment of Git the opportunity to participate in a Git and GitHub training session. Course instructor Tim Berglund explained how to use VCS effectively and not least the benefits for software projects due to distribution. Feedback from the participants was an unanimous thumbs up!