com.flagstone.transform
Class FSShapeStyle

java.lang.Object
  extended by com.flagstone.transform.FSTransformObject
      extended by com.flagstone.transform.FSShapeStyle
All Implemented Interfaces:
java.lang.Cloneable

public class FSShapeStyle
extends FSTransformObject

FSShapeStyle is used to change the drawing environment when a shape is drawn. Three operations can be performed:

An FSShapeStyle object can specify one or more of the operations rather than specifying them in separate FSShapeStyle objects - compacting the size of the binary data when the object is encoded. Conversely if an operation is not defined then the values may be omitted.

Attributes
lineStyle The index of the line style in the parent shape's line style array. Optional. May be set to the framework constant Transform.VALUE_NOT_SET if no style is selected.
fillStyle The index of the fill style in the parent shape's fill style array. Optional. May be set to the framework constant Transform.VALUE_NOT_SET if no style is selected.
altFillStyle The index of the alternate fill style in the parent shape's fill style array. Optional. May be set to the framework constant Transform.VALUE_NOT_SET if no style is selected.
moveX The absolute x-coordinate of the new drawing point. Optional. May be set to the framework constant Transform.VALUE_NOT_SET if the drawing point is not being moved.
moveY The absolute y-coordinate of the new drawing point. Optional. May be set to the framework constant Transform.VALUE_NOT_SET if the drawing point is not being moved.
lineStyles An array of new line styles for the parent shape. Optional. May be set to null or an empty array if no line or fill styles are being added.
fillStyles An array of new fill styles for the parent shape. Optional. May be set to null or an empty array if no line or fill styles are being added.

Line and Fill styles are selected by the index position, starting at 1, of the style in an array of styles. An index of zero means that no style is selected. Using the constant Transform.VALUE_NOT_SET means that the current style is unchanged. Two types of fill style are supported: fillStyle is used where a shape does not contain overlapping areas and altFillStyle is used where areas overlap. This differs from graphics environments that only support one fill style as the overlapping area would form a hole in the shape and not be filled.

In the following example, when a shape is drawn the fillStyle defines the style to the left of the line drawing the outline while the altFillStyle defines the style applied to the right of the outline.

New fill and line styles can be added to the FSShapeStyle object to change the way shapes are drawn.

A new drawing point is specified using the absolute x and y coordinates. If an FSShapeStyle object is the first in a shape then the current drawing point is the origin of the shape (0,0).

Optional Attributes

Since the FSShapeStyle object can encode three different types of operation, the unused attributes are optional. Setting line or fill styles to the framework constant Transform.VALUE_NOT_SET omits the attribute when the object is encoded - reduced the size.

For the line and fill styles setting the respective attribute to Transform.VALUE_NOT_SET is different from setting to zero. When the attribute is set to Transform.VALUE_NOT_SET attribute is not encoded. When the attribute is set to zero then that instructs the Flash Player that no current line or fill style is selected. The latter is important when filling areas of a shape that overlap - the altFillStyle attribute will be set to the desired style while the lineStyle and fillStyle attributes are set to zero.

Similarly moveX and moveY may be set to Transform.VALUE_NOT_SET to indicate that the current drawing point will not be changed. This can also be achieved by setting moveX and moveY to zero. However using Transform.VALUE_NOT_SET means that the attributes are not encoded reducing the binary representation. For large files the savings can be significant.

The line or fill style arrays May be empty if no new styles are being specified.

Note that the values for the moveX and moveY attributes and the line and fill styles arrays are defined in pairs and are optional only if both are set to zero or NULL respectively.

Examples

The class provides a range of constructors which define different subsets of the attributes according to the type of operation that will be performed. If an attribute is not specified in a constructor then it will be assigned the default value of Transform.VALUE_NOT_SET and will be omitted when the object is encoded.

1. Select line and fill styles.

  FSDefineShape shape = new FSShape(movie.newIdentifier(), ...);
 
  // Add fill styles to the shape definition
  shape.add(new FSSolidFill(FSColor(0, 0, 255)));
  shape.add(new FSBitmapFill(FSFillStyle.Tiled, imageId, transform));
 
  // Add a line styles to the shape definition
 
  shape.add(new FSSolidLine(20, FSColor(0, 0, 0)));
 
  // Select the solid line style and the bitmap fill style. Note that the
  // ordinal position of the styles is used. A style index of 0 means that
  // style is not set.
 
  shape.add(new FSShapeStyle(1, 2, 0));
 

2. Move the current drawing point.

The drawing point is changed by specifying the position from the current drawing point:

 FSShapeStyle style = new FSShapeStyle(x, y);
 

