TweetFollow Us on Twitter

TinyViewer, Part Deux

Volume Number: 19 (2003)
Issue Number: 7
Column Tag: Programming

Getting Started

TinyViewer, Part Deux

by Dave Mark

Last month's column was a lot of fun. So much so, that I was really torn on what to do in this month's column. I really want to continue the iPod notes exploration. And I've been playing with these cool AppleScripts that I'm just dying to write about. Then there's TinyViewer, the app from my May column. I really want to finish playing with Interface Builder and updating the TinyViewer interface. So that's what I'm gonna do this month and we'll start on the other stuff next month.

TinyViewer Recap

In last month's column, we used Interface Builder to build the beginnings of an interface for TinyViewer, our Cocoa update of the old PictViewer app. We used Project Builder to create a Cocoa Application project, then double-clicked on the MainMenu.nib file to open the nib file using Interface Builder.

We went through the four interface windows that appear - the app's main window, the menu bar window, the palette window, and the window labeled MainMenu.nib, which is a central repository for all the resources and instances from your project.

We dragged out an NSImageView from the palette window into the main app window, then used the dashed, blue lines to align and resize the NSImageView inside the window. We selected Show Info from the Tools menu and used the Info window to customize our NSImageView so it was Editable and Enabled. Making it Editable was especially important to our project as it allowed us to drag-and-drop an image on the window.

We also used the Info window to set the Autosizing settings, so when we resized the window, the image resized in a pleasing way.

Finally, we did the coolest thing of all. We used Interface Builder to take the interface for a spin by selecting Test Interface from the File menu. I absolutely love this part of Interface Builder. They idea of prototyping an app, then test driving the interface, all without writing a single line of code, is amazingly useful. But beyond that, I love the fact that you can archive complex object hierarchies inside a .nib file, then bring them to life inside a completely different application. Think about this. You design and test the TinyViewer interface inside Interface Builder, then save the .nib file, wheel over to Project Builder, build and run the app, and the exact same interface appears. Again, all without writing a single line of code.

Think back to your ResEdit days. You could edit the elements that made up the interface, even do a bit of stringing them together (though not much), but when it came time to bring them to life, you had to write a lot of code. Even though PowerPlant allowed you to create all the usual interface elements and nest them within nestable views, you still had to write the code that instantiated all your objects and brought them to life.

Interface Builder brings this process to a new level. And I like it.

Now What Do We Do?

OK, so what's next? Take a look at Figure 1. This is the menu that appears when you ask Project Buillder to build and run the TinyViewer application. A couple of notes here. First, the most eagle-eyed among you might have spotted a slight discrepancy between the title of this menu and what you see on your screen. Nicely done. When you run your app inside of Interface Builder, Interface Builder actually breathes life into your objects and yields control. In effect, Interface Builder turns into your running app, until you quit. You'll know this is happening cause your app's menu title will actually say Interface Builder.


Figure 1. TinyViewer's main menu.

When you run your app in Project Builder, Project Builder actually launches your app. As you can see in Figure 1, this version of TinyViewer features a TinyViewer menu, riddled with the generic name NewApplication. Let's change this menu to something a little more appropriate.

    Note that when you run your app under Interface Builder, the IB dock icon changes into a cool, single-pole, double-throw switch (ya know, like the one Gene Wilder threw to bring life to Young Frankenstein). Quit the app and the old familiar IB icon returns. Since your app is not running as a separate process, there's no separate dock icon for your app.

But when ProjectBuilder runs your app, you'll find your app represented by an elegantly designed dock icon distinct and separate from the Project Builder icon (and by elegant, I mean generic and boring, unless of course you've designed one yourself).

Changing the TinyViewer Menu

Quit your app if it is running, then (if you are not already in Interface Builder) double-click MainMenu.nib in the project window (Files tab, TinyViewer/Resources) to open the .nib file in Interface Builder. Find the MainMenu.nib main window (see Figure 2) and double-click on the MainMenu icon.


Figure 2. The MainMenu.nib window, with MainMenu selected.

When the MainMenu window appears, start by double-clicking the left -most menu title, the one that says NewApplication, and changing it to say TinyViewer.


Figure 3. Editing the TinyViewer menu title.

