home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / JAVA_ALL / IDE / SUBARTIC / SUB_ARCT / TEST / PERMANEN.JAV < prev    next >
Encoding:
Text File  |  1996-10-04  |  4.7 KB  |  182 lines

  1. package sub_arctic.test;
  2. import sub_arctic.lib.*;
  3. import sub_arctic.output.*;
  4. import sub_arctic.input.*;
  5. import sub_arctic.anim.*;
  6.  
  7. import java.net.URL;
  8. import java.net.MalformedURLException;
  9.  
  10. /**
  11.  * We have actually made the whole applet the animatable object, but
  12.  * you can make individual interactors animatable as well..
  13.  */
  14. public class permanent_test extends interactor_applet {
  15.   /**
  16.    * Hold the images
  17.    */
  18.   loaded_image boom[];
  19.   /**
  20.    * Sequence size is number of images.
  21.    */
  22.   int sequence_size;
  23.   /**
  24.    * Where is the sequence?
  25.    */
  26.   String sequence_name;
  27.   /**
  28.    * Current image number
  29.    */
  30.   int current_image=0;
  31.   /**
  32.    * Before the UI gets built load the images
  33.    */
  34.   public void pre_build_ui() {
  35.     String name,sequence_size;
  36.     int size;
  37.     /**
  38.      * Get parameters from the HTML file 
  39.      */
  40.     sequence_name=getParameter("SEQUENCENAME");
  41.     sequence_size=getParameter("SEQUENCESIZE");
  42.     try {
  43.       size=(new Integer(sequence_size)).intValue();
  44.     } catch (NumberFormatException e) {
  45.       size=0;
  46.     }
  47.     /* allocate space */
  48.     boom=new loaded_image[size];
  49.     try {
  50.       /* loop over them */
  51.       for (int i=0; i<size; ++i) {
  52.     name=sequence_name + (i+1) + ".gif";
  53.     System.out.println("loading image... " + name);
  54.     boom[i]=manager.load_doc_image(this,name);
  55.       }
  56.     } catch (MalformedURLException e) {
  57.       manager.handle_unexpected_exception(e);
  58.     }
  59.   }
  60.   /**
  61.    * This is the icon
  62.    */
  63.   animated_icon the_icon;
  64.   /**
  65.  
  66.    * Construct the UI... just a single object.
  67.    */
  68.   public void build_ui(base_parent_interactor tl) {
  69.     continuous_transition pt;
  70.     /* start in 5 seconds */
  71.     continuous_interval pi=new continuous_interval(time_interval.now()+5000);
  72.     /* make the icon */
  73.     the_icon=new animated_icon(boom);
  74.     /* make the transition */    
  75.     pt=new continuous_transition(the_icon, pi, 100);
  76.     manager.animation.schedule_transition(pt);
  77.     /* put it in the parent */
  78.     tl.add_child(the_icon);
  79.     /* set the constraints on location */
  80.     the_icon.set_x(tl.w()/2);
  81.     the_icon.set_y(tl.h()/2);
  82.   }
  83. }
  84.  
  85. /**
  86.  * This is an animated icon which can display an array of images.
  87.  * We are expecting that you will use an a
  88.  */
  89. class animated_icon extends icon implements animatable, move_press_draggable {
  90.   /* images to display */
  91.   loaded_image[] img;
  92.   /* number in the sequence */
  93.   int current=0;
  94.   /* construct one */
  95.   public animated_icon(loaded_image[] images) {
  96.     super(images[0]);
  97.     img=images;
  98.   }
  99.   /**
  100.    * Go to the next image
  101.    */
  102.   public void next_image() {
  103.     ++current;
  104.     if (current==img.length) current=0;
  105.     set_image(img[current]);
  106.   }
  107.   /* Don't bother doing anything here, we'll just do it all
  108.    * in the step function
  109.    */
  110.   public void start_transition(transition trans, trajectory traj,
  111.                    double start_t, Object start_obj, event e,
  112.                    Object user_info) {}
  113.   
  114.   /** 
  115.    * We ignore all the parameters and just draw the next image 
  116.    */
  117.   public void transition_step(transition trans, trajectory traj,
  118.                   double start_t, Object start_obj, 
  119.                   double end_t, Object end_obj,
  120.                   event e, Object user_info) {
  121.     /* update image */
  122.     next_image();
  123.   }
  124.   /* 
  125.    * since we are using a permanent transition, this never 
  126.    * gets called
  127.    */
  128.   public void end_transition(transition trans, trajectory traj,
  129.                  double start_t, Object start_obj,
  130.                  double end_t, Object end_obj,
  131.                  event e, Object user_info) {
  132.   }
  133.   /* just place the object */
  134.   public boolean drag_start(
  135.     event evt, 
  136.     int x, int y, 
  137.     int grab_x, int grab_y, 
  138.     Object user_info) {
  139.     set_x(x);
  140.     set_y(y);
  141.     return true;
  142.   }
  143.   /* just place it */
  144.   public boolean drag_end(
  145.     event evt,     
  146.     int x, int y, 
  147.     int start_x, int start_y, 
  148.     int grab_x, int grab_y, 
  149.     Object user_info) {
  150.     set_x(x);
  151.     set_y(y);
  152.     return true;
  153.   }
  154.   /* just place it */
  155.   public boolean drag_feedback(
  156.     event evt,     
  157.     int x, int y, 
  158.     int start_x, int start_y, 
  159.     int grab_x, int grab_y, 
  160.     Object user_info) {
  161.     set_x(x);
  162.     set_y(y);
  163.     return true;
  164.   }
  165. }
  166. /*=========================== COPYRIGHT NOTICE ===========================
  167.  
  168. This file is part of the subArctic user interface toolkit.
  169.  
  170. Copyright (c) 1996 Scott Hudson and Ian Smith
  171. All rights reserved.
  172.  
  173. The subArctic system is freely available for most uses under the terms
  174. and conditions described in 
  175.   http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html 
  176. and appearing in full in the lib/interactor.java source file.
  177.  
  178. The current release and additional information about this software can be 
  179. found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
  180.  
  181. ========================================================================*/
  182.