[TOC] [Prev] [Next] [Bottom]

NSColorList

Inherits From:
NSObject

Conforms To:
NSCoding
NSObject (NSObject)

Declared In:
AppKit/NSColorList.h

Class Description

An NSColorList is an ordered list of NSColors, identified by keys. Instances of NSColorList, or more simply, color lists, are used to manage named lists of NSColors. NSColorPanel's list-mode color picker uses instances of NSColorList to represent any lists of colors that come with the system, as well as any lists created by the user. An application can use NSColorList to manage document-specific color lists, which may be added to an application's NSColorPanel using its attachColorList: method.

An NSColorList is similar to a dictionary object: An NSColor is added to, looked up in, and removed from the list by specifying its key, which is an NSString. These keys are used to identify the colors in the list and are used to display the color to the user in the color panel. In addition, colors can be inserted at specified positions in the list.

The color list has a name, specified when you create the object using either the initWithName: or initWithName:fromFile: method.

Instances of NSColorList are created for all user-created color lists (those in the color panel) and various color catalogs available on the system.

An NSColorList saves and retrieves its colors from files with the extension ".clr" in directories defined by a standard search path. To access all the color lists in the standard search path, use the availableColorLists method; this returns an array of NSColorLists, from which you can retrieve the individual color lists by name.

The standard search path for color lists is:

NSColorList reads color list files in several different formats; it saves color lists using the archiver API.

NSColorList posts an NSColorListChanged notification when a color list is changed.


Adopted Protocols

NSCoding
- encodeWithCoder:
- initWithCoder:

Method Types

Initializing an NSColorList
- initWithName:
- initWithName:fromFile:
Getting All Color Lists
+ availableColorLists
Getting a Color List by Name
+ colorListNamed:
- name
Managing Colors by Key
- allKeys
- colorWithKey:
- insertColor:key:atIndex:
- removeColorWithKey:
- setColor:forKey:
Editing
- isEditable
Writing and Removing Files
- removeFile
- writeToFile:

Class Methods

availableColorLists

+ (NSArray *)availableColorLists

Returns an array of all NSColorLists found in the standard color list directories. Color lists created at run time aren't included in this list unless they're saved into one of the standard color list directories.

See also: + colorListNamed:


colorListNamed:

+ (NSColorList *)colorListNamed:(NSString *)name

Searches the array that's returned by availableColorLists and returns the NSColorList named name, or nil if no such color list exists. name must not include the ".clr" suffix.

See also: - name


Instance Methods

allKeys

- (NSArray *)allKeys

Returns an array of NSString objects that contains all the keys by which the NSColors are stored in the NSColorList. The length of this array equals the number of colors, and its contents are arranged according to the ordering specified when the colors were inserted.


colorWithKey:

- (NSColor *)colorWithKey:(NSString *)key

Returns the NSColor associated with key, or nil if there is none.


initWithName:

- (id)initWithName:(NSString *)name

Initializes and returns the receiver, registering it under the specified name if name isn't in use already. This method invokes initWithName:fromFile: with a fromFile: argument of nil, indicating that the color list doesn't need to be initialized from a file.


initWithName:fromFile:

- (id)initWithName:(NSString *)name
fromFile:(NSString *)path

Initializes and returns the receiver, registering it under the specified name if name isn't in use already. path should be the full path to the file for the color list; name should be the name of the file for the color list (minus the ".clr" extension). A nil path indicates that the color list should be initialized with no colors.


insertColor:key:atIndex:

- (void)insertColor:(NSColor *)color
key:(NSString *)key
atIndex:(unsigned)location

Inserts color at the specified location in the color list (which is numbered starting with 0). If the list already contains a color with the same key at a different location, it's removed from the old location. This method posts the NSColorListChangedNotification notification to the default notification center. It raises the NSColorListNotEditableException exception if the color list isn't editable.

See also: - colorWithKey:, - removeColorWithKey:, - setColor:forKey:


isEditable

- (BOOL)isEditable

Returns YES if the color list can be modified. This depends on the source of the list: If it came from a write-protected file, this method returns NO.


name

- (NSString *)name

Returns the name of the NSColorList.


removeColorWithKey:

- (void)removeColorWithKey:(NSString *)key

Removes the color associated with key from the list. This method does nothing if the list doesn't contain the key. This method posts the NSColorListChangedNotification notification to the default notification center. It raises the NSColorListNotEditableException exception if the color list is not editable.

See also: - insertColor:key:atIndex:, - setColor:forKey:


removeFile

- (void)removeFile

Removes the file from which the list was created, if the file is in a standard search path and is owned by the user. The receiver is removed from the list of available color lists returned by availableColorLists, but isn't released.


setColor:forKey:

- (void)setColor:(NSColor *)color
forKey:(NSString *)key

Associates the specified NSColor with key. If the list already contains key, this method sets the corresponding color to color; otherwise, it inserts color at the end of the list by invoking insertColor:key:atIndex:.

See also: - colorWithKey:, - insertColor:key:atIndex:, - removeColorWithKey:


writeToFile:

- (BOOL)writeToFile:(NSString *)path

If path is a directory, saves the NSColorList in a file named listname.clr in that directory (where listname is the name with which the NSColorList was initialized). If path includes a file name, this method saves the file under that name. If path is nil, this method saves the file as listname.clr in the standard location. Returns YES upon success and NO if it fails to write the file.

See also: - removeFile


Notifications

NSColorListChangedNotification
Notification Object The NSColorList Posted whenever a color list changes, as when



[TOC] [Prev] [Next] [Bottom]

Copyright © 1997, Apple Computer, Inc. All rights reserved.