|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.basedb.util.ColorGenerator
public class ColorGenerator
This class is used to generate colors for numerical values. Given a numeric range mith a start, mid and max value and one color for each of these values you can create new colors for values within the specified range.
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.
Field Summary | |
---|---|
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 Color |
maxColor
|
private float |
maxValue
|
private Color |
midColor
|
private float |
midValue
|
private 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 Summary | |
---|---|
ColorGenerator(Color minColor,
Color midColor,
Color maxColor,
float minValue,
float midValue,
float maxValue,
boolean log)
Create a new color generator. |
Method Summary | |
---|---|
static Color |
fromHex(String hexRGB)
Convert a hexadecimal color string such as one used in HTML to a Color object. |
Color |
getColor(float value)
Get the color for the value. |
static String |
toHex(Color color)
Generate a hex color string from a Color object. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
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 Color minColor
private Color midColor
private 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
Constructor Detail |
---|
public ColorGenerator(Color minColor, Color midColor, 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 <= maxValueMethod Detail |
---|
public static Color fromHex(String hexRGB)
hexRGB
- The hexadecimal color string
InvalidDataException
- If the string cannot be convertedpublic static String toHex(Color color)
color
- The color object
public 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
|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |