Jun 5 2007

Being Productive with Swing

Ben Galbraith, founding blogger at Ajaxian, gave an insightful presentation at JavaOne 2007 on Swing. Ben started off by saying that Swing isn’t in the ‘Wow’ game like WPF, Cocoa, or Flex/Apollo. According to him, JavaFX Script might fill that gap but not just yet. In software development, productivity is king. Productivity is the currency of IT development. According to Ben, the Swing Application Framework does not address productivity but instead focuses on basic architectural concerns.

A theme that I picked up from Ben was that there is too much freedom when working with Swing and everybody builds GUIs in their own fashion. Since there is no consistency in UI development even within a project and since there is no solidified framework, Swing applications are hard to maintain and support.

Basically, there is no opinionated software in Swing to provide a standard, convention over configuration, pattern for building Swing-based applications. The key concerns a Swing framework needs to address are data binding, actions, listeners, activation, consistent form, and life cycle events amongst others.

One invaluable recommendation made by Ben is to use the JGoodies Forms layout if you hand code your UIs. Otherwise stick with your favorite UI Builder. He recommended the UI builder over fidgeting with UI code by hand. He said that coding a UI by hand is like hand writing a 50 page TPS report. He also reminded the audience to not muck or edit generated UI code. Ben said to let the UI builder own the code.

Ben recommended JForm Designer as an excellent commercial GUI builder and NetBeans as an Open Source alternative. Without a UI builder, it is difficult to attain UI consistency while fudging with spacers, fonts, insets, etc. Having a framework helps to attain a consistent layout for you desktop application.

Ben also had time to mention his framework, Swing Clarity. Clarity is a Swing Rich Client Platform that borrows heavily from Ben’s experience as a Ajax/web developer. Clarity has a Prototype-like method, $(), which can find named UI components using CSS-like selectors. With Clarity you can bind behavior to components by the variable name of the component with the help of custom @FormUIField annotation. I will definitely look into this framework as it introduces some ideas that make web development exciting. Clarity also provides bi-directional data binding and allows for some amount of skinning.

As an interesting side note, Ben called Karten Lentzsch, JGoodies project lead, the God father of Swing experts.

Technorati Tags: , , , , , , , ,


Jun 5 2007

JavaOne 2007: Thursday General Session

Padmasree Warrior, Motorola Executive Vice President and Chief Technology Officer, gave the Thursday general session at JavaOne. As you can imagine, her theme was the mobile network. In a presentation entitled Platform Disturbia she stated that in the mobile device world each network, each device, each spacial domain is its own platform. She also presented some figures where she states the there are more cell phone devices than cars, or televisions, or any other electronic consumer good. Padmasree enthusiastically said, “The whole world is a hot spot.”

Padmasree had a quick panel discussion regarding which mobile technology will win, mobile AJAX vs J2ME. The panel discussion was with mobile tech writers and pundits AJit Jaokar and C. Enrique Ortiz. In the end, I think it was Enrique that said that both have their strengths and weaknesses. To me, the debate sounded a lot like the same one between the desktop and web applications.

One thing that Padmasree said that stuck with me was that software development is about the user experience not the user interface. Sometimes as engineers we do over think a solution. We often design a system which ends up looking and behaving like it was designed by a software engineer, not a real person.

Motorola also took the time to promote their Open Source initiatives and their Developer Studio.

Technorati Tags: , , , , ,


Jun 3 2007

Putting a Swing Front End on a Web Application

During this JavaOne 2007 BOF, David Wroton shared his experienced of porting a JavaServer Faces (JSF) front-end to a Swing desktop client. David started with the whole browser vs fat client debate. David listed his issues with the browser, such as HTML Scrolling, back button, Funky JSF URLs. He said that “the back button is something that is breaking society.” The benefit of developing a HTML web application is that it is easier to get started.

The issues listed by David as holding back a rich Swing desktop include installation, maintenance, and getting started from scratch. To work around installation issues David used Java Web Start and instead of writing the desktop client from scratch he looked into using a Rich Client Platform such as Eclipe, NetBeans or Spring. Regarding the choice for which RCP to use he said, “There was a review last year, the review said, man, they are all hard.” Ultimately he selected Spring RCP, mostly because of his previous exposure to Spring. According to the speaker, Spring RCP has good form, data binding, and validation support. The major draw back to Spring RCP is the lack of documentation, an issue descried in last years’ review of Rich Client Platforms.

