com.flagstone.transform
Class FSButton

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

public class FSButton
extends FSTransformObject

FSButton identifies the shape that is drawn when a button is in a particular state.

Shapes can be drawn for each of three button states, Over, Up and Down. Creating a button with more than one FSButton object each referencing a different shape allows the button to be animated as it is clicked.

A shape is also used to define active area of the button. When defining the active area the outline of the shape defines the boundary of the area. The shape is not drawn when the button is displayed. The button will only respond to mouse events when the cursor is placed inside the active area.

Attributes
state the state(s) the button is in when the shape will be drawn, either Up, Over or Down. Active is used to denote when a shape defined the active area of a button.
identifier The identifier, in the range 1..65535, of the object that contains the definition of the shape that is drawn.
layer The layer number defines the order in which shapes are displayed. Shapes with a higher layer number are displayed in front of those on a lower layer. Complex buttons can be created by displaying more than one shape for a given button state. The layer number may be in the range 1..65535 - the range is determined by the size of the field when the value is encoded to a Flash file - however the vast majority of buttons will typically only use layer numbers less than 10.
transform an FSCoordTransform object that defines a coordinate transform that will be applied to the shape when it is displayed. The transform is most commonly used to offset shapes to create a 3-D appearance. The size may also be changed allowing a single shape definition to be used to display buttons in a range of sizes while still maintaining the same look and feel.
colorTransform an optional FSColorTransform object that can be used to change the shape's colour when it is drawn.

An FSButton can define the appearance of the button for more than one state. Multiple states can be defined by bitwise Or-ing individual state codes together:

 int buttonState = FSButton.Up | FSButton.Over;
 

The purpose of the layer attribute is to define the order in which shapes are displayed for a given button state. This is analogous to the layer number in the Flash Player's display list - specified using objects such as FSPlaceObject. When a button is displayed it is placed on a single layer in the display list and the layer numbers assigned to shapes in a FSButton object do not interfere with shapes assigned to the same layer in the display list.

The coordinate transform is used to change the appearance of the button without changing the original shape definitions. If it is omitted then a unity transform will be encoded which does not change the way the shape is drawn.

History

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


Field Summary
static int Active
          Code for the active area of the button.
static int Down
          Code for the state of the button when the mouse is clicked the active area.
static int Over
          Code for the state of the button when the mouse is over the active area.
static int Up
          Code for the button in the up state.
 
Constructor Summary
FSButton(FSButton obj)
          Constructs an FSButton object by copying values from an existing object.
FSButton(FSCoder coder)
          Construct an FSButton object, initalizing it with values decoded from an encoded object.
FSButton(int aState, int anIdentifier, int aLayer)
          Constructs an FSButton object without a coordinate or colour transform that will be applied to the shape drawn for the button states.
FSButton(int aState, int anIdentifier, int aLayer, FSCoordTransform aTransform)
          Constructs an FSButton object with a coordinate transform that will be applied to the shape drawn for the button states.
FSButton(int aState, int anIdentifier, int aLayer, FSCoordTransform aTransform, FSColorTransform aColorTransform)
          Constructs an FSButton object with a coordinate and colour transform that will be applied to the shape drawn for the button states.
 
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.
 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.
 FSColorTransform getColorTransform()
          Gets the colour transform that will be applied to the button.
 int getIdentifier()
          Gets the identifier of the shape that this FSButton applies to.
 int getLayer()
          Gets the layer that the button will be displayed on.
 int getState()
          Get the state(s) of the button when the shape is drawn.
 FSCoordTransform getTransform()
          Gets the coordinate transform that will be applied to the button.
 boolean isActive()
          Does the Button Record defines a shape for the button's active area.
 boolean isDown()
          Does the Button Record define a shape for the button's 'down' state.
 boolean isOver()
          Does the Button Record define a shape for the button's 'over' state.
 boolean isUp()
          Does the Button Record define a shape for the button's 'up' state.
 int length(FSCoder coder)
           
 void setColorTransform(FSColorTransform aTransform)
          Sets the colour transform that will be applied to the shape to change it's colour.
 void setIdentifier(int anIdentifier)
          Sets the identifier of the FSDefineShape, FSDefineShape2 or FSDefineShape3 object that defines the appearance of the button when it is in the specified state(s).
 void setLayer(int aNumber)
          Sets the layer in the display list that the shape will be displayed on.
 void setState(int aNumber)
          Set the state(s) of the button when the shape is drawn.
 void setTransform(FSCoordTransform aTransform)
          Sets the coordinate transform that will be applied to the shape to change it's appearance.
 
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
 

Field Detail

Up

public static final int Up
Code for the button in the up state.

See Also:
Constant Field Values

Over

public static final int Over
Code for the state of the button when the mouse is over the active area.

See Also:
Constant Field Values

Down

public static final int Down
Code for the state of the button when the mouse is clicked the active area.

See Also:
Constant Field Values

Active

public static final int Active
Code for the active area of the button.

See Also:
Constant Field Values
Constructor Detail

FSButton

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

Parameters:
coder - an FSCoder containing the binary data.

FSButton

public FSButton(int aState,
                int anIdentifier,
                int aLayer)
Constructs an FSButton object without a coordinate or colour transform that will be applied to the shape drawn for the button states. The transforms default to unity transforms which do not change the location of colour of the shape for the button.

Parameters:
aState - the state of the button when the shape is drawn.
anIdentifier - the identifier of an FSDefineShape, FSDefineShape2 or FSDefineShape3 object.
aLayer - the layer in the display list on which the shape is drawn.

FSButton

public FSButton(int aState,
                int anIdentifier,
                int aLayer,
                FSCoordTransform aTransform)
Constructs an FSButton object with a coordinate transform that will be applied to the shape drawn for the button states.

Parameters:
aState - the state of the button when the shape is drawn.
anIdentifier - the identifier of an FSDefineShape, FSDefineShape2 or FSDefineShape3 object.
aLayer - the layer in the display list on which the shape is drawn.
aTransform - an FSCoordTransform object that changes the appearance of the shape when it is drawn.

FSButton

public FSButton(int aState,
                int anIdentifier,
                int aLayer,
                FSCoordTransform aTransform,
                FSColorTransform aColorTransform)
Constructs an FSButton object with a coordinate and colour transform that will be applied to the shape drawn for the button states.

Parameters:
aState - the state of the button when the shape is drawn.
anIdentifier - the identifier of an FSDefineShape, FSDefineShape2 or FSDefineShape3 object.
aLayer - the layer in the display list on which the shape is drawn.
aTransform - an FSCoordTransform object that changes the appearance of the shape when it is drawn.
aColorTransform - an FSColorTransform object that changes the colour of the shape when it is drawn.

FSButton

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

Parameters:
obj - an FSButton object.
Method Detail

getState

public int getState()
Get the state(s) of the button when the shape is drawn.

Returns:
the state of the button when the shape is drawn.

isActive

public boolean isActive()
Does the Button Record defines a shape for the button's active area.

Returns:
a boolean flag indicating whether the button record defines the button's active area.

isDown

public boolean isDown()
Does the Button Record define a shape for the button's 'down' state.

Returns:
a boolean flag indicating whether the button record defines the shape for the button's 'down' state.

isOver

public boolean isOver()
Does the Button Record define a shape for the button's 'over' state.

Returns:
a boolean flag indicating whether the button record defines the shape for the button's 'over' state.

isUp

public boolean isUp()
Does the Button Record define a shape for the button's 'up' state.

Returns:
a boolean flag indicating whether the button record defines the shape for the button's 'up' state.

getIdentifier

public int getIdentifier()
Gets the identifier of the shape that this FSButton applies to.

Returns:
the identifier of the shape.

getLayer

public int getLayer()
Gets the layer that the button will be displayed on.

Returns:
the layer on which the shape is displayed.

getTransform

public FSCoordTransform getTransform()
Gets the coordinate transform that will be applied to the button.

Returns:
the coordinate transform that is applied to the shape.

getColorTransform

public FSColorTransform getColorTransform()
Gets the colour transform that will be applied to the button.

Returns:
the colour transform that is applied to the shape.

setState

public void setState(int aNumber)
Set the state(s) of the button when the shape is drawn. The shape may be drawn for more than one state. Multiple states can be defined by bitwise-OR'ing individual states together, e.g. Up | Over.

Parameters:
aNumber - the state of the button when the shape is drawn.

setIdentifier

public void setIdentifier(int anIdentifier)
Sets the identifier of the FSDefineShape, FSDefineShape2 or FSDefineShape3 object that defines the appearance of the button when it is in the specified state(s).

Parameters:
anIdentifier - the identifier of the shape object that defines the shape's appearance.

setLayer

public void setLayer(int aNumber)
Sets the layer in the display list that the shape will be displayed on.

Parameters:
aNumber - the number of the layer in the display list where the shape is drawn.

setTransform

public void setTransform(FSCoordTransform aTransform)
Sets the coordinate transform that will be applied to the shape to change it's appearance.

Parameters:
aTransform - an FSCoordTransform object that will be applied to the shape.

setColorTransform

public void setColorTransform(FSColorTransform aTransform)
Sets the colour transform that will be applied to the shape to change it's colour.

Parameters:
aTransform - an FSColorTransform object that will be applied to the shape.

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