public class ColorGenerator
extends java.lang.Object
Example:
We have the range and colors: -1 (BLUE), 0 (WHITE) , +1 (YELLOW)
The value -0.5 is converted to a lighter blue and the value +0.5 is converted
to a ligther yellow. Values falling outside the min or max values are
assigned the endpoint colors. In this case, BLUE and YELLOW.
Modifier and Type | Field and Description |
---|---|
private int[] |
deltaMidMax
The difference of the RGB components of the mid and max
colors. [0] = red; [1] = green; [2] = blue
|
private int[] |
deltaMinMid
The difference of the RGB components of the min and mid
colors. [0] = red; [1] = green; [2] = blue
|
static float |
INVLN2
Constant holding the value of
1 / ln(2) . |
private boolean |
log |
private java.awt.Color |
maxColor |
private float |
maxValue |
private java.awt.Color |
midColor |
private float |
midValue |
private java.awt.Color |
minColor |
private float |
minValue |
private int[] |
offsetMid
The RGB components of the midpoint color. [0] = red; [1] = green; [2] = blue
|
private int[] |
offsetMin
The RGB components of the min color. [0] = red; [1] = green; [2] = blue
|
private float |
rangeMidMax
The inverted difference between the max and mid values:
1 / (maxValue - midValue)
|
private float |
rangeMinMid
The inverted difference between the mid and min values:
1 / (midValue - minValue)
|
Constructor and Description |
---|
ColorGenerator(java.awt.Color minColor,
java.awt.Color midColor,
java.awt.Color maxColor,
float minValue,
float midValue,
float maxValue,
boolean log)
Create a new color generator.
|
Modifier and Type | Method and Description |
---|---|
static java.awt.Color |
fromHex(java.lang.String hexRGB)
Convert a hexadecimal color string such as one used in HTML
to a Color object.
|
java.awt.Color |
getColor(float value)
Get the color for the value.
|
static java.lang.String |
toHex(java.awt.Color color)
Generate a hex color string from a Color object.
|
public static final float INVLN2
1 / ln(2)
. It is used
to calculate the two-based logarithm of values using the formula:
log2(x) = ln(x) / ln(2)
private java.awt.Color minColor
private java.awt.Color midColor
private java.awt.Color maxColor
private float minValue
private float midValue
private float maxValue
private boolean log
private final int[] offsetMin
private final int[] offsetMid
private final int[] deltaMinMid
private final int[] deltaMidMax
private final float rangeMinMid
private final float rangeMidMax
public ColorGenerator(java.awt.Color minColor, java.awt.Color midColor, java.awt.Color maxColor, float minValue, float midValue, float maxValue, boolean log)
minColor
- The color for the minimum endpointmidColor
- The color for the midpointmaxColor
- The color for the maximum endpointminValue
- The value for the minimum endpointmidValue
- The value for the midpointmaxValue
- The value for the maximum endpointlog
- If values should be logarithmised before beeing assigned a
color or not. Note the values in this constructor are not affected by this
setting.InvalidDataException
- If not the minValue <= midValue <= maxValuepublic static java.awt.Color fromHex(java.lang.String hexRGB)
hexRGB
- The hexadecimal color stringInvalidDataException
- If the string cannot be convertedpublic static java.lang.String toHex(java.awt.Color color)
color
- The color objectpublic java.awt.Color getColor(float value)
If the value is lower than the min endpoint the min endpoint color is returned. If the value is higher than the max endpoint the max endpoint color is returned. Otherwise a new color is calculated based on the difference between the value and the given points.
value
- The value