Next, click on the menu title TinyViewer. A menu should appear. Find the three occurrences of NewApplication and change them all to say TinyViewer (see Figure 4). Make the same change to the single occurrence of NewApplication in the Help menu.


Figure 4. The complete TinyViewer menu.

Change the Window Title

Next step: close the menu window and click on the TinyViewer window to bring it to the front. Now select Show Info from the Tools menu to bring up the inspector window. If you did this correctly, the inspector window will be titled NSWindow Info. Make sure Attributes is selected from the popup menu and change the window's title to TinyViewer. As soon as you hit enter or click out of the field, the TinyViewer window's title should change to TinyViewer.

    Very important! Be sure to save your .nib file in Interface Builder if you want to go back to Project Builder and test your changes.

Figure 5 shows my copy of TinyViewer with a picture dragged in and the Window's title changed. In a future column, we're going to add some code to the project to change the window title to the file name of the drag-and-dropped image. Any idea how to do this? One solution is to subclass NSImageView and insert your own dragging completion code. We'll also add in an NSScrollView to make the NSImageView scrollable. This one is doable completely within Interface Builder if you want to take a crack at this yourself.


Figure 5. TinyViewer in action. That's Ryan getting rid of my ball.

Create the About Panel

In the olden days of Mac development, the About Box was a modal dialog box with some text in it. Over time, people started customizing these dialogs and, eventually, replaced the canned About Box with customized windows. Some (Adobe PhotoShop, for example) even went so far as to write their own custom window procedures, leading to odd shaped windows, sometimes with holes in them.

Over time, the "official" method of producing About Boxes evolved, moving from About Boxes to About Windows to the current model, the About Panel. There's a terrific article on cocoadevcentral.com by Brock Brandeberg, that'll take you on a whirlwind tour of the modern About Panel:

http://cocoadevcentral.com/articles/000071.php

I'll give you the short version here, but definitely take a look at Brock's article. Well worth the read.

Just as the original Toolbox contained a canned routine for putting up an About Box, Cocoa's NSApplication class contains a member called orderFrontStandardAboutPanel:

- (void)orderFrontStandardAboutPanel:(id)sender;

This function is called automatically when About TinyViewer is selected from the TinyViewer menu (obviously, substitute your app name for TinyViewer). OrderFrontStandardAboutPanel: looks in your application's bundle for a set of elements it uses to build the About Panel. Alternatively, you can use the function orderFrontStandardAboutPanelWithOptions: to roll your own About Panel at run time:

- (void)orderFrontStandardAboutPanelWithOptions:
         (NSDictionary *)optionsDictionary;

This comment is from NSApplication.h. It describes the optionsDictionary parameter, but is useful in understanding what elements you can add to your application's bundle (more on this below):

/* Optional keys in optionsDictionary:
@"Credits": NSAttributedString displayed in the info area of the panel. If not specified, contents 
obtained from "Credits.rtf" in [NSBundle mainBundle];
if not available, blank.

@"ApplicationName": NSString displayed in place of the default app name. If not specified, uses the 
value of CFBundleName (localizable). Fallback is [[NSProcessInfo processInfo] processName].

@"ApplicationIcon": NSImage displayed in place of NSApplicationIcon. If not specified, use [NSImage 
imageNamed:@"NSApplicationIcon"]; if not available, generic icon.

@"Copyright": NSString containing the copyright string. If not specified, obtain from the value of 
NSHumanReadableCopyright (localizable) in infoDictionary; if not available, leave blank.

@"Version": NSString containing the build version number of the application ("58.4", "1.2d3"); 
displayed as "Version 58.4" or "1.0 (v58.4) depending on the presence of ApplicationVersion. If not 
specified, obtain from the CFBundleVersion key in infoDictionary; if not specified or empty string, 
leave blank.

@"ApplicationVersion": NSString displayed as the application version  ("1.0", "Mac OS X", "3", 
"WebObjects 3.5", ...), before the build version. If not specified, obtain from 
CFBundleShortVersionString key in infoDictionary..
*/

For starters, go into TextEdit and create your own About Panel text for TinyViewer. Save the file as Credits.rtf. Note that the name is case-sensitive and has to be exactly Credits.rtf. The file Credits.rtf has been used for About Panels since the birth of Mac OS X. Recent releases of the OS also recognize Credits.html and Credits.rtfd. Obviously, Credits.html allows you to include links in your About Panel and Credits.rtfd allows you to use an rtfd package. You can include all three files in your application's bundle, but priority is given to Credits.html, then Credits.rtf, then Credits.rtfd.

