EchoPoint
1.0

echopoint.util
Class ColorKit

java.lang.Object
  extended byechopoint.util.ColorKit

public class ColorKit
extends java.lang.Object

A utility to class to help with Color manipulation

Author:
Brad Baker

Field Summary
static double COLOR_FACTOR
          The default scale factor applied to the brighter and darker functions
static java.lang.String[] ColorConstantStrings
          Array for acceptable Color Constant strings
static nextapp.echo.Color[] ColorConstantValues
          An array for Color values matching ColorConstantStrings
static int SWAP_OP_BGR
          swapRGB Operation - R = B, G = G, B = R
static int SWAP_OP_BRG
          swapRGB Operation - R = B, G = R, B = G
static int SWAP_OP_GBR
          swapRGB Operation - R = G, G = B, B = R
static int SWAP_OP_GRB
          swapRGB Operation - R = G, G = R, B = B
static int SWAP_OP_RBG
          swapRGB Operation - R = R, G = B, B = G
 
Method Summary
static nextapp.echo.Color brighter(nextapp.echo.Color color)
          Creates a brighter version of this color.
static nextapp.echo.Color brighter(nextapp.echo.Color color, double factor)
          Creates a brighter version of this color, according to the provided factor.
static nextapp.echo.Color clr(int r, int g, int b)
          Shortcut synonym for makeColor(r,g,b);
static nextapp.echo.Color clr(java.lang.String colorString)
          Shortcut synonym for makeColor(colorString);
static nextapp.echo.Color darker(nextapp.echo.Color color)
          Creates a darker version of this color.
static nextapp.echo.Color darker(nextapp.echo.Color color, double factor)
          Creates a darker version of this color, according to the provided factor.
static nextapp.echo.Color findBackground(nextapp.echo.Component comp)
          Searchs the heirarchy tree of the component and finds the first non null background Color object.
static nextapp.echo.Color findForeground(nextapp.echo.Component comp)
          Searchs the heirarchy tree of the component and finds the first non null foreground Color object.
static nextapp.echo.Color invertColor(nextapp.echo.Color color)
          Returns the inversion of a color.
static boolean isColor(java.lang.String colorString)
          Returns true if the attrValue is a valid representation of a Color value.
static java.awt.Color makeAwtColor(nextapp.echo.Color echoColor, java.awt.Color defaultAwtColor)
          Creates an java.awt.Color object from a nextapp.echo.Color object, or uses the default AWT if the echoColor object is null
static nextapp.echo.Color makeColor(int r, int g, int b)
          Returns a Color object from the red, green and blue integer values.
static nextapp.echo.Color makeColor(java.lang.String colorString)
          Returns a Color object from the string representation The color string must be in the format :
- #rrggbb where rr, gg, bb are hexidecimal integer values
- rgb( r, g, b) where r,g,b are integer values
- color( r, g, b) where r,g,b are integer values
- null will return a null color otherwise an IllegalArgumentException is thrown.
static java.lang.String makeColorString(nextapp.echo.Color color)
          Returns the Color in the form : color(r,g,b);
static java.lang.String makeCSSColor(nextapp.echo.Color color)
          Returns the Hex W3C CSS color string for a given color ie #rrggbb
static java.lang.String makeHexColor(nextapp.echo.Color color)
          Returns the Hex string for a given color for example 'rrggbb' Note it does NOT have the # character at the front
static nextapp.echo.Color swapRGB(nextapp.echo.Color swapColor, int swapOperation)
          This will swap the red/green/blue elements of a color according to the swapOperation, which may be one of : SWAP_OP_RBG SWAP_OP_BGR SWAP_OP_BRG SWAP_OP_GRB SWAP_OP_GBR
static nextapp.echo.Color tint(nextapp.echo.Color clr, double red, double green, double blue)
          Tints a given color by a factor given in red, blue and green.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ColorConstantStrings

public static java.lang.String[] ColorConstantStrings
Array for acceptable Color Constant strings


ColorConstantValues

public static nextapp.echo.Color[] ColorConstantValues
An array for Color values matching ColorConstantStrings


COLOR_FACTOR

public static final double COLOR_FACTOR
The default scale factor applied to the brighter and darker functions

See Also:
Constant Field Values

SWAP_OP_BGR

public static final int SWAP_OP_BGR
swapRGB Operation - R = B, G = G, B = R

See Also:
Constant Field Values

SWAP_OP_BRG

public static final int SWAP_OP_BRG
swapRGB Operation - R = B, G = R, B = G

See Also:
Constant Field Values

SWAP_OP_GBR

public static final int SWAP_OP_GBR
swapRGB Operation - R = G, G = B, B = R

See Also:
Constant Field Values

SWAP_OP_GRB

public static final int SWAP_OP_GRB
swapRGB Operation - R = G, G = R, B = B

See Also:
Constant Field Values

SWAP_OP_RBG

public static final int SWAP_OP_RBG
swapRGB Operation - R = R, G = B, B = G

See Also:
Constant Field Values
Method Detail

brighter

public static nextapp.echo.Color brighter(nextapp.echo.Color color)
Creates a brighter version of this color.

This method applies a 0.7 scale factor to each of the three RGB components of the color to create a brighter version of the same color. Although brighter and darker are inverse operations, the results of a series of invocations of these two methods may be inconsistent because of rounding errors.

Parameters:
color - - the color to make brighter
Returns:
a new Color object, a brighter version of the color.

brighter

public static nextapp.echo.Color brighter(nextapp.echo.Color color,
                                          double factor)