3. Specifying New Styles.

Adding a new set of styles to an FSShapeStyle object will replace the existing set of styles defined for the shape.

 FSDefineShape shape = new FSDefineShape(movie.newIdentifier(), bounds,
                                fillStyles, lineStyles, shape);
 
 // Replace the existing set of fill and line styles in the shape definition
 
 ArrayList fillStyles = new ArrayList();
 ArrayList lineStyles = new ArrayList();
 
 fillStyles.add(new FSSolidFill(FSColor(255, 0, 0)));
 fillStyles.add(new FSSolidFill(FSColor(0, 255, 0)));
 fillStyles.add(new FSSolidFill(FSColor(0, 0, 255)));
 
 lineStyles.add(new FSSolidLine(1, FSColor(0, 0, 0)));
 
 shape.add(new FSShapeStyle(lineStyles, fillStyles));
 

4. Creating an overlapping shape.

 // Create the bounding rectangle for the shape. Two rectangles 100 x 100 pixels 
 // are drawn. The area overlap area is 50 x 50 pixels.
 
 FSBounds bounds = new FSBounds(0, -50, 150, 100);
 
 // Define the styles for the shape.
 
 ArrayList fillStyles = new ArrayList();
 ArrayList lineStyles = new ArrayList();
 
 fillStyles.add(new FSSolidFill(new FSColor(255, 0, 0)));
 fillStyles.add(new FSSolidFill(new FSColor(255, 255, 0)));
 fillStyles.add(new FSSolidFill(new FSColor(16, 123, 255)));
 
 lineStyles.add(new FSSolidLine(20, new FSColor(0, 0, 0)));
 
 FSDefineShape shape = new FSDefineShape(movie.newIdentifier, bounds,
                                fillStyles, lineStyles, new FSShape());
 
 // To create the overlapping shape shown above the following styles 
 // selections are made while the shape is drawn.
 
 shape.add(new FSShapeStyle(1, 1, 0, 0, 0));
 shape.add(new FSLine(50, 0));
 shape.add(new FSShapeStyle(1, 1, 3));
 shape.add(new FSLine(0, 50));
 shape.add(new FSLine(50, 0));
 shape.add(new FSShapeStyle(1, 0, 2));
 shape.add(new FSLine(50, 0));
 shape.add(new FSLine(0, -100));
 shape.add(new FSLine(-100, 0));
 shape.add(new FSLine(0, 50));
 shape.add(new FSShapeStyle(1, 3, 2));
 shape.add(new FSLine(50, 0));
 shape.add(new FSLine(0, 50));
 shape.add(new FSShapeStyle(1, 1, 0));
 shape.add(new FSLine(0, 50));
 shape.add(new FSLine(-100, 0));
 shape.add(new FSLine(0, -100));
 

History

The FSShapeStyle class represents the StyleChange record from the Macromedia Flash (SWF) File Format Specification. It was introduced in Flash 1.


Constructor Summary
FSShapeStyle(java.util.ArrayList lineStylesArray, java.util.ArrayList fillStylesArray)
          Constructs an FSShapeStyle object, specifying the new set of line and fill styles for the parent shape.
FSShapeStyle(FSCoder coder)
          Construct an FSShapeStyle object, initalizing it with values decoded from an encoded object.
FSShapeStyle(FSShapeStyle obj)
          Constructs an FSShapeStyle object by copying values from an existing object.
FSShapeStyle(int relativeX, int relativeY)
          Constructs an FSShapeStyle object, selecting the relative drawing point.
FSShapeStyle(int lineStyleIndex, int fillStyleIndex, int altFillStyleIndex)
          Constructs an FSShapeStyle object, selecting the line and fill styles.
FSShapeStyle(int lineStyleIndex, int fillStyleIndex, int altFillStyleIndex, java.util.ArrayList lineStylesArray, java.util.ArrayList fillStylesArray)
          Constructs an FSShapeStyle object, selecting the line and fill styles, new line and new fill styles.
FSShapeStyle(int lineStyleIndex, int fillStyleIndex, int altFillStyleIndex, int relativeX, int relativeY)
          Constructs an FSShapeStyle object, selecting the line and fill styles and drawing point.
FSShapeStyle(int lineStyleIndex, int fillStyleIndex, int altFillStyleIndex, int relativeX, int relativeY, java.util.ArrayList lineStylesArray, java.util.ArrayList fillStylesArray)
          Constructs an FSShapeStyle object, selecting the line and fill styles, drawing point, new line and new fill styles.
 
