Inherits from: NSObject
Package: com.apple.yellow.application
An NSColor object represents a color, which is defined in a color space, each point of which has a set of components (such as red, green, and blue) that uniquely define a color.
Various colorWith... and colorUsing... methods.Preset colors: blackColor, blueColor, etc.
colorUsingColorSpaceName | Creates an NSColor in the specified color space. |
set | Sets the drawing color. |
An NSColor object represents color and sometimes opacity (alpha). By sending a set message to an NSColor instance, you set the color for the current PostScript drawing context. This causes subsequently drawn graphics to have the color represented by the NSColor instance.
A color is defined in some particular color space. A color space consists of a set of dimensions-such as red, green, and blue in the case of RGB space. Each point in the space represents a unique color, and the point's location along each dimension is called a component. An individual color is usually specified by the numeric values of its components, which range from 0.0 to 1.0. For instance, a pure red is specified in RGB space by the component values 1.0, 0.0, and 0.0.
Some color spaces include an alpha component, which defines the color's opacity. An alpha value of 1.0 means completely opaque, and 0.0 means completely transparent. The alpha component is ignored when the color is used on a device that doesn't support alpha, such as a printer.
There are three kinds of color spaces in the Application Kit:
NSColors provided by the Application Kit use eight different color spaces, referred to by these global NSString variables:
Global Variable | Color Space Description |
NSGraphics.DeviceCMYKColorSpace |
Cyan, magenta, yellow, black, and alpha components |
NSGraphics.DeviceWhiteColorSpace |
White and alpha components |
NSGraphics.DeviceBlackColorSpace |
Black and alpha components |
NSGraphics.DeviceRGBColorSpace |
Red, green, blue, and alpha componentsHue, saturation, brightness, and alpha components |
NSGraphics.CalibratedWhiteColorSpace |
White and alpha components |
NSGraphics.CalibratedBlackColorSpace |
Black and alpha components |
NSGraphics.CalibratedRGBColorSpace |
Red, green, blue, and alpha componentsHue, saturation, brightness, and alpha components |
NSGraphics.NamedColorSpace |
Catalog name and color name components |
Color spaces whose names start with "Device" are device-dependent; those whose names start with "Calibrated" are device-independent.
There's usually no need to retrieve the individual components
of a color, but when needed, you can (using such methods as redComponent). However,
it's illegal to ask an NSColor for components that aren't defined
for its color space. You can identify the color space by sending
a colorSpaceName message
to the NSColor object. If you need to ask an NSColor for components
that aren't in its color space (for instance, when you've gotten
the color from the color panel), first convert the color to the
appropriate color space using the colorUsingColorSpaceName method.
If the color is already in the specified color space, you get the
same color back; otherwise you get a conversion that's usually
lossy or that's correct only for the current device. You get back null
if
the specified conversion can't be done.
Subclasses of NSColor need to implement the colorSpaceName and set methods, as well as the methods that return the components for that color space and the methods in the NSCoding protocol. Some other methods-such as colorWithAlphaComponent and colorUsingColorSpaceNameAndDevice-may also be implemented if they make sense for the color space.
NSColor has a number of methods which return "system" colors; colors that are controlled by user preferences. These colors-including controlColor, textColor, and selectedTextColor-should be used by developers who want to create custom controls or subclass existing controls while honoring the user's color preferences. System colors are implemented as named colors in a special color list named "System." To extract the components of a system color, you must use NSColor's colorUsingColorSpaceName method to convert the color to a color space known to respond to the component accessor methods you need.
An NSSystemColorsDidChangeNotification is sent when the system colors have been changed (such as through a system control panel interface). If you have any non-system colors that depend on the system colors, you can change them when you receive this notification.
- NSCoding
- - encodeWithCoder:
- - initWithCoder:
- NSCopying
- - copyWithZone:
- Creating an NSColor object from Component Values
- colorWithCalibratedHSB
- colorWithCalibratedRGB
- colorWithCalibratedWhite
- colorWithCatalogName
- colorWithDeviceCMYK
- colorWithDeviceHSB
- colorWithDeviceRGB
- colorWithDeviceWhite
- Creating an NSColor With Preset Components
- blackColor
- blueColor
- brownColor
- clearColor
- cyanColor
- darkGrayColor
- grayColor
- greenColor
- lightGrayColor
- magentaColor
- orangeColor
- purpleColor
- redColor
- whiteColor
- yellowColor
- Creating a system color-an NSColor whose value is specified by user preferences
- controlBackgroundColor
- controlColor
- controlHighlightColor
- controlLightHighlightColor
- controlShadowColor
- controlDarkShadowColor
- controlTextColor
- disabledControlTextColor
- gridColor
- highlightColor
- knobColor
- scrollBarColor
- selectedControlColor
- selectedControlTextColor
- selectedMenuItemColor
- selectedMenuItemTextColor
- selectedTextBackgroundColor
- selectedTextColor
- selectedKnobColor
- shadowColor
- textBackgroundColor
- textColor
- windowFrameColor
- windowFrameTextColor
- Ignoring Alpha Components
- ignoresAlpha
- setIgnoresAlpha
- Copying and Pasting
- colorFromPasteboard
- writeToPasteboard
- Retrieving a Set of Components
- getCyan:magenta:yellow:black:alpha:
- getHue:saturation:brightness:alpha:
- getRed:green:blue:alpha:
- getWhite:alpha:
- Retrieving Individual Components
- alphaComponent
- blackComponent
- blueComponent
- brightnessComponent
- catalogNameComponent
- colorNameComponent
- cyanComponent
- greenComponent
- hueComponent
- localizedCatalogNameComponent
- localizedColorNameComponent
- magentaComponent
- redComponent
- saturationComponent
- whiteCompo nent
- yellowComponent
- Converting to Another Color Space
- colorSpaceName
- colorUsingColorSpaceName
- colorUsingColorSpaceNameAndDevice
- Changing the Color
- blendedColorWithFractionOfColor
- colorWithAlphaComponent
- highlightWithLevel
- shadowWithLevel
- Drawing
- drawSwatchInRect
- set
public static NSColor blueColor()
NSGraphics.CalibratedRGBColorSpace
whose
RGB value is 0.0, 0.0, 1.0 and whose alpha value is 1.0.See Also: blueComponent
public static NSColor brownColor()
NSGraphics.CalibratedRGBColorSpace
whose
RGB value is 0.6, 0.4, 0.2 and whose alpha value is 1.0.public static NSColor clearColor()
NSGraphics.CalibratedWhiteColorSpace
whose grayscale
and alpha values are both 0.0.public static NSColor colorFromPasteboard(NSPasteboard pasteBoard)
null
if
the pasteboard doesn't contain color data. The
returned color's alpha component is set to 1.0 if ignoresAlpha returns true
.See Also: writeToPasteboard
public static NSColor colorWithCalibratedHSB(float hue, float saturation, float brightness, float alpha)
NSGraphics.CalibratedRGBColorSpace
,
whose opacity value is alpha, and whose
components in HSB space would be hue, saturation,
and brightness. (Values
below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted
as 1.0.)See Also: getHue:saturation:brightness:alpha:colorWithCalibratedRGB, colorWithDeviceHSB
public static NSColor colorWithCalibratedRGB(float red, float green, float blue, float alpha)
NSGraphics.CalibratedRGBColorSpace
,
whose opacity value is alpha, and whose
RGB components are red, green,
and blue. (Values
below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted
as 1.0.)See Also: getRed:green:blue:alpha:colorWithCalibratedHSB, colorWithDeviceRGB
public static NSColor colorWithCalibratedWhite(float white, float alpha)
NSGraphics.CalibratedWhiteColorSpace
,
whose opacity value is alpha, and whose
grayscale value is white. (Values
below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted
as 1.0.)See Also: getWhite:alpha:colorWithDeviceWhite
public static NSColor colorWithCatalogName (String listName, String colorName)
NSGraphics.NamedColorSpace
,
by finding the color named colorName in
the catalog named listName, which
may be a standard catalog.See Also: catalogNameComponent, colorNameComponent, localizedCatalogNameComponent
public static NSColor colorWithDeviceCMYK (float cyan, float magenta, float yellow, float black, float alpha)
NSGraphics.DeviceCMYKColorSpace
,
whose opacity value is alpha, and
whose CMYK components are cyan, magenta, yellow,
and black. (Values
below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted
as 1.0.) In PostScript, this colorspace corresponds directly to
the device-dependent operator setcmykcolor
.See Also: getCyan:magenta:yellow:black:alpha:
public static NSColor colorWithDeviceHSB (float hue, float saturation, float brightness, float alpha)
NSGraphics.DeviceRGBColorSpace
,
whose opacity value is alpha, and
whose components in HSB space would be hue, saturation,
and brightness. (Values
below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted
as 1.0.) In PostScript, this colorspace corresponds directly to
the device-dependent operator setrgbcolor
.See Also: getHue:saturation:brightness:alpha:colorWithCalibratedHSB, colorWithDeviceRGB
public static NSColor colorWithDeviceRGB(float red, float green, float blue, float alpha)
NSGraphics.DeviceRGBColorSpace
,
whose opacity value is alpha, and
whose RGB components are red, green,
and blue. (Values
below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted
as 1.0.) In PostScript, this colorspace corresponds directly to
the device-dependent operator setrgbcolor
.See Also: getRed:green:blue:alpha:colorWithCalibratedRGB, colorWithDeviceHSB
public static NSColor colorWithDeviceWhite(float white, float alpha)
NSGraphics.DeviceWhiteColorSpace
,
whose opacity value is alpha, and
whose grayscale value is white. (Values
below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted
as 1.0.) In PostScript, this colorspace corresponds directly to
the device-dependent operator setgray
.See Also: getWhite:alpha:colorWithCalibratedWhite
public static NSColor controlBackgroundColor()
COLOR_WINDOW
on
Windows. For general information on system colors, see System Colors.public static NSColor controlColor()
COLOR_3DFACE
in
Windows. A control's beveled edges, which set it in relief, are
drawn in the colors returned by controlShadowColor, controlDarkShadowColor, controlHighlightColor and controlLightHighlightColor.
When a control is selected-that is, clicked or dragged-it changes
to the color returned by selectedControlColor. The return value of controlColor is also the system color used for window backgrounds. For general information about system colors, see System Colors.
public static NSColor controlDarkShadowColor()
COLOR_3DDKSHADOW
on
Windows. For general information about system colors, see System Colors.See Also: controlShadowColor
public static NSColor controlHighlightColor()
COLOR_3DLIGHT
on
Windows. For general information about system colors, see System Colors.See Also: controlLightHighlightColor
public static NSColor controlLightHighlightColor()
COLOR_3DHILIGHT
on
Windows. For general information about system colors, see System Colors.See Also: controlHighlightColor
public static NSColor controlShadowColor()
COLOR_3DSHADOW
on
Windows. For general information about system colors, see System Colors.See Also: controlDarkShadowColor
public static NSColor controlTextColor()
COLOR_BTNTEXT
on
Windows. For general information about system colors, see System Colors.See Also: disabledControlTextColor
public static NSColor cyanColor()
NSGraphics.CalibratedRGBColorSpace
whose
RGB value is 0.0, 1.0, 1.0 and whose alpha value is 1.0.See Also: cyanComponent
public static NSColor disabledControlTextColor()
COLOR_3DSHADOW
on
Windows. For general information about system colors, see System Colors.See Also: controlTextColor
public static NSColor grayColor()
NSGraphics.CalibratedWhiteColorSpace
whose grayscale
value is 0.5 and whose alpha value is 1.0.See Also: lightGrayColordarkGrayColor
public static NSColor greenColor()
NSGraphics.CalibratedRGBColorSpace
whose
RGB value is 0.0, 1.0, 0.0 and whose alpha value is 1.0.See Also: greenComponent
public static NSColor gridColor()
COLOR_3DFACE
on Windows.
For general information about system colors, see System Colors.public static NSColor highlightColor()
COLOR_3DHILIGHT
on Windows.
This method is invoked by the highlightWithLevel method. For general
information about system colors, see System Colors.See Also: highlightWithLevel
public static boolean ignoresAlpha()
true
if
the application doesn't support alpha. This
value is consulted when an application imports alpha (through color
dragging, for instance). The value determines whether the color
panel has an opacity slider. This value is true
by
default, indicating that the opacity components of imported colors
will be set to 1.0. If an application wants alpha, it can invoke
the setIgnoresAlpha method with
a parameter of false
.See Also: setIgnoresAlpha, alphaComponent
public static NSColor keyboardFocusIndicatorColor()
public static NSColor knobColor()
COLOR_3DFACE
on
Windows. The knob's beveled edges, which set it in relief, are
drawn in highlighted and shadowed versions of the face color. When
a knob is selected, its color changes to selectedKnobColor. For general information
about system colors, see System
Colors.public static NSColor magentaColor()
NSGraphics.CalibratedRGBColorSpace
whose
RGB value is 1.0, 0.0, 1.0 and whose alpha value is 1.0.See Also: magentaComponent
public static NSColor orangeColor()
NSGraphics.CalibratedRGBColorSpace
whose
RGB value is 1.0, 0.5, 0.0 and whose alpha value is 1.0.public static NSColor purpleColor()
NSCalibratedRGBColorSpace
whose
RGB value is 0.5, 0.0, 0.5 and whose alpha value is 1.0.public static NSColor redColor()
See Also: redComponent
public static NSColor scrollBarColor()
COLOR_SCROLLBAR
on
Windows. On Windows, when a scroll bar is dragged, its color changes
to the return value of selectedControlColor;
on the Macintosh, however, its color does not change. For general
information about system colors, see System Colors.public static NSColor selectedControlColor()
COLOR_HIGHLIGHT
on
Windows. For general information about system colors, see System Colors.See Also: selectedControlTextColor
public static NSColor selectedControlTextColor()
COLOR_HIGHLIGHTTEXT
on
Windows. For general information about system colors, see System Colors.See Also: selectedControlColor
public static NSColor selectedKnobColor()
COLOR_HIGHLIGHT
on
Windows. For general information about system colors, see System Colors.See Also: knobColor
public static NSColor selectedMenuItemColor()
COLOR_HIGHLIGHT
on
Windows. For general information about system colors, see System Colors.See Also: selectedMenuItemTextColor
public static NSColor selectedMenuItemTextColor()
COLOR_HIGHLIGHTTEXT
on
Windows. For general information about system colors, see System Colors.See Also: selectedMenuItemColor
public static NSColor selectedTextBackgroundColor()
COLOR_HIGHLIGHT
on
Windows. For general information about system colors, see System Colors.See Also: selectedTextColor
public static NSColor selectedTextColor()
COLOR_HIGHLIGHTTEXT
on
Windows. For general information about system colors, see System Colors.See Also: selectedTextBackgroundColor
public static void setIgnoresAlpha(boolean flag)
true
,
the application won't support alpha. In this case, no opacity slider
is displayed in the color panel, and colors dragged in or pasted
have their alpha values set to 1.0. By default, applications ignore
alpha. Applications that need to import alpha can invoke this method
with flag set to false
and explicitly
make colors opaque in cases where it matters to them.See Also: ignoresAlpha, alphaComponent
public static NSColor shadowColor()
COLOR_3DDKSHADOW
on Windows.
For general information about system colors, see System Colors.See Also: shadowWithLevel
public static NSColor textBackgroundColor()
COLOR_WINDOW
on
Windows. When text is selected, its background color changes to
the return value of selectedTextBackgroundColor.
For general information about system colors, see System Colors.See Also: textColor
public static NSColor textColor()
COLOR_WINDOWTEXT
on Windows.
When text is selected, its background color changes to the return
value of selectedTextColor.
For general information about system colors, see System Colors.See Also: textBackgroundColor
public static NSColor whiteColor()
NSGraphics.CalibratedWhiteColorSpace
whose grayscale
and alpha values are both 1.0.See Also: whiteComponent
public static NSColor windowFrameColor()
COLOR_ACTIVEBORDER
on Windows.
For general information about system colors, see System Colors.See Also: windowFrameTextColor
public static NSColor windowFrameTextColor()
COLOR_CAPTIONTEXT
on
Windows. For general information about system colors, see System Colors.See Also: windowFrameColor
public static NSColor yellowColor()
NSGraphics.CalibratedRGBColorSpace
whose
RGB value is 1.0, 1.0, 0.0 and whose alpha value is 1.0.See Also: yellowComponent
public float alphaComponent()
See Also: getCyan:magenta:yellow:black:alpha:getHue:saturation:brightness:alpha:getRed:green:blue:alpha:getWhite:alpha:
public float blackComponent()
See Also: getCyan:magenta:yellow:black:alpha:
public NSColor blendedColorWithFractionOfColor(float fractiono, NSColor color)
NSGraphics.CalibratedRGBColorSpace
whose
component values are a weighted sum of the receiver's and color's. The method
converts color and a copy of the
receiver to RGB, and then sets each component of the returned color
to fraction of color's
value plus 1 - fraction of the
receiver's. Returns null
if
the colors can't be converted to NSGraphics.CalibratedRGBColorSpace
.public float blueComponent()
See Also: getRed:green:blue:alpha:
public float brightnessComponent()
See Also: getHue:saturation:brightness:alpha:
public String catalogNameComponent()
NSGraphics.NamedColorSpace
.See Also: colorWithCatalogName, colorNameComponent, localizedCatalogNameComponent
public String colorNameComponent()
NSGraphics.NamedColorSpace
.See Also: colorWithCatalogName, catalogNameComponent, localizedCatalogNameComponent
public String colorSpaceName()
See Also: colorUsingColorSpaceName, colorUsingColorSpaceNameAndDevice
public NSColor colorUsingColorSpaceName(String colorSpace)
null
,
the most appropriate color space is used.Returns null
if
the specified conversion cannot be done.
See Also: colorSpaceName
public NSColor colorUsingColorSpaceNameAndDevice(String colorSpace, NSDictionary deviceDescription)
null
,
the most appropriate color space is used.If deviceDescription is null
,
the current device (as obtained from the currently lockFocus'ed
view's window or, if printing, the current printer) is used.
Returns null
if
the specified conversion cannot be done.
See Also: colorSpaceName, colorUsingColorSpaceName
public NSColor colorWithAlphaComponent(float alpha)
See Also: alphaComponent, blendedColorWithFractionOfColor
public float cyanComponent()
See Also: getCyan:magenta:yellow:black:alpha:
public void drawSwatchInRect(NSRect rect)
public float greenComponent()
See Also: getRed:green:blue:alpha:
public NSColor highlightWithLevel(float highlightLevel)
NSGraphics.CalibratedRGBColorSpace
that
represents a blend between the receiver and the highlight color
returned by highlightColor. The
highlight color's contribution to the blend depends on highlightLevel, which
should be a number between 0.0 and 1.0. (A highlightLevel below
0.0 is interpreted as 0.0; a highlightLevel above
1.0 is interpreted as 1.0.)Returns null
if
the colors can't be converted to NSGraphics.CalibratedRGBColorSpace
.
Invoke this method when you want to brighten the receiving NSColor
for use in highlights.
See Also: shadowWithLevel
public float hueComponent()
See Also: getHue:saturation:brightness:alpha:
public String localizedCatalogNameComponent()
See Also: colorWithCatalogName, colorNameComponent
public String localizedColorNameComponent()
See Also: colorWithCatalogName, catalogNameComponent, colorNameComponent, localizedCatalogNameComponent
public float magentaComponent()
See Also: getCyan:magenta:yellow:black:alpha:
public float redComponent()
See Also: getRed:green:blue:alpha:
public float saturationComponent()
See Also: getHue:saturation:brightness:alpha:
public void set()
public NSColor shadowWithLevel(float shadowLevel)
NSGraphics.CalibratedRGBColorSpace
that
represents a blend between the receiver and the shadow color returned
by shadowColor. The
shadow color's contribution to the blend depends on shadowLevel,
which should be a number between 0.0 and 1.0. (A shadowLevel below
0.0 is interpreted as 0.0; a shadowLevel above
1.0 is interpreted as 1.0.)Returns null
if
the colors can't be converted to NSGraphics.CalibratedRGBColorSpace
.
Invoke this method when you want to darken the receiving NSColor
for use in shadows.
See Also: - highlightWithLevel:
public float whiteComponent()
See Also: getWhite:alpha:
public void writeToPasteboard(NSPasteboard pasteBoard)
See Also: colorFromPasteboard
public float yellowComponent()
See Also: getCyan:magenta:yellow:black:alpha:
Sent when the system colors have been changed (such as through a system control panel interface).
This notification contains no notification object and no userInfo dictionary.