Smalltalk and Object Orientation: an Introduction - Free
Smalltalk and Object Orientation: an Introduction - Free
Smalltalk and Object Orientation: an Introduction - Free
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
26.4 Views <strong><strong>an</strong>d</strong> subviews<br />
In the example in the previous section, it is unlikely that the button would actually have been h<strong><strong>an</strong>d</strong>led by<br />
the window controller or that the window view would have determined how it was displayed. Rather the<br />
button would have had its own ButtonView <strong><strong>an</strong>d</strong> associated ButtonController (indeed Figure 26.4 <strong><strong>an</strong>d</strong><br />
Figure 26.5 suggest this). The ButtonView would have been a subview of the main window <strong><strong>an</strong>d</strong> would<br />
have been responsible for displaying the button <strong><strong>an</strong>d</strong> checking whether the mouse was over the button.<br />
In fact views are designed to be nested. Most windows actually involve at least two views, one<br />
nested inside the other. The outermost view, known as the top component, m<strong>an</strong>ages the familiar<br />
window features (for example, the window menu bar etc.). It has <strong>an</strong> associated controller which<br />
m<strong>an</strong>ages the familiar moving, framing, collapsing <strong><strong>an</strong>d</strong> closing operations available from windowing<br />
environments.<br />
Inside the top component are one or more subviews, known as components, <strong><strong>an</strong>d</strong> their controllers<br />
(remember almost all views have <strong>an</strong> associated controller) which m<strong>an</strong>age specific elements of the view<br />
(e.g. buttons, scroll bars, selection boxes etc.). The subview (component) refers to the view it is <strong>an</strong><br />
element of, as its container. Thus a subview is held within a c ontainer <strong><strong>an</strong>d</strong> a container possesses<br />
components (which are its subviews).<br />
A component may, in turn, have additional components (although this is often not required). The<br />
container/component relationships are recorded in inst<strong>an</strong>ce variables within the views. Each component<br />
has a link to its container <strong><strong>an</strong>d</strong> a container possesses <strong>an</strong> ordered collection of components. Thus each<br />
window’s top component is the top of a hierarchy of components.<br />
Typically, this me<strong>an</strong>s that when creating a window you first inst<strong>an</strong>tiate the top most view <strong><strong>an</strong>d</strong> then<br />
create <strong><strong>an</strong>d</strong> place subviews within the top level view. Figure 26.9 illustrates exactly this for a very simple<br />
window. This is a working example which you c<strong>an</strong> type into a Workspace <strong><strong>an</strong>d</strong> evaluate.<br />
The actual source code c<strong>an</strong> be broken down into three sections. The first section creates a new<br />
ScheduledWindow. Scheduled windows represent the top connection to the host window system 13 .<br />
They are always the top of the view hierarchy (that is they are always t he top component). Scheduled<br />
windows c<strong>an</strong> have a label, a minimum <strong><strong>an</strong>d</strong> maximum size, c<strong>an</strong> possess a single component (which c<strong>an</strong><br />
be made up of multiple views), possess a St<strong><strong>an</strong>d</strong>ardSystemController (a controller specifically<br />
designed to work with scheduled window s) <strong><strong>an</strong>d</strong> of course a model. Having created the scheduled<br />
window, the code sets its controller, gives the window a label <strong><strong>an</strong>d</strong> specifies its minimum size.<br />
Figure 26.9: Creating a simple window<br />
The second part of the code creates a composite part. A composite part is essentially a view which is<br />
made up of one or more subviews. That is, it is a collection of subviews <strong><strong>an</strong>d</strong> appropriate behaviour for<br />
h<strong><strong>an</strong>d</strong>ling these subviews 14 . In the example in Figure 26.9, two components are added to the<br />
compositePart. One is a very simple view which is a composed text. Composed texts allow strings to be<br />
displayed as a view. Note that it is the compositePart which determines where the ‘Hello’ will be<br />
13<br />
“Scheduled” really relates to the fact that all ScheduledWindows are held by a control m<strong>an</strong>ager which determines<br />
(schedules) which of them is active at <strong>an</strong>y one moment in time. Note only one window c<strong>an</strong> be active for user input at <strong>an</strong>y<br />
particular moment.<br />
14<br />
There is of course more to it th<strong>an</strong> that, involving Wrappers <strong><strong>an</strong>d</strong> VisualComponents, however as these are essentially<br />
modifications of the basic MVC we shall leave <strong>an</strong> investigation of this issue to the reader.<br />
220