jsim.animator
Class AnimationImp

java.lang.Object
  extended by java.lang.Thread
      extended by jsim.animator.AnimationImp
All Implemented Interfaces:
java.lang.Runnable, Animator

public class AnimationImp
extends java.lang.Thread
implements Animator

This class implements the Animation front end for the JSIM Simulation package. It uses a shared data Structure to receive AnimatorMessages from the Simulator and then repaints the Animation to reflect these changes.


Nested Class Summary
 class AnimationImp.AnimationFrame
          Frame class for holding the components of the Animation
 class AnimationImp.AnimationPanel
          Panel Class for holding Animation components
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
protected static java.util.logging.Logger trc
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
AnimationImp(Graph g, AnimationQueue q)
          Constructor Initializes all dataMembers
AnimationImp(Graph g, AnimationQueue q, Model env)
          Constructor Initializes all dataMembers
 
Method Summary
 void beginSim()
          Begins the Animation by setting start to true
 void changeSpeed(int value)
          Controls the speed of the Animation
 void create(int shapeID, java.lang.String shape, java.awt.Label l, double x, double y, double w, double h, double arcW, double arcH, double x2, double y2, int type, double time)
          Adds a Shape at given location Shapes: Line2D, QuadCurve2D, CubicCurve2D, Rectangle2D, RoundRectangle2D, Arc2D, Ellipse2D Qparam shapeID id for the new Shape
 void dequeueEntity(int shapeID, double time)
          Dequeues an entity
 void destroy(int shapeID, double time)
          Destroys a Shape based on ShapeID
 void endSim()
          Ends the Animation by setting end to true
 void enqueueEntity(int shapeID, double time)
          Enqueues an entity
 void executeInstruction()
          Gets an instruction from the shared queue and performs the instruction
 void incrementLost()
          Increments the number of lost entities
static void main(java.lang.String[] args)
          Main Function used for testing purposes
 void move(int shapeID, int edgeID, int endNodeID, double time)
          Moves an entity from a starting node to an ending node along a given edge
 void rotate(int shapeID, double theta, double x, double y, double time)
          Rotates a shape
 void run()
          run() Responsible for the main control loop of the Animation Creates the Frame and Panel, then sleeps and repaints until the animation is through
 void scale(int shapeID, double sx, double sy, double time)
          Scales a Shape
 void setPaint(int shapeID, java.awt.Color c1, java.awt.Color c2, double time)
          Paint Method for gradient color, uses 2 Color arguments
 void setPaint(int shapeID, java.awt.Color c, double time)
          Paint Method for solid color, uses 1 Color argument
 void setToLocation(int shapeID, double x_location, double y_location)
          Moves an entity to the specified location
 void shear(int shapeID, double shx, double shy, double time)
          Shears a Shape
 void translate(int shapeID, double tx, double ty, double time)
          Translates a Shape to a new (x,y) location
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

trc

protected static java.util.logging.Logger trc
Constructor Detail

AnimationImp

public AnimationImp(Graph g,
                    AnimationQueue q)
Constructor Initializes all dataMembers

Parameters:
g - initial Graph for animation
q - Animation queue for communication with Simulator

AnimationImp

public AnimationImp(Graph g,
                    AnimationQueue q,
                    Model env)
Constructor Initializes all dataMembers

Parameters:
g - initial Graph for animation
q - Animation queue for communication with Simulator
env - creating Model object
Method Detail

create

public void create(int shapeID,
                   java.lang.String shape,
                   java.awt.Label l,
                   double x,
                   double y,
                   double w,
                   double h,
                   double arcW,
                   double arcH,
                   double x2,
                   double y2,
                   int type,
                   double time)
Adds a Shape at given location Shapes: Line2D, QuadCurve2D, CubicCurve2D, Rectangle2D, RoundRectangle2D, Arc2D, Ellipse2D Qparam shapeID id for the new Shape

Specified by:
create in interface Animator
Parameters:
shape - Shape of the object
l - Label for the created Shape
x - x-coordinate of the location
y - y-coordinate of the location
w - width of the shape
h - height of the shape
arcW - arc width for curves
arcH - arc height for curves
x2 - double needed for some shapes
y2 - double needed for some shapes
type - type needed for certian shapes
time - Simulation time
shapeID - id for the new Shape

destroy

public void destroy(int shapeID,
                    double time)
Destroys a Shape based on ShapeID

Specified by:
destroy in interface Animator
Parameters:
shapeID - id of the Shape to destroy
time - SImulation time

incrementLost

public void incrementLost()
Increments the number of lost entities


translate

public void translate(int shapeID,
                      double tx,
                      double ty,
                      double time)
Translates a Shape to a new (x,y) location

Specified by:
translate in interface Animator
Parameters:
shapeID - id of Shape to translate
tx - new x-coordinate
ty - new y-coordinate
time - Simulation time

rotate

public void rotate(int shapeID,
                   double theta,
                   double x,
                   double y,
                   double time)
Rotates a shape

Specified by:
rotate in interface Animator
Parameters:
shapeID - id of Shape to tanslate
theta - angle of rotation
x - new x-coordinate
y - new y-coordinate
time - Simulation time

scale

public void scale(int shapeID,
                  double sx,
                  double sy,
                  double time)
Scales a Shape

Specified by:
scale in interface Animator
Parameters:
shapeID - id of Shape to scale
sx - scaled x-coordinate
sy - scaled y-coordiante
time - simulation time

shear

public void shear(int shapeID,
                  double shx,
                  double shy,
                  double time)
Shears a Shape

Specified by:
shear in interface Animator
Parameters:
shapeID - id of Shape to shear
shx - scaled x-coordinate
shy - scaled y-cooordinate
time - Simulation time

setPaint

public void setPaint(int shapeID,
                     java.awt.Color c,
                     double time)
Paint Method for solid color, uses 1 Color argument

Specified by:
setPaint in interface Animator
Parameters:
shapeID - id for Shape to paint
c - Color for the Shape
time - Simulation time

setPaint

public void setPaint(int shapeID,
                     java.awt.Color c1,
                     java.awt.Color c2,
                     double time)
Paint Method for gradient color, uses 2 Color arguments

Specified by:
setPaint in interface Animator
Parameters:
shapeID - id for SHape to paint
c1 - 1st Color for Shape
c2 - 2nd Color for Shape
time - Simulation time

move

public void move(int shapeID,
                 int edgeID,
                 int endNodeID,
                 double time)
Moves an entity from a starting node to an ending node along a given edge

Parameters:
shapeID - id for Shape to move
edgeID - id for edge to move along
endNodeID - id of end node
time - Simulation time

setToLocation

public void setToLocation(int shapeID,
                          double x_location,
                          double y_location)
Moves an entity to the specified location

Parameters:
shapeID - id of shape to move
x_location - new x-coordinate
y_location - new y-coordinate

beginSim

public void beginSim()
Begins the Animation by setting start to true


endSim

public void endSim()
Ends the Animation by setting end to true


changeSpeed

public void changeSpeed(int value)
Controls the speed of the Animation

Parameters:
value - the value used to adjust speed

enqueueEntity

public void enqueueEntity(int shapeID,
                          double time)
Enqueues an entity

Parameters:
shapeID - id of the entity
time - time in simulation

dequeueEntity

public void dequeueEntity(int shapeID,
                          double time)
Dequeues an entity

Parameters:
shapeID - id of the entity
time - time in simulation

executeInstruction

public void executeInstruction()
Gets an instruction from the shared queue and performs the instruction


run

public void run()
run() Responsible for the main control loop of the Animation Creates the Frame and Panel, then sleeps and repaints until the animation is through

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

main

public static void main(java.lang.String[] args)
Main Function used for testing purposes