edu.kzoo.util
Class KColor

java.lang.Object
  |
  +--java.awt.Color
        |
        +--edu.kzoo.util.KColor
All Implemented Interfaces:
java.awt.Paint, java.io.Serializable, java.awt.Transparency

public class KColor
extends java.awt.Color

Kalamazoo College Utility Classes:
The edu.kzoo.util.KColor class extends the java.awt.Color class to provide static methods that generate random colors with and without variable levels of transparency. This class is a mess because I can't decide what to do with it. It should probably be a wrapper class around Color, so you could do something like Color c = new KColor(Color.BLUE); System.out.println(c); // lower case, or System.out.println(c.toString(KColor.MIXED_CASE)); Would have to implement delegation methods for all Color methods, though. Or maybe it should just be a class with handy static methods, so you could do something like Color c = Color.BLUE; System.out.println(KColor.toString(c)); // lower case, or System.out.println(KColor.toString(c, KColor.MIXED_CASE)); Maybe toString should be renamed in the latter case.

Version:
1 March 2004
Author:
Alyce Brady
See Also:
Serialized Form

Field Summary
static int LOWER_CASE
           
static int MIXED_CASE
           
static int UPPER_CASE
           
 
Fields inherited from class java.awt.Color
black, BLACK, blue, BLUE, cyan, CYAN, DARK_GRAY, darkGray, gray, GRAY, green, GREEN, LIGHT_GRAY, lightGray, magenta, MAGENTA, orange, ORANGE, pink, PINK, red, RED, white, WHITE, yellow, YELLOW
 
Fields inherited from interface java.awt.Transparency
BITMASK, OPAQUE, TRANSLUCENT
 
Constructor Summary
KColor(java.awt.color.ColorSpace cspace, float[] components, float alpha)
          Creates a color in the specified ColorSpace with the color components specified in the float array and the specified alpha.
KColor(float r, float g, float b)
          Creates an opaque sRGB color with the specified red, green, and blue values in the range (0.0 - 1.0).
KColor(float r, float g, float b, float a)
          Creates an sRGB color with the specified red, green, blue, and alpha values in the range (0.0 - 1.0).
KColor(int rgb)
          Creates an opaque sRGB color with the specified combined RGB value consisting of the red component in bits 16-23, the green component in bits 8-15, and the blue component in bits 0-7.
KColor(int rgba, boolean hasAlpha)
          Creates an sRGB color with the specified combined RGB value consisting of the red component in bits 16-23, the green component in bits 8-15, and the blue component in bits 0-7.
KColor(int r, int g, int b)
          Creates an opaque sRGB color with the specified red, green, and blue values in the range (0 - 255).
KColor(int r, int g, int b, int a)
          Creates an sRGB color with the specified red, green, blue, and alpha values in the range (0 - 255).
 
Method Summary
static java.awt.Color getRandomColor()
          Generates a pseudorandom Color value.
static java.awt.Color getRandomColor(int alpha)
          Generates a pseudorandom Color value with the specified transparency level.
static java.awt.Color getRandomOpaqueColor()
          Generates a pseudorandom opaque Color value.
 java.lang.String toString()
          Returns a string representing this color.
 java.lang.String toString(int characterCase)
          Returns a string representing this color.
 
Methods inherited from class java.awt.Color
brighter, createContext, darker, decode, equals, getAlpha, getBlue, getColor, getColor, getColor, getColorComponents, getColorComponents, getColorSpace, getComponents, getComponents, getGreen, getHSBColor, getRed, getRGB, getRGBColorComponents, getRGBComponents, getTransparency, hashCode, HSBtoRGB, RGBtoHSB
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

LOWER_CASE

public static final int LOWER_CASE
See Also:
Constant Field Values

MIXED_CASE

public static final int MIXED_CASE
See Also:
Constant Field Values

UPPER_CASE

public static final int UPPER_CASE
See Also:
Constant Field Values
Constructor Detail

KColor

public KColor(int r,
              int g,
              int b)
