Moon Travel Planner: Adding Icons

You may have noticed that, after you build and run the Moon Travel Planner application, the Finder uses generic icons to represent the application and its document files. In this section, you’ll add icons that inspire an interest in the moon and lunar travel. You won’t need to design any icons; just download the materials provided for this book. See the preface for details.

You’ll do the following:

  1. Import images into Icon Composer.

  2. Add icon files to the Moon Travel Planner project.

  3. Register the application file.

  4. Add a document type to the Moon Travel Planner project.

  5. Make sure the icons display in the Finder.

Note

An important prerequisite to adding icons to your application is adding the application’s creator code to the property list. You already entered the Moon Travel Planner creator code, 'MTPP', in Chapter 10.

Import Images to Icon Composer

Icon Composer creates a file with a .icns extension in the format used by Mac OS X to store icons. You’ll only import a thumbnail image for the Moon Travel Planner application. You’d use the same procedure to import images of other sizes, if you had them.

Follow these steps to create Icon Composer files for the application and document icons provided with the Moon Travel Planner application. These icons are in the MTP.tif and MTPDoc.tif files, respectively. See the preface for details on how to obtain the materials.

You should follow these procedures twice: once to create an Icon Composer file for the application icon, and the second time to create an Icon Composer file for the document icon:

  1. Double-click Icon Composer in the /Developer/Applications directory. Icon Composer automatically opens an untitled file for your icons.

  2. Choose Import Image from the File menu.

  3. Select the file that contains the application icon, as shown in Figure 13.3. You can select the MTP.tif or MTPDoc.tif file provided with the Moon Travel Planner materials. If you created your own icon, you can use it instead of the one provided.

    Importing an image into Icon Composer

    Figure 13-3. Importing an image into Icon Composer

  4. Choose a data size from the Import To pop-up menu. The MTP.tif and MTPDoc.tif files each contain a thumbnail icon, so you should select “Thumbnail 32 bit data” then click Open. If you have an icon of a different size, choose the appropriate size from the pop-up menu. The MTP.icns file appears in the Icon Composer window, as shown in Figure 13.4.

    A thumbnail icon in an Icon Composer file

    Figure 13-4. A thumbnail icon in an Icon Composer file

  5. Add any icons you’ve created in other sizes. Mac OS X requires that you add a thumbnail icon; all other sizes are optional. If you have additional smaller images to import, either repeat steps 2-4 for each image or just drag the desired image from the Finder into the appropriate box in Icon Composer. When you add any icon other than the thumbnail, you’ll see a dialog asking if you want Icon Composer to extract a mask for the image. Unless you have special masking needs, you should let Icon Composer extract the mask. Otherwise, you’ll need to add a mask for each image (other than the thumbnail) you add.

  6. Choose Save from the File menu. Type MTP or MTPDoc as the filename and save the file in the Moon Travel Planner project folder. Icon Composer automatically appends .icns to the filename.

Add the Icon Files

Now that you’ve created the MTP.icns or MTPDoc.icns file, you need to add it to the Moon Travel Planner project, then make the appropriate settings so the new icon replaces the generic one. For each file, follow these steps:

  1. Open the Moon Travel Planner project. If the Moon Travel Planner is already open, click its icon in the Dock to make it active.

  2. Add the file to the Moon Travel Planner project. Choose Add Files from the Project menu. In the sheet that appears, select the MTP.icns or MTPDoc.icns file and click Open. Then click Add. If you need to, drag the MTP.icns or MTPDoc.icns file reference to the Resources group.

Register the Application Icon File

Now that you’ve added the MTP.icns file, you need to make the appropriate settings so the new icon replaces the generic one:

  1. Open the Application Settings pane. Click the Targets tab, select Moon Travel Planner from the Targets list, and then click the Application Settings tab.

  2. Enter MTP as the name of the file. Type MTP in the Icon File text field, as shown in Figure 13.5.

    Note

    Make sure you do not add the .icns extension; Project Builder does that for you automatically.

Entering the icon file name in the Application Settings pane

Figure 13-5. Entering the icon file name in the Application Settings pane

Add a Document Type

Now that you’ve created an Icon Composer file for a Moon Travel Planner document, and you’ve added it to your project, you need to set file type information. Follow these steps:

  1. In the Application Settings tab, scroll until you can see the Type Information group box (as shown in Figure 13.6). You must add information for each document type your application will open or save. The Moon Travel Planner application will open a custom document type—iTin (an itinerary file).

    Note

    We’ve made up the itinerary file type just to show you how to add a custom file type. If you create your own application that uses a custom file type, you must also define the custom file format and write functions that allow your application to store and retrieve data of that format. The Moon Travel Planner itinerary file type is just a text file.

    Adding document type information in Project Builder

    Figure 13-6. Adding document type information in Project Builder

  2. Enter a name for the file type. In the Name field type Itinerary.

    Note

    When you provide type information, you are actually assigning values to the CFBundleDocumentTypes property keys defined in Chapter 10. The Name field is the CFBundleTypeName property.

  3. Enter extensions information. This is the CFBundleTypeExtensions property. Extensions can help the user distinguish between various types of document files. Entering extension information is optional. Leave the Extensions field blank; the Moon Travel Planner application does not add an extension to document filenames. If you provide an extension, your file-saving functions should add the appropriate extension to the filename that the user enters in the Save dialog.

  4. Enter an OS type. We’re using the four-character code iTin to denote the itinerary file type. Type iTin in the “OS types” text field. This is the CFBundleTypeOSTypes property.

  5. Enter a filename for document icon file. Type MTPDoc in the “Icon file” text field. Make sure you do not add the .icns extension; that’s done automatically. This is the CFBundleTypeIconFile property.

  6. Click Add. The document type should appear in the Document Types list, as shown in Figure 13.6.

To add another file type, click in the blank area of the Document Types list to clear the Type Information fields. Then, repeat steps 2 through 6. The procedure for adding a generic type, such as 'TEXT', is the same as the one for adding a custom type.

Make Sure the Icons Display in the Finder

Let’s make sure that the application and its documents use the icons you’ve added. You’ll need to build and run the application, then check the icons in the Finder:

  1. Click the Build button in the upper-left corner of the Moon Travel Planner project window.

  2. Click the Run button in the upper-left corner of the project window. Look at the Dock as the Moon Travel Planner application launches. You should see the new icon as the application starts up.

  3. Open an itinerary file. In the Moon Travel Planner application, choose Open Itinerary from the File menu, then select a file to open.

  4. Save the itinerary file under a new name. Choose Save Itinerary As from the File menu and type a new filename.

  5. In the Finder, navigate to the directory where you saved the itinerary file.

  6. If you need to, click the icon view button. The saved itinerary file should appear with the custom document icon.

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

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