Designing an Application

An application consists of two components: a view and its manager. In this chapter you will look at an existing golfing simulation to see how these two components are constructed.

To see the golfing simulation, you must

This simulation lets you see the effects of various atmospheric and sports variables on the trajectory of a golf ball. Click on Plot to hit the ball, Erase to erase the trajectories and Reset to reset the scales. You may click and drag on any of the scale sliders and then plot to see their effect on the trajectory. Click on Exit when done.

Editing a View

To build an application you should first design the application view. For the Golf example, it is the window which contains the scales, drawing window and menu of pushbuttons which you used to operate the simulation. In this section, you will learn how to find and edit this view.

Warning: ABC depends on the objects you see in the master directory. Do not delete them, move them to another directory or rename them. However, you may add objects if you so desire.

The view, called golfdb, is stored in the Master directory in the folder entitled Widgets. Edit this folder and then edit the golfdb widget. You should see the View Editor shown below.

Caution: While you are in the editor, you may make any changes you wish by experimenting with the options. However, when you leave make sure that you select the option to Ignore your changes.

At the left of the editor is a listbox of Widget types. If you click on the Add button, a widget of the type selected will be added. Try adding a pushbutton. It should appear in the work area in the upper left corner.

Select the widget by clicking on it. The cursor should change to a hand when it is within the selected widget. You can position the widget by dragging it to a new location, move it to the nearest millimeter with Align or center it horizontally with Center.

You can edit its attributes like its name or label by clicking on Edit in the View ToolBar. A Widget Attributes window should appear showing a list of attributes.

To change the label from 'New Button' to 'Test', click on the label attribute in the Attributes Listbox and Edit on the Attributes ToolBar. The current value will appear in the Attributes editor. Change it to 'Test' and then click on Assign. The button label should change. Click on the 'name' attribute to see the name of the widget. This name is used in your ABC code to refer to the widget. When you are done changing attributes, click on Edit on the View ToolBar. Then click on Delete to delete this pushbutton.

To edit the menu items, click on the menu and then Edit on the View ToolBar. Edit the items attribute and a text description of the menu will appear in the Attributes editor. The format for this text is described in a later chapter. If you change the title of a pushbutton and click on Assign, you will see how a menu can be modified.

When you have finished trying out the View Editor, click on Exit and be sure to specify that you want to ignore changes.

After exiting the View Editor, the display of the 'master' and 'widgets' folders should still be visible. To view the master folder again, click on the folder tab labeled Master.

Editing a Manager

Thus far you have worked with what the user sees on the screen. Now you will work with the ABC code necessary to make it functional. This is called a Manager. The manager contains the code to display the view and respond to the events (e.g. button presses, key presses, dragging) which are generated when the user interacts with the view. For the Golf Simulation, the primary events which must be dealt with are the activate events which occur when the four pushbuttons are pressed.

The name of the Golf Simulation manager is called Golfman. To look at it, select the Run/Edit Types option from the ABC MenuBar. The Type Manager window should appear as shown below.

A type defines what an object of that type consists of -- its parts -- and what it can do -- its methods. The Type Manager window displays all the types in the system. Scroll through this list and click on 'Golfman'. The parts and methods for this type will then be displayed.

The first method that a Golfman object will execute is manageAt:. The parameter to manageAt: is the location of the upper left corner where the view will be displayed. To see the code for this method, click on the method name and select Method/edit. Alternatively, you may double-click on the method name.

The purpose of this method is to create the view, create the three golfer and ball icons for the animation, show the view and reset all the scales. Note that 'me' refers to the Golfman object. The first statement refers to view:titled:at: which is not listed here. It is located in another type called its parent which we will discuss in more detail later. resetActivate is listed in the methods and is called as the last statement in manageAt:. You may wish to look at resetActivate and see what it does.

When the view appears on the screen, the manager is notified that the window named 'golfwin' has appeared on the screen and the golfwinExpose will be executed. This method erases the screen and displays the golfer. Once all this is done, ABC waits for the user to make the next move.

Typically, the user will press the Plot button. When this happens, ABC notifies the Golfman object that the 'Activate' event for the pushbutton 'plot' has occurred. It will do this by executing plotActivate. This code is complicated but can be divided into three sections: getting the current scale settings, making initial calculations and plotting the trajectory. Note how the whileDo loop plots the trajectory while the ball is within the window border.

When the user clicks on Exit, exitActivate is executed. Since it is not listed here, ABC will again look in the parent type for the method. The method that it finds there will delete the view which will cause it to disappear from the screen.

That is all there is to it! You may wish to edit the Play Golf method to see how Golfman gets started. Once a manager is up and running, there is an interplay between the view and its manager until the manager exits. In fact, you have already used the managers Progman, Dirman, Viewman, Typeman and Golfman and their associated views. Most of your programming will revolve around designing the views, manager types and supporting types to build your application.