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.
Author:
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
      Parameters:
      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.
      Parameters:
      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[]).
      Parameters:
      r - red 0-255
      g - green 0-255
      b - blue 0-255
      Throws:
      IllegalArgumentException - when color values exceed allowed range
    • fromXY

      @Deprecated public static HSBType fromXY(float x, float y) throws IllegalArgumentException
      Deprecated.
      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
      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

      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
      Returns:
      all constituents with their names
    • getHue

      public DecimalType getHue()
    • getSaturation

      public PercentType getSaturation()
    • getBrightness

      public PercentType getBrightness()
    • getRed

      @Deprecated public PercentType getRed()
      Deprecated.
    • getGreen

      @Deprecated public PercentType getGreen()
      Deprecated.
    • getBlue

      @Deprecated public PercentType getBlue()
      Deprecated.
    • getRGB

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

      public String toString()
      Overrides:
      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
      Overrides:
      toFullString in class DecimalType
      Returns:
      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
      Overrides:
      format in class DecimalType
      Parameters:
      pattern - the pattern to use
      Returns:
      the formatted string
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class DecimalType
    • equals

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

      @Deprecated public PercentType[] toRGB()
      Deprecated.
    • 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
      Returns:
      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
      Overrides:
      as in class PercentType
      Parameters:
      target - the desired State type
      Returns:
      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.
      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.