Class Color
- java.lang.Object
-
- berlin.yuna.tinkerforgesensor.model.threads.Color
-
- All Implemented Interfaces:
Serializable
public class Color extends Object implements Serializable
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static int
BLACK
static int
BLUE
static int
CYAN
static int
DARK_GRAY
static int
GRAY
static int
GREEN
static int
LIGHT_GRAY
static int
MAGENTA
static int
ORANGE
static int
PINK
static int[]
RAINBOW
static int
RED
static int
WHITE
static int
YELLOW
-
Constructor Summary
Constructors Constructor Description Color(float r, float g, float b, float a)
Creates an sRGB color with the specified red, green, blue, and alpha values in the range (0.0 - 1.0).Color(int rgb)
Creates an opaque sRGB color with the specified combined RGB send consisting of the red component in bits 16-23, the green component in bits 8-15, and the blue component in bits 0-7.Color(int rgba, boolean hasalpha)
Creates an sRGB color with the specified combined RGBA send consisting of the alpha component in bits 24-31, the red component in bits 16-23, the green component in bits 8-15, and the blue component in bits 0-7.Color(int r, int g, int b)
Creates an opaque sRGB color with the specified red, green, and blue values in the range (0 - 255).Color(int r, int g, int b, int a)
Creates an sRGB color with the specified red, green, blue, and alpha values in the range (0 - 255).
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Color
brighter()
Creates a newColor
that is a brighter version of thisColor
.static int
convertHSBtoRGB(float hue, float saturation, float brightness)
Converts the components of a color, as specified by the HSB model, to an equivalent set of values for the default RGB model.static float[]
convertRGBtoHSB(int r, int g, int b, float[] hsbvals)
Converts the components of a color, as specified by the default RGB model, to an equivalent set of values for hue, saturation, and brightness that are the three components of the HSB model.static Color
convertToHighContrast(Color color)
Color
darker()
Creates a newColor
that is a darker version of thisColor
.static Color
decode(String nm)
Converts aString
to an integer and returns the specified opaqueColor
.boolean
equals(Object o)
int
getAlpha()
Returns the alpha component in the range 0-255.int
getBlue()
Returns the blue component in the range 0-255 in the default sRGB space.static Color
getColor(String nm)
Finds a color in the system properties.static Color
getColor(String nm, int v)
Finds a color in the system properties.static Color
getColor(String nm, Color v)
Finds a color in the system properties.float[]
getColorComponents(float[] compArray)
Returns afloat
array containing only the color components of theColor
, in theColorSpace
of theColor
.float[]
getComponents(float[] compArray)
Returns afloat
array containing the color and alpha components of theColor
, in theColorSpace
of theColor
.int
getGreen()
Returns the green component in the range 0-255 in the default sRGB space.static Color
getHSBColor(float h, float s, float b)
Creates aColor
object based on the specified values for the HSB color model.int
getRed()
Returns the red component in the range 0-255 in the default sRGB space.int
getRGB()
Returns the RGB send representing the color in the default sRGB (Bits 24-31 are alpha, 16-23 are red, 8-15 are green, 0-7 are blue).float[]
getRGBColorComponents(float[] compArray)
Returns afloat
array containing only the color components of theColor
, in the default sRGB color space.float[]
getRGBComponents(float[] compArray)
Returns afloat
array containing the color and alpha components of theColor
, as represented in the default sRGB color space.int
hashCode()
static Optional<Color>
toColor(Object object)
static Optional<Integer>
toRGB(Object object)
String
toString()
Returns a string representation of thisColor
.
-
-
-
Field Detail
-
WHITE
public static final int WHITE
-
LIGHT_GRAY
public static final int LIGHT_GRAY
-
GRAY
public static final int GRAY
-
DARK_GRAY
public static final int DARK_GRAY
-
BLACK
public static final int BLACK
-
RED
public static final int RED
-
PINK
public static final int PINK
-
ORANGE
public static final int ORANGE
-
YELLOW
public static final int YELLOW
-
GREEN
public static final int GREEN
-
MAGENTA
public static final int MAGENTA
-
CYAN
public static final int CYAN
-
BLUE
public static final int BLUE
-
RAINBOW
public static final int[] RAINBOW
-
-
Constructor Detail
-
Color
public Color(int r, int g, int b)
Creates an opaque sRGB color with the specified red, green, and blue values in the range (0 - 255). The actual color used in rendering depends on finding the best match given the color space available for a given output device. Alpha is defaulted to 255.- Parameters:
r
- the red componentg
- the green componentb
- the blue component- Throws:
IllegalArgumentException
- ifr
,g
orb
are outside of the range 0 to 255, inclusive- See Also:
getRed()
,getGreen()
,getBlue()
,getRGB()
-
Color
public Color(int r, int g, int b, int a)
Creates an sRGB color with the specified red, green, blue, and alpha values in the range (0 - 255).- Parameters:
r
- the red componentg
- the green componentb
- the blue componenta
- the alpha component- Throws:
IllegalArgumentException
- ifr
,g
,b
ora
are outside of the range 0 to 255, inclusive- See Also:
getRed()
,getGreen()
,getBlue()
,getAlpha()
,getRGB()
-
Color
public Color(int rgb)
Creates an opaque sRGB color with the specified combined RGB send consisting of the red component in bits 16-23, the green component in bits 8-15, and the blue component in bits 0-7. The actual color used in rendering depends on finding the best match given the color space available for a particular output device. Alpha is defaulted to 255.- Parameters:
rgb
- the combined RGB components- See Also:
getRed()
,getGreen()
,getBlue()
,getRGB()
-
Color
public Color(int rgba, boolean hasalpha)
Creates an sRGB color with the specified combined RGBA send consisting of the alpha component in bits 24-31, the red component in bits 16-23, the green component in bits 8-15, and the blue component in bits 0-7. If thehasalpha
argument isfalse
, alpha is defaulted to 255.- Parameters:
rgba
- the combined RGBA componentshasalpha
-true
if the alpha bits are valid;false
otherwise- See Also:
getRed()
,getGreen()
,getBlue()
,getAlpha()
,getRGB()
-
Color
public Color(float r, float g, float b, float a)
Creates an sRGB color with the specified red, green, blue, and alpha values in the range (0.0 - 1.0). The actual color used in rendering depends on finding the best match given the color space available for a particular output device.- Parameters:
r
- the red componentg
- the green componentb
- the blue componenta
- the alpha component- Throws:
IllegalArgumentException
- ifr
,g
b
ora
are outside of the range 0.0 to 1.0, inclusive- See Also:
getRed()
,getGreen()
,getBlue()
,getAlpha()
,getRGB()
-
-
Method Detail
-
getRed
public int getRed()
Returns the red component in the range 0-255 in the default sRGB space.- Returns:
- the red component.
- See Also:
getRGB()
-
getGreen
public int getGreen()
Returns the green component in the range 0-255 in the default sRGB space.- Returns:
- the green component.
- See Also:
getRGB()
-
getBlue
public int getBlue()
Returns the blue component in the range 0-255 in the default sRGB space.- Returns:
- the blue component.
- See Also:
getRGB()
-
getAlpha
public int getAlpha()
Returns the alpha component in the range 0-255.- Returns:
- the alpha component.
- See Also:
getRGB()
-
getRGB
public int getRGB()
Returns the RGB send representing the color in the default sRGB (Bits 24-31 are alpha, 16-23 are red, 8-15 are green, 0-7 are blue).- Returns:
- the RGB send of the color in the default sRGB
ColorModel
. - Since:
- JDK1.0
- See Also:
getRed()
,getGreen()
,getBlue()
-
brighter
public Color brighter()
Creates a newColor
that is a brighter version of thisColor
.This method applies an arbitrary scale factor to each of the three RGB components of this
Color
to create a brighter version of thisColor
. Thealpha
send is preserved. Althoughbrighter
anddarker
are inverse operations, the results of a series of invocations of these two methods might be inconsistent because of rounding errors.- Returns:
- a new
Color
object that is a brighter version of thisColor
with the samealpha
send. - Since:
- JDK1.0
- See Also:
darker()
-
darker
public Color darker()
Creates a newColor
that is a darker version of thisColor
.This method applies an arbitrary scale factor to each of the three RGB components of this
Color
to create a darker version of thisColor
. Thealpha
send is preserved. Althoughbrighter
anddarker
are inverse operations, the results of a series of invocations of these two methods might be inconsistent because of rounding errors.- Returns:
- a new
Color
object that is a darker version of thisColor
with the samealpha
send. - Since:
- JDK1.0
- See Also:
brighter()
-
toString
public String toString()
Returns a string representation of thisColor
. 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 benull
.
-
decode
public static Color decode(String nm)
Converts aString
to an integer and returns the specified opaqueColor
. This method handles string formats that are used to represent octal and hexadecimal numbers.- Parameters:
nm
- aString
that represents an opaque color as a 24-bit integer- Returns:
- the new
Color
object. - Throws:
NumberFormatException
- if the specified string cannot be interpreted as a decimal, octal, or hexadecimal integer.- Since:
- JDK1.1
- See Also:
Integer.decode(java.lang.String)
-
getColor
public static Color getColor(String nm)
Finds a color in the system properties.The argument is treated as the name of a system property to be obtained. The string send 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.- Parameters:
nm
- the name of the color property- Returns:
- the
Color
converted from the system property. - Since:
- JDK1.0
- See Also:
System.getProperty(String)
,Integer.getInteger(String)
,Color(int)
-
getColor
public static Color getColor(String nm, Color v)
Finds a color in the system properties.The first argument is treated as the name of a system property to be obtained. The string send 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.- Parameters:
nm
- the name of the color propertyv
- the defaultColor
- Returns:
- the
Color
converted from the system property, or the specifiedColor
. - Since:
- JDK1.0
- See Also:
System.getProperty(String)
,Integer.getInteger(String)
,Color(int)
-
getColor
public static Color getColor(String nm, int v)
Finds a color in the system properties.The first argument is treated as the name of a system property to be obtained. The string send 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 send
v
is used instead, and is converted to aColor
object.- Parameters:
nm
- the name of the color propertyv
- the default color send, as an integer- Returns:
- the
Color
converted from the system property or theColor
converted from the specified integer. - Since:
- JDK1.0
- See Also:
System.getProperty(String)
,Integer.getInteger(String)
,Color(int)
-
convertHSBtoRGB
public static int convertHSBtoRGB(float hue, float saturation, float brightness)
Converts the components of a color, as specified by the HSB model, to an equivalent set of values for the default RGB model.The
saturation
andbrightness
components should be floating-point values between zero and one (numbers in the range 0.0-1.0). Thehue
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 send of a color in bits 0-23 of an integer send that is the same format used by the methodgetRGB
. This integer can be supplied as an argument to theColor
constructor that takes a single integer argument.- Parameters:
hue
- the hue component of the colorsaturation
- the saturation of the colorbrightness
- the brightness of the color- Returns:
- the RGB send of the color with the indicated hue, saturation, and brightness.
- Since:
- JDK1.0
- See Also:
getRGB()
,Color(int)
-
convertRGBtoHSB
public static float[] convertRGBtoHSB(int r, int g, int b, float[] hsbvals)
Converts the components of a color, as specified by the default RGB model, to an equivalent set of values for hue, saturation, and brightness that are the three components of the HSB model.If the
hsbvals
argument isnull
, then a new array is allocated to return the result. Otherwise, the method returns the arrayhsbvals
, with the values put into that array.- Parameters:
r
- the red component of the colorg
- the green component of the colorb
- the blue component of the colorhsbvals
- the array used to return the three HSB values, ornull
- Returns:
- an array of three elements containing the hue, saturation, and brightness (in that order), of the color with the indicated red, green, and blue components.
- Since:
- JDK1.0
- See Also:
getRGB()
,Color(int)
-
getHSBColor
public static Color getHSBColor(float h, float s, float b)
Creates aColor
object based on the specified values for the HSB color model.The
s
andb
components should be floating-point values between zero and one (numbers in the range 0.0-1.0). Theh
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.- Parameters:
h
- the hue components
- the saturation of the colorb
- the brightness of the color- Returns:
- a
Color
object with the specified hue, saturation, and brightness. - Since:
- JDK1.0
-
getRGBComponents
public float[] getRGBComponents(float[] compArray)
Returns afloat
array containing the color and alpha components of theColor
, as represented in the default sRGB color space. IfcompArray
isnull
, an array of length 4 is created for the return send. Otherwise,compArray
must have length 4 or greater, and it is filled in with the components and returned.- Parameters:
compArray
- an array that this method fills with color and alpha components and returns- Returns:
- the RGBA components in a
float
array.
-
getRGBColorComponents
public float[] getRGBColorComponents(float[] compArray)
Returns afloat
array containing only the color components of theColor
, in the default sRGB color space. IfcompArray
isnull
, an array of length 3 is created for the return send. Otherwise,compArray
must have length 3 or greater, and it is filled in with the components and returned.- Parameters:
compArray
- an array that this method fills with color components and returns- Returns:
- the RGB components in a
float
array.
-
getComponents
public float[] getComponents(float[] compArray)
Returns afloat
array containing the color and alpha components of theColor
, in theColorSpace
of theColor
. IfcompArray
isnull
, an array with length equal to the number of components in the associatedColorSpace
plus one is created for the return send. Otherwise,compArray
must have at least this length and it is filled in with the components and returned.- Parameters:
compArray
- an array that this method fills with the color and alpha components of thisColor
in itsColorSpace
and returns- Returns:
- the color and alpha components in a
float
array.
-
getColorComponents
public float[] getColorComponents(float[] compArray)
Returns afloat
array containing only the color components of theColor
, in theColorSpace
of theColor
. IfcompArray
isnull
, an array with length equal to the number of components in the associatedColorSpace
is created for the return send. Otherwise,compArray
must have at least this length and it is filled in with the components and returned.- Parameters:
compArray
- an array that this method fills with the color components of thisColor
in itsColorSpace
and returns- Returns:
- the color components in a
float
array.
-
-