Chapter 2. Specifying a Carbon Application: Moon Travel Planner

Specifying a Carbon application is similar to specifying any application. You need to define the goal of the application, sketch out the interface, define the behavior of the interface, and outline the implementation details. Before you start creating the application, it’s helpful to sort out what needs to be done in Interface Builder and what complementary things need to be done in Project Builder. Although you’ll find yourself switching back and forth between the two development tools, once you get the hang of it, you’ll see it’s fairly easy and fast to create an application with a great looking interface.

You’ll create a sample specification that shows:

  • Aspects of the interface that need to be created in Interface Builder and what needs to be done in Project Builder to support the interface

  • Other code that needs to be written in C using Project Builder

  • Items that should be created as a localizable file or other resource

  • Tasks taken care of by the operating system

You’ll create the Moon Travel Planner application that’s specified in this chapter throughout the course of the book. Once you define the goals of the sample application, the specification progresses according to what the user will see in the interface.

Windows and menus are the two basic elements users see in any interface. So you’ll sketch out each window and menu, describe its behavior, and outline the implementation details. This chapter includes cross references to the chapters in which you’ll actually implement the details.

The Moon Travel Planner Window

You’ll need a window to give the user an idea, in practical terms, of how far away the moon is from the earth. Let’s call it the Moon Travel Planner window. You’ll let the user compute the travel time to the moon for various modes of transportation. Figure 2.1 shows a sketch of what the main window of the application should look like. You’ll use this sketch as a model when you actually create the interface.

The Moon Travel Planner window

Figure 2-1. The Moon Travel Planner window

Behavior

The Moon Travel Planner window will display an image of the moon, a list of modes of transportation, a field that shows computed travel time, and two buttons. One button will compute travel time, and the other will quit the application. The window’s title bar will display the words “Moon Travel Planner.”

The window opens when the application launches and closes when the application quits. The user will be able to minimize the window so its icon displays in the Dock. The user should be able to quit the program by clicking the Quit button.

Note

The Dock is a feature of Mac OS X that appears at the bottom of the monitor. The Dock displays an icon for each open application and minimized document, as well as web site links and commonly used items, such as System Preferences and Trash. It’s designed to help combat onscreen clutter and to aid in organizing work.

When the user clicks the minimize button on a window, the window shrinks and moves to the Dock. If the user clicks the miniaturized window in the Dock, the window expands to full size.

The window should be movable, but it won’t be resizable. It will become inactive when other windows are open.

When the pointer is placed over the graphic in the window, a help tag appears.

Implementation

For the Moon Travel Planner, you’ll need to use Interface Builder to:

  • Define the window size, background, and title. See Chapter 4 for details.

  • Add controls, a text field, and static text fields (labels); adjust the layout of the window and controls; assign a command to the Compute Travel Time and Quit buttons; assign control ID information to the radio button group and the text field that shows the time it takes to travel to the moon. See Chapter 5 for details.

  • Add an image resource of the moon to the window. See Chapter 5 for details.

  • Define a help tag for the graphic in the window. See Chapter 12 for details.

In Project Builder, you’ll need to:

  • Add code to the main function to create the window from the nib file. See Chapter 3 for details.

  • Write a function that reads the radio button settings, computes travel time, and writes the value to the travel time text field; write a handler that responds to the Compute Travel Time command and calls your function for computing travel time. See Chapter 6 for details.

  • Add a PICT resource file that contains an image of the moon to the Moon Travel Planner project. See Chapter 5 for details.

  • Initialize the help tags. See Chapter 12 for details.

For the image of the moon that you use in Chapter 5 you can use an image we provide (see the preface for details on getting materials needed to build the Moon Travel Planner application), or use a graphics application to create an image of the moon and save it as a PICT resource file.

What you won’t need to do:

  • Implement the Quit command assigned to the Quit button. The operating system does that.

  • Write code to minimize or move the window. The operating system takes care of that as well.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.236.27