org.opengts.util
Class ColorTools

java.lang.Object
  extended by org.opengts.util.ColorTools

public class ColorTools
extends java.lang.Object

Color handling and conversion tools


Nested Class Summary
static class ColorTools.RGB
          RGB class.
 
Field Summary
static java.awt.Color black
           
static ColorTools.RGB BLACK
           
static java.awt.Color blue
           
static ColorTools.RGB BLUE
           
static java.awt.Color brown
           
static ColorTools.RGB BROWN
           
static ColorTools.RGB COLOR_BLACK
           
static ColorTools.RGB COLOR_BLUE
           
static ColorTools.RGB COLOR_BROWN
           
static ColorTools.RGB COLOR_CYAN
           
static ColorTools.RGB COLOR_DARK_GRAY
           
static ColorTools.RGB COLOR_DARK_YELLOW
           
static ColorTools.RGB COLOR_GRAY
           
static ColorTools.RGB COLOR_GREEN
           
static ColorTools.RGB COLOR_LIGHT_GRAY
           
static ColorTools.RGB COLOR_MAGENTA
           
static ColorTools.RGB COLOR_ORANGE
           
static ColorTools.RGB COLOR_PINK
           
static ColorTools.RGB COLOR_PURPLE
           
static ColorTools.RGB COLOR_RED
           
static ColorTools.RGB COLOR_WHITE
           
static ColorTools.RGB COLOR_YELLOW
           
static java.awt.Color cyan
           
static ColorTools.RGB CYAN
           
static ColorTools.RGB DARK_GRAY
           
static ColorTools.RGB DARK_YELLOW
           
static java.awt.Color darkGray
           
static java.awt.Color darkYellow
           
static java.awt.Color gray
           
static ColorTools.RGB GRAY
           
static java.awt.Color green
           
static ColorTools.RGB GREEN
           
static ColorTools.RGB LIGHT_GRAY
           
static java.awt.Color lightGray
           
static java.awt.Color magenta
           
static ColorTools.RGB MAGENTA
           
static java.awt.Color orange
           
static ColorTools.RGB ORANGE
           
static java.awt.Color pink
           
static ColorTools.RGB PINK
           
static java.awt.Color purple
           
static ColorTools.RGB PURPLE
           
static java.awt.Color red
           
static ColorTools.RGB RED
           
static java.awt.Color white
           
static ColorTools.RGB WHITE
           
static java.awt.Color yellow
           
static ColorTools.RGB YELLOW
           
 
Constructor Summary
ColorTools()
           
 
Method Summary
static java.awt.Color darker(java.awt.Color c, double percent)
          Creates a new Color that is darker than the specified Color
static java.awt.Color darker(java.awt.Color c, float percent)
          Creates a new Color that is darker than the specified Color
static boolean isColor(java.lang.String color)
          Returns true if the specified string is a valid color
static java.awt.Color lighter(java.awt.Color c, double percent)
          Creates a new Color that is lighter than the specified Color
static java.awt.Color lighter(java.awt.Color c, float percent)
          Creates a new Color that is lighter than the specified Color
static void main(java.lang.String[] argv)
           
static java.awt.Color mix(java.awt.Color color1, java.awt.Color color2)
          Creates a new Color that is the average of the 2 specified Colors, based on a 50% weighting from the first Color to the second Color.
static java.awt.Color mix(java.awt.Color color1, java.awt.Color color2, double weight)
          Creates a new Color that is a mix of the 2 specified Colors, based on the specified 'weighting' from the first Color to the second Color.
static java.awt.Color mix(java.awt.Color color1, java.awt.Color color2, float weight)
          Creates a new Color that is a mix of the 2 specified Colors, based on the specified 'weighting' from the first Color to the second Color.
static java.awt.Color parseColor(java.lang.String color, java.awt.Color dft)
          Parses the Color String representation into a Color instance.
static ColorTools.RGB parseColor(java.lang.String color, ColorTools.RGB dft)
          Parses the Color String representation into a Color instance.
static java.awt.Color randomColor()
          Returns a random color
static java.awt.Color randomColor(java.util.Random R)
          Returns a random color
static java.lang.String toHexString(java.awt.Color color)
          Returns a hex String representation of the specified Color.
static java.lang.String toHexString(java.awt.Color color, boolean inclHash)
          Returns a hex String representation of the specified Color.
static java.lang.String toHexString(int color, boolean inclHash)
          Returns a hex String representation of the specified Color.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BLACK

public static ColorTools.RGB BLACK

BROWN

public static ColorTools.RGB BROWN

RED

public static ColorTools.RGB RED

ORANGE

public static ColorTools.RGB ORANGE

YELLOW

public static ColorTools.RGB YELLOW

DARK_YELLOW

public static ColorTools.RGB DARK_YELLOW

GREEN

public static ColorTools.RGB GREEN

BLUE

public static ColorTools.RGB BLUE

PURPLE

public static ColorTools.RGB PURPLE

GRAY

public static ColorTools.RGB GRAY

DARK_GRAY

public static ColorTools.RGB DARK_GRAY

LIGHT_GRAY

public static ColorTools.RGB LIGHT_GRAY

WHITE

public static ColorTools.RGB WHITE

CYAN

public static ColorTools.RGB CYAN

PINK

public static ColorTools.RGB PINK

MAGENTA

public static ColorTools.RGB MAGENTA

COLOR_BLACK

public static ColorTools.RGB COLOR_BLACK

COLOR_BROWN

public static ColorTools.RGB COLOR_BROWN

COLOR_RED

public static ColorTools.RGB COLOR_RED

COLOR_ORANGE

public static ColorTools.RGB COLOR_ORANGE

COLOR_YELLOW

public static ColorTools.RGB COLOR_YELLOW

