de.matthiasmann.twl
Class Color

java.lang.Object
  extended by de.matthiasmann.twl.Color

public final class Color
extends java.lang.Object

A immutable color class. Colors are represented as bytes.


Field Summary
static Color AQUA
           
static Color BLACK
           
static Color BLUE
           
static Color FUCHSIA
           
static Color GRAY
           
static Color GREEN
           
static Color LIGHTBLUE
           
static Color LIGHTCORAL
           
static Color LIGHTCYAN
           
static Color LIGHTGRAY
           
static Color LIGHTGREEN
           
static Color LIGHTPINK
           
static Color LIGHTSALMON
           
static Color LIGHTSKYBLUE
           
static Color LIGHTYELLOW
           
static Color LIME
           
static Color MAROON
           
static Color NAVY
           
static Color OLIVE
           
static Color ORANGE
           
static Color PURPLE
           
static Color RED
           
static Color SILVER
           
static Color SKYBLUE
           
static Color TEAL
           
static Color TRANSPARENT
           
static Color WHITE
           
static Color YELLOW
           
 
Constructor Summary
Color(byte r, byte g, byte b, byte a)
           
Color(int argb)
          Creates a new color object from an integer in ARGB order.
 
Method Summary
 boolean equals(java.lang.Object obj)
           
 byte getA()
           
 int getAlpha()
           
 float getAlphaFloat()
           
 byte getB()
           
 int getBlue()
           
 float getBlueFloat()
           
static Color getColorByName(java.lang.String name)
          Retrieves a color by it's name.
 void getFloats(float[] dst, int off)
           
 byte getG()
           
 int getGreen()
           
 float getGreenFloat()
           
 byte getR()
           
 int getRed()
           
 float getRedFloat()
           
 int hashCode()
           
 Color multiply(Color other)
           
static Color parserColor(java.lang.String value)
          Parses a numeric or symbolic color.
 int toARGB()
          Converts this color into an integer in ARGB format
 java.lang.String toString()
          Converts this color into it's hex string.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

BLACK

public static final Color BLACK

SILVER

public static final Color SILVER

GRAY

public static final Color GRAY

WHITE

public static final Color WHITE

MAROON

public static final Color MAROON

RED

public static final Color RED

PURPLE

public static final Color PURPLE

FUCHSIA

public static final Color FUCHSIA

GREEN

public static final Color GREEN

LIME

public static final Color LIME

OLIVE

public static final Color OLIVE

ORANGE

public static final Color ORANGE

YELLOW

public static final Color YELLOW

NAVY

public static final Color NAVY

BLUE

public static final Color BLUE

TEAL

public static final Color TEAL

AQUA

public static final Color AQUA

SKYBLUE

public static final Color SKYBLUE

LIGHTBLUE

public static final Color LIGHTBLUE

LIGHTCORAL

public static final Color LIGHTCORAL

LIGHTCYAN

public static final Color LIGHTCYAN

LIGHTGRAY

public static final Color LIGHTGRAY

LIGHTGREEN

public static final Color LIGHTGREEN

LIGHTPINK

public static final Color LIGHTPINK

LIGHTSALMON

public static final Color LIGHTSALMON

LIGHTSKYBLUE

public static final Color LIGHTSKYBLUE

LIGHTYELLOW

public static final Color LIGHTYELLOW

TRANSPARENT

public static final Color TRANSPARENT
Constructor Detail

Color

public Color(byte r,
             byte g,
             byte b,
             byte a)

Color

public Color(int argb)
Creates a new color object from an integer in ARGB order. bits 0- 7 are blue bits 8-15 are green bits 16-23 are red bits 24-31 are alpha

Parameters:
argb - the color value as integer
Method Detail

toARGB

public int toARGB()
Converts this color into an integer in ARGB format

Returns:
the color value as integer
See Also:
Color(int)

getR

public byte getR()

getG

public byte getG()

getB

public byte getB()

getA

public byte getA()

getRed

public int getRed()

getGreen

public int getGreen()

getBlue

public int getBlue()

getAlpha

public int getAlpha()

getRedFloat

public float getRedFloat()

getGreenFloat

public float getGreenFloat()

getBlueFloat

public float getBlueFloat()

getAlphaFloat

public float getAlphaFloat()

getFloats

public void getFloats(float[] dst,
                      int off)

getColorByName

public static Color getColorByName(java.lang.String name)
Retrieves a color by it's name. This uses the case insensitive lookup for the color constants defined in this class.

Parameters:
name - the color name to lookup
Returns:
a Color or null if the name was not found

parserColor

public static Color parserColor(java.lang.String value)
                         throws java.lang.NumberFormatException
Parses a numeric or symbolic color. Symbolic names are resolved by getColorByName The following hex formats are supported: #RGB #ARGB #RRGGBB #AARRGGBB

Parameters:
value - the color to parse
Returns:
a Color object or null
Throws:
java.lang.NumberFormatException - if the hex color code can't be parsed
See Also:
getColorByName(java.lang.String)

toString

public java.lang.String toString()
Converts this color into it's hex string. If alpha is 255 then a string in "#RRGGBB" format is created, otherwise the "#AARRGGBB" format is created

Overrides:
toString in class java.lang.Object
Returns:
hex representation of this color

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

multiply

public Color multiply(Color other)