|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.awt.Color | +--edu.kzoo.util.KColor
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.
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 |
public static final int LOWER_CASE
public static final int MIXED_CASE
public static final int UPPER_CASE
Constructor Detail |
public KColor(int r, int g, int b)
r
- the red componentg
- the green componentb
- the blue componentColor.Color(int, int, int)
public KColor(int r, int g, int b, int a)
r
- the red componentg
- the green componentb
- the blue componenta
- the alpha componentColor.Color(int, int, int, int)
public KColor(int rgb)
rgb
- the combined RGB componentsColor.Color(int)
public KColor(int rgba, boolean hasAlpha)
hasalpha
argument is false
, alpha is
defaulted to 255.
rgba
- the combined RGBA componentshasAlpha
- true
if the alpha bits are valid;
false
otherwiseColor.Color(int, boolean)
public KColor(float r, float g, float b)
r
- the red componentg
- the green componentb
- the blue componentColor.Color(float, float, float)
public KColor(float r, float g, float b, float a)
r
- the red componentg
- the green componentb
- the blue componenta
- the alpha componentColor.Color(float, float, float, float)
public KColor(java.awt.color.ColorSpace cspace, float[] components, float alpha)
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.
components
- an arbitrary number of color components that is
compatible with thealpha
- alpha value
java.lang.IllegalArgumentException
- if any of the values in the
components array or alpha is outside of the
range 0.0 to 1.0Color.Color(ColorSpace, float[], float)
Method Detail |
public static java.awt.Color getRandomOpaqueColor()
Color
value.
public static java.awt.Color getRandomColor(int alpha)
Color
value with the
specified transparency level.
alpha
- the transparency level to use, in the range
of 0 to 255 where 255 is completely opaque
public static java.awt.Color getRandomColor()
Color
value. Colors returned
by this method have a random alpha (transparency) component, as well
as random red, green, and blue components.
public java.lang.String toString()
toString
in class java.awt.Color
public java.lang.String toString(int characterCase)
characterCase
which should be one of KColor.LOWER_CASE, KColor.MIXED_CASE, or
KColor.UPPER_CASE.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |