home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-10-04 | 7.1 KB | 229 lines |
- package sub_arctic.anim;
- import sub_arctic.lib.interactor;
- import sub_arctic.input.event;
-
- /**
- * Class that implements the transitions, just like in the paper
- * (Hudson & Stasko, UIST '93) and in artkit.<p>
- *
- * @author Ian Smith
- */
- public class transition {
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Interactor we are operating on. */
- protected animatable _target;
-
- /**
- * Retrieve the interactor we are operating on.
- * @return animatable the target object for this animation.
- */
- public animatable target() { return _target;};
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Time interval we are going on. */
- protected time_interval _interval;
-
- /**
- * Retrieve the time interval over which we are operating.
- * @return time_interval the time interval for this transition
- */
- public time_interval interval() { return _interval;};
-
- /**
- * This function sets the time interval for this transition. In
- * general, it is an <b>extremely</b> bad idea for user level
- * code to be manipulating the transitions timing information
- * after the transition has been created. It is quite likely that
- * unless you understand exactly how the animation system's scheduling
- * works, you will hose yourself if you try to manipulate this while
- * the transition is running.<P>
- *
- * This function has
- * been made protected so subclasses of transition can use it, but
- * in general user level code cannot.
- *
- * @param time_interval t the new time interval to use for this transition
- */
- public void set_interval(time_interval t) { _interval=t;}
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * The trajectory we are using.
- */
- protected trajectory _traj;
-
- /**
- * Retrieve the trajectory for this object.
- * @return trajectory the trajectory over which the animation happens
- */
- public trajectory traj() { return _traj;};
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Build a transition, given a target animatable, a time interval,
- * and a trajectory.<p>
- *
- * @param animatable i the target of the animation or transition
- * @param time_interval t the time interval over which this transition occurs
- * @param trajectory t the trajectory over which this transition is mapped
- */
- public transition(animatable i, time_interval t,
- trajectory j) {
- _target=i;
- _interval=t;
- _traj=j;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This lets the world know that we have seen a time that is larger
- * than our end.
- */
- protected boolean _finished;
-
- /**
- * Are we done? (Has time passed us by...).
- * @return boolean returns true if this transition has been completed
- */
- public boolean finished() { return _finished;};
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * What was the last time seen? This function is usually used by
- * code trying to figure out what time interval is "next".
- *
- * @return double the last time (in milliseconds) that we have dealt with
- */
- public double last_time() { return _last_time;};
-
- /**
- * Store the last time seen.
- */
- protected double _last_time;
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Start a transition. This is where the work gets done of calling the
- * start_transition function on the interactor.<p>
- *
- * @param event e the animation event that caused things to get going
- * @param Object user_info the object passed to the animation agent when
- * the animatable joined its focus set
- */
- public void start(event e,Object user_info) {
- Object result;
-
- /* set the last time seen */
- _last_time=0.0;
-
- /* compute the result using the trajectory */
- if (traj()==null) {
- result=null;
- } else {
- result=traj().object_for_parm(0.0);
- }
-
- /* make the call to start him */
- target().start_transition(this, traj(), 0.0, result, e, user_info);
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Perform a step... this sends the transition_step message to the
- * interactor.<p>
- *
- * @param event e the animation event for this step
- * @param Object user_info the object passed to the animation agent when
- * the animatable joined its focus set
- * @param long current_time the time it is "now" for this time step
- */
- public void step(event e, Object user_info, long current_time) {
- Object start_result, end_result;
- double c_time;
- time_interval i=interval();
- long diff_time;
-
- /* how far past the start are we*/
- diff_time=current_time-(i.start_time());
-
- /* are we past the end or at it?*/
- if (current_time>=i.end_time()) {
- /* set the flag that we are finished */
- _finished=true;
- return;
- }
-
- /* compute the actual time as a real */
- c_time=(double)diff_time/((double)(i.duration()));
-
- /* now compute the two objects via the trajectory */
- if (traj()==null) {
- start_result=null;
- end_result=null;
- } else {
- start_result=traj().object_for_parm(_last_time);
- end_result=traj().object_for_parm(c_time);
- }
-
- /* send the message to the interactor */
- target().transition_step(this, traj(), _last_time, start_result,
- c_time, end_result, e, user_info);
-
- /* now reset what time we have seen */
- _last_time=c_time;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Send the end message to the interactor.<p>
- *
- * @param event e the animation event for this step
- * @param Object user_info the object passed to the animation agent when
- * the animatable joined its focus set
- */
- public void end(event e, Object user_info) {
- Object start_result, end_result;
-
- /* compute the two objects via the trajectory */
- if (traj()==null) {
- start_result=null;
- end_result=null;
- } else {
- start_result=traj().object_for_parm(_last_time);
- end_result=traj().object_for_parm(1.0);
- }
-
- /* send the message to the interactor */
- target().end_transition(this, traj(), _last_time, start_result,
- 1.0, end_result, e, user_info);
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
- }
- /*=========================== COPYRIGHT NOTICE ===========================
-
- This file is part of the subArctic user interface toolkit.
-
- Copyright (c) 1996 Scott Hudson and Ian Smith
- All rights reserved.
-
- The subArctic system is freely available for most uses under the terms
- and conditions described in
- http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html
- and appearing in full in the lib/interactor.java source file.
-
- The current release and additional information about this software can be
- found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
-
- ========================================================================*/
-