JHotDraw Pattern Language

JHotDraw Domain Overview

Description: U:\PLJHD\Patterns\Netapp.JPG

An example JHotDraw application - NetApp

JHotDraw is a framework for the creation of drawing editors. It provides support for a range of programs from simple paint package style editors to more complex programs that have rules about how their elements can be used and altered (e.g. a UML diagramming tool). The framework provides support for the creation of geometric and user defined shapes, editing those shapes, creating behavioural constraints in the editor and animation.

The applications created by JHotDraw are not 'bit-mapped' (or rasterised) paint programs. They maintain a collection of shapes that are separate from each other and can be manipulated as separate entities (unless explicitly grouped together). The Drawing class is responsible for keeping track of which shapes have been added to the drawing. To increase its flexibility JHotDraw follows the principals of the MVC design pattern by separating its model (data) from its view (appearance). The Drawing can be thought of as the model as it contains the current state of the application, a separate class called DrawingView represents the drawing's appearance in the application's GUI.

Applications in JHotDraw are defined by the DrawApplication class. This class is responsible for the creation of the graphical user interface (GUI) and for controlling access to the main elements of a JHotDraw application. In JHotDraw all applications are comprised of a drawing, an associated drawing view, a set of drawing shapes and at least one tool.

The shapes that make up a drawing are represented by the concept of Figures in JHotDraw. Figures are defined as rectangular areas of a drawing (displayBox) but are free to define the visual area inside that rectangle (i.e. the bit the user sees) as they wish. JHotDraw comes presupplied with many commonly used figures but it is possible for developers to create custom figures for use in their own applications.

Most applications in JHotDraw will require mechanisms for creating and editing the figures that make up a drawing. Figure creation is usually performed with a tool (a button that, when selected, alters the behaviour of the mouse).Editing figures is largely dependent on the type of figure and the set of attributes it allows to be altered. By default most figures allow their size and position to be changed, some allow their colours (outline and fill) to be changed and a few will support more esoteric options such as text editing, etc. Editing behaviour is usually limited to the current selection on a drawing.

There are three main ways to define editing behaviour in JHotDraw, using Handles (small icons that appear on the selected figure in the drawing), ActionTools (a special type of tool) or menus. In many cases these different mechanisms can be used interchangeably but occasionally the unique benefits and limitations of each approach have to be considered to create suitable edit functionality for an application.

Constraints are used to impose limits on an application's behavior and are useful when creating applications that require specific relationships between their elements (example constraints include, controlling where figures can be positioned, which of their attributes can be altered, connecting two figures together, etc).

In JHotDraw there are a number of ways in which constraints may be modelled. Constraints can be local to a class of Figure (for example to force the figure to be a certain size or stay in a given position). Or constraints can be applied to subclasses of the Drawing (for constraints that affect groups of figures). Finally it is possible to create connections between figures in the drawing. These are represented on the Drawing by a special type of figure called a ConnectionFigure.

All the different elements mentioned above (i.e. Figures, Handles, etc) need to be positioned on the drawing. This can be done by specifying absolute coordinates for that element's position or by using Locators, special classes that can be used to describe positions relative to other elements in the drawing (for example a Locator could be used to position a handle in the centre of a figure).

JHotDraw also supports simple animation capabilities at both the drawing and figure levels of the application.

Copyright Douglas Kirk