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.

29.2 The custom view widget<br />

29.2.1 What is a custom view widget?<br />

Any widget displayed in a window created using the window building facilities of the c<strong>an</strong>vas, the<br />

palette <strong><strong>an</strong>d</strong> the c<strong>an</strong>vas tools uses a view to display itself. This view determines what will be displayed,<br />

what the associated view does <strong><strong>an</strong>d</strong> how it links with your application. However, not everything you will<br />

wish to do is covered by the widgets provided by the palette. For example, if you wish to display a<br />

network of nodes, then there is no built in widget to do this - you must write the code which will display<br />

such a network using a custom view.<br />

Figure 29.2: The View Holder Palette icon<br />

A custom view is held within a view holder which c<strong>an</strong> be placed onto a window usi ng the user interface<br />

builder. This is done using the view holder icon which is available on the user interface builder’s<br />

palette. It allows the user to place a view holder widget onto the c<strong>an</strong>vas being designed. Such a holder<br />

c<strong>an</strong> take adv<strong>an</strong>tage of some of the widget properties defined by the user interface builder such as sliders<br />

etc. However, the developer must supply the majority of the code that connects the graphic contents of<br />

the view holder to the application as well as the code which actually generates the graphics.<br />

29.2.2 How do you create a custom view?<br />

Figure 29.3: Defining a custom view<br />

To create a custom view a user must first place a view holder onto the c<strong>an</strong>vas representing the wind ow<br />

being constructed. For example, in Figure 29.3, we have placed a view holder across the majority of the<br />

window <strong><strong>an</strong>d</strong> added a horizontal <strong><strong>an</strong>d</strong> vertical slider. This view is then linked to the window via <strong>an</strong><br />

inst<strong>an</strong>ce variable specified in the view’s properties window.<br />

The result of this is that when the user interface window building software encounters this window’s<br />

definition (held in a class side window specification method) it will construct a window with four<br />

buttons <strong><strong>an</strong>d</strong> a scrollable view. However that is all that it will do. It will not attempt to perform <strong>an</strong>y<br />

operations to determine what the interior of the view should look like.<br />

29.2.3 M<strong>an</strong>aging a custom view<br />

Associated with this view holder will be a model, a controller <strong><strong>an</strong>d</strong> a view inst<strong>an</strong>ce. As you will note<br />

from these classes custom views are implemented <strong><strong>an</strong>d</strong> controlled using the traditional MVC framework<br />

described earlier in this part of the book. Remember:<br />

245

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

Saved successfully!

Ooh no, something went wrong!