Color
class is used to encapsulate colors in the default
sRGB color space or colors in arbitrary color spaces identified by a
ColorSpace
. Every color has an implicit alpha value of 1.0 or
an explicit one provided in the constructor. The alpha value
defines the transparency of a color and can be represented by
a float value in the range 0.0 - 1.0 or 0 - 255.
An alpha value of 1.0 or 255 means that the color is completely
opaque and an alpha value of 0 or 0.0 means that the color is
completely transparent.
When constructing a Color
with an explicit alpha or
getting the color/alpha components of a Color
, the color
components are never premultiplied by the alpha component.
The default color space for the Java 2D(tm) API is sRGB, a proposed standard RGB color space. For further information on sRGB, see http://www.w3.org/pub/WWW/Graphics/Color/sRGB.html .
hasalpha
argument is false
, alpha
is defaulted to 255.ColorSpace
with the color components specified in the float
array and the specified alpha. The number of components is
determined by the type of the ColorSpace
. For
example, RGB requires 3 components, but CMYK requires 4
components.Color
that is a brighter version of this
Color
.
This method applies an arbitrary scale factor to each of the three RGB
components of this Color
to create a brighter version
of this Color
. Although brighter
and
darker
are inverse operations, the results of a
series of invocations of these two methods might be inconsistent
because of rounding errors.
Since the API documentation was not specific about this in
releases before 1.4, there may be implementations of
Paint
that do not accept a null
ColorModel
argument.
If a developer is writing code which passes a null
ColorModel
argument to the
createContext
method of Paint
objects from arbitrary sources it would be wise to code defensively
by manufacturing a non-null ColorModel
for those
objects which throw a NullPointerException
.
Color
that is a darker version of this
Color
.
This method applies an arbitrary scale factor to each of the three RGB
components of this Color
to create a darker version of
this Color
. Although brighter
and
darker
are inverse operations, the results of a series
of invocations of these two methods might be inconsistent because
of rounding errors.
String
to an integer and returns the
specified opaque Color
. This method handles string
formats that are used to represent octal and hexidecimal numbers.Color
.
The result is true
if and only if the argument is not
null
and is a Color
object that has the same
red, green, blue, and alpha values as this object.
The argument is treated as the name of a system property to
be obtained. The string value of this property is then interpreted
as an integer which is then converted to a Color
object.
If the specified property is not found or could not be parsed as
an integer then null
is returned.
The first argument is treated as the name of a system property to
be obtained. The string value of this property is then interpreted
as an integer which is then converted to a Color
object.
If the specified property is not found or cannot be parsed as
an integer then the Color
specified by the second
argument is returned instead.
The first argument is treated as the name of a system property to
be obtained. The string value of this property is then interpreted
as an integer which is then converted to a Color
object.
If the specified property is not found or could not be parsed as
an integer then the integer value v
is used instead,
and is converted to a Color
object.
float
array containing only the color
components of the Color
in the
ColorSpace
specified by the cspace
parameter. If compArray
is null
, an array
with length equal to the number of components in
cspace
is created for the return value. Otherwise,
compArray
must have at least this length, and it is
filled in with the components and returned.float
array containing only the color
components of the Color
, in the
ColorSpace
of the Color
.
If compArray
is null
, an array with
length equal to the number of components in the associated
ColorSpace
is created for
the return value. Otherwise, compArray
must have at
least this length and it is filled in with the components and
returned.ColorSpace
of this Color
.float
array containing the color and alpha
components of the Color
, in the
ColorSpace
specified by the cspace
parameter. If compArray
is null
, an
array with length equal to the number of components in
cspace
plus one is created for the return value.
Otherwise, compArray
must have at least this
length, and it is filled in with the components and returned.float
array containing the color and alpha
components of the Color
, in the
ColorSpace
of the Color
.
If compArray
is null
, an array with
length equal to the number of components in the associated
ColorSpace
plus one is created for
the return value. Otherwise, compArray
must have at
least this length and it is filled in with the components and
returned.Color
object based on the specified values
for the HSB color model.
The s
and b
components should be
floating-point values between zero and one
(numbers in the range 0.0-1.0). The h
component
can be any floating-point number. The floor of this number is
subtracted from it to create a fraction between 0 and 1. This
fractional number is then multiplied by 360 to produce the hue
angle in the HSB color model.
float
array containing only the color
components of the Color
, in the default sRGB color
space. If compArray
is null
, an array of
length 3 is created for the return value. Otherwise,
compArray
must have length 3 or greater, and it is
filled in with the components and returned.float
array containing the color and alpha
components of the Color
, as represented in the default
sRGB color space.
If compArray
is null
, an array of length
4 is created for the return value. Otherwise,
compArray
must have length 4 or greater,
and it is filled in with the components and returned.Color
. This is
required to implement the Paint
interface.Color
.
The saturation
and brightness
components
should be floating-point values between zero and one
(numbers in the range 0.0-1.0). The hue
component
can be any floating-point number. The floor of this number is
subtracted from it to create a fraction between 0 and 1. This
fractional number is then multiplied by 360 to produce the hue
angle in the HSB color model.
The integer that is returned by HSBtoRGB
encodes the
value of a color in bits 0-23 of an integer value that is the same
format used by the method getRGB
.
This integer can be supplied as an argument to the
Color
constructor that takes a single integer argument.
wait
methods.
The awakened thread will not be able to proceed until the current thread relinquishes the lock on this object. The awakened thread will compete in the usual manner with any other threads that might be actively competing to synchronize on this object; for example, the awakened thread enjoys no reliable privilege or disadvantage in being the next thread to lock this object.
This method should only be called by a thread that is the owner of this object's monitor. A thread becomes the owner of the object's monitor in one of three ways:
synchronized
statement
that synchronizes on the object.
Class,
by executing a
synchronized static method of that class.
Only one thread at a time can own an object's monitor.
wait
methods.
The awakened threads will not be able to proceed until the current thread relinquishes the lock on this object. The awakened threads will compete in the usual manner with any other threads that might be actively competing to synchronize on this object; for example, the awakened threads enjoy no reliable privilege or disadvantage in being the next thread to lock this object.
This method should only be called by a thread that is the owner
of this object's monitor. See the notify
method for a
description of the ways in which a thread can become the owner of
a monitor.
If the hsbvals
argument is null
, then a
new array is allocated to return the result. Otherwise, the method
returns the array hsbvals
, with the values put into
that array.
Color
. This
method is intended to be used only for debugging purposes. The
content and format of the returned string might vary between
implementations. The returned string might be empty but cannot
be null
.
The current thread must own this object's monitor. The thread
releases ownership of this monitor and waits until another thread
notifies threads waiting on this object's monitor to wake up
either through a call to the notify
method or the
notifyAll
method. The thread then waits until it can
re-obtain ownership of the monitor and resumes execution.
As in the one argument version, interrupts and spurious wakeups are possible, and this method should always be used in a loop:
synchronized (obj) { while (<condition does not hold>) obj.wait(); ... // Perform action appropriate to condition }This method should only be called by a thread that is the owner of this object's monitor. See the
notify
method for a
description of the ways in which a thread can become the owner of
a monitor.The current thread must own this object's monitor.
This method causes the current thread (call it T) to place itself in the wait set for this object and then to relinquish any and all synchronization claims on this object. Thread T becomes disabled for thread scheduling purposes and lies dormant until one of four things happens:
A thread can also wake up without being notified, interrupted, or timing out, a so-called spurious wakeup. While this will rarely occur in practice, applications must guard against it by testing for the condition that should have caused the thread to be awakened, and continuing to wait if the condition is not satisfied. In other words, waits should always occur in loops, like this one:
synchronized (obj) { while (<condition does not hold>) obj.wait(timeout); ... // Perform action appropriate to condition }(For more information on this topic, see Section 3.2.3 in Doug Lea's "Concurrent Programming in Java (Second Edition)" (Addison-Wesley, 2000), or Item 50 in Joshua Bloch's "Effective Java Programming Language Guide" (Addison-Wesley, 2001).
If the current thread is interrupted by another thread while it is waiting, then an InterruptedException is thrown. This exception is not thrown until the lock status of this object has been restored as described above.
Note that the wait method, as it places the current thread into the wait set for this object, unlocks only this object; any other objects on which the current thread may be synchronized remain locked while the thread waits.
This method should only be called by a thread that is the owner
of this object's monitor. See the notify
method for a
description of the ways in which a thread can become the owner of
a monitor.
This method is similar to the wait
method of one
argument, but it allows finer control over the amount of time to
wait for a notification before giving up. The amount of real time,
measured in nanoseconds, is given by:
1000000*timeout+nanos
In all other respects, this method does the same thing as the method of one argument. In particular, wait(0, 0) means the same thing as wait(0).
The current thread must own this object's monitor. The thread releases ownership of this monitor and waits until either of the following two conditions has occurred:
notify
method
or the notifyAll
method.
timeout
milliseconds plus nanos
nanoseconds arguments, has
elapsed.
The thread then waits until it can re-obtain ownership of the monitor and resumes execution.
As in the one argument version, interrupts and spurious wakeups are possible, and this method should always be used in a loop:
synchronized (obj) { while (<condition does not hold>) obj.wait(timeout, nanos); ... // Perform action appropriate to condition }This method should only be called by a thread that is the owner of this object's monitor. See the
notify
method for a
description of the ways in which a thread can become the owner of
a monitor.