Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.flagstone.transform
Class FSColor

    java.lang.Object
      com.flagstone.transform.FSTransformObject
          com.flagstone.transform.FSColor

All Implemented Interfaces:
  java.lang.Cloneable

    public class FSColor

extends FSTransformObject

FSColor is used to represent colours.

The FSColor class supports the RGB colour space with an optional alpha channel which is used to specify the transparency of an object. An FSColor object supports 32-bit colours with 8 bits per colour channel.

Attributes
red | The red channel of the colour, with values in the range 0..255.
green | The green channel of the colour, with values in the range 0..255.
blue | The blue channel of the colour, with values in the range 0..255.
alpha | The alpha channel of the colour, with values in the range 0..255.

Whether a colour contains transparency information is determined by the context created by the object that contains the colour. For example colours within the FSDefineShape and FSDefineShape2 objects do not contain alpha channel information while those in an FSDefineShape3 object do. To simplify the use of the colours only a single class is provided. The alpha channel can be ignored if not required within the object the colour is defined for. When a FSColor object is encoded or decoded the object notifies the colour objects it contains whether the alpha channel information should also be encoded or decoded. As of Version 5 of the Macromedia Flash (SWF) File Format Specification only the FSPlaceObject2, FSDefineText2 and FSDefineShape3 classes use colours containing an alpha channel.

The class provides a range of constructors to instantiate objects using colour information presented in a variety of formats. To create a colour, specifying values for colour channels in the following order: red, green, blue and optionally alpha:

     FSColor red = new FSColor(255, 0, 0);

     FSColor green = new FSColor(0, 255, 0);

     FSColor blue = new FSColor(0, 0, 255);

When the alpha channel is not specified it defaults to a value of 255 which defines the colour to be completely opaque. For transparent colours the alpha channel determines how opaque the colour is. 0 represents a fully transparent colour and 255 is fully opaque.

     FSColor transparentRed = new FSColor(255, 0, 0, 128);

     FSColor transparentGreen = new FSColor(0, 255, 0, 128);

     FSColor transparentBlue = new FSColor(0, 0, 255, 128);

When the alpha channel is not specified it defaults to a value of 255 which defines the colour to be completely opaque. The classes that contain colour objects control whether the value for the alpha channel is encoded. For example FSDefineShape and FSDefineShape2 support opaque colours while FSDefineShape3 supports transparent colours. If only opaque colours are supported then the alpha channel can be ignored when creating and manipulating FSColor objects.

# History

FSColor class represents the colour data types, RGB and RGBA in the Macromedia Flash (SWF) File Format Specification. The colour data structure was available was introduced in Flash 1 and transparent colours were introduced in Flash 3.

Constructor Summary
`FSColor(FSCoder coder)` Construct an FSColor object and initialise it with values decoded from a binary encoded FSColor object.
`FSColor(FSColor obj)` Construct an FSColor object and initialise it with value from another FSColor object.
`FSColor(int r, int g, int b)` Constructs an FSColor object containing red, green and blue channels.
`FSColor(int r, int g, int b, int a)` Constructs an FSColor object containing red, green, blue and alpha channels.

Method Summary
`void` | `appendDescription(java.lang.StringBuffer buffer, int depth)` AppendDescription is used to present a string description of the object including all nested objects up to a specified depth.
`void` | `decode(FSCoder coder)`
`void` | `encode(FSCoder coder)`
`boolean` | `equals(java.lang.Object anObject)` Returns true if anObject is equal to this one.
`int` | `getAlpha()` Gets the value for the alpha colour channel.
`int` | `getBlue()` Gets the value for the blue colour channel.
`int` | `getGreen()` Gets the value for the green colour channel.
`int` | `getRed()` Gets the value for the red colour channel.
`int` | `length(FSCoder coder)`
`void` | `setAlpha(int a)` Set the value for the alpha channel.
`void` | `setBlue(int b)` Set the value for the blue colour channel.
`void` | `setChannels(int r, int g, int b)` Set the values for the red, green and blue colour channels.
`void` | `setChannels(int r, int g, int b, int a)` Set the values for each of the four colour channels.
`void` | `setGreen(int g)` Set the value for the green colour channel.
`void` | `setRed(int r)` Set the value for the red colour channel.

Methods inherited from class com.flagstone.transform.FSTransformObject
`clone, name, toString`