Why have more than one? Your best bet is to include Credits.rtf, in case your app is used by someone with an old version of Mac OS X installed. Whether you supplement this with Credits.rtfd or Credits.html is your call.

Adding Credits.rtf to the Project File

Let's add Credits.rtf to our project. Once you get that to work, it's an easy step to add Credits.html or Credits.rtfd to the mix.

In the project window, select the Files tab, then make sure the Resources triangle is open. In the Finder, click on your Credits.rtf file and drag it into the project window, into the Resources area. As you drag, you'll see a bold black line appear that indicates where the file will be dropped (see Figure 6).


Figure 6. Dragging Credits.rtf into the project file.

When you release your mouse button, the dialog in Figure 7 will appear. Be sure to check the "Copy items" checkbox at the top of the dialog. This tells Project Builder to copy the file into your project hierarchy. You can then do as you like with the original, cause Project Builder lets you edit the copy by double-clicking it.


Figure 7. The Add File dialog. Be sure the "Copy items" checkbox is checked.

Fill in the Bundle

My Alert Panel is shown in Figure 8. It is made up of a collection of resources, including an icon, a collection of info.plist strings, and the Credits.rtf file. You already know how to add the Credits.rtf file. To create your application's icons, you'll want to use a program like PhotoShop to create the artwork, then import that artwork into IconComposer. IconComposer is part of the developer tools and is found in /Developer/Applications/.


Figure 8. My TinyViewer About Panel. Hey! That's Kelley!

Building an icon is entire column in itself. The key is to make sure you create an alpha channel for the 128-by-128 version of the icon, save as a tiff, then import into IconComposer. If your icon looks funky when you save and reopen it, you've probably not done the alpha channel magic properly. We'll tackle this in a future column. If you want to try your hand at doing this, be sure to save the icon as a .icns file, then drag it into the project, just as you did with Credits.rtf. I called my icon TinyViewer.icns.

Your next step is to click on the Targets tab in the Project Window, then click on the TinyViewer target. This will bring up a list of settings you'll need to edit in order to fill out the rest of your About Panel, add an icon to the project, etc. Figure 9 shows my settings.


Figure 9. TinyViewer's Info.plist entries.

    Note that the CFBundleSignature is set to GETs. I logged on to http://developer.apple.com and registered this creator code with Apple specifically for TinyViewer. Feel free to use this code yourself, since I'll only use it for Getting Started projects. We'll dig into registering creator codes in a future column.

Once those changes are made, go back to the Files tab and open the Resources triangle. Click on the InfoPlist.strings item. You'll see something that looks like this:

/* Localized versions of Info.plist keys */
CFBundleName = "TinyViewer";
CFBundleShortVersionString = "TinyViewer version 1.0";
CFBundleGetInfoString = "TinyViewer 1.0, Copyright 2003 by Dave Mark. All Rights Reserved.";
NSHumanReadableCopyright = "Copyright 2003 by Dave Mark. All Rights Reserved.";

I've edited my versions to reflect the settings I want for TinyViewer. Note that the InfoPlist.strings file is your localized strings file. You might contract out to a localizing firm to take your English plist file and translate it to a German plist file. You'd keep both localized files in your project and the right strings would be displayed, depending on the language setting on your computer.

Think of the Info.plist file as the true repository for your plist keys. Any strings that need to be localized should be kept in each localized InfoPlist.strings file. The localized version, if it exists, will override any matching key in the Info.plist file. When building your project, just do the Targets version first, then do the Files version and you should be fine.

    A couple of books that really helped with this month's column: Joe Zobkiw's excellent Mac OS X, Advanced Development Techniques really digs deep into a wide variety of Cocoa-related topics. And, as I've mentioned in a previous column, Bill Cheeseman's Cocoa Recipes for Mac OS X: The Vermont Recipes is an invaluable resource. I definitely owe both these guys a beverage of their choice. And an extra tall one for Mike Trent for helping to unravel all those pesky Cocoa mysteries. Thanks!

Till Next Month...

Man.

