ilog.views.util
Class IlvColorUtil

java.lang.Object
  extended by ilog.views.util.IlvColorUtil

public class IlvColorUtil
extends Object

The IlvColorUtil class consists of static methods that are of general use when working with colors. This class defines a color map that consists of keyword/color pairs. These colors correspond to the predefined color names that are recognized by the SVG specification; see http://www.w3.org/TR/SVG/types.html#ColorKeywords.

The color names defined in SVG take over the ones in Java. For instance, gray, green, and orange are not the same in the two color spaces. It is possible to control this behavior through the (@link javaNamesFirst #setJavaNamesFirst} method.

Since:
JViews 5.5

Constructor Summary
protected IlvColorUtil()
          Singleton class.
 
Method Summary
static void addColor(String name, Color color)
          Adds a new named color to the color map.
static Color brighter(Color c)
          Returns a brighter version of the specified color.
static Color darker(Color c)
          Returns a darker version of the specified color.
static float getBrightness(Color c)
          Returns the brightness of the specified color.
static Color getColor(String colorName)
          Returns a named color from the color map.
static Map getColorMap()
          Returns the color map.
static float getHue(Color c)
          Returns the hue of the specified color.
static float getLuminance(Color color)
          Returns the luminance of the specified color.
static Color getRandomColor()
          Creates a random color.
static float getSaturation(Color c)
          Returns the saturation of the specified color.
static boolean isJavaNamesFirst()
          Returns whether Java color names take over SVG color names.
static Color setAlpha(Color c, float alpha)
          Returns a color with a modified alpha value.
static Color setBrightness(Color c, float brightness)
          Returns a color with a modified brightness.
static Color setHue(Color c, float hue)
          Returns a color with a modified hue.
static void setJavaNamesFirst(boolean val)
          Specifies whether Java colors take over the SVG color definition.
static Color setSaturation(Color c, float saturation)
          Returns a color with a modified saturation.
static Color slightlyBrighter(Color c)
          Returns a slightly brighter version of the specified color.
static Color slightlyDarker(Color c)
          Returns a slightly darker version of the specified color.
static Color toColor(String text)
          Returns the color corresponding to the specified string.
static String toHumanReadableString(Color c)
          Returns a string representation of the specified color.
static String toString(Color c)
          Returns a string representation of the specified color.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IlvColorUtil

protected IlvColorUtil()
Singleton class.

Method Detail

addColor

public static void addColor(String name,
                            Color color)
Adds a new named color to the color map.

Parameters:
name - The name of the color.
color - The color.

getColorMap

public static Map getColorMap()
Returns the color map.

Returns:
An unmodifiable version of the internal color map. Each entry of the color map is made of a string key that represents the color name and of the color itself.
See Also:
addColor(java.lang.String, java.awt.Color)

setJavaNamesFirst

public static void setJavaNamesFirst(boolean val)
Specifies whether Java colors take over the SVG color definition.

Parameters:
val - The boolean specification.

isJavaNamesFirst

public static boolean isJavaNamesFirst()
Returns whether Java color names take over SVG color names.

See Also:
setJavaNamesFirst(boolean)

getColor

public static final Color getColor(String colorName)
Returns a named color from the color map.

Parameters:
colorName - The name of the color.
Returns:
The color associated with the specified name, or null if the name is not registered in the color map.

getRandomColor

public static Color getRandomColor()
Creates a random color.


setAlpha

public static Color setAlpha(Color c,
                             float alpha)
Returns a color with a modified alpha value.

Parameters:
c - The original color.
alpha - The new alpha value, in the range [0 .. 1].
Returns:
A new color with the modified alpha value.

getBrightness

public static float getBrightness(Color c)
Returns the brightness of the specified color.

Note: This function returns the maximum of the three components (red, green, blue), as a floating-point value between 0 and 1. It does not reflect the brightness at it appears to the human eye; for this, see getLuminance(java.awt.Color).

Parameters:
c - The color.
Returns:
The brightness of the color.

setBrightness

public static Color setBrightness(Color c,
                                  float brightness)
Returns a color with a modified brightness.

Parameters:
c - The original color.
brightness - The new brightness value, in the range [0 .. 1].
Returns:
A new color with the modified brightness.

getSaturation

public static float getSaturation(Color c)
Returns the saturation of the specified color.

Parameters:
c - The color.
Returns:
The saturation of the color.

setSaturation

public static Color setSaturation(Color c,
                                  float saturation)
Returns a color with a modified saturation.

Parameters:
c - The original color.
saturation - The new saturation value, in the range [0 .. 1].
Returns:
A new color with the modified saturation.

getHue

public static float getHue(Color c)
Returns the hue of the specified color.

Parameters:
c - The color.
Returns:
The hue of the color.

setHue

public static Color setHue(Color c,
                           float hue)
Returns a color with a modified hue.

Parameters:
c - The original color.
hue - The new hue value, in the range [0 .. 1].
Returns:
A new color with the modified hue.

brighter

public static Color brighter(Color c)
Returns a brighter version of the specified color.

Parameters:
c - The original color.
Returns:
A brighter version of the specified color.

slightlyBrighter

public static Color slightlyBrighter(Color c)
Returns a slightly brighter version of the specified color.

Parameters:
c - The original color.
Returns:
A slightly brighter version of the specified color.

darker

public static Color darker(Color c)
Returns a darker version of the specified color.

Parameters:
c - The original color.
Returns:
A darker version of the specified color.

slightlyDarker

public static Color slightlyDarker(Color c)
Returns a slightly darker version of the specified color.

Parameters:
c - The original color.
Returns:
A slightly darker version of the specified color.

getLuminance

public static float getLuminance(Color color)
Returns the luminance of the specified color. This is the brightness of the color, as it appears to the human eye.

This function is suitable for color to grayscale conversion.

Returns:
A floating-point value between 0 and 1.
Since:
JViews 8.0
See Also:
getBrightness(java.awt.Color)

toColor

public static Color toColor(String text)
                     throws IllegalArgumentException
Returns the color corresponding to the specified string.

The specified string can have the following forms:

Parameters:
text - The string to parse.
Returns:
The color corresponding to the specified string.
Throws:
IllegalArgumentException - The specified string cannot be parsed.
See Also:
toString(java.awt.Color)

toHumanReadableString

public static String toHumanReadableString(Color c)
Returns a string representation of the specified color.

Parameters:
c - The considered color.
Returns:
the color name when found, otherwise RGB triple, or hexadecimal form when alpha is > 0
Since:
JViews 6.5
See Also:
toColor(java.lang.String)

toString

public static String toString(Color c)
Returns a string representation of the specified color.

Parameters:
c - The considered color.
Returns:
The string representation of the color, in hexadecimal form.
See Also:
toColor(java.lang.String)


Copyright © 1996-2007 ILOG S.A. All rights reserved.   Documentation homepage.   . All Rights Reserved.