Creates a brighter version of this color, according to the provided factor.

This method applies an the scale factor to each of the three RGB components of the color to create a brighter version of the same color. Although brighter and darker are inverse operations, the results of a series of invocations of these two methods may be inconsistent because of rounding errors.

Parameters:
color - - the color to make brighter
factor - - the factor by which to make it brighter.
Returns:
a new Color object, a brighter version of the color.

darker

public static nextapp.echo.Color darker(nextapp.echo.Color color)
Creates a darker version of this color.

This method applies an arbitrary 0.7 scale factor to each of the three RGB components of the color to create a darker version of the same color. Although brighter and darker are inverse operations, the results of a series of invocations of these two methods may be inconsistent because of rounding errors.

Parameters:
color - - the color to make darker
Returns:
a new Color object,a darker version of this color.

darker

public static nextapp.echo.Color darker(nextapp.echo.Color color,
                                        double factor)
Creates a darker version of this color, according to the provided factor.

This method applies an the scale factor to each of the three RGB components of the color to create a darker version of the same color. Although brighter and darker are inverse operations, the results of a series of invocations of these two methods may be inconsistent because of rounding errors.

Parameters:
color - - the color to make darker
factor - - the factor by whcih to make it darker.
Returns:
a new Color object,a darker version of the color.

findBackground

public static nextapp.echo.Color findBackground(nextapp.echo.Component comp)
Searchs the heirarchy tree of the component and finds the first non null background Color object. It will return EchoInstance.DEFAULT_BACKGROUND if no ancestor components have a background set, but in practice this is unlikely to be the case.

Parameters:
comp - - the component to start searching at
Returns:
- the background color of the component or its parents

findForeground

public static nextapp.echo.Color findForeground(nextapp.echo.Component comp)
Searchs the heirarchy tree of the component and finds the first non null foreground Color object. It will return EchoInstance.DEFAULT_FOREGROUND if no ancestor components have a background set, but in practice this is unlikely to be the case.

Parameters:
comp - - the component to start searching at
Returns:
- the foreground color of the component or its parents

invertColor

public static nextapp.echo.Color invertColor(nextapp.echo.Color color)
Returns the inversion of a color.

Parameters:
color - - the color to invert
Returns:
the inverted color

makeAwtColor

public static java.awt.Color makeAwtColor(nextapp.echo.Color echoColor,
                                          java.awt.Color defaultAwtColor)
Creates an java.awt.Color object from a nextapp.echo.Color object, or uses the default AWT if the echoColor object is null

Parameters:
echoColor - - the nextapp.echo.Color object to convert
defaultAwtColor - - the AWT color to use if the echoColor is null
Returns:
a new AWT color object

makeCSSColor

public static java.lang.String makeCSSColor(nextapp.echo.Color color)
Returns the Hex W3C CSS color string for a given color ie #rrggbb

Parameters:
color - - the color to convert to a W3C hex CSS string value
Returns:
the W3C hex CSS string value

makeColorString

public static java.lang.String makeColorString(nextapp.echo.Color color)
Returns the Color in the form : color(r,g,b);

Parameters:
color - - the color to convert to a color string representation
Returns:
the color string representation

makeHexColor

public static java.lang.String makeHexColor(nextapp.echo.Color color)
Returns the Hex string for a given color for example 'rrggbb' Note it does NOT have the # character at the front

Parameters:
color - the color in question
Returns:
the string in the form rrggbb

makeColor

public static nextapp.echo.Color makeColor(java.lang.String colorString)
Returns a Color object from the string representation

The color string must be in the format :
- #rrggbb where rr, gg, bb are hexidecimal integer values
- rgb( r, g, b) where r,g,b are integer values
- color( r, g, b) where r,g,b are integer values
- null will return a null color

otherwise an IllegalArgumentException is thrown.

The results of these operations are cached in a static cache, so that Color objects can be re-used. This is okay since Color objects are immutable.

Parameters:
colorString - - the color string representation
Returns:
a new Color object

isColor

public static boolean isColor(java.lang.String colorString)
Returns true if the attrValue is a valid representation of a Color value.

The allowable forms are :

- colorconstant where colorconstant in (red,blue,green...) - #rrggbb where rr, gg, bb are hexidecimal integer values
- rgb( r, g, b) where r,g,b are integer values
- color( r, g, b) where r,g,b are integer values


clr

public static nextapp.echo.Color clr(java.lang.String colorString)
Shortcut synonym for makeColor(colorString);

See Also:
makeColor(String)

clr

public static nextapp.echo.Color clr(int r,
                                     int g,
                                     int b)
Shortcut synonym for makeColor(r,g,b);

See Also:
makeColor(int, int, int)

makeColor

public static nextapp.echo.Color makeColor(int r,
                                           int g,
                                           int b)
Returns a Color object from the red, green and blue integer values.

The results of these operations are cached in a static cache, so that Color objects can be re-used. This is okay since Color objects are immutable.

Parameters:
r - - the red color component
g - - the green color component
b - - the blue color component
Returns:
a new Color object

tint

public static nextapp.echo.Color tint(nextapp.echo.Color clr,
                                      double red,
                                      double green,
                                      double blue)
Tints a given color by a factor given in red, blue and green.

The red, green and blue arguments should be around 1.0


swapRGB

public static nextapp.echo.Color swapRGB(nextapp.echo.Color swapColor,
                                         int swapOperation)
This will swap the red/green/blue elements of a color according to the swapOperation, which may be one of :

EchoPoint
1.0