COLOR_DARK_YELLOW

public static ColorTools.RGB COLOR_DARK_YELLOW

COLOR_GREEN

public static ColorTools.RGB COLOR_GREEN

COLOR_BLUE

public static ColorTools.RGB COLOR_BLUE

COLOR_PURPLE

public static ColorTools.RGB COLOR_PURPLE

COLOR_GRAY

public static ColorTools.RGB COLOR_GRAY

COLOR_DARK_GRAY

public static ColorTools.RGB COLOR_DARK_GRAY

COLOR_LIGHT_GRAY

public static ColorTools.RGB COLOR_LIGHT_GRAY

COLOR_WHITE

public static ColorTools.RGB COLOR_WHITE

COLOR_CYAN

public static ColorTools.RGB COLOR_CYAN

COLOR_PINK

public static ColorTools.RGB COLOR_PINK

COLOR_MAGENTA

public static ColorTools.RGB COLOR_MAGENTA

black

public static java.awt.Color black

brown

public static java.awt.Color brown

red

public static java.awt.Color red

orange

public static java.awt.Color orange

yellow

public static java.awt.Color yellow

darkYellow

public static java.awt.Color darkYellow

green

public static java.awt.Color green

blue

public static java.awt.Color blue

purple

public static java.awt.Color purple

gray

public static java.awt.Color gray

darkGray

public static java.awt.Color darkGray

lightGray

public static java.awt.Color lightGray

white

public static java.awt.Color white

cyan

public static java.awt.Color cyan

pink

public static java.awt.Color pink

magenta

public static java.awt.Color magenta
Constructor Detail

ColorTools

public ColorTools()
Method Detail

parseColor

public static ColorTools.RGB parseColor(java.lang.String color,
                                        ColorTools.RGB dft)
Parses the Color String representation into a Color instance.

Parameters:
color - The color String representation to parse
dft - The default Color returned if unable to parse a Color from the String
Returns:
The parsed Color instance.

isColor

public static boolean isColor(java.lang.String color)
Returns true if the specified string is a valid color

Parameters:
color - The color String representation to test
Returns:
True if the specified string is a valid color

lighter

public static java.awt.Color lighter(java.awt.Color c,
                                     double percent)
Creates a new Color that is lighter than the specified Color

Parameters:
c - The Color to make lighter
percent - The percent to make lighter
Returns:
The new 'ligher' Color

lighter

public static java.awt.Color lighter(java.awt.Color c,
                                     float percent)
Creates a new Color that is lighter than the specified Color

Parameters:
c - The Color to make lighter
percent - The percent to make lighter
Returns:
The new 'ligher' Color

darker

public static java.awt.Color darker(java.awt.Color c,
                                    double percent)
Creates a new Color that is darker than the specified Color

Parameters:
c - The Color to make darker
percent - The percent to make darker
Returns:
The new 'darker' Color

darker

public static java.awt.Color darker(java.awt.Color c,
                                    float percent)
Creates a new Color that is darker than the specified Color

Parameters:
c - The Color to make darker
percent - The percent to make darker
Returns:
The new 'darker' Color

mix

public static java.awt.Color mix(java.awt.Color color1,
                                 java.awt.Color color2)
Creates a new Color that is the average of the 2 specified Colors, based on a 50% weighting from the first Color to the second Color.

Parameters:
color1 - The first Color which will be averaged
color2 - The second Color which will be averaged
Returns:
The new 'averaged' Color

mix

public static java.awt.Color mix(java.awt.Color color1,
                                 java.awt.Color color2,
                                 float weight)
Creates a new Color that is a mix of the 2 specified Colors, based on the specified 'weighting' from the first Color to the second Color.

Parameters:
color1 - The first Color which will be averaged
color2 - The second Color which will be averaged
weight - The 'weighting' from the first Color to the second Color. A 'weight' of '0.0' will produce the first Color. A 'weight' of '1.0' will produce the second Color.
Returns:
The new 'averaged' Color

mix

public static java.awt.Color mix(java.awt.Color color1,
                                 java.awt.Color color2,
                                 double weight)
Creates a new Color that is a mix of the 2 specified Colors, based on the specified 'weighting' from the first Color to the second Color.

Parameters:
color1 - The first Color which will be averaged
color2 - The second Color which will be averaged
weight - The 'weighting' from the first Color to the second Color. A 'weight' of '0.0' will produce the first Color. A 'weight' of '1.0' will produce the second Color.
Returns:
The new 'averaged' Color

parseColor

public static java.awt.Color parseColor(java.lang.String color,
                                        java.awt.Color dft)
Parses the Color String representation into a Color instance.

Parameters:
color - The color String representation to parse
dft - The default Color returned if unable to parse a Color from the String
Returns:
The parsed Color instance.

randomColor

public static java.awt.Color randomColor(java.util.Random R)
Returns a random color

Parameters:
R - The radomizer (null to create a new Random instance)
Returns:
The generated random color

randomColor

public static java.awt.Color randomColor()
Returns a random color

Returns:
The generated random color

toHexString

public static java.lang.String toHexString(java.awt.Color color)
Returns a hex String representation of the specified Color.

Parameters:
color - The Color to convert to a String representation
Returns:
The Color String representation

toHexString

public static java.lang.String toHexString(java.awt.Color color,
                                           boolean inclHash)
Returns a hex String representation of the specified Color.

Parameters:
color - The Color to convert to a String representation
inclHash - Prefix with '#' if true
Returns:
The Color String representation

toHexString

public static java.lang.String toHexString(int color,
                                           boolean inclHash)
Returns a hex String representation of the specified Color.

Parameters:
color - The RGB value to convert to a String representation
inclHash - Prefix with '#' if true
Returns:
The color String representation

main

public static void main(java.lang.String[] argv)