com.flagstone.transform.fillstyle
Class Gradient

java.lang.Object
  extended by com.flagstone.transform.fillstyle.Gradient
All Implemented Interfaces:
SWFEncodeable

public final class Gradient
extends Object
implements SWFEncodeable

Gradient defines a control point that is used to specify how a gradient colour is displayed.

Two or more control points are used to define how the colour changes across the gradient square. Each control point specifies the ratio indicating the location of the control point across the gradient square and the colour to be displayed at that point.

The ratio is a number between 0 and 255 - that specifies the relative location in the square. For Linear Gradient Fills a ratio of zero is mapped to the left side of the gradient square and 255 is mapped to the right side of the square. For Radial Gradient Fills a ratio of zero is mapped to the centre of the gradient square and 255 is mapped to the edge of the largest circle that fits inside the gradient square. A ratio is used rather than specifying coordinates within the gradient square as the coordinate space is transformed to fit the shape that the gradient is being displayed in.

Note that the object used to create the shape definition determines whether the alpha channel is encoded in the gradient colours. Simply specifying the level of transparency in the Color object is not sufficient.

See Also:
GradientFill

Field Summary
static int MAX_GRADIENTS
          Maximum number of gradient records.
 
Constructor Summary
Gradient(int aRatio, Color aColor)
          Creates a Gradient object with the specified ratio and color.
Gradient(SWFDecoder coder, Context context)
          Creates and initialises a Gradient object using values encoded in the Flash binary format.
 
Method Summary
 void encode(SWFEncoder coder, Context context)
          Encode an object to the Flash binary format.
 boolean equals(Object object)
           
 Color getColor()
          Get the colour that is displayed at the control point across the gradient square defined by the ratio.
 int getRatio()
          Get the ratio that defines the relative point across the gradient square.
 int hashCode()
           
 int prepareToEncode(Context context)
          Prepare an object for encoding, returning the expected size of an object when it is encoded.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_GRADIENTS

public static final int MAX_GRADIENTS
Maximum number of gradient records.

See Also:
Constant Field Values
Constructor Detail

Gradient

public Gradient(SWFDecoder coder,
                Context context)
         throws IOException
Creates and initialises a Gradient object using values encoded in the Flash binary format.

Parameters:
coder - an SWFDecoder object that contains the encoded Flash data.
context - a Context object used to manage the decoders for different type of object and to pass information on how objects are decoded.
Throws:
IOException - if an error occurs while decoding the data.

Gradient

public Gradient(int aRatio,
                Color aColor)
Creates a Gradient object with the specified ratio and color.

Parameters:
aRatio - the ratio along the gradient square. Must be in the range 0..255.
aColor - the color at the control point. Must not be null.
Method Detail

getRatio

public int getRatio()
Get the ratio that defines the relative point across the gradient square.

Returns:
the ratio for the gradient in the range 0..255.

getColor

public Color getColor()
Get the colour that is displayed at the control point across the gradient square defined by the ratio.

Returns:
the colour for the gradient at the ratio point.

toString

public String toString()
Overrides:
toString in class Object

equals

public boolean equals(Object object)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

prepareToEncode

public int prepareToEncode(Context context)
Prepare an object for encoding, returning the expected size of an object when it is encoded. This method also used to initialise variables, such as offsets and flags that will be used when the object is encoded. Generally the method returns the size in bytes, however when called on objects that use bit fields such as shapes the methods will return the size in bits.

Specified by:
prepareToEncode in interface SWFEncodeable
Parameters:
context - an Context that allows information to be passed between objects to control how they are initialised for encoding.
Returns:
the size of the object when it is encoded.

encode

public void encode(SWFEncoder coder,
                   Context context)
            throws IOException
Encode an object to the Flash binary format.

Specified by:
encode in interface SWFEncodeable
Parameters:
coder - an SWFEncoder object.
context - an Context that allows information to be passed between objects to control how they are initialised for encoding.
Throws:
IOException - if an error occurs while encoding the object.


Copyright © 2002-2010 Flagstone Software Ltd.. All Rights Reserved.