|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Color
public class Color
This class represents a color value in the AWT system. It uses the sRGB (standard Red-Green-Blue) system, along with an alpha value ranging from transparent (0.0f or 0) and opaque (1.0f or 255). The color is not pre-multiplied by the alpha value an any of the accessor methods. Further information about sRGB can be found at http://www.w3.org/pub/WWW/Graphics/Color/sRGB.html.
ColorSpace
,
AlphaComposite
,
Serialized FormField Summary | |
---|---|
static Color |
black
Constant for the color black: R=0, G=0, B=0. |
static Color |
BLACK
Constant for the color black: R=0, G=0, B=0. |
static Color |
blue
Constant for the color blue: R=0, G=0, B=255. |
static Color |
BLUE
Constant for the color blue: R=0, G=0, B=255. |
static Color |
cyan
Constant for the color cyan: R=0, G=255, B=255. |
static Color |
CYAN
Constant for the color cyan: R=0, G=255, B=255. |
static Color |
DARK_GRAY
Constant for the color dark gray: R=64, G=64, B=64. |
static Color |
darkGray
Constant for the color dark gray: R=64, G=64, B=64. |
static Color |
gray
Constant for the color gray: R=128, G=128, B=128. |
static Color |
GRAY
Constant for the color gray: R=128, G=128, B=128. |
static Color |
green
Constant for the color green: R=0, G=255, B=0. |
static Color |
GREEN
Constant for the color green: R=0, G=255, B=0. |
static Color |
LIGHT_GRAY
Constant for the color light gray: R=192, G=192, B=192. |
static Color |
lightGray
Constant for the color light gray: R=192, G=192, B=192. |
static Color |
magenta
Constant for the color magenta: R=255, G=0, B=255. |
static Color |
MAGENTA
Constant for the color magenta: R=255, G=0, B=255. |
static Color |
orange
Constant for the color orange: R=255, G=200, B=0. |
static Color |
ORANGE
Constant for the color orange: R=255, G=200, B=0. |
static Color |
pink
Constant for the color pink: R=255, G=175, B=175. |
static Color |
PINK
Constant for the color pink: R=255, G=175, B=175. |
static Color |
red
Constant for the color red: R=255, G=0, B=0. |
static Color |
RED
Constant for the color red: R=255, G=0, B=0. |
static Color |
white
Constant for the color white: R=255, G=255, B=255. |
static Color |
WHITE
Constant for the color white: R=255, G=255, B=255. |
static Color |
yellow
Constant for the color yellow: R=255, G=255, B=0. |
static Color |
YELLOW
Constant for the color yellow: R=255, G=255, B=0. |
Fields inherited from interface java.awt.Transparency |
---|
BITMASK, OPAQUE, TRANSLUCENT |
Constructor Summary | |
---|---|
Color(ColorSpace space,
float[] components,
float alpha)
Creates a color in the given ColorSpace with the specified alpha. |
|
Color(float red,
float green,
float blue)
Initializes a new instance of Color using the specified
RGB values. |
|
Color(float red,
float green,
float blue,
float alpha)
Initializes a new instance of Color using the specified
RGB and alpha values. |
|
Color(int value)
Initializes a new instance of Color using the specified
RGB value. |
|
Color(int value,
boolean hasalpha)
Initializes a new instance of Color using the specified
RGB value. |
|
Color(int red,
int green,
int blue)
Initializes a new instance of Color using the specified
red, green, and blue values, which must be given as integers in the
range of 0-255. |
|
Color(int red,
int green,
int blue,
int alpha)
Initializes a new instance of Color using the specified
red, green, blue, and alpha values, which must be given as integers in
the range of 0-255. |
Method Summary | |
---|---|
Color |
brighter()
Returns a brighter version of this color. |
PaintContext |
createContext(ColorModel cm,
Rectangle deviceBounds,
Rectangle2D userBounds,
AffineTransform xform,
RenderingHints hints)
Returns a paint context, used for filling areas of a raster scan with this color. |
Color |
darker()
Returns a darker version of this color. |
static Color |
decode(String str)
Converts the specified string to a number, using Integer.decode, and creates a new instance of Color from the value. |
boolean |
equals(Object obj)
Tests this object for equality against the specified object. |
int |
getAlpha()
Returns the alpha value for this color, as an integer in the range 0-255. |
int |
getBlue()
Returns the blue value for this color, as an integer in the range 0-255 in the sRGB color space. |
static Color |
getColor(String prop)
Returns a new instance of Color from the value of the
system property named by the specified string. |
static Color |
getColor(String prop,
Color defcolor)
Returns a new instance of Color from the value of the
system property named by the specified string. |
static Color |
getColor(String prop,
int defrgb)
Returns a new instance of Color from the value of the
system property named by the specified string. |
float[] |
getColorComponents(ColorSpace space,
float[] array)
Returns a float array containing the color components of this color in the given ColorSpace. |
float[] |
getColorComponents(float[] array)
Returns a float array containing the color components of this color in the ColorSpace it was created with (the constructors which do not take a ColorSpace parameter use a default sRGB ColorSpace). |
ColorSpace |
getColorSpace()
Returns the color space of this color. |
float[] |
getComponents(ColorSpace space,
float[] array)
Returns a float array containing the color and alpha components of this color in the given ColorSpace. |
float[] |
getComponents(float[] array)
Returns a float array containing the color and alpha components of this color in the ColorSpace it was created with (the constructors which do not take a ColorSpace parameter use a default sRGB ColorSpace). |
int |
getGreen()
Returns the green value for this color, as an integer in the range 0-255 in the sRGB color space. |
static Color |
getHSBColor(float hue,
float saturation,
float brightness)
Returns a new instance of Color based on the specified
HSB values. |
int |
getRed()
Returns the red value for this color, as an integer in the range 0-255 in the sRGB color space. |
int |
getRGB()
Returns the RGB value for this color, in the sRGB color space. |
float[] |
getRGBColorComponents(float[] array)
Returns a float array with the red, green, and blue components, in the default sRGB space, with values in the range 0.0-1.0. |
float[] |
getRGBComponents(float[] array)
Returns a float array with the red, green, and blue components, and the alpha value, in the default sRGB space, with values in the range 0.0-1.0. |
int |
getTransparency()
Returns the transparency level of this color. |
int |
hashCode()
Returns a hash value for this color. |
static int |
HSBtoRGB(float hue,
float saturation,
float brightness)
Converts from the HSB (hue, saturation, brightness) color model to the RGB (red, green, blue) color model. |
static float[] |
RGBtoHSB(int red,
int green,
int blue,
float[] array)
Converts from the RGB (red, green, blue) color model to the HSB (hue, saturation, brightness) color model. |
String |
toString()
Returns a string representation of this object. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final Color white
public static final Color WHITE
public static final Color lightGray
public static final Color LIGHT_GRAY
public static final Color gray
public static final Color GRAY
public static final Color darkGray
public static final Color DARK_GRAY
public static final Color black
public static final Color BLACK
public static final Color red
public static final Color RED
public static final Color pink
public static final Color PINK
public static final Color orange
public static final Color ORANGE
public static final Color yellow
public static final Color YELLOW
public static final Color green
public static final Color GREEN
public static final Color magenta
public static final Color MAGENTA
public static final Color cyan
public static final Color CYAN
public static final Color blue
public static final Color BLUE
Constructor Detail |
---|
public Color(int red, int green, int blue)
Color
using the specified
red, green, and blue values, which must be given as integers in the
range of 0-255. Alpha will default to 255 (opaque). When drawing to
screen, the actual color may be adjusted to the best match of hardware
capabilities.
red
- the red component of the RGB valuegreen
- the green component of the RGB valueblue
- the blue component of the RGB value
IllegalArgumentException
- if the values are out of range 0-255getRed()
,
getGreen()
,
getBlue()
,
getRGB()
,
Color(int, int, int, int)
public Color(int red, int green, int blue, int alpha)
Color
using the specified
red, green, blue, and alpha values, which must be given as integers in
the range of 0-255. When drawing to screen, the actual color may be
adjusted to the best match of hardware capabilities.
red
- the red component of the RGB valuegreen
- the green component of the RGB valueblue
- the blue component of the RGB valuealpha
- the alpha value of the color
IllegalArgumentException
- if the values are out of range 0-255getRed()
,
getGreen()
,
getBlue()
,
getAlpha()
,
getRGB()
public Color(int value)
Color
using the specified
RGB value. The blue value is in bits 0-7, green in bits 8-15, and
red in bits 16-23. The other bits are ignored. The alpha value is set
to 255 (opaque). When drawing to screen, the actual color may be
adjusted to the best match of hardware capabilities.
value
- the RGB valueColorModel.getRGBdefault()
,
getRed()
,
getGreen()
,
getBlue()
,
getRGB()
,
Color(int, boolean)
public Color(int value, boolean hasalpha)
Color
using the specified
RGB value. The blue value is in bits 0-7, green in bits 8-15, and
red in bits 16-23. The alpha value is in bits 24-31, unless hasalpha
is false, in which case alpha is set to 255. When drawing to screen, the
actual color may be adjusted to the best match of hardware capabilities.
value
- the RGB valuehasalpha
- true if value includes the alphaColorModel.getRGBdefault()
,
getRed()
,
getGreen()
,
getBlue()
,
getAlpha()
,
getRGB()
public Color(float red, float green, float blue)
Color
using the specified
RGB values. These must be in the range of 0.0-1.0. Alpha is assigned
the value of 1.0 (opaque). When drawing to screen, the actual color may
be adjusted to the best match of hardware capabilities.
red
- the red component of the RGB valuegreen
- the green component of the RGB valueblue
- the blue component of the RGB value
IllegalArgumentException
- tf the values are out of range 0.0f-1.0fgetRed()
,
getGreen()
,
getBlue()
,
getRGB()
,
Color(float, float, float, float)
public Color(float red, float green, float blue, float alpha)
Color
using the specified
RGB and alpha values. These must be in the range of 0.0-1.0. When drawing
to screen, the actual color may be adjusted to the best match of
hardware capabilities.
red
- the red component of the RGB valuegreen
- the green component of the RGB valueblue
- the blue component of the RGB valuealpha
- the alpha value of the color
IllegalArgumentException
- tf the values are out of range 0.0f-1.0fgetRed()
,
getGreen()
,
getBlue()
,
getAlpha()
,
getRGB()
public Color(ColorSpace space, float[] components, float alpha)
space
- the color space of componentscomponents
- the color components, except alphaalpha
- the alpha value of the color
NullPointerException
- if cpsace or components is null
ArrayIndexOutOfBoundsException
- if components is too small
IllegalArgumentException
- if alpha or any component is out of rangegetComponents(float[])
,
getColorComponents(float[])
Method Detail |
---|
public int getRed()
getRGB()
public int getGreen()
getRGB()
public int getBlue()
getRGB()
public int getAlpha()
getRGB()
public int getRGB()
ColorModel.getRGBdefault()
,
getRed()
,
getGreen()
,
getBlue()
,
getAlpha()
public Color brighter()
darker()
method are not necessarily inverses.
darker()
public Color darker()
brighter()
method are not necessarily inverses.
brighter()
public int hashCode()
hashCode
in class Object
Object.equals(Object)
,
System.identityHashCode(Object)
public boolean equals(Object obj)
Color
and has the same 8-bit integer red, green, and blue
values as this object. Note that two colors may be slightly different
as float values, but round to the same integer values. Also note that
this does not accurately compare SystemColors, since that class does
not store its internal data in RGB format like regular colors.
equals
in class Object
obj
- the object to compare to
Object.hashCode()
public String toString()
getClass().getName() + "[r=" + getRed() + ",g=" + getGreen()
+ ",b=" + getBlue() + ']'
.
toString
in class Object
Object.getClass()
,
Object.hashCode()
,
Class.getName()
,
Integer.toHexString(int)
public static Color decode(String str)
Color
from the value. The alpha
value will be 255 (opaque).
str
- the numeric color string
Color
for the string
NumberFormatException
- if the string cannot be parsed
NullPointerException
- if the string is nullInteger.decode(String)
,
Color(int)
public static Color getColor(String prop)
Color
from the value of the
system property named by the specified string. If the property does not
exist, or cannot be parsed, then null
will be returned.
prop
- the system property to retrieve
SecurityException
- if getting the property is deniedgetColor(String, Color)
,
Integer.getInteger(String)
public static Color getColor(String prop, Color defcolor)
Color
from the value of the
system property named by the specified string. If the property does
not exist, or cannot be parsed, then the default color value will be
returned.
prop
- the system property to retrievedefcolor
- the default color
SecurityException
- if getting the property is deniedInteger.getInteger(String)
public static Color getColor(String prop, int defrgb)
Color
from the value of the
system property named by the specified string. If the property does
not exist, or cannot be parsed, then the default RGB value will be
used to create a return value.
prop
- the system property to retrievedefrgb
- the default RGB value
SecurityException
- if getting the property is deniedgetColor(String, Color)
,
Integer.getInteger(String, int)
public static int HSBtoRGB(float hue, float saturation, float brightness)
hue
- the hue of the HSB valuesaturation
- the saturation of the HSB valuebrightness
- the brightness of the HSB value
getRGB()
,
Color(int)
,
ColorModel.getRGBdefault()
public static float[] RGBtoHSB(int red, int green, int blue, float[] array)
red
- the red part of the RGB valuegreen
- the green part of the RGB valueblue
- the blue part of the RGB valuearray
- an array for the result (at least 3 elements), or null
ArrayIndexOutOfBoundsException
- of array is too smallgetRGB()
,
Color(int)
,
ColorModel.getRGBdefault()
public static Color getHSBColor(float hue, float saturation, float brightness)
Color
based on the specified
HSB values. The hue may be any floating point; it's fractional portion
is used to select the angle in the HSB model. The saturation and
brightness must be between 0 and 1.
hue
- the hue of the HSB valuesaturation
- the saturation of the HSB valuebrightness
- the brightness of the HSB value
Color
objectpublic float[] getRGBComponents(float[] array)
array
- the array to put results into (at least 4 elements), or null
ArrayIndexOutOfBoundsException
- if array is too smallpublic float[] getRGBColorComponents(float[] array)
array
- the array to put results into (at least 3 elements), or null
ArrayIndexOutOfBoundsException
- if array is too smallpublic float[] getComponents(float[] array)
array
- the array to put results into, or null
ArrayIndexOutOfBoundsException
- if array is too smallpublic float[] getColorComponents(float[] array)
array
- the array to put results into, or null
ArrayIndexOutOfBoundsException
- if array is too smallpublic float[] getComponents(ColorSpace space, float[] array)
space
- the color space to translate toarray
- the array to put results into, or null
ArrayIndexOutOfBoundsException
- if array is too small
NullPointerException
- if space is nullpublic float[] getColorComponents(ColorSpace space, float[] array)
space
- the color space to translate to
ArrayIndexOutOfBoundsException
- if array is too small
NullPointerException
- if space is nullpublic ColorSpace getColorSpace()
public PaintContext createContext(ColorModel cm, Rectangle deviceBounds, Rectangle2D userBounds, AffineTransform xform, RenderingHints hints)
createContext
in interface Paint
cm
- the requested color modeldeviceBounds
- the bounding box in device coordinates, ignoreduserBounds
- the bounding box in user coordinates, ignoredxform
- the bounds transformation, ignoredhints
- any rendering hints, ignored
public int getTransparency()
getTransparency
in interface Transparency
Transparency.OPAQUE
, Transparency.BITMASK
, or Transparency.TRANSLUCENT
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |