|
|||||||||
| Home >> All >> java >> [ awt overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.awt
Class Color

java.lang.Objectjava.awt.Color
- All Implemented Interfaces:
- Paint, java.io.Serializable, Transparency
- Direct Known Subclasses:
- SystemColor
- public class Color
- extends java.lang.Object
- implements Paint, java.io.Serializable
- extends java.lang.Object
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.
- Since:
- 1.0
| Field Summary | |
(package private) static int |
ALPHA_MASK
Internal mask for alpha. |
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. |
private static int |
BLUE_MASK
Internal mask for blue. |
private static float |
BRIGHT_SCALE
Amount to scale a color by when brightening or darkening. |
(package private) ColorPaintContext |
context
The paint context for this solid color. |
private java.awt.color.ColorSpace |
cs
The ColorSpace. |
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. |
private float |
falpha
The alpha value. |
private float[] |
frgbvalue
The color value, in sRGB. |
private float[] |
fvalue
The color value, in the native ColorSpace components. |
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. |
private static int |
GREEN_MASK
Internal mask for green. |
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. |
private static int |
RED_MASK
Internal mask for red. |
private static long |
serialVersionUID
Compatible with JDK 1.0+. |
(package private) int |
value
The color value, in sRGB. |
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(java.awt.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. |
private static int |
convert(float red,
float green,
float blue,
float alpha)
Converts float values to integer value. |
PaintContext |
createContext(java.awt.image.ColorModel cm,
Rectangle deviceBounds,
java.awt.geom.Rectangle2D userBounds,
java.awt.geom.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(java.lang.String str)
Converts the specified string to a number, using Integer.decode, and creates a new instance of Color from the value. |
boolean |
equals(java.lang.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(java.lang.String prop)
Returns a new instance of Color from the value of the
system property named by the specified string. |
static Color |
getColor(java.lang.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(java.lang.String prop,
int defrgb)
Returns a new instance of Color from the value of the
system property named by the specified string. |
float[] |
getColorComponents(java.awt.color.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). |
java.awt.color.ColorSpace |
getColorSpace()
Returns the color space of this color. |
float[] |
getComponents(java.awt.color.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. |
java.lang.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 |
serialVersionUID
private static final long serialVersionUID
- Compatible with JDK 1.0+.
- See Also:
- Constant Field Values
white
public static final Color white
- Constant for the color white: R=255, G=255, B=255.
WHITE
public static final Color WHITE
- Constant for the color white: R=255, G=255, B=255.
- Since:
- 1.4
lightGray
public static final Color lightGray
- Constant for the color light gray: R=192, G=192, B=192.
LIGHT_GRAY
public static final Color LIGHT_GRAY
- Constant for the color light gray: R=192, G=192, B=192.
- Since:
- 1.4
gray
public static final Color gray
- Constant for the color gray: R=128, G=128, B=128.
GRAY
public static final Color GRAY
- Constant for the color gray: R=128, G=128, B=128.
- Since:
- 1.4
darkGray
public static final Color darkGray
- Constant for the color dark gray: R=64, G=64, B=64.
DARK_GRAY
public static final Color DARK_GRAY
- Constant for the color dark gray: R=64, G=64, B=64.
- Since:
- 1.4
black
public static final Color black
- Constant for the color black: R=0, G=0, B=0.
BLACK
public static final Color BLACK
- Constant for the color black: R=0, G=0, B=0.
- Since:
- 1.4
red
public static final Color red
- Constant for the color red: R=255, G=0, B=0.
RED
public static final Color RED
- Constant for the color red: R=255, G=0, B=0.
- Since:
- 1.4
pink
public static final Color pink
- Constant for the color pink: R=255, G=175, B=175.
PINK
public static final Color PINK
- Constant for the color pink: R=255, G=175, B=175.
- Since:
- 1.4
orange
public static final Color orange
- Constant for the color orange: R=255, G=200, B=0.
ORANGE
public static final Color ORANGE
- Constant for the color orange: R=255, G=200, B=0.
- Since:
- 1.4
yellow
public static final Color yellow
- Constant for the color yellow: R=255, G=255, B=0.
YELLOW
public static final Color YELLOW
- Constant for the color yellow: R=255, G=255, B=0.
- Since:
- 1.4
green
public static final Color green
- Constant for the color green: R=0, G=255, B=0.
GREEN
public static final Color GREEN
- Constant for the color green: R=0, G=255, B=0.
- Since:
- 1.4
magenta
public static final Color magenta
- Constant for the color magenta: R=255, G=0, B=255.
MAGENTA
public static final Color MAGENTA
- Constant for the color magenta: R=255, G=0, B=255.
- Since:
- 1.4
cyan
public static final Color cyan
- Constant for the color cyan: R=0, G=255, B=255.
CYAN
public static final Color CYAN
- Constant for the color cyan: R=0, G=255, B=255.
- Since:
- 1.4
blue
public static final Color blue
- Constant for the color blue: R=0, G=0, B=255.
BLUE
public static final Color BLUE
- Constant for the color blue: R=0, G=0, B=255.
- Since:
- 1.4
RED_MASK
private static final int RED_MASK
- Internal mask for red.
- See Also:
- Constant Field Values
GREEN_MASK
private static final int GREEN_MASK
- Internal mask for green.
- See Also:
- Constant Field Values
BLUE_MASK
private static final int BLUE_MASK
- Internal mask for blue.
- See Also:
- Constant Field Values
ALPHA_MASK
static final int ALPHA_MASK
- Internal mask for alpha. Package visible for use in subclass.
- See Also:
- Constant Field Values
BRIGHT_SCALE
private static final float BRIGHT_SCALE
- Amount to scale a color by when brightening or darkening.
- See Also:
- Constant Field Values
value
final int value
- The color value, in sRGB. Note that the actual color may be more
precise if frgbvalue or fvalue is non-null. This class stores alpha, red,
green, and blue, each 0-255, packed in an int. However, the subclass
SystemColor stores an index into an array. Therefore, for serial
compatibility (and because of poor design on Sun's part), this value
cannot be used directly; instead you must use
getRGB().- See Also:
getRGB()55
frgbvalue
private float[] frgbvalue
- The color value, in sRGB. This may be null if the color was constructed
with ints; and it does not include alpha. This stores red, green, and
blue, in the range 0.0f - 1.0f.
- Since:
- 1.2
- See Also:
getRGBColorComponents(float[])55 ,getRGBComponents(float[])55
fvalue
private float[] fvalue
- The color value, in the native ColorSpace components. This may be null
if the color was constructed with ints or in the sRGB color space; and
it does not include alpha.
- Since:
- 1.2
- See Also:
getRGBColorComponents(float[])55 ,getRGBComponents(float[])55
falpha
private final float falpha
- The alpha value. This is in the range 0.0f - 1.0f, but is invalid if
deserialized as 0.0 when frgbvalue is null.
- Since:
- 1.2
- See Also:
getRGBComponents(float[])55 ,getComponents(float[])55
cs
private final java.awt.color.ColorSpace cs
- The ColorSpace. Null means the default sRGB space.
- Since:
- 1.2
- See Also:
getColor(String)55 ,getColorSpace()55 ,getColorComponents(float[])55
context
transient ColorPaintContext context
- The paint context for this solid color. Package visible for use in
subclass.
| Constructor Detail |
Color
public Color(int red,
int green,
int blue)
- Initializes a new instance of
Colorusing 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.
Color
public Color(int red,
int green,
int blue,
int alpha)
- Initializes a new instance of
Colorusing 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.
Color
public Color(int value)
- Initializes a new instance of
Colorusing 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.
Color
public Color(int value,
boolean hasalpha)
- Initializes a new instance of
Colorusing 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.
Color
public Color(float red,
float green,
float blue)
- Initializes a new instance of
Colorusing 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.
Color
public Color(float red,
float green,
float blue,
float alpha)
- Initializes a new instance of
Colorusing 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.
Color
public Color(java.awt.color.ColorSpace space, float[] components, float alpha)
- Creates a color in the given ColorSpace with the specified alpha. The
array must be non-null and have enough elements for the color space
(for example, RGB requires 3 elements, CMYK requires 4). When drawing
to screen, the actual color may be adjusted to the best match of
hardware capabilities.
| Method Detail |
getRed
public int getRed()
- Returns the red value for this color, as an integer in the range 0-255
in the sRGB color space.
getGreen
public int getGreen()
- Returns the green value for this color, as an integer in the range 0-255
in the sRGB color space.
getBlue
public int getBlue()
- Returns the blue value for this color, as an integer in the range 0-255
in the sRGB color space.
getAlpha
public int getAlpha()
- Returns the alpha value for this color, as an integer in the range 0-255.
getRGB
public int getRGB()
- Returns the RGB value for this color, in the sRGB color space. The blue
value will be in bits 0-7, green in 8-15, red in 16-23, and alpha value in
24-31.
brighter
public Color brighter()
- Returns a brighter version of this color. This is done by increasing the
RGB values by an arbitrary scale factor. The new color is opaque (an
alpha of 255). Note that this method and the
darker()method are not necessarily inverses.
darker
public Color darker()
- Returns a darker version of this color. This is done by decreasing the
RGB values by an arbitrary scale factor. The new color is opaque (an
alpha of 255). Note that this method and the
brighter()method are not necessarily inverses.
hashCode
public int hashCode()
- Returns a hash value for this color. This is simply the color in 8-bit
precision, in the format 0xAARRGGBB (alpha, red, green, blue).
equals
public boolean equals(java.lang.Object obj)
- Tests this object for equality against the specified object. This will
be true if and only if the specified object is an instance of
Colorand 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.
toString
public java.lang.String toString()
- Returns a string representation of this object. Subclasses may return
any desired format, except for null, but this implementation returns
getClass().getName() + "[r=" + getRed() + ",g=" + getGreen() + ",b=" + getBlue() + ']'.
decode
public static Color decode(java.lang.String str)
- Converts the specified string to a number, using Integer.decode, and
creates a new instance of
Colorfrom the value. The alpha value will be 255 (opaque).- Since:
- 1.1
getColor
public static Color getColor(java.lang.String prop)
- Returns a new instance of
Colorfrom the value of the system property named by the specified string. If the property does not exist, or cannot be parsed, thennullwill be returned.
getColor
public static Color getColor(java.lang.String prop, Color defcolor)
- Returns a new instance of
Colorfrom 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.
getColor
public static Color getColor(java.lang.String prop, int defrgb)
- Returns a new instance of
Colorfrom 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.
HSBtoRGB
public 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. 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. The result is
suitable for creating an RGB color with the one-argument constructor.
RGBtoHSB
public 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. If the array is null, a new one
is created, otherwise it is recycled. The results will be in the range
0.0-1.0 if the inputs are in the range 0-255.
getHSBColor
public static Color getHSBColor(float hue, float saturation, float brightness)
- Returns a new instance of
Colorbased 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.
getRGBComponents
public 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.
If the array is null, a new one is created, otherwise it is recycled.
getRGBColorComponents
public 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. If the array is
null, a new one is created, otherwise it is recycled.
getComponents
public 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). If the
array is null, a new one is created, otherwise it is recycled, and must
have at least one more position than components used in the color space.
getColorComponents
public 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). If the array is
null, a new one is created, otherwise it is recycled, and must have at
least as many positions as used in the color space.
getComponents
public float[] getComponents(java.awt.color.ColorSpace space, float[] array)
- Returns a float array containing the color and alpha components of this
color in the given ColorSpace. If the array is null, a new one is
created, otherwise it is recycled, and must have at least one more
position than components used in the color space.
getColorComponents
public float[] getColorComponents(java.awt.color.ColorSpace space, float[] array)
- Returns a float array containing the color components of this color in
the given ColorSpace. If the array is null, a new one is created,
otherwise it is recycled, and must have at least as many positions as
used in the color space.
getColorSpace
public java.awt.color.ColorSpace getColorSpace()
- Returns the color space of this color. Except for the constructor which
takes a ColorSpace argument, this will be an implementation of
ColorSpace.CS_sRGB.
createContext
public PaintContext createContext(java.awt.image.ColorModel cm, Rectangle deviceBounds, java.awt.geom.Rectangle2D userBounds, java.awt.geom.AffineTransform xform, RenderingHints hints)
- Returns a paint context, used for filling areas of a raster scan with
this color. Since the color is constant across the entire rectangle, and
since it is always in sRGB space, this implementation returns the same
object, regardless of the parameters. Subclasses, however, may have a
mutable result.
- Specified by:
createContextin interfacePaint
getTransparency
public int getTransparency()
- Returns the transparency level of this color.
- Specified by:
getTransparencyin interfaceTransparency
convert
private static int convert(float red,
float green,
float blue,
float alpha)
- Converts float values to integer value.
|
|||||||||
| Home >> All >> java >> [ awt overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
java.awt.Color