Method Summary
 void add(FSFillStyle aFillStyle)
          Add the fill style object to the array of fill styles.
 void add(FSLineStyle aLineStyle)
          Add a FSSolidLine object to the array of line styles.
 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.
 int getAltFillStyle()
          Gets the index of the fill style that will be applied to any overlapping area filled.
 int getFillStyle()
          Gets the index of the fill style that will be applied to any area filled.
 java.util.ArrayList getFillStyles()
          Gets the array of new fill styles.
 int getLineStyle()
          Gets the index of the line style that will be applied to any line drawn.
 java.util.ArrayList getLineStyles()
          Gets the array of new line styles.
 int getMoveX()
          Gets the x-coordinate of any relative move specified.
 int getMoveY()
          Gets the y-coordinate of any relative move specified.
 int length(FSCoder coder)
           
 void setAltFillStyle(int anIndex)
          Sets the index of the fill style that will be applied to any overlapping area filled.
 void setFillStyle(int anIndex)
          Sets the index of the fill style that will be applied to any area filled.
 void setFillStyles(java.util.ArrayList anArray)
          Sets the array of new fill styles.
 void setLineStyle(int anIndex)
          Sets the index of the line style that will be applied to any line drawn.
 void setLineStyles(java.util.ArrayList anArray)
          Sets the array of new line styles.
 void setMove(int x, int y)
          Sets the drawing point.
 void setMoveX(int aNumber)
          Sets the x-coordinate of any relative move.
 void setMoveY(int aNumber)
          Sets the y-coordinate of any relative move.
 
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

FSShapeStyle

public FSShapeStyle(FSCoder coder)
Construct an FSShapeStyle object, initalizing it with values decoded from an encoded object.

Parameters:
coder - an FSCoder containing the binary data.

FSShapeStyle

public FSShapeStyle(int lineStyleIndex,
                    int fillStyleIndex,
                    int altFillStyleIndex)
Constructs an FSShapeStyle object, selecting the line and fill styles.

Parameters:
lineStyleIndex - selects the line style at lineStyleIndex in the line styles array of the parent FSShape object.
fillStyleIndex - selects the fill style at fillStyleIndex in the fill styles array of the parent FSShape object.
altFillStyleIndex - selects the alternate fill style at altFillStyleIndex in the fill styles array of the parent FSShape object.

FSShapeStyle

public FSShapeStyle(int relativeX,
                    int relativeY)
Constructs an FSShapeStyle object, selecting the relative drawing point.

Parameters:
relativeX - move the current point by relativeX in the x direction.
relativeY - move the current point by relativeY in the y direction.

FSShapeStyle

public FSShapeStyle(java.util.ArrayList lineStylesArray,
                    java.util.ArrayList fillStylesArray)
Constructs an FSShapeStyle object, specifying the new set of line and fill styles for the parent shape.

Parameters:
lineStylesArray - an array of FSLineStyle objects.
fillStylesArray - an array of fill style objects.

FSShapeStyle

public FSShapeStyle(int lineStyleIndex,
                    int fillStyleIndex,
                    int altFillStyleIndex,
                    int relativeX,
                    int relativeY)
Constructs an FSShapeStyle object, selecting the line and fill styles and drawing point.

Parameters:
lineStyleIndex - selects the line style at lineStyleIndex in the line styles array of the parent FSShape object.
fillStyleIndex - selects the fill style at fillStyleIndex in the fill styles array of the parent FSShape object.
altFillStyleIndex - selects the alternate fill style at altFillStyleIndex in the fill styles array of the parent FSShape object.
relativeX - move the current point by relativeX in the x direction.
relativeY - move the current point by relativeY in the y direction.

FSShapeStyle

public FSShapeStyle(int lineStyleIndex,
                    int fillStyleIndex,
                    int altFillStyleIndex,
                    java.util.ArrayList lineStylesArray,
                    java.util.ArrayList fillStylesArray)
Constructs an FSShapeStyle object, selecting the line and fill styles, new line and new fill styles.

Parameters:
lineStyleIndex - selects the line style at lineStyleIndex in the line styles array of the parent FSShape object.
fillStyleIndex - selects the fill style at fillStyleIndex in the fill styles array of the parent FSShape object.
altFillStyleIndex - selects the alternate fill style at altFillStyleIndex in the fill styles array of the parent FSShape object.
lineStylesArray - an array of FSLineStyle objects.
fillStylesArray - an array of fill style objects.

FSShapeStyle

public FSShapeStyle(int lineStyleIndex,
                    int fillStyleIndex,
                    int altFillStyleIndex,
                    int relativeX,
                    int relativeY,
                    java.util.ArrayList lineStylesArray,
                    java.util.ArrayList fillStylesArray)
