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: , , , ,


May 30 2007

Anatomy of an Eclipse Rich Client Platform Application

Wayne Beaton, Eclipse Foundation evangelist, gave an overview of the Eclipse Rich Client Platform (RCP). As he spoke, I thought of Eclipse RCP as a Fat Client minus the lard. Wayne described a Rich Client Platform as a system that provides a rich user experience, is platform independent and extensible, and provides a component model.

The Eclipse IDE is itself a collection of plugins, or components, on top of the base Eclipse platform. A big aspect of Eclipse RCP is Equinox, the OSGi based module system used to discover Eclipse plugins. In this context, plugins, modules, and components are used interchangeably.

Wayne gave a quick overview of the plugin structure of Eclipse. Basically Eclipse provides extension or plugin points at its core level. Adding or removing functionality is as simple as adding and removing files from the plugin directory in the Eclipse installation directory.

Wayne also mentioned Mylar. Mylar monitors and remembers which resources a developer is interested in for a recorded task and hides the rest. Wayne said, “You need to look into Mylar. Mylar will change your life.”

Technorati Tags: , , , , , ,


May 30 2007

Extreme GUI Makeover 2007

This is one of the most enjoyable session in all of JavaOne. Last years Extreme GUI Makeover, the gang made over a typical looking mail client. This year Christopher Campbell, Shannon Hickey, Hans Muller, and Romain Guy presented transformed a pizza box-like business User Interface (UI) into a visually stunning UI with Swing and Java 2D. The first type presented by the extreme makeover folks is to use a modern Look and Feel like Nimbus.

According to Romain, it makes a good idea to add a splash screen, and in Java 6 this is easier than ever with the new -splash JVM option. You should also make good use of non-rectangular UI splash screen with a drop shadow, and a progress indicator. The demo here faded the splash screen image from sepia to a full color image to indicate the loading progress.

They demoed JGoodies form validation which paints a little warning icon on the text field. Another demonstration showed a modal dialog with rounded corners ala Web 2.0 which blurred the main application window below. They rounded the border by overriding the paintBorder method on the Swing component. They use of gradients everywhere. They demonstrated a set of thumbnails with reflection using ReflectionRender which you can find in SwingX project from the SwingLabs. The demo also demonstrated custom table cell rendering. The speakers said that the default cell renderer is a JLabel but that you can use any JCoponent with any layout.

The demo had some animated effects for sorting and filtering table rows by extending a TableRowSorter available in Java 6. The demo used the Timing Framework to drive the animation and used the Glass Pane to paint the animation.

One of the best moments of the demo was when Romain Guy joked, “One thing I don’t like about UI is that it is constrained inside the frame of the window.” Why stick square components inside to the bounds of a window? Romain demoed a translucent non-rectangular dialog window that floated outside the main application window. To get this effect he said he used the JNA API, which I understood him to be described as JNI for Swing.

In speaking about boring business application UIs Romain joked, “You want to call the police to arrest the guy that wrote that UI.”

In summary, if you want to makeover your Swing UI, use Java 2D, Timing Framework, SwingX, and the Nimbus L&F.

Technorati Tags: , , , , , ,


May 30 2007

Building JavaServer Faces Applications with Spring and Hibernate

This technical JavaOne 2007 session was presented by Kito Mann, author of JavaServer Faces in Action, and Chris Richardson, author of POJOs in Action. Kito and Chris talked about the holy trinity of Java-based web application development, JavaServer Faces (JSF), Spring, and Hibernate.

JSF is a server-side UI component/event model with a basic set of UI components out of the box, and a simple MVC-style framework with a basic Dependency Injection container. The standard UI component model of JSF enables third-party and open source market place for additional components.

The Spring framework simplifies JEE development with AOP, ORM support, and Dependency Injection. Spring Beans are objects created and managed by Spring. Spring AOP allows modular implementation of cross cutting concerns, such as security, logging, and more.

Hibernate is a super set of Java Persistence API (JPA). JPA is a standardized ORM, providing transparent persistence, tracks changes of objects, manages identity, and maintains concurrency. Hibernate improves productivity, performance, maintainability, and portability.

If you are going to be doing web application development with JSF, Spring, and Hibernate then you should look into JBoss Seam. JBoss Seam integrates JSF, Spring, and Hibernate with a set of generators and conventions. Seam is greater than the sum of its parts.

Technorati Tags: , , , , , ,