29.11.2014 Views

Smalltalk and Object Orientation: an Introduction - Free

Smalltalk and Object Orientation: an Introduction - Free

Smalltalk and Object Orientation: an Introduction - Free

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Finally, it is interesting to note a comment made in Ralph Johnson’s paper “The implementation [of<br />

HotDraw for <strong>Object</strong>Works Rel 4.0] was simpler th<strong>an</strong> previous ones because the design of the user<br />

interface framework for release 4.0 was influenced by HotDraw”.<br />

21.3.4 Facilities provided by HotDraw<br />

So what does HotDraw provide in this framework. (I will use the term framework to describe the basic<br />

HotDraw editor). You get the following facilities:<br />

• A ToolPaletteView. This is the tool bar down the left h<strong><strong>an</strong>d</strong> side of the display.<br />

• A DrawingView. This is the area a user would actually draw in.<br />

• A DrawingEditor. This is the model for the DrawingView <strong><strong>an</strong>d</strong> Drawing Controller.<br />

• A Drawing. This is also a model used by the DrawingView <strong><strong>an</strong>d</strong> Drawing Controller.<br />

• A DrawingController. which allows you to interact with the application.<br />

All these are already connected together in the appropriate m<strong>an</strong>ner, unlike m<strong>an</strong>y class -only packages, in<br />

which you as the developer must determine how to bring these elements together.<br />

21.4 Where do you start?<br />

Figure 21.1: The BoxDraw application to be built<br />

The remainder of this document is in effect a sample pattern which illustrates how you create a simple<br />

extension to the drawing editor. The problem to be addressed by this pattern is:<br />

The basic facilities provided by HotDraw make it very easy to construct a simple graphic<br />

editor for drawing diagrams. One useful feature of such diagrams is the ability to link figu res<br />

together <strong><strong>an</strong>d</strong> to get those links to move when the figures are moved. Thus there needs to be a<br />

way to link two figures together.<br />

21.4.1 The DrawingEditor<br />

You will almost always start by subclassing the DrawingEditor. This is the basic element of <strong>an</strong>y<br />

HotDraw tool. In this case we shall subclass DrawingEditor to create BoxDrawEditor, which will be the<br />

basis of our application BoxDraw. The definition of the BoxDrawEditor is presented below:<br />

DrawingEditor subclass: #BoxDrawEditor<br />

176

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!