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

  1. package sub_arctic.input;
  2.  
  3. import sub_arctic.lib.interactor;
  4. import sub_arctic.lib.manager;
  5.  
  6.  
  7. /**
  8.  * This is the class that implements the positional input dispatch policy.
  9.  * This policy delivers inputs to objects "under" the position recorded in
  10.  * various input events.
  11.  *
  12.  * @author Scott Hudson
  13.  */
  14. public class positional_policy_class extends input_policy {
  15.  
  16.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  17.  
  18.   /**
  19.    * Construct a positional policy. User's shouldn't need to do this,
  20.    * it is done as part of toolkit initialization.
  21.    */
  22.   public positional_policy_class()
  23.     {
  24.     }
  25.  
  26.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  27.  
  28.   /** 
  29.    * Current pick list.  This may get shared by several policies.  Policies
  30.    * which use pick should all call current_pick_list() to get access to an 
  31.    * up to date copy. 
  32.    */
  33.   protected static pick_collector _current_pick_list = new pick_collector();
  34.  
  35.   /** 
  36.    * Event sequence number for which the pick collection is valid 
  37.    */
  38.   protected static int _pick_valid_seq_num = -1;
  39.  
  40.   /** 
  41.    * Get an up to date pick list for objects picked by the given event 
  42.    * (which is assumed to be the "current" event in unmodified form).   
  43.    * The resulting list should be treated as read-only.  Note that the
  44.    * pick list is cached and reused for all requests that occur 
  45.    * until the next event is dispatched by the system as a 
  46.    * whole (i.e., until manager.event_seq_num() changes).
  47.    * 
  48.    * @param event picked_by_event the event to return the pick_list for
  49.    * @return pick_collector the pick collector whose contents are those 
  50.    *                        picked by the event
  51.    */  
  52.   public static pick_collector current_pick_list(event picked_by_event)
  53.     {
  54.       /* give them the cached copy if its still valid */
  55.       if (_pick_valid_seq_num != manager.event_seq_num())
  56.     {
  57.           /* if not reset */
  58.           _pick_valid_seq_num = manager.event_seq_num();
  59.           _current_pick_list.reset();
  60.  
  61.           /* and do a new pick */
  62.           if (picked_by_event!=null && picked_by_event.root_interactor()!=null)
  63.         picked_by_event.root_interactor().pick(
  64.               picked_by_event.global_x(), picked_by_event.global_y(), 
  65.               _current_pick_list);
  66.     }
  67.  
  68.       return _current_pick_list;
  69.     }
  70.  
  71.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  72.  
  73.   /**
  74.    * This is called by the event dispatch infrastructure to tell this
  75.    * policy to handle an event. 
  76.    *
  77.    * @param event evt the event to dispatch
  78.    * @return boolean the policy returns true if it dispatches the event
  79.    */
  80.   public boolean dispatch_event(event evt)
  81.     {
  82.       pick_collector   cur_pick;
  83.       int              i, agnt;
  84.       interactor       to_obj;
  85.       dispatch_agent   an_agent;
  86.       user_info_holder user_info;
  87.  
  88.       /* do a pick with the event. */
  89.       cur_pick = current_pick_list(evt);
  90.  
  91.       /* loop over all the objects "under" the event (i.e., picked) */
  92.       for (i = 0; i < cur_pick.num_picks(); i++)
  93.     {
  94.       /* get the candidate object and its user_info */
  95.       user_info = cur_pick.pick(i);
  96.       to_obj = user_info.obj;
  97.  
  98.       /* sanity check */
  99.       if (to_obj == null) continue;
  100.  
  101.       /* loop over all the agents and try to dispatch the event */
  102.       for (agnt = 0; agnt < num_agents(); agnt++)
  103.         {
  104.           /* pull out the agent */
  105.           an_agent = (dispatch_agent)_agent_list.elementAt(agnt);
  106.  
  107.           /* if the agent doesn't want this kind of event just move on */
  108.           if (!an_agent.event_is_useful(evt))
  109.         continue;
  110.  
  111.           /* try to dispatch the event to the object via the agent.  if it 
  112.            *  takes it we're done */
  113.           if (an_agent.dispatch_event(evt, user_info.info, to_obj, 
  114.                             manager.event_seq_num()))
  115.         return true;
  116.         }
  117.     }
  118.  
  119.       /* nobody wanted it so return false */
  120.       return false;
  121.     }
  122.  
  123.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  124. }
  125.  
  126. /*=========================== COPYRIGHT NOTICE ===========================
  127.  
  128. This file is part of the subArctic user interface toolkit.
  129.  
  130. Copyright (c) 1996 Scott Hudson and Ian Smith
  131. All rights reserved.
  132.  
  133. The subArctic system is freely available for most uses under the terms
  134. and conditions described in 
  135.   http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html 
  136. and appearing in full in the lib/interactor.java source file.
  137.  
  138. The current release and additional information about this software can be 
  139. found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
  140.  
  141. ========================================================================*/
  142.