Creates an opaque sRGB color with the specified red, green, and blue values in the range (0 - 255). The actual color used in rendering depends on finding the best match given the color space available for a particular output device. Alpha is defaulted to 255.

Parameters:
r - the red component
g - the green component
b - the blue component
See Also:
Color.Color(int, int, int)

KColor

public KColor(int r,
              int g,
              int b,
              int a)
Creates an sRGB color with the specified red, green, blue, and alpha values in the range (0 - 255). The actual color used in rendering depends on finding the best match given the color space available for a particular output device.

Parameters:
r - the red component
g - the green component
b - the blue component
a - the alpha component
See Also:
Color.Color(int, int, int, int)

KColor

public KColor(int rgb)
Creates an opaque sRGB color with the specified combined RGB value consisting of the red component in bits 16-23, the green component in bits 8-15, and the blue component in bits 0-7. The actual color used in rendering depends on finding the best match given the color space available for a particular output device. Alpha is defaulted to 255.

Parameters:
rgb - the combined RGB components
See Also:
Color.Color(int)

KColor

public KColor(int rgba,
              boolean hasAlpha)
Creates an sRGB color with the specified combined RGB value consisting of the red component in bits 16-23, the green component in bits 8-15, and the blue component in bits 0-7. The actual color used in rendering depends on finding the best match given the color space available for a particular output device. If the hasalpha argument is false, alpha is defaulted to 255.

Parameters:
rgba - the combined RGBA components
hasAlpha - true if the alpha bits are valid; false otherwise
See Also:
Color.Color(int, boolean)

KColor

public KColor(float r,
              float g,
              float b)
Creates an opaque sRGB color with the specified red, green, and blue values in the range (0.0 - 1.0). Alpha is defaulted to 1.0. The actual color used in rendering depends on finding the best match given the color space available for a particular output device.

Parameters:
r - the red component
g - the green component
b - the blue component
See Also:
Color.Color(float, float, float)

KColor

public KColor(float r,
              float g,
              float b,
              float a)
Creates an sRGB color with the specified red, green, blue, and alpha values in the range (0.0 - 1.0). The actual color used in rendering depends on finding the best match given the color space available for a particular output device.

Parameters:
r - the red component
g - the green component
b - the blue component
a - the alpha component
See Also:
Color.Color(float, float, float, float)

KColor

public KColor(java.awt.color.ColorSpace cspace,
              float[] components,
              float alpha)
Creates a color in the specified ColorSpace with the color components specified in the float array and the specified alpha. The number of components is determined by the type of the ColorSpace. For example, RGB requires 3 components, but CMYK requires 4 components.

Parameters:
components - an arbitrary number of color components that is compatible with the
alpha - alpha value
Throws:
java.lang.IllegalArgumentException - if any of the values in the components array or alpha is outside of the range 0.0 to 1.0
See Also:
Color.Color(ColorSpace, float[], float)
Method Detail

getRandomOpaqueColor

public static java.awt.Color getRandomOpaqueColor()
Generates a pseudorandom opaque Color value.

Returns:
the new pseudorandom opaque color

getRandomColor

public static java.awt.Color getRandomColor(int alpha)
Generates a pseudorandom Color value with the specified transparency level.

Parameters:
alpha - the transparency level to use, in the range of 0 to 255 where 255 is completely opaque
Returns:
the new pseudorandom color with the specified transparency level

getRandomColor

public static java.awt.Color getRandomColor()
Generates a pseudorandom Color value. Colors returned by this method have a random alpha (transparency) component, as well as random red, green, and blue components.

Returns:
the new pseudorandom color

toString

public java.lang.String toString()
Returns a string representing this color. If the color is one of the defined fields in the java.awt.Color class, the string is the name of the color in all lower-case characters.

Overrides:
toString in class java.awt.Color

toString

public java.lang.String toString(int characterCase)
Returns a string representing this color. If the color is one of the defined fields in the java.awt.Color class, the string is the name of the color in all lower-case, mixed case, or all upper-case characters, depending on the value of characterCase which should be one of KColor.LOWER_CASE, KColor.MIXED_CASE, or KColor.UPPER_CASE.