Cocoa: How To Sync Views With A Color Preference Slider
2008-03-27
Much of my spare time is being used up very gradually writing a new photography-oriented application which I have code-named PP. This being my first sizable Mac app I also spend a lot of time reading, figuring out, rewriting code, and debugging as I encounter each challenge and work through it. While I am not going to blog the entire thing as I did with Random Wok, I am going to contribute pieces of what I have learned along the way.
PP has a thumbnail browser, as any photography-oriented app has, and I want to be able to control its background color. Just like Aperture I have a slider in my prefs panel that changes the gray level of the background and need to have that stored in the user's preferences. Since PP is a document-based app (I can have many document windows open at the same time), changing the browser background has to affect all the open documents and should do so in real time so the user can see the result.
Here is my prefs panel. Not much there yet:

The slider is set up to deliver a number between 0.0 and 1.0 and continuously return its state. The prefs panel XIB file also has an NSUserDefaultsController. The file's owner is a custom window controller:

I use three separate mechanisms for keeping everything in sync: actions, bindings, and notifications. Here is all of it together in one diagram:

The slider, NSUserDefaultsController and preferences file are joined together with bindings. I bind the slider's value to NSUserDefaultsController:

so that the controller is notified of all changes to the slider value. The NSUserDefaultsController keeps the prefs file on disk in sync. That is 100% of what is needed to handle the slider and the prefs. To set up the initial preferences I create the defaults in my application object:

To keep the browser background color in sync with the slider I have to be able to tell the browser's view controller that the value has changed so that it can get it from the NSUserDefaultsController object. This is a two-stage process: the slider tells its window controller via its action and the window controller tells the browser view controller through a notification:

To update the browser views, each instance of the browser view controller listens for notifications that indicate the color has changed and sends the appropriate message to its view:

The above two methods are called at appropriate times by the browser's window controller. The color is updated like this as the notification is received:

Finally, to set up the initial color the browser view controller implements this code:

That's it. Having set all of this up I can use the same mechanisms for handling other preferences and parameters that affect the browser or other views. I'm understanding the value of following the MVC pattern: it gives everything a place -- if you can figure out where that should be.
PP has a thumbnail browser, as any photography-oriented app has, and I want to be able to control its background color. Just like Aperture I have a slider in my prefs panel that changes the gray level of the background and need to have that stored in the user's preferences. Since PP is a document-based app (I can have many document windows open at the same time), changing the browser background has to affect all the open documents and should do so in real time so the user can see the result.
Here is my prefs panel. Not much there yet:

The slider is set up to deliver a number between 0.0 and 1.0 and continuously return its state. The prefs panel XIB file also has an NSUserDefaultsController. The file's owner is a custom window controller:

I use three separate mechanisms for keeping everything in sync: actions, bindings, and notifications. Here is all of it together in one diagram:

The slider, NSUserDefaultsController and preferences file are joined together with bindings. I bind the slider's value to NSUserDefaultsController:

so that the controller is notified of all changes to the slider value. The NSUserDefaultsController keeps the prefs file on disk in sync. That is 100% of what is needed to handle the slider and the prefs. To set up the initial preferences I create the defaults in my application object:

To keep the browser background color in sync with the slider I have to be able to tell the browser's view controller that the value has changed so that it can get it from the NSUserDefaultsController object. This is a two-stage process: the slider tells its window controller via its action and the window controller tells the browser view controller through a notification:

To update the browser views, each instance of the browser view controller listens for notifications that indicate the color has changed and sends the appropriate message to its view:

The above two methods are called at appropriate times by the browser's window controller. The color is updated like this as the notification is received:

Finally, to set up the initial color the browser view controller implements this code:
That's it. Having set all of this up I can use the same mechanisms for handling other preferences and parameters that affect the browser or other views. I'm understanding the value of following the MVC pattern: it gives everything a place -- if you can figure out where that should be.
|
Aperture: A Fix For The Leopard Printing Bug
2008-03-26
Apple has released Security Update 2008-002 v1.1 (Leopard): an update to the security update that was causing printing problems for Aperture users on Leopard.
Security Update 2008-002 v1.1 addresses reliability issues with the "Printer Settings..." button in Aperture 2.0 on systems running Mac OS X v10.5.2. No applications other than Aperture 2.0 are affected.
Firmware Update For The Canon 30D
2008-03-25
Canon has announced a firmware update for the 30D, version 1.0.6. No changes to the tethering behavior.
- Allows the latest lens names to be recorded in the Exif information of images taken
- Adds lenses that are compatible with the Digital Photo Professional 3.2 lens aberration correction function
How To Report A Bug
2008-03-23

