public final class ConsistentColor
extends java.lang.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.
input
to the generate(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();
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);}
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);
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)
and hashCode()
: Two instances of this classes are equal, if their RGB values are equal.
This class is immutable.
Modifier and Type | Class and Description |
---|---|
static class |
ConsistentColor.ColorVisionDeficiency
Represents 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.
|
Modifier and Type | Method and Description |
---|---|
ConsistentColor |
adaptForBackground(float red,
float green,
float blue)
Adapts the color for a background color.
|
boolean |
equals(java.lang.Object o) |
static ConsistentColor |
generate(java.lang.CharSequence input)
Generates a color for an input string.
|
static ConsistentColor |
generate(java.lang.CharSequence input,
ConsistentColor.ColorVisionDeficiency colorVisionDeficiency)
Generates a color for an input string and for a color vision deficiency.
|
static ConsistentColor |
generate(java.lang.CharSequence input,
ConsistentColor.ColorVisionDeficiency colorVisionDeficiency,
float y)
Generates a color for an input string and for a color vision deficiency.
|
float |
getBlue()
Gets the blue component of the color, in the range
0.0-1.0 . |
float |
getGreen()
Gets the green component of the color, in the range
0.0-1.0 . |
float |
getRed()
Gets the red component of the color, in the range
0.0-1.0 . |
int |
hashCode() |
java.lang.String |
toString() |
public static ConsistentColor generate(java.lang.CharSequence input)
Generates a color for an input string.
input
- The input string.generate(CharSequence, ColorVisionDeficiency)
public static ConsistentColor generate(java.lang.CharSequence input, ConsistentColor.ColorVisionDeficiency colorVisionDeficiency)
Generates a color for an input string and for a color vision deficiency.
input
- The input string.colorVisionDeficiency
- The color vision deficiency.generate(CharSequence, ColorVisionDeficiency, float)
public static ConsistentColor generate(java.lang.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.
input
- The input string.colorVisionDeficiency
- The color vision deficiency.y
- The Y value in the YCbCr color space.public final ConsistentColor adaptForBackground(float red, float green, float blue)
Adapts the color for a background color.
red
- The red component of the background color in the range 0.0-1.0
.green
- The green component of the background color in the range 0.0-1.0
.blue
- The blue component of the background color in the range 0.0-1.0
.java.lang.IllegalArgumentException
- If the parameters are out of range.public final float getRed()
Gets the red component of the color, in the range 0.0-1.0
.
public final float getGreen()
Gets the green component of the color, in the range 0.0-1.0
.
public final float getBlue()
Gets the blue component of the color, in the range 0.0-1.0
.
public final boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public final int hashCode()
hashCode
in class java.lang.Object
public final java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2014–2019 XMPP.rocks. All rights reserved.