Package org.openhab.core.library.types
Class HSBType
- java.lang.Object
-
- java.lang.Number
-
- org.openhab.core.library.types.DecimalType
-
- org.openhab.core.library.types.PercentType
-
- org.openhab.core.library.types.HSBType
-
- All Implemented Interfaces:
Serializable
,Comparable<DecimalType>
,Command
,ComplexType
,PrimitiveType
,State
,Type
@NonNullByDefault public class HSBType extends PercentType implements ComplexType, State, Command
The HSBType is a complex type with constituents for hue, saturation and brightness and can be used for color items.- Author:
- Kai Kreuzer - Initial contribution, Chris Jackson - Added fromRGB
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static HSBType
BLACK
static HSBType
BLUE
static HSBType
GREEN
protected BigDecimal
hue
static String
KEY_BRIGHTNESS
static String
KEY_HUE
static String
KEY_SATURATION
static HSBType
RED
protected BigDecimal
saturation
static HSBType
WHITE
-
Fields inherited from class org.openhab.core.library.types.PercentType
HUNDRED, ZERO
-
Fields inherited from class org.openhab.core.library.types.DecimalType
value
-
-
Constructor Summary
Constructors Constructor Description HSBType()
HSBType(String value)
Constructs a HSBType instance from a given string.HSBType(DecimalType h, PercentType s, PercentType b)
Constructs a HSBType instance with the given values
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends State>
@Nullable Tas(@Nullable Class<T> target)
Convert thisState
's value into another typeboolean
equals(@Nullable Object obj)
static HSBType
fromRGB(int r, int g, int b)
Create HSB from RGBstatic HSBType
fromXY(float x, float y)
Returns a HSBType object representing the provided xy color values in CIE XY color model.PercentType
getBlue()
PercentType
getBrightness()
SortedMap<String,PrimitiveType>
getConstituents()
Returns all constituents with their names as a sorted mapPercentType
getGreen()
DecimalType
getHue()
PercentType
getRed()
int
getRGB()
Returns the RGB value representing the color in the default sRGB color model.PercentType
getSaturation()
int
hashCode()
String
toFullString()
Get a string representation that contains the whole internal representation of the type.PercentType[]
toRGB()
String
toString()
PercentType[]
toXY()
Returns the xyY values representing this object's color in CIE XY color model.static HSBType
valueOf(String value)
-
Methods inherited from class org.openhab.core.library.types.DecimalType
compareTo, defaultConversion, doubleValue, floatValue, format, intValue, longValue, toBigDecimal
-
Methods inherited from class java.lang.Number
byteValue, shortValue
-
-
-
-
Field Detail
-
KEY_HUE
public static final String KEY_HUE
- See Also:
- Constant Field Values
-
KEY_SATURATION
public static final String KEY_SATURATION
- See Also:
- Constant Field Values
-
KEY_BRIGHTNESS
public static final String KEY_BRIGHTNESS
- See Also:
- Constant Field Values
-
BLACK
public static final HSBType BLACK
-
WHITE
public static final HSBType WHITE
-
RED
public static final HSBType RED
-
GREEN
public static final HSBType GREEN
-
BLUE
public static final HSBType BLUE
-
hue
protected BigDecimal hue
-
saturation
protected BigDecimal saturation
-
-
Constructor Detail
-
HSBType
public HSBType()
-
HSBType
public HSBType(DecimalType h, PercentType s, PercentType b)
Constructs a HSBType instance with the given values- Parameters:
h
- the hue value in the range from 0 <= h < 360s
- the saturation as a percent valueb
- the brightness as a percent value
-
HSBType
public HSBType(String value)
Constructs a HSBType instance from a given string. The string has to be in comma-separated format with exactly three segments, which correspond to the hue, saturation and brightness values. where the hue value in the range from 0 <= h < 360 and the saturation and brightness are percent values.- Parameters:
value
- a stringified HSBType value in the format "hue,saturation,brightness"
-
-
Method Detail
-
fromRGB
public static HSBType fromRGB(int r, int g, int b)
Create HSB from RGB- Parameters:
r
- red 0-255g
- green 0-255b
- blue 0-255
-
fromXY
public static HSBType fromXY(float x, float y)
Returns a HSBType object representing the provided xy color values in CIE XY color model. Conversion from CIE XY color model to sRGB using D65 reference white Returned color is set to full brightness- Parameters:
x
- , y color information 0.0 - 1.0- Returns:
- new HSBType object representing the given CIE XY color, full brightness
-
getConstituents
public SortedMap<String,PrimitiveType> getConstituents()
Description copied from interface:ComplexType
Returns all constituents with their names as a sorted map- Specified by:
getConstituents
in interfaceComplexType
- Returns:
- all constituents with their names
-
getHue
public DecimalType getHue()
-
getSaturation
public PercentType getSaturation()
-
getBrightness
public PercentType getBrightness()
-
getRed
public PercentType getRed()
-
getGreen
public PercentType getGreen()
-
getBlue
public PercentType getBlue()
-
getRGB
public int getRGB()
Returns the RGB value representing the color in the default sRGB color model. (Bits 24-31 are alpha, 16-23 are red, 8-15 are green, 0-7 are blue).- Returns:
- the RGB value of the color in the default sRGB color model
-
toString
public String toString()
- Overrides:
toString
in classDecimalType
-
toFullString
public String toFullString()
Description copied from interface:Type
Get a string representation that contains the whole internal representation of the type.The returned string could be consumed by the static 'valueOf(String)' method of the respective type to build a new type that is equal to this type.
- Specified by:
toFullString
in interfaceType
- Overrides:
toFullString
in classDecimalType
- Returns:
- a full string representation of the type to be consumed by 'valueOf(String)'
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classDecimalType
-
equals
public boolean equals(@Nullable Object obj)
- Overrides:
equals
in classDecimalType
-
toRGB
public PercentType[] toRGB()
-
toXY
public PercentType[] toXY()
Returns the xyY values representing this object's color in CIE XY color model. Conversion from sRGB to CIE XY using D65 reference white xy pair contains color information Y represents relative luminance- Parameters:
HSBType
- color object- Returns:
- PercentType[x, y, Y] values in the CIE XY color model
-
-