ch.aplu.util
Class X11Color

java.lang.Object
  extended by java.awt.Color
      extended by ch.aplu.util.X11Color
All Implemented Interfaces:
java.awt.Paint, java.awt.Transparency, java.io.Serializable

public class X11Color
extends java.awt.Color

This class provides the mapping of X11 colors names (in string notation) to RGB colors represented the java.awt.Color class. See

http://en.wikipedia.org/wiki/X11_color_names

for the names and a view of the colors.

See Also:
Serialized Form

Field Summary
static java.awt.Color[] RAINBOW_COLORS
           
 
Fields inherited from class java.awt.Color
black, BLACK, blue, BLUE, cyan, CYAN, DARK_GRAY, darkGray, gray, GRAY, green, GREEN, LIGHT_GRAY, lightGray, magenta, MAGENTA, orange, ORANGE, pink, PINK, red, RED, white, WHITE, yellow, YELLOW
 
Fields inherited from interface java.awt.Transparency
BITMASK, OPAQUE, TRANSLUCENT
 
Constructor Summary
X11Color(java.lang.String colorStr)
          Creates a color with given X11 color name.
 
Method Summary
static java.lang.String[] getColorNames()
          Returns the implemented X11 color names.
static java.awt.Color getRandomColor()
          Returns a random color from the X11 color set.
static java.lang.String getRandomColorStr()
          Returns a random X11 color from the X11 color set.
static java.awt.Color toColor(java.lang.String colorStr)
          Returns the color reference attributed to the given X11 color name.
static java.lang.String toColorStr(java.awt.Color color)
          Returns the X11 color name attributed to the given color.
static java.awt.Color wavelengthToColor(int wavelength)
          Returns the color corresponding to the spectral wavelength.
 
Methods inherited from class java.awt.Color
brighter, createContext, darker, decode, equals, getAlpha, getBlue, getColor, getColor, getColor, getColorComponents, getColorComponents, getColorSpace, getComponents, getComponents, getGreen, getHSBColor, getRed, getRGB, getRGBColorComponents, getRGBComponents, getTransparency, hashCode, HSBtoRGB, RGBtoHSB, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

RAINBOW_COLORS

public static java.awt.Color[] RAINBOW_COLORS
Constructor Detail

X11Color

public X11Color(java.lang.String colorStr)
Creates a color with given X11 color name. If the given color name is not part of the implemented color names, Color.black is created.

Parameters:
colorStr - the X11 color name (case insensitive)
Method Detail

getColorNames

public static java.lang.String[] getColorNames()
Returns the implemented X11 color names.

Returns:
an alphabetically sorted string array with all implemented color names

toColor

public static java.awt.Color toColor(java.lang.String colorStr)
Returns the color reference attributed to the given X11 color name.

Parameters:
colorStr - the X11 color name (case insensitive)
Returns:
the color reference or null, if the given color name is not part of the implemented color names

toColorStr

public static java.lang.String toColorStr(java.awt.Color color)
Returns the X11 color name attributed to the given color. The name is lowercase and has no blanks. Colors containing 'grey' are returned with 'gray'.

Parameters:
color - the color to search for the X11 name
Returns:
the X11 color name or null, if the given color is not part of the implemented X11 colors

getRandomColor

public static java.awt.Color getRandomColor()
Returns a random color from the X11 color set. Additional color names terminating with a number are excluded.

Returns:
a random X11 color

getRandomColorStr

public static java.lang.String getRandomColorStr()
Returns a random X11 color from the X11 color set. Additional color names terminating with a number are excluded.

Returns:
a random X11 color name

wavelengthToColor

public static java.awt.Color wavelengthToColor(int wavelength)
Returns the color corresponding to the spectral wavelength.

Parameters:
wavelength - the wavelength in nm (between 380nm and 780nm).
Returns:
the RGB color