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 FSGradientFill

    java.lang.Object
      com.flagstone.transform.FSTransformObject
          com.flagstone.transform.FSFillStyle
              com.flagstone.transform.FSGradientFill

All Implemented Interfaces:
  java.lang.Cloneable

    public class FSGradientFill

extends FSFillStyle

FSGradientFill defines how a colour changes across an area to be filled with colour.

Two types of gradient fill are supported:

Linear | The gradient changes in one direction across the area to be filled.
Radial | The gradient changes radially from the centre of the area to be filled.

Gradients are defined in terms of a standard space called the gradient square, centred at (0,0) and extending from (-16384, -16384) to (16384, 16384).

A coordinate transform is required to map the gradient square to the coordinates of the filled area. The transformation is applied in two steps. First the gradient square is scaled so the colour covers the shape followed by a translation to map the gradient square coordinates to the coordinate range of the shape.

A series of control points is used to control how the colour displayed changes across the gradient. At least two control points are required to define a gradient - one for the starting colour and one for the final colour. Up to eight control points may be specified to generate complex colour transitions. When the Flash Player displays the control points they are sorted by the ratio defined in each FSGradient object, with the smallest ratio value displayed first.

Attributes
type | The type of gradient fill, either FSFillStyle.Linear or FSFillStyle.Radial.
transform | A coordinate transformation used to map the gradient square into the coordinates of the area to be filled.
gradients | An array of up to eight FSGradient objects that define the control points across the gradient square that control the colour transitions. The Flash Player performs the interpolation of the colour values between the control points.

In addition to specifying the type of gradient fill that will be displayed the type attribute may be used when iterating through an array of fill style objects to identify the type of fill style without using run-time type checking.

# Example

For the coordinate transformation, the scaling factor is calculated by diving the width of the gradient square by the width of the shape:

     float gradientSquareWidth = 32768.0f;

     float scale = gradientSquareWidth / shapeWidth;

The translation is defined by calculating the difference between the minimum coordinates of the scaled gradient square and the minimum coordinates of the shape:

     int gradientX = -16384; // minimum x coordinate of the gradient square.

     int gradientY = -16384; // minimum y coordinate of the gradient square.

     // Get the minimum coordinates of the shape being filled;
     int shapeX = shape.getBounds().getMinX();

     int shapeY = shape.getBounds().getMinY();

     // Now calculate the translation
     int translateX = shapeX - (gradientX / scale);

     int translateY = shapeY - (gradientY / scale);

The FSCoordTransform has a convenient constructor to create the two-step transformation:

     FSCoordTransform composite = new FSCoordTransform(translateX, translateY,
                                    scale, scale);

The transform is independent of any transformation defined for the parent shape in which the gradient is displayed. The gradient will be displayed correctly if the shape is scaled, rotated, etc., when it is added to the display list.

# History

The FSGradientFill class represents the FillStyle structure from the Macromedia Flash (SWF) File Format Specification. It was introduced in Flash 1.

Field Summary

Fields inherited from class com.flagstone.transform.FSFillStyle
`Clipped, Linear, Radial, Solid, Tiled, type, Unsmoothed_Clipped, Unsmoothed_Tiled`

Constructor Summary
`FSGradientFill(FSCoder coder)` Construct an FSGradientFill object, initialising it with values decoded from an encoded object.
`FSGradientFill(FSGradientFill obj)` Constructs an FSGradientFill object by copying values from an existing object.
`FSGradientFill(int aType, FSCoordTransform aTransform, java.util.ArrayList anArray)` Constructs an FSGradientFill object specifying the type, coordinate transform and array of gradient records.

Method Summary
`void` | `add(FSGradient aGradient)` Add a FSGradient object to the array of gradient objects.
`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.
`java.lang.Object` | `clone()` Creates a deep copy of the entire object.
`void` | `decode(FSCoder coder)`
`void` | `encode(FSCoder coder)`
`boolean` | `equals(java.lang.Object anObject)` Returns true if anObject is equal to this one.
`java.util.ArrayList` | `getGradients()` Gets the array of up to eight FSGradient objects defining the control points for the gradient.
`FSCoordTransform` | `getTransform()` Gets the coordinate transform mapping the gradient square onto physical coordinates.
`int` | `length(FSCoder coder)`
`void` | `setGradients(java.util.ArrayList anArray)` Sets the array of control points that define the gradient.
`void` | `setTransform(FSCoordTransform aTransform)` Sets the coordinate transform mapping the gradient square onto physical coordinates.

Methods inherited from class com.flagstone.transform.FSFillStyle
`getType, setType`

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

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

Constructor Detail

### FSGradientFill

    public FSGradientFill(FSCoder coder)

  Construct an FSGradientFill object, initialising it with values decoded from an encoded object.

  Parameters:
    `coder` - an FSCoder containing the binary data.

### FSGradientFill

    public FSGradientFill(int aType,
                          FSCoordTransform aTransform,
                          java.util.ArrayList anArray)

  Constructs an FSGradientFill object specifying the type, coordinate transform and array of gradient records.

  Parameters:
    `aType` - the type of gradient fill, either FSFillStyle.Linear or FSFillStyle.Radial.
    `aTransform` - the coordinate transform mapping the gradient square onto physical coordinates.
    `anArray` - an array of up to eight FSGradient objects defining the control points for the gradient.

### FSGradientFill

    public FSGradientFill(FSGradientFill obj)

  Constructs an FSGradientFill object by copying values from an existing object.

  Parameters:
    `obj` - an FSGradientFill object.

Method Detail

### add

    public void add(FSGradient aGradient)

  Add a FSGradient object to the array of gradient objects.

  Parameters:
    `aGradient` - an FSGradient object.

### getTransform

    public FSCoordTransform getTransform()

  Gets the coordinate transform mapping the gradient square onto physical coordinates.

  Returns:
    the coordinate transform.

### getGradients

    public java.util.ArrayList getGradients()

  Gets the array of up to eight FSGradient objects defining the control points for the gradient.

  Returns:
    the array of control points.

### setTransform

    public void setTransform(FSCoordTransform aTransform)

  Sets the coordinate transform mapping the gradient square onto physical coordinates.

  Parameters:
    `aTransform` - the coordinate transform.

### setGradients

    public void setGradients(java.util.ArrayList anArray)

  Sets the array of control points that define the gradient.

  Parameters:
    `anArray` - an array of up to eight FSGradient objects.

### clone

    public java.lang.Object clone()

  Description copied from class: `FSTransformObject`
  Creates a deep copy of the entire object.

  Overrides:
    `clone` in class `FSTransformObject`
  Returns:
    a copy of the object.

### equals

    public boolean equals(java.lang.Object anObject)

  Description copied from class: `FSFillStyle`
  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 `FSFillStyle`
  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)

  Overrides:
    `length` in class `FSFillStyle`

### encode

    public void encode(FSCoder coder)

  Overrides:
    `encode` in class `FSFillStyle`

### decode

    public void decode(FSCoder coder)

  Overrides:
    `decode` in class `FSFillStyle`

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