Package resources

Class Settings.Colour

  • All Implemented Interfaces:
    java.awt.Paint, java.awt.Transparency, java.io.Serializable
    Enclosing class:
    Settings

    public static class Settings.Colour
    extends java.awt.Color
    A Color subclass that is specialized to convert more easily to and from setting values. This class is identical to Color except that it provides an additional constructor that takes a setting value, and its toString() method returns a setting value.
    Since:
    2.1
    See Also:
    Serialized Form
    • Field Summary

      • Fields inherited from class java.awt.Color

        black, BLACK, blue, BLUE, cyan, CYAN, DARK_GRAY, darkGray, gray, GRAY, green, GREEN, LIGHT_GRAY, lightGray, magenta, MAGENTA, orange, ORANGE, pink, PINK, red, RED, white, WHITE, yellow, YELLOW
      • Fields inherited from interface java.awt.Transparency

        BITMASK, OPAQUE, TRANSLUCENT
    • Constructor Summary

      Constructors 
      Constructor Description
      Colour​(double argb)
      Creates a colour from a JavaScript Number object.
      Colour​(double argb, boolean hasAlpha)
      Creates a colour from a JavaScript Number object.
      Colour​(float r, float g, float b)
      Creates an opaque sRGB colour with the specified red, green, and blue values in the range (0.0 - 1.0).
      Colour​(float r, float g, float b, float a)
      Creates an sRGB colour with the specified red, green, blue, and alpha values in the range (0.0 - 1.0).
      Colour​(int rgb)
      Creates an opaque sRGB colour with the specified combined RGB value consisting of the red component in bits 16-23, the green component in bits 8-15, and the blue component in bits 0-7.
      Colour​(int argb, boolean hasAlpha)
      Creates an sRGB colour with the specified combined ARGB value 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.
      Colour​(int r, int g, int b)
      Creates an sRGB colour with the specified red, green, blue, and alpha values in the range (0 - 255).
      Colour​(int r, int g, int b, int a)
      Creates an sRGB colour with the specified red, green, blue, and alpha values in the range (0 - 255).
      Colour​(java.awt.color.ColorSpace cspace, float[] components, float alpha)
      Creates a colour in the specified ColorSpace with the colour components specified in the float array and the specified alpha.
      Colour​(java.lang.String settingValue)
      Creates a colour from a setting value.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Settings.Colour derive​(float newAlpha)
      Returns a version of this colour with a different alpha value.
      Settings.Colour derive​(float hueShift, float satFactor, float briFactor)
      Returns a derived colour that shifts the hue and scales the brightness and saturation of this colour.
      static Settings.Colour from​(java.awt.Color c)
      Given a standard Color object, converts it to a Colour.
      Settings.Colour mix​(java.awt.Color with)
      Mixes this colour with an equal amount of another colour.
      Settings.Colour mix​(java.awt.Color with, float thisAmount)
      Mixes this colour with another colour.
      java.lang.String toString()
      Returns a string suitable for storing this colour as a setting value.
      • Methods inherited from class java.awt.Color

        brighter, createContext, darker, decode, equals, getAlpha, getBlue, getColor, getColor, getColor, getColorComponents, getColorComponents, getColorSpace, getComponents, getComponents, getGreen, getHSBColor, getRed, getRGB, getRGBColorComponents, getRGBComponents, getTransparency, hashCode, HSBtoRGB, RGBtoHSB
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Colour

        public Colour​(java.lang.String settingValue)
        Creates a colour from a setting value.
        Parameters:
        settingValue - a hex digit string encoding the colour value in RRGGBB or AARRGGBB format
        See Also:
        toString(), Settings.colour(java.lang.String)
      • Colour

        public Colour​(java.awt.color.ColorSpace cspace,
                      float[] components,
                      float alpha)
        Creates a colour in the specified ColorSpace with the colour components specified in the float array and the specified alpha. The number of components is determined by the type of the ColorSpace. For example, RGB requires 3 components, but CMYK requires 4 components.
        Parameters:
        cspace - the ColorSpace to be used to interpret the components
        components - an arbitrary number of color components that is compatible with the ColorSpace
        alpha - alpha value
        Throws:
        java.lang.IllegalArgumentException - if any of the values in the components array or alpha is outside of the range 0.0 to 1.0
        See Also:
        Color.getComponents(float[]), Color.getColorComponents(float[])
      • Colour

        public Colour​(float r,
                      float g,
                      float b,
                      float a)
        Creates an sRGB colour with the specified red, green, blue, and alpha values in the range (0.0 - 1.0). The actual colour used in rendering depends on finding the best match given the colour space available for a particular output device.
        Parameters:
        r - the red component
        g - the green component
        b - the blue component
        a - the alpha component
        Throws:
        java.lang.IllegalArgumentException - if r, g b or a are outside of the range 0.0 to 1.0, inclusive
        See Also:
        Color.getRed(), Color.getGreen(), Color.getBlue(), Color.getAlpha(), Color.getRGB()
      • Colour

        public Colour​(float r,
                      float g,
                      float b)
        Creates an opaque sRGB colour with the specified red, green, and blue values in the range (0.0 - 1.0). Alpha is defaulted to 1.0. The actual colour used in rendering depends on finding the best match given the color space available for a particular output device.
        Parameters:
        r - the red component
        g - the green component
        b - the blue component
        Throws:
        java.lang.IllegalArgumentException - if r, g or b are outside of the range 0.0 to 1.0, inclusive
        See Also:
        Color.getRed(), Color.getGreen(), Color.getBlue(), Color.getRGB()
      • Colour

        public Colour​(int argb,
                      boolean hasAlpha)
        Creates an sRGB colour with the specified combined ARGB value 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 the hasAlpha argument is false, alpha is defaulted to 255.
        Parameters:
        argb - the combined ARGB components
        hasAlpha - true if the alpha bits are valid; false otherwise
        See Also:
        ColorModel.getRGBdefault(), Color.getRed(), Color.getGreen(), Color.getBlue(), Color.getAlpha(), Color.getRGB()
      • Colour

        public Colour​(int rgb)
        Creates an opaque sRGB colour with the specified combined RGB value 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 colour used in rendering depends on finding the best match given the colour space available for a particular output device. Alpha is defaulted to 255.
        Parameters:
        rgb - the combined RGB components
        See Also:
        ColorModel.getRGBdefault(), Color.getRed(), Color.getGreen(), Color.getBlue(), Color.getRGB()
      • Colour

        public Colour​(int r,
                      int g,
                      int b,
                      int a)
        Creates an sRGB colour with the specified red, green, blue, and alpha values in the range (0 - 255).
        Parameters:
        r - the red component
        g - the green component
        b - the blue component
        a - the alpha component
        Throws:
        java.lang.IllegalArgumentException - if r, g, b or a are outside of the range 0 to 255, inclusive
        See Also:
        Color.getRed(), Color.getGreen(), Color.getBlue(), Color.getAlpha(), Color.getRGB()
      • Colour

        public Colour​(int r,
                      int g,
                      int b)
        Creates an sRGB colour with the specified red, green, blue, and alpha values in the range (0 - 255).
        Parameters:
        r - the red component
        g - the green component
        b - the blue component
        Throws:
        java.lang.IllegalArgumentException - if r, g, b or a are outside of the range 0 to 255, inclusive
        See Also:
        Color.getRed(), Color.getGreen(), Color.getBlue(), Color.getAlpha(), Color.getRGB()
      • Colour

        public Colour​(double argb)
        Creates a colour from a JavaScript Number object. This is equivalent to Colour(int rgb) for script code.
        Parameters:
        argb - the combined RGB components
      • Colour

        public Colour​(double argb,
                      boolean hasAlpha)
        Creates a colour from a JavaScript Number object. This is equivalent to Colour(int argb, boolean translucent) for script code.
        Parameters:
        argb - the combined RGB components
        hasAlpha - true if the alpha bits are valid; false otherwise
    • Method Detail

      • from

        public static Settings.Colour from​(java.awt.Color c)
        Given a standard Color object, converts it to a Colour.
        Parameters:
        c - the color to convert
        Returns:
        the original object if it is already a Colour, otherwise an equivalent Colour; returns null if passed null
      • mix

        public Settings.Colour mix​(java.awt.Color with)
        Mixes this colour with an equal amount of another colour.
        Parameters:
        with - the colour to mix this colour with
        Returns:
        the mixed colour
        See Also:
        mix(java.awt.Color, float)
      • mix

        public Settings.Colour mix​(java.awt.Color with,
                                   float thisAmount)
        Mixes this colour with another colour. The colours are mixed in a linear RGB (not sRGB) space for results that more closely match human perception. Only the colours are mixed; the new colour will retain the alpha value of this colour.
        Parameters:
        with - the colour to mix this colour with
        thisAmount - the proportion of this colour to include, from 0f-1f
        Returns:
        the mixed colour
      • derive

        public Settings.Colour derive​(float newAlpha)
        Returns a version of this colour with a different alpha value.
        Parameters:
        newAlpha - the new alpha value, from 0 to 1
        Returns:
        the adjusted colour
      • derive

        public Settings.Colour derive​(float hueShift,
                                      float satFactor,
                                      float briFactor)
        Returns a derived colour that shifts the hue and scales the brightness and saturation of this colour. The result will have the same alpha value as this colour.
        Parameters:
        hueShift - the angle to shift the hue by, in rotations
        satFactor - the factor to apply to the saturation
        briFactor - the factor to apply to the brightness
        Returns:
        the derived colour
      • toString

        public java.lang.String toString()
        Returns a string suitable for storing this colour as a setting value.
        Overrides:
        toString in class java.awt.Color
        Returns:
        a string of either 6 or 8 hexadecimal digits (depending on whether the colour is translucent, with alpha < 255), in RRGGBB or AARRGGBB order