Adding Color to GraphPaper
In the remainder of this chapter, we’ll add color to our GraphPaper application. To do this, we’ll add a Preferences panel (users refer to it as a Preferences dialog) that will let the user choose three distinct colors for drawing the graph, the equation, and the axes.
To isolate the parts of the GraphView that deal solely with color, we’ll create a GraphView subclass called ColorGraphView. This way, we won’t need to make any changes to the GraphView class itself, yet we can use all of its functionality. This is called reusability of classes.
The user probably won’t want to change the
graph’s colors every time the GraphPaper application
is run, so we’ll put the Preferences panel in its
own nib file rather than in MainMenu.nib
. That
way, the Preferences panel will be loaded and take up memory only
when the user chooses to see it. The ColorGraphView class will have
three NSColor instance variables, to keep track of the colors
currently being used.
We’ll also set up a new class called
PrefController to take care of modifying
these instance variables when the Preferences panel is displayed. If
the Preferences panel isn’t loaded, the
ColorGraphView class will use reasonable defaults for the color
instance variables. In Chapter 21,
we’ll see how to set the values for these colors
from the Mac OS X defaults database, application- defaults
information stored in every user’s
~/Library/Preferences
folder. (The application’s defaults database was introduced in ...
Get Building Cocoa Applications: A Step by Step Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.