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
Rather than cram both aspects of the Model-UI pattern into one huge article, I've decided to split up the concept into two, more easily digestible articles. This month, I'll demonstrate how to use the model portion of JTree to capture hierarchical structures; look for my discussion of the UI portion sometime in early '99.
We'll begin with a brief look at the MVC architectural pattern and examine how it is integrated into Swing. Then, we'll move into a detailed discussion of the Swing tree package and its interfaces. Along the way, we'll examine listeners and various strategies for using the tree package. Finally, we'll bring our discussion to a close with a look at a simple program that demonstrates Swing's tree capabilities in action.
We've got a lot to cover, so let's get started!
Swing's Model-UI architecture is a variation of the MVC (Model-View-Controller) pattern (see Resources). The MVC pattern, first introduced in Smalltalk-80, was designed to reduce the programming effort required to build systems that made use of multiple, synchronized presentations of the same data. The MVC consists of three distinct parts:
The MVC pattern prompts the following software qualities, which make it such a novel idea:
Loose coupling -- The model publishes only an interface for notification. Each view implements this interface, but the model does not know, nor, care about the view beyond this interface.
Pluggabilty -- We can add new views easily, without changing the model.
The MVC design pattern is typically used for constructing user interfaces that may present multiple views of the same data.
The design pattern is extremely important because it completely de-couples data display from data representation. This means
that the user interface of an application can be completely changed -- even dynamically, under direction of the user -- without need for any change to the underlying data subsystem
of the application. As long as you can implement the model (TreeModel, more on this later), your view does not have to change.