In closing, the David told the audience that the desktop is far more rich than any web based application, but AJAX goes a long way making a web application more user friendly and for many applications that is enough. Finally, he said there are still no clear lightweight/agile solution for a Swing framework.

Technorati Tags: , , , , ,


May 31 2007

Seamless Web Browser Integration

The complete title for this JavaOne 2007 BOF was Ingredients for a Killer Application – Adding Mojo to Your Swing and Ajax Applications with Seamless Web Browser Integration. Wow, what a mouthful. It might not be immediately clear from the title but the focus of this BOF was the use of the JDesktop Integration Components (JDIC) Web Browser embedded in a Swing application. As we all know Swing does not a complete Java-based web browser component, although there is a good XHTML Renderer. With the JDIC you can embed a native browser (IE, Firefox, or Safari) in your Swing application. Unlike the XHTML Renderer, the native browser allows you to run JavaScript code, apply AJAX/Web.2.0 effects, manipulate the DOM, and more.

Integrating JDIC into your project is as simple as adding the jar. A key demonstration of this BOF was to show how to have bi-directional native browser communication with your Swing application. To use the JDIC native browser, just create a WebBrowser object and invoke the executeScript method passing some JavaScript code in a string to communicate from the JVM to the browser.

To work your way from the broswer to the Java process you need to listen to the statusTextChange method on the WebBrowserListener. The statusTextChange method would be called when you set a string value to the browser window, as in the following JavaScript code.

[source:javascript]
window.status = “message passed to the JVM”;
window.status = “”;
[/source]

The speaker did warn the audience that using the status text to listen for processing instructions from the browser was a total and complete hack. The speaker recommended that as soon set the status to communicate with the JVM that you clear the command/message. The speaker talked about having your own mini-protocol to pass data and instructions to the JVM, I would recommend you use a standard like JSON.

Someone in the audience asked about having access to the x, y location of DOM elements in the browsers to combine with Java 2D overlays and effects, but the speaker was not sure how to go about implementing such a task.

Using the JDIC native web browser in your Swing application you can take advantage of Web 2.0 services such as Google Maps and Flickr in a Swing/Web 2.0 mashup. I have been looking into the JDIC web browser so that I can create a offline standalone web-based application by embedding a browser, Jetty, HSQLDB, and JRuby on Rails. Embedding all these components is easy enough to integrate, although you might have to write some glue code to make into a fully stacked framework.

Technorati Tags: , , , , , , , , ,


May 31 2007

Dive into the GlassFish Aquarium

During this Bird of a Feather session Eduardo Pelegri-Llopart, Distinguished Engineer at Sun, covered similar material as the slides presented during the GlassFish Day at Community One. The key take aways from the BOF was that GlassFish is a production quality application server. GlassFish also enjoys plenty of support from third-party vendors and a large collection of accompanying projects such as jMaki, Phobos, Blogapps, Hudson, Rome, and more. Eduardo announced the first ever GlassFish Champions in recognition of their key contributions to the community.

Technorati Tags: , , ,


May 31 2007

Tricks and Tips with NIO

This JavaOne 2007 technical session, Tricks and Tips with NIO – Using the Grizzly Framework, provided some general advice when working with the NIO classes. The most important piece of advice was to use the Grizzly Framework. The Grizzly project hides the programming complexity of using NIO so that developers can focus on implementing large scale servers. Grizzly is in use in the GlassFish Application Server.

For those not working with the Grizzly Framework, Jean-Francois Arcand of Sun gave a quick overview of NIO, or the new IO library introduced in Java 1.4. Jean-Francois reminded the audience that traditionally Java sockets are blocking but NIO channels can be either blocking or non-blocking. The talked described some very technical tricks and tips when working with NIO. The last tip and most important piece of advice was to use the Grizzly project when working with NIO.

Technorati Tags: , , , ,