Download NetBeans!

20061027 Friday October 27, 2006

Interview: How I moved my Swing application to the NetBeans Platform

Here are the experiences of Aljoscha "Josh" Rittner who ported his Swing application to the NetBeans Platform. In fact, he turned it into a NetBeans module and loaded it into the NetBeans IDE, which is itself a Swing application... that's another way of porting your application: instead of porting it to a standalone application, just turn it into a module (or a set of related modules), install it in NetBeans IDE, and then... you'll only need to start up one application where before you needed to start up two!

Here's how his application looked initially, before porting. As you can see, it is a standalone Postfachinspektor, i.e., an e-mail client:

And this is how the application looks now, ported to a Swing application, i.e., integrated as a module in NetBeans IDE:

Roumen and I met Josh in Gottingen, in Germany, when we went there a month or so ago, to the university there. He told us that he had happily ported his application and I sent him a lot of questions by e-mail afterwards. Below are his responses. (If you want to see a picture of Josh, scroll to the end of the interview.)

Firstly, please tell us about your experience with NetBeans. How did you get started?

I came into contact with NetBeans at a very early stage. I already developed applications with DeveloperX2. At that time I used Java 1.1.8 and the Swing library 1.1.1. The most important feature for me was the form editor, for the provision of GUI masks.

Currently, I work with NetBeans 6.0 M4—productively. I was convinced to do so by the UI improvements in this milestone (dockable windows, full screen mode...)

Over time, the IDE's range has become increasingly indispensable to me—Java editor with code completion, hyperlinking, syntax coloring and integrated help assistance, Ant building, source versioning, GUI editor, and refactoring.

Why did you want to port an application to the NetBeans Platform?

I wanted to bring the future to one of my largest software projects, in order to be able to use the advantages of the extensive NetBeans APIs. Above all, the modern GUI framework (i.e., the NetBeans Platform itself) inspires me. In the past I programmed everything by myself. But I would like to make use of this complete development environment as a basis instead.

My project is a customer relationship groupware software. The development of a small plugin was for me a test, in order to learn the NetBeans platform... and so the porting of the e-mail client ("Postfachinspektor") started.

You can find some pictures and info (in German) here, in my blog.

How has your application improved as a result of porting it?

I was not concerned with getting new features in the module. The plan was that the module should function accurately and in the same way as it worked before, when it was a standalone application. Nevertheless, there are points, which brought me advantages. For example, the mails are now loading in a background process, without blocking the UI. In addition, I now see all output messages directly in the IDE without needing to open any logfile. The most important thing—I have now no extra application anymore, so I don't need to start a separate application to check my e-mail.

What are the main lessons/interesting things that you learnt?

To write a NetBeans plugin is simpler than I thought. Particularly, the tutorials under http://platform.netbeans.org/tutorials/index.html helped me to solve certain things quickly. In addition, the API documentation at http://www.netbeans.org/download/dev/javadoc/ is indispensable.

What problems did you encounter? How did you solve them?

With the "modes", I haven't come through that part so clearly yet. From time to time my TopComponent window appeared within the editor position, although it should be at the lower edge of the window. I will implement a new "mode" now. (Geertjan, you should know the tutorial... Creating A New Mode In Your Application .)

With a more current version of NetBeans, my program conflicts with a new provided Mail API. I use the version 1.4.0. I packed my Mail API with the library wrapper. But unfortunately the mail.jar from the ide8/modules/ext path slipped into the classpath. After I disabled a few libraries in the project.properties of the module suite, my plugin functioned again. In my opinion, too many libraries are activated, which one needs only rarely in plugin development.

Which NetBeans APIs did you use?

  • Dialogs API (to display messages)
  • Execution API (for background processes, such as the loading of mail header)
  • I/O API (for outputs)
  • Options Dialog and SPI (for options such as Mail-Account settings)
  • Progress API (for background processes)
  • Swing Layout Extension (for the Matisse GroupLayout)
  • UI Utilities API (for L18N)
  • Utilities API (for the LookUp of TopComponents)
  • Window System API (for my TopComponent)

(With the Dialogs API, it is not completely clear to me what NotifyDesscriptor.Exception does, because it does not show the stack trace nor the exception.)

Is your application in use in real life? How is that going?

Yes, since I integrated the e-mail client to a NetBeans plugin, I use it every day to query my different mail boxes, without removing the mails from the mail server.

Do you have plans for more modules or applications on the NetBeans Platform?

Absolutely. I needed two days for converting the old application to a NetBeans plugin. One day for the refactoring. One day for integrating the program as a plugin, including the new Options window extension.

That gave me the courage to begin converting my larger application to NetBeans. In the last week I threw the old source administration CVS overboard and converted my entire sources to Subversion 1.4

The project contains over 5800 Java files (45.2 MB source code) and 160 form files. The files were maintained since 1999 in CVS. The CVS repositories in the meantime have a size of 160MB in sources, diffs, and history data. With Subversion that became somewhat more compact.

Then I activated Subversion in "NetBeans 6.0 M4", removed CVS, and checked out all sources. It runs perfectly and is substantially faster than CVS. But the most important is that I now can refactor my source code without losing my history. Because Subversion supports the move and copy of files.

Now I split all the program areas of my software still further, so that I can use the advantages of the plugin administration of the NetBeans Platform. The Subversion support, the refactoring and the JDepend plugin by Bernhard Huber helps me to do this job.

Of course, I'll need three to six months to complete the biggest changes in the application I've ever made. But I think it's a great deal to get a modern framework for this work.

Thanks Josh! Also, congratulations for winning one of the cool Sun jackets for your NetBeans enthusiasm, at the NetBeans User Group meeting in Munich...

By the way, in my next two blog entries (in my blog) I'll explain the conversion of CVS repositiories to Subversion and a blog article with the "Postfachinspektor" as a ready-to-download plugin for NB 6.0 (localized in German and English).

Above, a picture of Josh, relaxing in his garden, satisfied with his ported application. Notice he's wearing his NetBeans t-shirt. When I told him he'd won a Sun jacket, he wrote back: "Cool, then only trousers and underwear with NB logo are missing..."

In other news. One of my pet annoyances, and also something people have been asking about on the mailing lists, has been "solved", kind of: "How to brand the 'IDE Help' text in the IDE Help's title bar." I found the file containing the text in the sources (core\javahelp\src\org\netbeans\modules\javahelp\resources\masterHelpSet.xml). There I changed the value of the title tag, recompiled the module, and used that one instead of the default JavaHelp module. Obviously it would be better to be able to brand it without changing the sources, but I haven't worked out that part yet (you'd need to set up the correct branding structure in your module suite, which I so far haven't been able to do). But it's good to know which file is involved and that making a change in that file really does result in the IDE Help's title bar changing as expected. Now to get the branding folder structure right... (Update: Here's the solution.)

Finally... if you want to do something similar to what Josh's module does, and check your GMail account inside NetBeans IDE, you should give the NetBeans Gmail Checker Module Tutorial a look...

Oct 27 2006, 12:43:23 AM PDT Permalink

Trackback URL: http://blogs.sun.com/geertjan/entry/porting_a_swing_app_to
Comments:

Its realy Useful to me.

Posted by vimalraj.m on October 30, 2006 at 06:16 AM PST #

Its realy Useful to me.

Posted by vimalraj.m on October 30, 2006 at 06:16 AM PST #

it is of great help to me

Posted by murari mohan goswami on October 30, 2006 at 07:44 PM PST #

?

Posted by 212.191.87.62 on November 24, 2006 at 05:12 AM PST #

Post a Comment:

Name:
E-Mail:
URL:

Your Comment:

HTML Syntax: NOT allowed