Home For Some: 1/1000s f/4.5 ISO200 200mm, -0.3ev, Canon 30D, Canon 70-200L IS f2.8
Apple has a long and comprehensive guide for reporting bugs. It strikes me that this information should be built in to the bug reporter page. If I have a Mail bug and I state that in the drop-down menu, then the Mail-specific information should appear so I know what to provide. Similarly the template format should appear as just that: a template.
But I know exactly what to do: file a bug. See rdar://problem/5815223. (That link won't work for anyone outside Apple).
Aperture: Digital Camera RAW Support 2.0
2008-03-21
Maybe this will put an and to the arguments about RAW converter updates being tied to the operating system. You can download the updater directly from Apple.
Shooting A Movie By Candlelight
2008-03-20

Fencepost: 1/1600s f/8.0 ISO400 150mm, -0.3ev, Canon 30D, Canon 70-200L IS f2.8
Stanley Kubrick shot the movie Barry Lyndon in 1975 using whatever light was available, often very little; candlelight even. He used a lens that was originally made for NASA that had an aperture of f/0.7.
Aperture 2.0: Processing 11,000 Images, 136GBytes
2008-03-18
James Duncan Davidson recounts how he recently shot ETech and eComm: 11,000 photos in total, and processed them all with Aperture.
Busy
2008-03-17

The Road Ahead: 1/400s f/4.5 ISO200 200mm -0.3ev, Canon 30D, Canon 70-200L IS f2.8
I took the photo above of a cyclist as he went past at some speed, not knowing if I actually had a photo at all. There is a neat reflection of the road ahead in the sunglasses.
Not many updates recently since there have been many things competing for my time: family, taxes, work, job hunting, and coding being the main distractions. Some photography, but not a huge amount. Aperture is fast and there is just not a lot of news about it right now, so not so much to blog about it.
I've been working as a technical writer and advisor for a chip company in Cupertino for the last month, but that's a temporary position and the hunt for a real job continues. It's an interesting contrast to my previous employer: no phone calls, no meetings, and almost no email. I can actually sit and get things done all day.
After thinking about a photo-oriented Mac OS X application for a long time, I've taken the plunge and started bashing out code. I'm learning great chunks of Cocoa as I go along, so progress is slow but rewarding. I have no idea when I will be done, or even what "done" will be right now, but my plans are to make it useful and valuable enough that photographers will buy it. It will be Leopard-only.
Ars Technica Reviews Aperture 2.0
2008-03-10
Aperture: 2.0.1 Brings New Applescript Features
2008-03-04
Apple's Applescript pages are showing how new features introduced by Aperture 2.0.1 allow integration with Adobe InDesign CS3. By fingerprinting images with a number in a metadata field, applications that receive previews have, via Applescript, a away to get the original. InDesign uses this to work with previews as proxies until the document is exported for print. At that time the originals are retrieved and put into the final document. There are two short videos that show how it is done.
Aperture 2.0.1 Update Available
2008-03-03
Apple has updated Aperture to 2.0.1. You can get the download via the 2.0.1 update page. It includes lots of fixes:
- Upgrading libraries from earlier versions of Aperture
- Publishing .Mac Web Gallery albums
- Preview generation and deletion
- Creating and ordering books
- AppleScript support
- Keyboard shortcut customization
- Appearance of metadata overlays in the Browser, Filmstrip, and on light tables
- Watermarking of emailed photos
- Highlight Hot and Cold Areas
- Loupe
- Smart Albums
- All Projects View
- Straighten Tool
- Filmstrip
- Drag and drop import
- Thumbnail generation
- Import window
- Export plug-in reliability
Pixar - A Human History Of Computer Graphics
2008-03-02

From the Computer History Museum comes 101 minutes with some of the pioneers of computer graphics: Brad Bird, Writer/Director, The Incredibles, Pixar Animation Studios, Ed Catmull, Co-Founder and President, Pixar Animation Studios, Alvy Ray Smith, Co-Founder of four centers of computer graphics excellence (Altamira, Pixar, Lucasfilm, New York Tech) and a Microsoft Fellow, Andrew Stanton, Writer/ Director, Finding Nemo, Pixar Animation Studios , and Michael Rubin, Moderator, Author of Droidmaker: George Lucas and the Digital Revolution.
Catmull and Smith were two of the pioneers of computer graphics algorithms and hardware, inventing many of the fundamental techniques that are at the root of everything done today. Lots of discussion about computer animation as a medium, not an end in itself, and the importance of story over technology.
The Bagelturf site welcomes Donations of any size
