Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

Automate dependency tracking, Part 3

Create a rich, interactive experience for your user

  • Print
  • Feedback
In the past, manual notification mechanisms were the de facto standards for updating dependent data in an object-oriented application. Patterns such as Observer, Publish-Subscribe, Document-View, and Model-View-Controller were certainly important as graphical user interfaces (GUIs) matured. But now that interactive applications have grown more sophisticated, expressive, and complex, the chore of notification now burdens productivity.

In this series of articles, I have introduced a mechanism that removes manual labor from dependency tracking. This mechanism automatically discovers dependencies within the application and ensures that dependent information is always up to date.

Read the whole series on automatic dependency tracking:



Along the way, I developed Nebula, a network design application that demonstrates a typical GUI application's many key features. It models a problem in such a way that the user can build, traverse, and apply the solution. And it presents a graphical user interface that allows simple repositioning and component editing. However, Nebula is not yet complete; it lacks true user interaction.

An interactive application provides feedback for most user actions. The feedback tells the user what the program expects and foreshadows events. It allows the user to combine several small actions to achieve a larger result. And it lets the user see what is going on inside the model itself.

To achieve a rich user experience, you must add visual feedback for such actions as selection, dragging, placing new devices, and running simulations. Just as automatic dependency tracking helps simplify the construction of the UI itself, it also helps you add rich user interaction. You simply identify the system's dependent and dynamic state.

Recall that an event changes dynamic state, whereas dependent state simply reacts to other state. Once you identify dynamic and dependent attributes, you use sentries to express them in code (refer to the sidebar, "Coding Practices for Automatic Dependency Tracking" for more information). In the previous two installments, we used sentries to capture the dependency of the user interface (UI) on the information model (IM). In this installment, we implement the following four dependency cases:

  1. A UI component's drag behavior depends upon the mouse position and state
  2. Selection is a dynamic attribute of each UI component
  3. The entire UI depends upon a macro operation's current mode
  4. Calculation results depend upon inputs


Drag behavior depends upon mouse behavior

First, we tackle how to add visual feedback as the user repositions a device. We want to pick a device when the user presses the mouse button, track the mouse position while the button is pressed, and repaint the device as the mouse moves. We have already written the code that moves the device when the user releases the mouse; now we just need to provide some feedback for the drag.

  • Print
  • Feedback

Resources
  • Download the source code that accompanies this article as a zip file
    http://www.javaworld.com/jw-10-2001/automatic/jw-1019-automatic.zip
  • Download the source code that accompanies this article as a jar file
    http://www.javaworld.com/jw-10-2001/automatic/jw-1019-automatic.jar
  • Design PatternsElements of Reusable Object-Oriented Software, Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides (Addison-Wesley, 1995; ISBN 0201633612), is the definitive reference for reusable software solutions. It discusses, among others, the Observer pattern, in which observers register for notification of subject changes. Though automatic dependency tracking is an alternative to the Observer pattern, the mechanism relies upon other patterns found in the book
    http://www.amazon.com/exec/obidos/ASIN/0201633612/javaworld
  • Suchitra Gupta has written a thorough review of various update mechanisms and discusses the Event Notifier (or Publish-Subscribe) pattern in detail
    http://www.users.qwest.net/~hartkopf/notifier/
  • Browse our Topical Index for more articles on Applied Java: http://www.javaworld.com/channel_content/jw-applied-index.shtml
  • Read more JavaWorld articles on User Interface Design: http://www.javaworld.com/channel_content/jw-ui-index.shtml
  • Sign up for JavaWorld's free weekly email newsletters
    http://www.idg.net/jw-subscribe
  • You'll find a wealth of IT-related articles from our sister publications at IDG.net