Package resources
Class Settings.Colour
- java.lang.Object
-
- java.awt.Color
-
- resources.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
AColor
subclass that is specialized to convert more easily to and from setting values. This class is identical toColor
except that it provides an additional constructor that takes a setting value, and itstoString()
method returns a setting value.- Since:
- 2.1
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Colour(double argb)
Creates a colour from a JavaScriptNumber
object.Colour(double argb, boolean hasAlpha)
Creates a colour from a JavaScriptNumber
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 specifiedColorSpace
with the colour components specified in thefloat
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 standardColor
object, converts it to aColour
.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
-
-
-
-
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 specifiedColorSpace
with the colour components specified in thefloat
array and the specified alpha. The number of components is determined by the type of theColorSpace
. For example, RGB requires 3 components, but CMYK requires 4 components.- Parameters:
cspace
- theColorSpace
to be used to interpret the componentscomponents
- an arbitrary number of color components that is compatible with theColorSpace
alpha
- alpha value- Throws:
java.lang.IllegalArgumentException
- if any of the values in thecomponents
array oralpha
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 componentg
- the green componentb
- the blue componenta
- the alpha component- Throws:
java.lang.IllegalArgumentException
- ifr
,g
b
ora
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 componentg
- the green componentb
- the blue component- Throws:
java.lang.IllegalArgumentException
- ifr
,g
orb
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 thehasAlpha
argument isfalse
, alpha is defaulted to 255.- Parameters:
argb
- the combined ARGB componentshasAlpha
-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 componentg
- the green componentb
- the blue componenta
- the alpha component- Throws:
java.lang.IllegalArgumentException
- ifr
,g
,b
ora
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 componentg
- the green componentb
- the blue component- Throws:
java.lang.IllegalArgumentException
- ifr
,g
,b
ora
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 JavaScriptNumber
object. This is equivalent toColour(int rgb)
for script code.- Parameters:
argb
- the combined RGB components
-
Colour
public Colour(double argb, boolean hasAlpha)
Creates a colour from a JavaScriptNumber
object. This is equivalent toColour(int argb, boolean translucent)
for script code.- Parameters:
argb
- the combined RGB componentshasAlpha
-true
if the alpha bits are valid;false
otherwise
-
-
Method Detail
-
from
public static Settings.Colour from(java.awt.Color c)
Given a standardColor
object, converts it to aColour
.- Parameters:
c
- the color to convert- Returns:
- the original object if it is already a
Colour
, otherwise an equivalentColour
; 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 withthisAmount
- 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 rotationssatFactor
- the factor to apply to the saturationbriFactor
- 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 classjava.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
-
-