ubc.cs.JLog.Animation
Class aAnimationObject

java.lang.Object
  extended by ubc.cs.JLog.Animation.aAttributeTranslation
      extended by ubc.cs.JLog.Animation.aAnimationObject
All Implemented Interfaces:
iAttributes

public class aAnimationObject
extends aAttributeTranslation

This represents a graphical object which is composed from possibly several collection of aAnimationShapes. Each collection is a particular view of that object (multiple views permit animation). An object also has a level attribute that determines its order when displayed in the environment (to determine overlap of the object's image). Animation objects can also keep track of the path they have traversed. Objects are not themselves visible (the enclosed shapes give the visible manifestation), but they do have coordinates and rotation attributes. Coordinates are given the canonical global coordinates (i.e., with magnification of 1.0) and rotation of an object is given in radians. Enclosed shapes have local canonical coordinates and rotations which are offsets from the object values. A display point (non-canonical) is the global point with magnifcation applied.

Author:
Glendon Holst

Field Summary
protected  aAnimationEnvironment environment
           
protected  int level
           
static java.lang.String LEVEL_ATTR_KEY
           
protected  java.lang.String name
           
static java.lang.String NAME_ATTR_KEY
           
protected  java.util.Hashtable[] named_shapes
           
protected  java.util.Vector path
           
protected  java.awt.Color path_colour
           
protected  int path_size
           
protected  int path_skip
           
protected  int path_skipcount
           
static java.lang.String PATHCOLOUR_ATTR_KEY
           
static java.lang.String PATHSIZE_ATTR_KEY
           
static java.lang.String PATHSKIP_ATTR_KEY
           
protected  float rotation
           
static java.lang.String ROTATION_ATTR_KEY
           
protected  java.util.Vector[] shapes
           
protected  int view
           
static java.lang.String VIEW_ATTR_KEY
           
protected  float x
           
static java.lang.String X_ATTR_KEY
           
protected  float y
           
static java.lang.String Y_ATTR_KEY
           
 
Constructor Summary
aAnimationObject(aAnimationEnvironment ae, java.lang.String n, int l, int vs)
          The constructor.
 
Method Summary
protected  void addPath(float x, float y)
          Add a location to the path.
 void addShape(aAnimationShape as)
          Add an aAnimationShape.
 void draw(java.awt.Graphics g)
          Draw the current view of the object in the Graphics environment provided.
 java.util.Enumeration enumShapes()
          Get an Enumeration of the shapes in the current view.
 java.util.Hashtable getAttributes()
          Returns a hashtable of every attribute associated with this object.
 java.awt.Rectangle getBounds()
          Returns the bounding rectangle for this object in the current view, given in global coordinates.
 java.awt.Point getDisplayPointFromLocalPoint(float dx, float dy)
          Calculates the display coordinates for given local (i.e., shape relative) point.
 java.awt.Point getDisplayPointFromLocalPosition(float dx, float dy, float dr)
          Calculates the display coordinates for given local (i.e., shape relative) point and rotation.
 aAnimationEnvironment getEnvironment()
           
 float getGlobalRotationFromLocal(float dr)
           
 float getGlobalXPositionFromLocal(float dx)
           
 float getGlobalYPositionFromLocal(float dy)
           
 int getLevel()
           
 java.lang.String getName()
           
 int getPathSize(boolean allowed)
          Get the size of the path.
 aAnimationShape getShape(java.lang.String name)
          Get a shape in the current view with the given name.
 int getShapeView(aAnimationShape s)
          Get the view containing the given shape.
 jTermTranslation getTermTranslation()
          Get the current translation unit for this object.
 int getView()
          Get the current display view.
 void removeShape(aAnimationShape as)
          Remove an aAnimationShape from the current view.
 void setAttributes(java.util.Hashtable attributes)
          Set the attributes of the object to those in the given Hashtable.
static void setDefaultsForTranslation(jTermTranslation t)
           
 void setLevel(int l)
          Set the object level in the display heirarchy.
 void setName(java.lang.String n)
           
 void setPathSize(int sz, int sk, java.awt.Color c)
          Set the path attributes.
 void setPosition(float x, float y)
          Adjust the global location of the object to the given position.
 void setRotation(float r)
          Adjust the rotation of the object to the given angle in radians.
 void setView(int v)
          Set the current view to display.
 void updateMagnification()
          Update notification.
 
Methods inherited from class ubc.cs.JLog.Animation.aAttributeTranslation
convertFromColor, convertFromFont, convertFromPolygon, convertFromRectangle, convertToAnimationObject, convertToAnimationShape, convertToAttributesObject, convertToBoolean, convertToColor, convertToFloat, convertToFont, convertToInt, convertToList, convertToPolygon, convertToRectangle, convertToString, convertToTerms, convertToTerms, setObjectDefaults, setStringKeysForTranslation, setTermDefaults
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

X_ATTR_KEY

public static final java.lang.String X_ATTR_KEY
See Also:
Constant Field Values

Y_ATTR_KEY

public static final java.lang.String Y_ATTR_KEY
See Also:
Constant Field Values

ROTATION_ATTR_KEY

public static final java.lang.String ROTATION_ATTR_KEY
See Also:
Constant Field Values

NAME_ATTR_KEY

public static final java.lang.String NAME_ATTR_KEY
See Also:
Constant Field Values

LEVEL_ATTR_KEY

public static final java.lang.String LEVEL_ATTR_KEY
See Also:
Constant Field Values

VIEW_ATTR_KEY

public static final java.lang.String VIEW_ATTR_KEY
See Also:
Constant Field Values

PATHSIZE_ATTR_KEY

public static final java.lang.String PATHSIZE_ATTR_KEY
See Also:
Constant Field Values

PATHSKIP_ATTR_KEY

public static final java.lang.String PATHSKIP_ATTR_KEY
See Also:
Constant Field Values

PATHCOLOUR_ATTR_KEY

public static final java.lang.String PATHCOLOUR_ATTR_KEY
See Also:
Constant Field Values

environment

protected aAnimationEnvironment environment

level

protected int level

view

protected int view

name

protected java.lang.String name

path

protected java.util.Vector path

path_size

protected int path_size

path_skip

protected int path_skip

path_skipcount

protected int path_skipcount

path_colour

protected java.awt.Color path_colour

shapes

protected java.util.Vector[] shapes

named_shapes

protected java.util.Hashtable[] named_shapes

x

protected float x

y

protected float y

rotation

protected float rotation
Constructor Detail

aAnimationObject

public aAnimationObject(aAnimationEnvironment ae,
                        java.lang.String n,
                        int l,
                        int vs)
The constructor. Requires that the aAnimationEnvironment, name, level, and the maximum views.

Parameters:
ae - The graphical environment that encloses this object. Animation object can only belong to one environment.
n - The name of the object.
l - The level at which this object floats in the environment. Lower numbers are deeper in environment (they are drawn first), while larger numbers appear towards the top of the environment (drawn last).
vs - The maximum number of views the object will have. Each view must be populated with aAnimationShapes.
Method Detail

getEnvironment

public aAnimationEnvironment getEnvironment()

getShape

public aAnimationShape getShape(java.lang.String name)
Get a shape in the current view with the given name.

Parameters:
name - The name of the shape.
Returns:
An aAnimationShape from the current view, with the given name.

enumShapes

public java.util.Enumeration enumShapes()
Get an Enumeration of the shapes in the current view.

Returns:
An enumeration of the enclosed aAnimationShape shape object from the current view.

addShape

public void addShape(aAnimationShape as)
Add an aAnimationShape. The shape must already be created with this object being its parent object. Shape is added to the current view.

Parameters:
as - The aAnimationShape to add.

removeShape

public void removeShape(aAnimationShape as)
Remove an aAnimationShape from the current view.

Parameters:
as - The aAnimationShape to remove.

draw

public void draw(java.awt.Graphics g)
Draw the current view of the object in the Graphics environment provided. Includes any path that the object has recorded.

Parameters:
g - The Graphics environment to draw into.

getBounds

public java.awt.Rectangle getBounds()
Returns the bounding rectangle for this object in the current view, given in global coordinates.

Returns:
The Rectangle bounding this object.

getName

public java.lang.String getName()

setName

public void setName(java.lang.String n)

getLevel

public int getLevel()

setLevel

public void setLevel(int l)
Set the object level in the display heirarchy.

Parameters:
l - The level at which this object floats in the environment. Lower numbers are deeper in environment (they are drawn first), while larger numbers appear towards the top of the environment (drawn last).

getView

public int getView()
Get the current display view.

Returns:
The view number (zero based).

getShapeView

public int getShapeView(aAnimationShape s)
Get the view containing the given shape.

Parameters:
s - The shape, which this object should contain.
Returns:
The view number (zero based) for the given shape, or the current view if shape not found.

setView

public void setView(int v)
Set the current view to display. Does not cause the environment to re-paint.

Parameters:
v - The view number (zero based).

setDefaultsForTranslation

public static void setDefaultsForTranslation(jTermTranslation t)

getTermTranslation

public jTermTranslation getTermTranslation()
Description copied from class: aAttributeTranslation
Get the current translation unit for this object. Usually, it will get a translation unit for the class. The returned unit should not be modified (since it belongs to the class).

Overrides:
getTermTranslation in class aAttributeTranslation
Returns:
The jTermTranslation translation unit.

getAttributes

public java.util.Hashtable getAttributes()
Description copied from interface: iAttributes
Returns a hashtable of every attribute associated with this object. Each attribute must have a String name key, and its associated value (non-null).

Returns:
The Hashtable of attribute name-value pairings.

setAttributes

public void setAttributes(java.util.Hashtable attributes)
Description copied from interface: iAttributes
Set the attributes of the object to those in the given Hashtable. Errors such as Non-applicable attributes, or invalid values can be handled as the receiving object prefers (e.g., silently ignore, or throw exception).

Parameters:
attributes - The Hashtable of attribute name-value pairings.

getDisplayPointFromLocalPosition

public final java.awt.Point getDisplayPointFromLocalPosition(float dx,
                                                             float dy,
                                                             float dr)
Calculates the display coordinates for given local (i.e., shape relative) point and rotation. The display coordinate is the global coordinate after magnification.

Parameters:
dx - Local (shape relative) x position offset from the objects position.
dy - Local (shape relative) y position offset from the objects position.
dr - Local (shape relative) rotation offset.

getDisplayPointFromLocalPoint

public final java.awt.Point getDisplayPointFromLocalPoint(float dx,
                                                          float dy)
Calculates the display coordinates for given local (i.e., shape relative) point. The display coordinate is the global coordinate after magnification.

Parameters:
dx - Local (shape relative) x position offset from the objects position.
dy - Local (shape relative) y position offset from the objects position.

getGlobalRotationFromLocal

public final float getGlobalRotationFromLocal(float dr)

getGlobalXPositionFromLocal

public final float getGlobalXPositionFromLocal(float dx)

getGlobalYPositionFromLocal

public final float getGlobalYPositionFromLocal(float dy)

setPathSize

public void setPathSize(int sz,
                        int sk,
                        java.awt.Color c)
Set the path attributes. The path is a history of previous locations for this object. The path is drawn, unless no historical locations are recorded.

Parameters:
sz - The number of previous locations to keep track of.
sk - The number of previous locations skip over before recording a location (used to prevent sampling every location).
c - The colour to draw the path in.

getPathSize

public int getPathSize(boolean allowed)
Get the size of the path.

Parameters:
allowed - true if we want the maximum number of previous locations allowed, false if we just want to know how many locations are already recorded in the path.
Returns:
If allowed is true, then returns the maximum number of previous locations to record, otherwise returns the number of previous locations currently recorded.

addPath

protected void addPath(float x,
                       float y)
Add a location to the path. Invoked internally when the object moves.

Parameters:
x - The x component of the location.
y - The y component of the location.

setPosition

public void setPosition(float x,
                        float y)
Adjust the global location of the object to the given position. Moves the object. Notifies child shapes that the object position has changed.

Parameters:
x - The x component of the location.
y - The y component of the location.

setRotation

public void setRotation(float r)
Adjust the rotation of the object to the given angle in radians. Adjusts the real location of the child shapes by the given rotation.

Parameters:
r - The angle of the object in radians.

updateMagnification

public void updateMagnification()
Update notification. The environment magnification value changed.