Package rocks.xmpp.extensions.colors
Class ConsistentColor
- java.lang.Object
-
- rocks.xmpp.extensions.colors.ConsistentColor
-
public final class ConsistentColor extends Object
A consistent color which is generated from an input string such as a nickname or a bare JID. Consistent means, the resulting color is always the same for same input strings.Generating a Color
To generate a color pass either a nickname or the bare JID of the conversation as
inputto thegenerate(CharSequence)method. Generally, nick names should be preferred over bare JIDs.ConsistentColor color = ConsistentColor.generate(input); float red = color.getRed(); float green = color.getGreen(); float blue = color.getBlue();Corrections for Color Vision Deficiencies
In order to ensure accessibility to users with color vision deficiencies, you can generate corrected colors.
ConsistentColor color = ConsistentColor.generate(input, ConsistentColor.ColorVisionDeficiency.RED_GREEN_BLINDNESS);}Adapting the Color for specific Background Colors
To increase readability on colored background, you may want to adapt the color for background colors.
ConsistentColor color = ConsistentColor.generate(input); // Adaption for black background ConsistentColor adapted = color.adaptForBackground(0, 0, 0);Integration with JavaFX and AWT
ConsistentColor c = ConsistentColor.generate(input); javafx.scene.paint.Color color = javafx.scene.paint.Color.color(c.getRed(), c.getGreen(), c.getBlue()); java.awt.Color color = new java.awt.Color(c.getRed(), c.getGreen(), c.getBlue());The default Y value in the YCbCr color space is 0.732.
Note that this class overrides
equals(Object)andhashCode(): Two instances of this classes are equal, if their RGB values are equal.This class is immutable.
- See Also:
- XEP-0392: Consistent Color Generation
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classConsistentColor.ColorVisionDeficiencyRepresents a color vision deficiency, used to re-map the angle to map it away from ranges which can not be distinguished by people with the respective color vision deficiencies.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ConsistentColoradaptForBackground(float red, float green, float blue)Adapts the color for a background color.booleanequals(Object o)static ConsistentColorgenerate(CharSequence input)Generates a color for an input string.static ConsistentColorgenerate(CharSequence input, ConsistentColor.ColorVisionDeficiency colorVisionDeficiency)Generates a color for an input string and for a color vision deficiency.static ConsistentColorgenerate(CharSequence input, ConsistentColor.ColorVisionDeficiency colorVisionDeficiency, float y)Generates a color for an input string and for a color vision deficiency.floatgetBlue()Gets the blue component of the color, in the range0.0-1.0.floatgetGreen()Gets the green component of the color, in the range0.0-1.0.floatgetRed()Gets the red component of the color, in the range0.0-1.0.inthashCode()StringtoString()
-
-
-
Method Detail
-
generate
public static ConsistentColor generate(CharSequence input)
Generates a color for an input string.- Parameters:
input- The input string.- Returns:
- The color.
- See Also:
generate(CharSequence, ColorVisionDeficiency)
-
generate
public static ConsistentColor generate(CharSequence input, ConsistentColor.ColorVisionDeficiency colorVisionDeficiency)
Generates a color for an input string and for a color vision deficiency.- Parameters:
input- The input string.colorVisionDeficiency- The color vision deficiency.- Returns:
- The color.
- See Also:
generate(CharSequence, ColorVisionDeficiency, float)
-
generate
public static ConsistentColor generate(CharSequence input, ConsistentColor.ColorVisionDeficiency colorVisionDeficiency, float y)
Generates a color for an input string and for a color vision deficiency. This method also allow to pass other values than 0.732 for the Y value in the YCbCr color space.- Parameters:
input- The input string.colorVisionDeficiency- The color vision deficiency.y- The Y value in the YCbCr color space.- Returns:
- The color.
-
adaptForBackground
public final ConsistentColor adaptForBackground(float red, float green, float blue)
Adapts the color for a background color.- Parameters:
red- The red component of the background color in the range0.0-1.0.green- The green component of the background color in the range0.0-1.0.blue- The blue component of the background color in the range0.0-1.0.- Returns:
- The adapted color.
- Throws:
IllegalArgumentException- If the parameters are out of range.
-
getRed
public final float getRed()
Gets the red component of the color, in the range0.0-1.0.- Returns:
- The red component.
-
getGreen
public final float getGreen()
Gets the green component of the color, in the range0.0-1.0.- Returns:
- The green component.
-
getBlue
public final float getBlue()
Gets the blue component of the color, in the range0.0-1.0.- Returns:
- The blue component.
-
-