com.yospace.yae.yogi
Class ColorUtil

java.lang.Object
  |
  +--com.yospace.yae.yogi.ColorUtil

public class ColorUtil
extends java.lang.Object

This class provides a set of static constants representing integer color values, and a set of static utility methods for manipulating them. This class cannot be instantiated.


Field Summary
static int BLACK
          integer color with value 0x000000
static int BLUE
          integer color with value 0x0000FF
static int CYAN
          integer color with value 0x00FFFF
static int DARK
          Used to indicate "darkening" for getShadedColor(color,shade)
static int DARK_GRAY
          integer color with value 0x404040
static int GRAY
          integer color with value 0x808080
static int GREEN
          integer color with value 0x00FF00
static int LIGHT
          Used to indicate "lightening" for getShadedColor(color,shade)
static int LIGHT_GRAY
          integer color with value 0xC0C0C0
static int MAGENTA
          integer color with value 0xFF00FF
static int ORANGE
          integer color with value 0xFFC800
static int PINK
          integer color with value 0xFFAFAF
static int RED
          integer color with value 0xFF0000
static int WHITE
          integer color with value 0xFFFFFF
static int YELLOW
          integer color with value 0xFFFF00
 
Method Summary
static int getColor(int r, int g, int b)
          Gives the color value for the color specified by its red, green and blue components.
static int getShadedColor(int color, int shade)
          This method takes a color and lightens or darkens it.
static int parseColor(java.lang.String s)
          Parses a string denoting a color name, and returns the relevant integer value.
static java.lang.String toString(int color)
          This method is the converse of parseColor(color) above.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BLACK

public static final int BLACK
integer color with value 0x000000

WHITE

public static final int WHITE
integer color with value 0xFFFFFF

RED

public static final int RED
integer color with value 0xFF0000

GREEN

public static final int GREEN
integer color with value 0x00FF00

BLUE

public static final int BLUE
integer color with value 0x0000FF

PINK

public static final int PINK
integer color with value 0xFFAFAF

ORANGE

public static final int ORANGE
integer color with value 0xFFC800

YELLOW

public static final int YELLOW
integer color with value 0xFFFF00

MAGENTA

public static final int MAGENTA
integer color with value 0xFF00FF

CYAN

public static final int CYAN
integer color with value 0x00FFFF

LIGHT_GRAY

public static final int LIGHT_GRAY
integer color with value 0xC0C0C0

GRAY

public static final int GRAY
integer color with value 0x808080

DARK_GRAY

public static final int DARK_GRAY
integer color with value 0x404040

DARK

public static final int DARK
Used to indicate "darkening" for getShadedColor(color,shade)

LIGHT

public static final int LIGHT
Used to indicate "lightening" for getShadedColor(color,shade)
Method Detail

getColor

public static int getColor(int r,
                           int g,
                           int b)
Gives the color value for the color specified by its red, green and blue components.
Parameters:
r - the value of the red component of the desired color, from 0 to 255.
g - the value of the green component of the desired color, from 0 to 255.
b - the value of the blue component of the desired color, from 0 to 255.
Returns:
the derived color as a 24 bit integer.
Throws:
java.lang.IllegalArgumentException - if any color component is out of range

getShadedColor

public static int getShadedColor(int color,
                                 int shade)
This method takes a color and lightens or darkens it.
Parameters:
color - the starting color
shade - one of LIGHT or DARK
Returns:
a new color value that is lighter or darker than color

parseColor

public static int parseColor(java.lang.String s)
                      throws java.lang.IllegalArgumentException
Parses a string denoting a color name, and returns the relevant integer value. Valid strings can either be the name of a recognised color in English, a comma-separated list of the R,G,B values of the desired color (in the range 0-255, no spaces), or a hex-string optionally starting with "0x".

If the color name is not recognised or the RGB representation is invalid then an IllegalArgumentException is thrown.

Parameters:
s - the String representation of the color. This is non-case-sensitive, and the accepted names are the same as the constant names defined in this class (e.g., BLACK, WHITE, etc.).
Returns:
the parsed color as 24 bit RGB integer.
Throws:
java.lang.IllegalArgumentException - if s is neither one of the color names, nor a hex-number, nor a ','-separated list of 3 numbers with no spaces.

toString

public static java.lang.String toString(int color)
This method is the converse of parseColor(color) above. Given a color value, it will produce the corresponding string name in English, or a hex string with a leading "0x" if not a recognized value.
Parameters:
color - a number representing a color in 0xRRGGBB format
Returns:
a String representation of that color, acceptable as input to parseColor(color)

Copyright 2002 Yospace Holdings Ltd. All Rights Reserved.