|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.instantreality.InstantIO.Color
public class Color
Helper class for exchanging RGB colors of three float components.
Color is a basic helper class for exchanging colors of three
float components between different software components. It does
not contain any means for color arithmetics, only methods for
setting and getting the color components. It is not meant to be used
directly by software components for color representation. Instead,
software components should use their own, appropriate classes for
handling colors. Only when sending colors to an OutSlot
,
or when receiving colors from an InSlot
, the internal
representation of colors should be converted to Color's. This
ensures the interoperability between different software components
that use different internal representations for colors.
The first component of the color is the red component, the second component the green component, and the third component the blue component. All components must be between 0 and 1, inclusively. 0 means no intensity, and 1 means maximum intensity.
The following example creates a Color object that represents the color "red", and prints its components to the console:
Color red = new Color(1.0f, 0.0f, 0.0f); System.out.println("red component = " + red.getRed()); System.out.println("green component = " + red.getGreen()); System.out.println("blue component = " + red.getBlue());
Constructor Summary | |
---|---|
Color(Color color)
Constructor that initializes the components of the Color object with the components taken from another Color object. |
|
Color(float[] color)
Constructor that initializes the components of the Color object with the values of a given float array. |
|
Color(float red,
float green,
float blue)
Constructor that initializes the components of the Color object with the given float values. |
Method Summary | |
---|---|
boolean |
equals(java.lang.Object obj)
Compares the color to another object. |
void |
get(float[] color)
Returns the values of the red, green and blue components. |
float |
getBlue()
Returns the value of the blue component. |
float |
getGreen()
Returns the value of the green component. |
float |
getRed()
Returns the value of the red component. |
java.lang.String |
toString()
Converts the color to a string. |
static Color |
valueOf(java.lang.String str)
Converts a string to a Color object. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Color(float red, float green, float blue)
The following example demonstrates how to create a Color object that represents the color "red":
float red_component = 1.0f; float green_component = 0.0f; float blue_component = 0.0f; Color color = new Color(red_component, green_component, blue_component);
red
- Value of the red component of the new color.green
- Value of the green component of the new color.blue
- Value of the blue component of the new color.public Color(float[] color)
The following example demonstrates how to create a Color object that represents the color "red":
float red_component = 1.0f; float green_component = 0.0f; float blue_component = 0.0f; float[] color_components = new float[] { red_component, green_component, blue_component }; Color color = new Color(color_components);
color
- An array of at least three float values. The red component
of the color is set to the value of the first element of the array,
the green component is set to the value of the second element of the
array, and the blue component is set to the value of the third element of the
array.public Color(Color color)
The following example demonstrates how to create a Color object that is an exact copy of another Color object:
Color given_color = ...; Color color = new Color(given_color);
color
- The other color used to initialize the new color.Method Detail |
---|
public final float getRed()
The following example demonstrates how to print the red color component of a Color object to the console:
Color color = ...; System.out.println("red component = " + color.getRed());
public final float getGreen()
The following example demonstrates how to print the green color component of a Color object to the console:
Color color = ...; System.out.println("green component = " + color.getGreen());
public final float getBlue()
The following example demonstrates how to print the blue color component of a Color object to the console:
Color color = ...; System.out.println("blue component = " + color.getBlue());
public final void get(float[] color)
The following example prints the color components of a Color object to the console:
Color color = ...; float[] color_components = new float[3]; color.get(color_components); System.out.println("red component = " + color_components[0]); System.out.println("green component = " + color_components[1]); System.out.println("blue component = " + color_components[2]);
color
- A float array that gets filled with the components of the
color. This array must have at least three elements. The first
element of the array is set to the red component of the color, the
second element of the array is set to the green component of the color,
and the third element of the array is set to the blue component of the
color.public final boolean equals(java.lang.Object obj)
The following example compares two colors and prints the result to the console:
Color color1 = ...; Color color2 = ...; System.out.println("Colors are the same: " + color1.equals(color2));
equals
in class java.lang.Object
obj
- the object to compare the color to
public final java.lang.String toString()
The following example prints the string representation of a Color object to the console:
Color color = ...; System.out.println("Color = " + color.toString());
toString
in class java.lang.Object
public static final Color valueOf(java.lang.String str)
The following example creates a new Color object that represents the color "red":
Color color = Color.valueOf("1.0 0.0 0.0");
str
- The string representation of the color.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |