org.instantreality.InstantIO
Class Color

java.lang.Object
  extended by org.instantreality.InstantIO.Color

public class Color
extends java.lang.Object

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());
 

Author:
Patrick Dähne

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

Color

public Color(float red,
             float green,
             float blue)
Constructor that initializes the components of the Color object with the given float values.

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);
 

Parameters:
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.

Color

public Color(float[] color)
Constructor that initializes the components of the Color object with the values of a given float array.

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);
 

Parameters:
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.

Color

public Color(Color color)
Constructor that initializes the components of the Color object with the components taken from another Color object.

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);
 

Parameters:
color - The other color used to initialize the new color.
Method Detail

getRed

public final float getRed()
Returns the value of the red component.

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());
 

Returns:
The value of the red component

getGreen

public final float getGreen()
Returns the value of the green component.

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());
 

Returns:
The value of the green component

getBlue

public final float getBlue()
Returns the value of the blue component.

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());
 

Returns:
The value of the blue component

get

public final void get(float[] color)
Returns the values of the red, green and blue components.

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]);
 

Parameters:
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.

equals

public final boolean equals(java.lang.Object obj)
Compares the color to another object. The result is true if the other object is not null and is a Color object and the components of the other Color object are the same as the components of this color.

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));
 

Overrides:
equals in class java.lang.Object
Parameters:
obj - the object to compare the color to
Returns:
true when the colors are equal, false otherwise

toString

public final java.lang.String toString()
Converts the color to a string. The string representation consists of the red component, the green component and the blue component, separated by space characters.

The following example prints the string representation of a Color object to the console:

 Color color = ...;
 System.out.println("Color = " + color.toString());
 

Overrides:
toString in class java.lang.Object
Returns:
A string representation of the color

valueOf

public static final Color valueOf(java.lang.String str)
Converts a string to a Color object. The string must consist of the red component, the green component and the blue component, separated by space characters.

The following example creates a new Color object that represents the color "red":

 Color color = Color.valueOf("1.0 0.0 0.0");
 

Parameters:
str - The string representation of the color.
Returns:
The new Color object, parsed from the string.