Saturday, August 8, 2009

The Simplistic Swing Application

This post shows and explains the application that we will be porting to the NetBeans Platform. We will also add enhancements based on anything that is of interest in the book The Definitive Guide to the NetBeans Platform.

Luckily, I created a quick app for a colleague to help demonstrate the Model View Controller (MVC) design as well as handling PropertyChangeEvents. Before I go into an explanation of how the app works, here is a screenshot:


It doesn't look like much, and it doesn't do much. It does have a nice separation between the model and the view, and it also makes use of some framework classes to help with the MVC design as well as add some nice UI features. We want to see how all of these affect the porting process (how easy is it to re-create your app), which makes it the perfect example for our learning the API's! First, let me go over the functional aspects of the application:

  1. When any data exists in the "Request ID" field, the "Send Request" button should be enabled; otherwise it will be disabled.
  2. When you send the request ID, the "Request ID" field will be cleared (thus disabling the button).
  3. The request ID can be sent by pressing the "Send Request" button, using the keyboard shortcut for the "Send Request" button (Alt-R), or by simply hitting the Enter key on the keyboard when the "Request ID" field has the focus.
  4. When a Request ID is sent, the status bar (bottom of the window) should display a message stating the ID that was sent.

So what's up with those colored squares? Well, those are status indicators that change color based on the current status that it is tracking. There should be some business rules that govern how they work, but for my app, I simply have a class that randomly generates status changes at a constant time interval. Like I said, this was just a simple example to illustrate handling events. Ideally, it would be nice to be able to plug in new implementations of this event generator that were implemented to some sort of interface. This way we could randomly generate status changes in one implementation (my example), and maybe later plug in a different implementation that reads status values from a database. This could be a later post about the NetBeans Lookup library.

So, from the functional specs, we know that a status bar exists at the bottom of the app as well as the visible Clock component. Here is another screenshot with the button enabled and text in the status bar:


Thanks to the Clock component, you can see how long it takes me to actually write this post! We now have the Swing application that we will be porting. Before we start that process, I will need to explain the code, which I will save for the next post (I am trying to keep these short). Let me just go through some high-level aspects right now.

The status bar on the bottom is a reusable component taken from Swing Hacks. The Clock is also a reusable component that was added to the status bar. The MVC implementation is created with the help of 2 other framework classes. The first is an abstract class called Model.java which really does nothing more than implement all the PropertyChange methods that exist (firing events and registering listeners). The second is an abstract class called FormInputPanel.java and it provides a mechanism for building form panels with a backing model for the data. We of course want to keep using all these in the NetBeans Platform version - either as-is, or via some new and easy Platform API. So we will see how possible that is (or is not).

Hopefully I am not going too slow for this project, but I am trying to avoid posts that are 50 pages in length. I am betting they will already be plenty long when I start into the code. Let me know any thoughts and comments - on the posts themselves, or the code I will be covering. That is, if anyone is listening. Anyone? Bueller? Bueller? Bueller? ....

No comments:

Post a Comment