// Trajectory for a moving object package ciips.animation; import java.awt.*; import java.util.*; /** * A trajectory is a set of points which an object will follow on * the screen. * As an example, it can be used to define the path followed by * a node as it moves down a tree looking for the insertion point * It would usually be passed to the * animate method from DrawingPanel. * @see DrawingPanel#animate */ public class Trajectory { private static final int MIN_PTS = 10; private Vector pts; public static final int NO_INTERPOLATION = 0; public static final int LINEAR_INTERPOLATION = 1; public static final int ARC_INTERPOLATION = 2; private int interpolation; public Trajectory() { pts = new Vector( MIN_PTS ); interpolation = NO_INTERPOLATION; } /** Make a new trajectory which starts where the previous one left off **/ public Trajectory( Trajectory previous ) { this(); int last = previous.pts.size() - 1; if ( last >= 0 ) pts.add( previous.pts.elementAt( last ) ); } /** Add a Point x to the trajectory **/ public void addPoint( Point x ) { // pts.add( x ); pts.addElement( x ); } /** Make an object move to a point offset from another one **/ public void addPoint( DrawingObj a, Point offset ) { Point x = new Point( a.getX()+offset.x, a.getY()+offset.y ); // pts.add( x ); pts.addElement( x ); } /** Get the points - used by animate */ public Point getPoint( int k ) { return (Point)(pts.elementAt(k)); } /** Get the points - used by animate */ public Vector getPoints() { return pts; } }