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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

the button. The selection colors are the colors which the button ch<strong>an</strong>ges to when a user selects the exit<br />

button. The contrast between red <strong><strong>an</strong>d</strong> blue helps the user identify that they have selected this button.<br />

You have now defined all that is required to display the window. You are therefore ready to install<br />

the window onto a class. To do this you should now select the Install button from the C<strong>an</strong>vas Tool<br />

window. You should install the window on a class called VisualOrg<strong>an</strong>izer which is a subclass of<br />

ApplicationModel. The window selector name should be left as windowSpec. Don’t forget to<br />

ch<strong>an</strong>ge the category to Visual Org<strong>an</strong>izer Classes otherwise it will be placed in the default category.<br />

Once you have installed the window onto a class you are now ready to define the action methods for<br />

the window (a.k.a. the method t o run when the button is clicked). You c<strong>an</strong> do this by selecting the<br />

Define option in the C<strong>an</strong>vas Tool window. Do this now. The definer should define four methods named<br />

after the action properties you defined above.<br />

28.2.2 The VisualOrg<strong>an</strong>izer class<br />

Now go to the System Browser <strong><strong>an</strong>d</strong> look at the class definition for VisualOrg<strong>an</strong>izer. You will see that a<br />

full class definition has been generated for you by the User interface builder. Your newly created class<br />

definition should look like this:<br />

ApplicationModel subclass: #VisualOrg<strong>an</strong>izer<br />

inst<strong>an</strong>ceVariableNames: ''<br />

classVariableNames: ''<br />

poolDictionaries: ''<br />

category: 'Visual Org<strong>an</strong>izer Classes'<br />

Next add a class comment. This is left as <strong>an</strong> exercise for the reader.<br />

28.2.3 The “actions” protocol<br />

Methods for each of the buttons in t he window are defined by the User interface builder when the<br />

Define option is selected (the user c<strong>an</strong> select not to define methods using a scrolling selection window).<br />

These methods are placed in the “actions” protocols. By default, these methods are define d to return the<br />

value of self. For example, the definitions generated by the User interface builder are:<br />

openAddresses<br />

^self<br />

openNotes<br />

^self<br />

openDiary<br />

^self<br />

doExit<br />

^self<br />

If we wish them to do <strong>an</strong>ything useful, then we need to edit these methods <strong><strong>an</strong>d</strong> define what they should<br />

do.<br />

We shall first look at the doExit method as this is the simplest method. This method will close the<br />

window. To do this we use the closeRequest method defined in the ApplicationModel class.<br />

We therefore merely need to send the message closeRequest to self.<br />

doExit<br />

"This method closes the associated window"<br />

self closeRequest.<br />

This method is associated with the “exit” button on the VisualOrg<strong>an</strong>izer Launcher.<br />

The other three actions are associated with the three launch buttons on the VisualOrg<strong>an</strong>izer<br />

Launcher. These are used to open the address book, the diary <strong><strong>an</strong>d</strong> the notes tool. The openDiary <strong><strong>an</strong>d</strong><br />

openNotes methods will remain unch<strong>an</strong>ged. They will return self when called. Extending the<br />

application for appointments <strong><strong>an</strong>d</strong> notes is left as <strong>an</strong> exercise for the reader.<br />

The only action method which possesses “content” will be openAddress book. This should send<br />

the message open to the AddressBook class. This causes <strong>an</strong> inst<strong>an</strong>ce of AddressBook to be<br />

created <strong><strong>an</strong>d</strong> the default window defined on this class opened:<br />

openAddresses<br />

AddressBook open.<br />

Define this now <strong><strong>an</strong>d</strong> accept it (leave <strong>an</strong>y classes undefined when VisualWorks warns you about them).<br />

238

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

Saved successfully!

Ooh no, something went wrong!