Inherits From:
NSObject
Conforms To:
NSCoding
NSObject (NSObject)
Declared In:
AppKit/NSColorList.h
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:
/NextLibrary/Colors
/LocalLibrary/Colors
~/Library/Colors
NSColorList posts an NSColorListChanged notification when a color list is changed.
(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:
(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
(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.
(NSColor *)colorWithKey:
(NSString *)key
Returns the NSColor associated with key, or nil
if there is none.
(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.
(id)initWithName:
(NSString *)namefromFile:
(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.
(void)insertColor:
(NSColor *)colorkey:
(NSString *)keyatIndex:
(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:
(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.
(NSString *)name
Returns the name of the NSColorList.
(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:
(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.
(void)setColor:
(NSColor *)colorforKey:
(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:
(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
Notification Object
The NSColorList
Posted whenever a color list changes, as when