JHotDraw Pattern Language

Adding Buttons to the Toolbar



A toolbar displaying a range of different tools

Tools are displayed as buttons on the toolbar that usually runs down the left hand side of the application window. The buttons on the toolbar can represent tools to create new figures, create new connections or to edit figure attributes. There can only be one tool active at all times.

The DrawApplication class creates the toolbar and it initialises the toolbar with one tool (the selection tool). Sub-classes of DrawApplication can add additional tools by overriding the createTools(Palette) method and creating a new ToolButton to add to the Palette (the toolbar). ToolButtons represent tools on the toolbar. When they are selected the current tool in the DrawApplication is replaced with the tool for the selected button.


A ToolButton

ToolButtons require an image to create a button. JHotDraw comes with several predefined images  (JHotDraw5.1/CH/ifa/draw/images). Each of the predefined images are 24 X 24 pixels in size and in the GIF file format. A ToolButton requires three separate images for each state that it can be in; available, pressed and selected. There is a naming scheme for the filenames of each image. They should all begin with the same identifier then end in a number (e.g. the SelectionTool images are saved as SEL1.gif, SEL2.gif and SEL3.gif for the available, pressed and selected states respectively).


Three states of a ToolButton

Although it is possible to remove the toolbar completely caution must be taken as other parts of the framework rely on the existence of a current tool and unless steps are taken to supply one the application will not function correctly.

   


Copyright Douglas Kirk