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
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, Andrew Fiddian-Green - closeTo (copied from binding)
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final HSBType
static final HSBType
static final HSBType
protected BigDecimal
static final String
static final String
static final String
static final HSBType
protected BigDecimal
static final HSBType
Fields inherited from class org.openhab.core.library.types.PercentType
HUNDRED, ZERO
Fields inherited from class org.openhab.core.library.types.DecimalType
BIG_DECIMAL_HUNDRED, value
-
Constructor Summary
ConstructorDescriptionHSBType()
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
Modifier and TypeMethodDescription<T extends State>
@Nullable TConvert thisState
's value into another typeboolean
Helper method for checking if two HSBType colors are close to each other.boolean
Formats the value of this type according to a pattern (seeFormatter
).static HSBType
fromRGB
(int r, int g, int b) Create HSB from RGB.static HSBType
fromXY
(float x, float y) Deprecated.getBlue()
Deprecated.UseColorUtil.hsbToRgb(HSBType)
insteadReturns all constituents with their names as a sorted mapgetGreen()
Deprecated.UseColorUtil.hsbToRgb(HSBType)
insteadgetHue()
getRed()
Deprecated.UseColorUtil.hsbToRgb(HSBType)
insteadint
getRGB()
Deprecated.UseColorUtil.hsbTosRgb(HSBType)
instead.int
hashCode()
Get a string representation that contains the whole internal representation of the type.toRGB()
Deprecated.toString()
toXY()
Returns the xyY values representing this object's color in CIE XY color model.static HSBType
Methods inherited from class org.openhab.core.library.types.DecimalType
compareTo, defaultConversion, doubleValue, floatValue, intValue, longValue, toBigDecimal
Methods inherited from class java.lang.Number
byteValue, shortValue
-
Field Details
-
KEY_HUE
- See Also:
-
KEY_SATURATION
- See Also:
-
KEY_BRIGHTNESS
- See Also:
-
BLACK
-
WHITE
-
RED
-
GREEN
-
BLUE
-
hue
-
saturation
-
-
Constructor Details
-
HSBType
public HSBType() -
HSBType
Constructs a HSBType instance with the given values- Parameters:
h
- the hue value in the range from0 <= h < 360
s
- the saturation as a percent valueb
- the brightness as a percent value
-
HSBType
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 from0 <= h < 360
and the saturation and brightness are percent values.- Parameters:
value
- a stringified HSBType value in the format "hue,saturation,brightness"
-
-
Method Details
-
valueOf
-
fromRGB
Create HSB from RGB. See alsoColorUtil.rgbToHsb(int[])
.- Parameters:
r
- red 0-255g
- green 0-255b
- blue 0-255- Throws:
IllegalArgumentException
- when color values exceed allowed range
-
fromXY
Deprecated.UseColorUtil.xyToHsb(double[])
orColorUtil.xyToHsb(double[], ColorUtil.Gamut)
instead. 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
- Throws:
IllegalArgumentException
- when input array has wrong size or exceeds allowed value range
-
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
-
getSaturation
-
getBrightness
-
getRed
Deprecated.UseColorUtil.hsbToRgb(HSBType)
instead -
getGreen
Deprecated.UseColorUtil.hsbToRgb(HSBType)
instead -
getBlue
Deprecated.UseColorUtil.hsbToRgb(HSBType)
instead -
getRGB
Deprecated.UseColorUtil.hsbTosRgb(HSBType)
instead. 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
- Overrides:
toString
in classDecimalType
-
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)'
-
format
Description copied from interface:Type
Formats the value of this type according to a pattern (seeFormatter
).- Specified by:
format
in interfaceType
- Overrides:
format
in classDecimalType
- Parameters:
pattern
- the pattern to use- Returns:
- the formatted string
-
hashCode
public int hashCode()- Overrides:
hashCode
in classDecimalType
-
equals
- Overrides:
equals
in classDecimalType
-
toRGB
Deprecated. -
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- Returns:
- PercentType[x, y, Y] values in the CIE XY color model
-
as
Description copied from interface:State
Convert thisState
's value into another type -
closeTo
Helper method for checking if two HSBType colors are close to each other. A maximum deviation is specifid in percent.- Parameters:
other
- an HSBType containing the other color.maxPercentage
- the maximum allowed difference in percent (range 0.0..1.0).- Throws:
IllegalArgumentException
- if percentage is out of range.
-
ColorUtil.xyToHsb(double[])
orColorUtil.xyToHsb(double[], ColorUtil.Gamut)
instead.