Constructs an FSShapeStyle object, selecting the line and fill styles, drawing point, new line and new fill styles.

Parameters:
lineStyleIndex - selects the line style at lineStyleIndex in the line styles array of the parent FSShape object.
fillStyleIndex - selects the fill style at fillStyleIndex in the fill styles array of the parent FSShape object.
altFillStyleIndex - selects the alternate fill style at altFillStyleIndex in the fill styles array of the parent FSShape object.
relativeX - move the current point by relativeX in the x direction.
relativeY - move the current point by relativeY in the y direction.
lineStylesArray - an array of FSLineStyle objects.
fillStylesArray - an array of fill style objects.

FSShapeStyle

public FSShapeStyle(FSShapeStyle obj)
Constructs an FSShapeStyle object by copying values from an existing object.

Parameters:
obj - an FSShapeStyle object.
Method Detail

add

public void add(FSLineStyle aLineStyle)
Add a FSSolidLine object to the array of line styles.

Parameters:
aLineStyle - and FSSolidLine object.

add

public void add(FSFillStyle aFillStyle)
Add the fill style object to the array of fill styles.

Parameters:
aFillStyle - and FSFillStyle object.

getMoveX

public int getMoveX()
Gets the x-coordinate of any relative move specified.

Returns:
the x-coordinate of the relative move.

getMoveY

public int getMoveY()
Gets the y-coordinate of any relative move specified. If the attribute is set to Transform.VALUE_NOT_SET then the value is not affected.

Returns:
the y-coordinate of the relative move.

getLineStyle

public int getLineStyle()
Gets the index of the line style that will be applied to any line drawn. Returns the value Transform.VALUE_NOT_SET if no line style is defined.

Returns:
the index of the selected line style.

getFillStyle

public int getFillStyle()
Gets the index of the fill style that will be applied to any area filled. Returns the value Transform.VALUE_NOT_SET if no fill style is defined.

Returns:
the index of the selected fill style.

getAltFillStyle

public int getAltFillStyle()
Gets the index of the fill style that will be applied to any overlapping area filled. Returns the value Transform.VALUE_NOT_SET if no alternate fill style is defined.

Returns:
the index of the selected alternate style.

getLineStyles

public java.util.ArrayList getLineStyles()
Gets the array of new line styles.

Returns:
the array of FSLineStyle objects.

getFillStyles

public java.util.ArrayList getFillStyles()
Gets the array of new fill styles.

Returns:
the array of fill style objects.

setMoveX

public void setMoveX(int aNumber)
Sets the x-coordinate of any relative move. May be set to Transform.VALUE_NOT_SET if the attribute should not be encoded.

Parameters:
aNumber - move the current point by aNumber in the x direction.

setMoveY

public void setMoveY(int aNumber)
Sets the y-coordinate of any relative move. May be set to Transform.VALUE_NOT_SET if the attribute should not be encoded.

Parameters:
aNumber - move the current point by aNumber in the y direction.

setMove

public void setMove(int x,
                    int y)
Sets the drawing point.

Parameters:
x - the x-coordinate of the drawing point.
y - the y-coordinate of the drawing point.

setFillStyle

public void setFillStyle(int anIndex)
Sets the index of the fill style that will be applied to any area filled. May be set to zero if no style is selected or Transform.VALUE_NOT_SET if the attribute should not be encoded.

Parameters:
anIndex - selects the fill style at anIndex in the fill styles array of the parent FSShape object.

setAltFillStyle

public void setAltFillStyle(int anIndex)
Sets the index of the fill style that will be applied to any overlapping area filled. May be set to zero if no style is selected or Transform.VALUE_NOT_SET if the attribute should not be encoded.

Parameters:
anIndex - selects the alternate fill style at anIndex in the fill styles array of the parent FSShape object.

setLineStyle

public void setLineStyle(int anIndex)
Sets the index of the line style that will be applied to any line drawn. May be set to zero if no style is selected or Transform.VALUE_NOT_SET if the attribute should not be encoded.

Parameters:
anIndex - selects the line style at anIndex in the line styles array of the parent FSShape object.

setLineStyles

public void setLineStyles(java.util.ArrayList anArray)
Sets the array of new line styles. May be set to null if no styles are being defined.

Parameters:
anArray - an array of FSLineStyle objects.

setFillStyles

public void setFillStyles(java.util.ArrayList anArray)
Sets the array of new fill styles. May be set to null if no styles are being defined.

Parameters:
anArray - an array of fill style 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)
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