org.instantreality.InstantIO
Class ColorRGBA

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

public class ColorRGBA
extends java.lang.Object

Helper class for exchanging RGBA colors of four float components.

ColorRGBA is a basic helper class for exchanging colors of four 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 ColorRGBA'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, the third component the blue component, and the fourth component the alpha component. All components must be between 0 and 1, inclusively. For color components, 0 means no intensity, and 1 means maximum intensity. For the alpha component, 0 means fully transparent, and 1 means fully opaque.

The following example creates a ColorRGBA object that represents the color "red", and prints its components to the console:

 ColorRGBA red = new ColorRGBA(1.0f, 0.0f, 0.0f, 1.0f);
 System.out.println("red component = " + red.getRed());
 System.out.println("green component = " + red.getGreen());
 System.out.println("blue component = " + red.getBlue());
 System.out.println("alpha component = " + red.getAlpha());
 

Author:
Patrick Dähne

Constructor Summary
ColorRGBA(ColorRGBA color)
          Constructor that initializes the components of the ColorRGBA object with the components taken from another ColorRGBA object.
ColorRGBA(float[] color)
          Constructor that initializes the components of the ColorRGBA object with the values of a given float array.
ColorRGBA(float red, float green, float blue, float alpha)
          Constructor that initializes the components of the ColorRGBA 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, blue and alpha components.
 float getAlpha()
          Returns the value of the alpha component.
 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 ColorRGBA valueOf(java.lang.String str)
          Converts a string to a ColorRGBA object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ColorRGBA

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

The following example demonstrates how to create a ColorRGBA object that represents the color "red":

 float red_component = 1.0f;
 float green_component = 0.0f;
 float blue_component = 0.0f;
 float alpha_component = 1.0f;
 ColorRGBA color = new ColorRGBA(red_component, green_component, blue_component, alpha_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.
alpha - Value of the alpha component of the new color.

ColorRGBA

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

The following example demonstrates how to create a ColorRGBA object that represents the color "red":

 float red_component = 1.0f;
 float green_component = 0.0f;
 float blue_component = 0.0f;
 float alpha_component = 1.0f;
 float[] color_components = new float[] { red_component, green_component, blue_component, alpha_component };
 ColorRGBA color = new ColorRGBA(color_components);
 

Parameters:
color - An array of at least four 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, the blue component is set to the value of the third element of the array and the alpha component is set to the value of the fourth element of the array.

ColorRGBA

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

The following example demonstrates how to create a ColorRGBA object that is an exact copy of another ColorRGBA object:

 ColorRGBA given_color = ...;
 ColorRGBA color = new ColorRGBA(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 ColorRGBA object to the console:

 ColorRGBA 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 ColorRGBA object to the console:

 ColorRGBA 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 ColorRGBA object to the console:

 ColorRGBA color = ...;
 System.out.println("blue component = " + color.getBlue());
 

Returns:
The value of the blue component

getAlpha

public final float getAlpha()
Returns the value of the alpha component.

The following example demonstrates how to print the alpha color component of a ColorRGBA object to the console:

 ColorRGBA color = ...;
 System.out.println("alpha component = " + color.getAlpha());
 

Returns:
The value of the alpha component

get

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

The following example prints the color components of a ColorRGBA object to the console:

 ColorRGBA color = ...;
 float[] color_components = new float[4];
 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]);
 System.out.println("alpha component = " + color_components[3]);
 

Parameters:
color - A float array that gets filled with the components of the color. This array must have at least four 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, the third element of the array is set to the blue component of the color, and the fourth element of the array is set to the alpha 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 object is not null and is a ColorRGBA object and the components of the other ColorRGBA object are the same as the components of this color.

The following example compares two colors and prints the result to the console:

 ColorRGBA color1 = ...;
 ColorRGBA 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, the blue component and the alpha component, separated by space characters.

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

 ColorRGBA 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 ColorRGBA valueOf(java.lang.String str)
Converts a string to a ColorRGBA object. The string must consist of the red component, the green component, the blue component and the alpha component, separated by space characters.

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

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

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