There was way more that I wanted to get into. I just ran out of space. I am just loving Project Builder, Interface Builder and Cocoa. Not sure what we'll dig into next month. There's a little more iPod madness left in me. I also just got this really good AppleScript book. Hrm. Maybe a column on scripting my iPod? See you soon...


Dave Mark is a long-time Mac developer and MacTech contributor. Random facts about Dave? He is addicted to Age of Empires. He can't seem to stop camping. And his iPod has him hypnotized with its shiny silver grooviness.

 
AAPL
$524.94
Apple Inc.
+5.93
MSFT
$40.01
Microsoft Corpora
-0.39
GOOG
$536.10
Google Inc.
-20.44

MacTech Search:
Community Search:

Software Updates via MacUpdate

VMware Fusion 6.0.3 - Run Windows apps a...
VMware Fusion allows you to create a Virtual Machine on your Mac and run Windows (including Windows 8.1) and Windows software on your Mac. Run your favorite Windows applications alongside Mac... Read more
Tweetbot 1.5.1 - Popular iOS twitter cli...
Tweetbot is a full-featured OS X Twitter client with a lot of personality. Whether it's the meticulously-crafted interface, sounds and animation, or features like multiple timelines and column views... Read more
Mac DVDRipper Pro 4.1.7 - Copy, backup,...
Mac DVDRipper Pro is the DVD backup solution that lets you protect your DVDs from scratches, save your batteries by reading your movies from your hard disk, manage your collection with just a few... Read more
PDFpenPro 6.2 - Advanced PDF toolkit for...
PDFpenPro allows users to edit PDF's easily. Add text, images and signatures. Fill out PDF forms. Merge or split PDF documents. Reorder and delete pages. Even correct text and edit graphics! Create... Read more
PDFpen 6.2 - Edit and annotate PDFs with...
PDFpen allows users to easily edit PDF's. Add text, images and signatures. Fill out PDF forms. Merge or split PDF documents. Reorder and delete pages. Even correct text and edit graphics! Features... Read more
Monolingual 1.5.9 - Remove unwanted OS X...
Monolingual is a program for removing unnecesary language resources from OS X, in order to reclaim several hundred megabytes of disk space. It requires a 64-bit capable Intel-based Mac and at least... Read more
Maya 2015 - Professional 3D modeling and...
Maya is an award-winning software and powerful, integrated 3D modeling, animation, visual effects, and rendering solution. Because Maya is based on an open architecture, all your work can be scripted... Read more
Starcraft II: Wings of Liberty 1.1.1.180...
Download the patch by launching the Starcraft II game and downloading it through the Battle.net connection within the app. Starcraft II: Wings of Liberty is a strategy game played in real-time. You... Read more
Sibelius 7.5.0 - Music notation solution...
Sibelius is the world's best-selling music notation software for Mac. It is as intuitive to use as a pen, yet so powerful that it does most things in less than the blink of an eye. The demo includes... Read more
Typinator 5.9 - Speedy and reliable text...
Typinator turbo-charges your typing productivity. Type a little. Typinator does the rest. We've all faced projects that require repetitive typing tasks. With Typinator, you can store commonly used... Read more

Latest Forum Discussions

See All

This Week at 148Apps: April 14-18, 2014
Spring Into Our App Reviews   | Read more »
Have a Special Dead Trigger 2 Easter Bas...
Have a Special Dead Trigger 2 Easter Basket Full of Goodies, Courtesy of Madfinger Games Posted by Rob Rich on April 18th, 2014 [ permalink ] Dead Trigger 2 | Read more »
Almost All of Playdek’s Library is on Sa...
Almost All of Playdek’s Library is on Sale Right Now, and You Should Check it Out Posted by Rob Rich on April 18th, 2014 [ permalink ] Playdek has released quite a few great iOS ports of board and card games over the years, and now most of them... | Read more »
Zynga Launches Brand New Farmville Exper...
Zynga Launches Brand New Farmville Experience with Farmville 2: Country Escape Posted by Tre Lawrence on April 18th, 2014 [ permalink ] | Read more »
David. Review
David. Review By Cata Modorcea on April 18th, 2014 Our Rating: :: MINIMALISTIC IN A DIFFERENT WAYUniversal App - Designed for iPhone and iPad David is a minimalistic game wrapped inside of a soothing atmosphere in which the hero... | Read more »
Eyefi Unveils New Eyefi Cloud Service Th...
Eyefi Unveils New Eyefi Cloud Service That Allows Users to Share Media Across Personal Devices Posted by Tre Lawrence on April 18th, 2014 [ permalink ] | Read more »
Tales from the Dragon Mountain: The Lair...
Tales from the Dragon Mountain: The Lair Review By Jennifer Allen on April 18th, 2014 Our Rating: :: STEADY ADVENTURINGiPad Only App - Designed for the iPad Treading a safe path, Tales from the Dragon Mountain: The Lair is a... | Read more »
Yahoo Updates Flickr App with Advanced E...
Yahoo Updates Flickr App with Advanced Editing Features and More Posted by Tre Lawrence on April 18th, 2014 [ permalink ] | Read more »
My Incredible Body - A Kid's App to...
My Incredible Body - A Kid's App to Learn about the Human Body 1.1.00 Device: iOS Universal Category: Education Price: $2.99, Version: 1.1.00 (iTunes) Description: Wouldn’t it be cool to look inside yourself and see what was going on... | Read more »
Trials Frontier Review
Trials Frontier Review By Carter Dotson on April 18th, 2014 Our Rating: :: A ROUGH LANDINGUniversal App - Designed for iPhone and iPad Trials Frontier finally brings the famed stunt racing franchise to mobile, but how much does its... | Read more »

Price Scanner via MacPrices.net

Android Leads in Operating System Share Andro...
Consumer Intelligence Research Partners, LLC (CIRP) has released its latest results of its research on mobile phone operating systems for the calendar quarter that ended March 31, 2014. This analysis... Read more
Pelican Products, Inc. Introduces New Lineup...
Pelican Products, Inc., the global leader in the design and manufacture of high-performance protective cases, today announced the launch of a new line of rugged phone cases for both the Apple iPhone... Read more
SaveDrives – Car Dashboard Video Camera &...
Drivers who want to help reduce potential damage to their health and finances in the event of an accident can download the innovative new no-cost app SaveDrives – Car Dashboard Video Camera &... Read more
Deal Alert! 13-inch MacBook Pro on sale for $...
Best Buy has the 13″ 2.5GHz MacBook Pro on sale for $999.99 on their online store. Choose free shipping or free instant local store pickup (if available). Their price is $200 off MSRP. Price is valid... Read more
Free HopTo 2.2 Helps Enhance Your Productivit...
The HopTo app helps you do more on your iPad by providing more and easier adaccess to files and documents. Version 2.2 adds Egnyte and HopTo’s Mac OSX File Connector. If you already have the hopTo... Read more
National Distracted Driving Awareness Month:...
As the country recognizes National Distracted Driving Awareness Month, Sprint is reminding wireless consumers to focus on driving while behind the wheel, to not text or email while driving, and to... Read more
13-inch 2.4GHz Retina MacBook Pro available f...
Abt has the 13″ 2.4GHz 128GB Retina MacBook Pro available for $1229 including free shipping. Their price is $70 off MSRP. Read more
iMacs on sale for up to $160 off MSRP this we...
Best Buy has iMacs on sale for up to $160 off MSRP for a limited time. Choose free home shipping or free instant local store pickup (if available). Prices are valid for online orders only, in-store... Read more
iPad Airs on sale this weekend for up to $100...
Best Buy has WiFi iPad Airs on sale for $50 off MSRP and WiFi + Cellular iPad Airs on sale for $100 off MSRP on their online store for a limited time, with prices now starting at $449. Choose free... Read more
Apple restocks refurbished Mac minis starting...
The Apple Store has restocked Apple Certified Refurbished Mac minis for up to $150 off the cost of new models. Apple’s one-year warranty is included with each mini, and shipping is free: - 2.5GHz Mac... Read more

Jobs Board

*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
Position Opening at *Apple* - Apple (United...
…customers purchase our products, you're the one who helps them get more out of their new Apple technology. Your day in the Apple Store is filled with a range of Read more
*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
*Apple* Inc. Research Data Specialist - Appl...
…of Worldwide Market Research & Intelligence. The team is responsible for conducting Apple branded consumer market research. It is also responsible for analyzing data Read more
*Apple* Automotive Parts Department position...
Apple Automotive is one of the fastest growing dealer…and it shows. Consider making the switch to the Apple Automotive Group today! At Apple Automotive, we Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.