Methods inherited from class java.lang.Object
`finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### FSColor

    public FSColor(FSCoder coder)

  Construct an FSColor object and initialise it with values decoded from a binary encoded FSColor object.

  Parameters:
    `coder` - an FSCoder object containing an FSColor encoded as binary data.

### FSColor

    public FSColor(int r,
                   int g,
                   int b)

  Constructs an FSColor object containing red, green and blue channels. The alpha channel defaults to the value 255 - defining an opaque colour.

  Parameters:
    `r` - value for the red channel, in the range 0..255.
    `g` - value for the green channel, in the range 0..255.
    `b` - value for the blue channel, in the range 0..255.

### FSColor

    public FSColor(int r,
                   int g,
                   int b,
                   int a)

  Constructs an FSColor object containing red, green, blue and alpha channels.

  Parameters:
    `r` - value for the red channel, in the range 0..255.
    `g` - value for the green channel, in the range 0..255.
    `b` - value for the blue channel, in the range 0..255.
    `a` - value for the alpha channel, in the range 0..255.

### FSColor

    public FSColor(FSColor obj)

  Construct an FSColor object and initialise it with value from another FSColor object.

  Parameters:
    `obj` - an FSColor object.

Method Detail

### getRed

    public int getRed()

  Gets the value for the red colour channel.

  Returns:
    the value for the red channel in the range 0..255.

### getGreen

    public int getGreen()

  Gets the value for the green colour channel.

  Returns:
    the value for the green channel in the range 0..255.

### getBlue

    public int getBlue()

  Gets the value for the blue colour channel.

  Returns:
    the value for the blue channel in the range 0..255.

### getAlpha

    public int getAlpha()

  Gets the value for the alpha colour channel.

  Returns:
    the value for the alpha channel in the range 0..255.

### setRed

    public void setRed(int r)

  Set the value for the red colour channel.

  Parameters:
    `r` - value for the red channel.

### setGreen

    public void setGreen(int g)

  Set the value for the green colour channel.

  Parameters:
    `g` - value for the green channel.

### setBlue

    public void setBlue(int b)

  Set the value for the blue colour channel.

  Parameters:
    `b` - value for the blue channel, in the range 0..255.

### setAlpha

    public void setAlpha(int a)

  Set the value for the alpha channel.

  Parameters:
    `a` - value for the alpha channel, in the range 0..255.

### setChannels

    public void setChannels(int r,
                            int g,
                            int b)

  Set the values for the red, green and blue colour channels. The alpha channel is not changed.

  Parameters:
    `r` - value for the red channel, in the range 0..255.
    `g` - value for the green channel, in the range 0..255.
    `b` - value for the blue channel, in the range 0..255.

### setChannels

    public void setChannels(int r,
                            int g,
                            int b,
                            int a)

  Set the values for each of the four colour channels.

  Parameters:
    `r` - value for the red channel, in the range 0..255.
    `g` - value for the green channel, in the range 0..255.
    `b` - value for the blue channel, in the range 0..255.
    `a` - value for the alpha channel, in the range 0..255.

### equals

    public boolean equals(java.lang.Object anObject)

  Returns true if anObject is equal to this one. Objects are considered equal if they would generate identical binary data when they are encoded to a Flash file.

  Overrides:
    `equals` in class `FSTransformObject`
  Returns:
    true if this object would be identical to anObject when encoded.

### appendDescription

    public void appendDescription(java.lang.StringBuffer buffer,
                                  int depth)

  Description copied from class: `FSTransformObject`
  AppendDescription is used to present a string description of the object including all nested objects up to a specified depth. This method provide a more controlled way of creating a string representation of an object since large objects such as font or shape definitions can contain dozens of nested objects. The representation of the object is appended to the StringBuffer, showing the name of the class and values of the attributes it contains. If the object contains any attributes that are objects then the object graph will be traversed up to the specified depth. If objects are nested at a level less than specified depth then the full string representation of the object is displayed. For objects at the specified depth only the name of the class is displayed. Any objects below this depth are not displayed.

  Specified by:
    `appendDescription` in class `FSTransformObject`
  Parameters:
    `buffer` - a StringBuffer to which the description of each object is appended.
    `depth` - the maximum level of nesting up to which objects will be displayed.

### length

    public int length(FSCoder coder)

  Specified by:
    `length` in class `FSTransformObject`

### encode

    public void encode(FSCoder coder)

  Specified by:
    `encode` in class `FSTransformObject`

### decode

    public void decode(FSCoder coder)

  Specified by:
    `decode` in class `FSTransformObject`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD