danger.ui
Class Color

java.lang.Object
  extended by danger.ui.Color


public class Color
extends Object

The Color class is a basic type used to contain color information and is used by many classes in the danger.ui package.


Field Summary
 int a
          The alpha component.
 int b
          The blue component.
static int BLACK
          Packed integer representation of the color black.
static int BLUE
          Packed integer representation of the color blue.
static int CYAN
          Packed integer representation of the color cyan.
static int FUCHSIA
          Packed integer representation of a shade of fuchsia.
 int g
          The green component.
static int GRAY0
          Packed integer representation of a shade of gray.
static int GRAY1
          Packed integer representation of a shade of gray.
static int GRAY10
          Packed integer representation of a shade of gray.
static int GRAY11
          Packed integer representation of a shade of gray.
static int GRAY12
          Packed integer representation of a shade of gray.
static int GRAY13
          Packed integer representation of a shade of gray.
static int GRAY14
          Packed integer representation of a shade of gray.
static int GRAY15
          Packed integer representation of a shade of gray.
static int GRAY2
          Packed integer representation of a shade of gray.
static int GRAY3
          Packed integer representation of a shade of gray.
static int GRAY4
          Packed integer representation of a shade of gray.
static int GRAY5
          Packed integer representation of a shade of gray.
static int GRAY6
          Packed integer representation of a shade of gray.
static int GRAY7
          Packed integer representation of a shade of gray.
static int GRAY8
          Packed integer representation of a shade of gray.
static int GRAY9
          Packed integer representation of a shade of gray.
static int GREEN
          Packed integer representation of the color green.
static int MAGENTA
          Packed integer representation of the color magenta.
static int ORANGE
          Packed integer representation of the color orange.
static int PINK
          Packed integer representation of the color pink.
static int PURPLE
          Packed integer representation of the color purple.
 int r
          The red component.
static int RED
          Packed integer representation of the color red.
static int VIOLET
          Packed integer representation of the color violet.
static int WHITE
          Packed integer representation of the color white.
static int YELLOW
          Packed integer representation of the color yellow.
 
Constructor Summary
Color()
          Construct a new color which is completely black.
Color(Color c)
          Create a color object which is the same color as the specified color.
Color(int packedColor)
          Construct a new color from a packed rgb value.
Color(int inR, int inG, int inB)
          Construct a new color which has the specified R, G, and B values.
Color(int inR, int inG, int inB, int inA)
          Construct a new color which has the specified R, G, and B values, as well as the specified alpha value.
Color(String s)
          Construct a new color from a string value.
 
Method Summary
 void assign(int packedColor)
          Change this color to have the specified color value
 void assign(int inR, int inG, int inB)
          Change this color to have the specified red, green, and blue values.
 void assign(String s)
          Change this color to have the specified color.
static int blend(int fg, int bg, int opacity)
          Blend two packed RGB color using a given opacity.
static int colorize(int color, int r, int g, int b)
          Colorize one color with another.
static boolean colorsEqual(int color1, int color2)
          Compare two colors.
static int fromString(String s)
          Return an integer value which represents the color specified by the string.
static int pack(int r, int g, int b)
          Return an integer which represents the color with the specified red, green, and blue values.
static int pack(int r, int g, int b, int a)
          Return an integer which represents the color with the specified red, green, blue, and alpha values.
 int toPacked()
          Return an integer which represents this color.
 String toString()
          Return a string representation of the color, in hex format.
static String toString(int packedColor)
          Return a string representation of the specified packed color.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

a

public int a
The alpha component. Value is between 0 and 255.


r

public int r
The red component. Value is between 0 and 255.


g

public int g
The green component. Value is between 0 and 255.


b

public int b
The blue component. Value is between 0 and 255.


BLACK

public static final int BLACK
Packed integer representation of the color black.

See Also:
Constant Field Values

WHITE

public static final int WHITE
Packed integer representation of the color white.

See Also:
Constant Field Values

RED

public static final int RED
Packed integer representation of the color red.

See Also:
Constant Field Values

GREEN

public static final int GREEN
Packed integer representation of the color green.

See Also:
Constant Field Values

BLUE

public static final int BLUE
Packed integer representation of the color blue.

See Also:
Constant Field Values

CYAN

public static final int CYAN
Packed integer representation of the color cyan.

See Also:
Constant Field Values

MAGENTA

public static final int MAGENTA
Packed integer representation of the color magenta.

See Also:
Constant Field Values

ORANGE

public static final int ORANGE
Packed integer representation of the color orange.

See Also:
Constant Field Values

PURPLE

public static final int PURPLE
Packed integer representation of the color purple.

See Also:
Constant Field Values

VIOLET

public static final int VIOLET
Packed integer representation of the color violet.

See Also:
Constant Field Values

YELLOW

public static final int YELLOW
Packed integer representation of the color yellow.

See Also:
Constant Field Values

PINK

public static final int PINK
Packed integer representation of the color pink.

See Also:
Constant Field Values

GRAY0

public static final int GRAY0
Packed integer representation of a shade of gray.

