Class 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.
Kai Kreuzer - Initial contribution, Chris Jackson - Added fromRGB, Andrew Fiddian-Green - closeTo (copied from binding)
See Also:
  • Field Details

  • Constructor Details

    • HSBType

      public HSBType()
    • HSBType

      public HSBType(DecimalType h, PercentType s, PercentType b)
      Constructs a HSBType instance with the given values
      h - the hue value in the range from 0 <= h < 360
      s - the saturation as a percent value
      b - 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.
      value - a stringified HSBType value in the format "hue,saturation,brightness"
  • Method Details

    • valueOf

      public static HSBType valueOf(String value)
    • fromRGB

      public static HSBType fromRGB(int r, int g, int b) throws IllegalArgumentException
      Create HSB from RGB. See also ColorUtil.rgbToHsb(int[]).
      r - red 0-255
      g - green 0-255
      b - blue 0-255
      IllegalArgumentException - when color values exceed allowed range
    • fromXY

      @Deprecated public static HSBType fromXY(float x, float y) throws IllegalArgumentException
      Use ColorUtil.xyToHsb(double[]) or ColorUtil.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
      x - , y color information 0.0 - 1.0
      new HSBType object representing the given CIE XY color, full brightness
      IllegalArgumentException - when input array has wrong size or exceeds allowed value range
    • 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 interface ComplexType
      all constituents with their names
    • getHue

      public DecimalType getHue()
    • getSaturation

      public PercentType getSaturation()
    • getBrightness

      public PercentType getBrightness()
    • getRed

      @Deprecated public PercentType getRed()
    • getGreen

      @Deprecated public PercentType getGreen()
    • getBlue

      @Deprecated public PercentType getBlue()
    • getRGB

      @Deprecated public int getRGB()
      Use ColorUtil.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).
      the RGB value of the color in the default sRGB color model
    • toString

      public String toString()
      toString in class DecimalType
    • 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 interface Type
      toFullString in class DecimalType
      a full string representation of the type to be consumed by 'valueOf(String)'
    • format

      public String format(String pattern)
      Description copied from interface: Type
      Formats the value of this type according to a pattern (see Formatter).
      Specified by:
      format in interface Type
      format in class DecimalType
      pattern - the pattern to use
      the formatted string
    • hashCode

      public int hashCode()
      hashCode in class DecimalType
    • equals

      public boolean equals(@Nullable Object obj)
      equals in class DecimalType
    • toRGB

      @Deprecated 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
      PercentType[x, y, Y] values in the CIE XY color model
    • as

      public <T extends State> @Nullable T as(@Nullable Class<T> target)
      Description copied from interface: State
      Convert this State's value into another type
      Specified by:
      as in interface State
      as in class PercentType
      target - the desired State type
      the State's value in the given type's representation, or null if the conversion was not possible
    • closeTo

      public boolean closeTo(HSBType other, double maxPercentage) throws IllegalArgumentException
      Helper method for checking if two HSBType colors are close to each other. A maximum deviation is specifid in percent.
      other - an HSBType containing the other color.
      maxPercentage - the maximum allowed difference in percent (range 0.0..1.0).
      IllegalArgumentException - if percentage is out of range.