See Also:
Constant Field Values

GRAY1

public static final int GRAY1
Packed integer representation of a shade of gray.

See Also:
Constant Field Values

GRAY2

public static final int GRAY2
Packed integer representation of a shade of gray.

See Also:
Constant Field Values

GRAY3

public static final int GRAY3
Packed integer representation of a shade of gray.

See Also:
Constant Field Values

GRAY4

public static final int GRAY4
Packed integer representation of a shade of gray.

See Also:
Constant Field Values

GRAY5

public static final int GRAY5
Packed integer representation of a shade of gray.

See Also:
Constant Field Values

GRAY6

public static final int GRAY6
Packed integer representation of a shade of gray.

See Also:
Constant Field Values

GRAY7

public static final int GRAY7
Packed integer representation of a shade of gray.

See Also:
Constant Field Values

GRAY8

public static final int GRAY8
Packed integer representation of a shade of gray.

See Also:
Constant Field Values

GRAY9

public static final int GRAY9
Packed integer representation of a shade of gray.

See Also:
Constant Field Values

GRAY10

public static final int GRAY10
Packed integer representation of a shade of gray.

See Also:
Constant Field Values

GRAY11

public static final int GRAY11
Packed integer representation of a shade of gray.

See Also:
Constant Field Values

GRAY12

public static final int GRAY12
Packed integer representation of a shade of gray.

See Also:
Constant Field Values

GRAY13

public static final int GRAY13
Packed integer representation of a shade of gray.

See Also:
Constant Field Values

GRAY14

public static final int GRAY14
Packed integer representation of a shade of gray.

See Also:
Constant Field Values

GRAY15

public static final int GRAY15
Packed integer representation of a shade of gray.

See Also:
Constant Field Values

FUCHSIA

public static final int FUCHSIA
Packed integer representation of a shade of fuchsia.

See Also:
Constant Field Values
Constructor Detail

Color

public Color(Color c)
Create a color object which is the same color as the specified color.


Color

public Color()
Construct a new color which is completely black.


Color

public Color(int packedColor)
Construct a new color from a packed rgb value.

Parameters:
packedColor - An integer with packed 8bit per channel RGB values. Blue is the LSB. Alpha is the MSB.

Color

public Color(int inR,
             int inG,
             int inB)
Construct a new color which has the specified R, G, and B values. The values should be from 0 to 255.


Color

public Color(int inR,
             int inG,
             int inB,
             int inA)
Construct a new color which has the specified R, G, and B values, as well as the specified alpha value. The values should be from 0 to 255.


Color

public Color(String s)
Construct a new color from a string value. For possible values for the string, see fromString(java.lang.String).

Method Detail

toPacked

public int toPacked()
Return an integer which represents this color. Alpha is the MSB and blue is the LSB.


pack

public static int pack(int r,
                       int g,
                       int b)
Return an integer which represents the color with the specified red, green, and blue values. Alpha is the MSB and blue is the LSB. The values should be from 0 to 255.


pack

public static int pack(int r,
                       int g,
                       int b,
                       int a)
Return an integer which represents the color with the specified red, green, blue, and alpha values. Alpha is the MSB and blue is the LSB. The values should be from 0 to 255.


toString

public String toString()
Return a string representation of the color, in hex format.

Overrides:
toString in class Object

toString

public static String toString(int packedColor)
Return a string representation of the specified packed color. Blue is the LSB and alpha is the MSB.


fromString

public static int fromString(String s)
Return an integer value which represents the color specified by the string. Blue is the LSB and alpha is the MSB. The string should be of the form "#ff0088", or one of the symbolic color constants: "black", "white", "red", "green", "blue", "cyan", "magenta", "orange", "purple", "violet", "yellow", "pink", "gray0" through "gray15"


assign

public void assign(int inR,
                   int inG,
                   int inB)
Change this color to have the specified red, green, and blue values. The values should be from 0 to 255.


assign

public void assign(int packedColor)
Change this color to have the specified color value

Parameters:
packedColor - An integer with packed 8bit per channel RGB values. Blue is the LSB. Alpha is the MSB.

assign

public void assign(String s)
Change this color to have the specified color.

Parameters:
s - The color specified as a string. See fromString(java.lang.String) for possible values.

colorsEqual

public static boolean colorsEqual(int color1,
                                  int color2)
Compare two colors. This method disregards the alpha channel when comparing the two colors. Blue is the LSB and alpha is the MSB.

Returns:
true if the colors are equivalent

blend

public static int blend(int fg,
                        int bg,
                        int opacity)
Blend two packed RGB color using a given opacity.

Parameters:
fg - the foreground color.
bg - the background color.
opacity - the opacity with which to blend the foreground on the background. 0x00 is fully transparent. 0xff is fully opaque.
Returns:
the blended color.

colorize

public static int colorize(int color,
                           int r,
                           int g,
                           int b)
Colorize one color with another.

Parameters:
color - the color.
r - red component to colorize color by.
g - green component to colorize color by.
b - blue component to colorize color by.
Returns:
the colorized color.