home *** CD-ROM | disk | FTP | other *** search
- package sub_arctic.input;
-
- import sub_arctic.lib.interactor;
- import sub_arctic.lib.manager;
-
-
- /**
- * This is the class that implements the positional input dispatch policy.
- * This policy delivers inputs to objects "under" the position recorded in
- * various input events.
- *
- * @author Scott Hudson
- */
- public class positional_policy_class extends input_policy {
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Construct a positional policy. User's shouldn't need to do this,
- * it is done as part of toolkit initialization.
- */
- public positional_policy_class()
- {
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Current pick list. This may get shared by several policies. Policies
- * which use pick should all call current_pick_list() to get access to an
- * up to date copy.
- */
- protected static pick_collector _current_pick_list = new pick_collector();
-
- /**
- * Event sequence number for which the pick collection is valid
- */
- protected static int _pick_valid_seq_num = -1;
-
- /**
- * Get an up to date pick list for objects picked by the given event
- * (which is assumed to be the "current" event in unmodified form).
- * The resulting list should be treated as read-only. Note that the
- * pick list is cached and reused for all requests that occur
- * until the next event is dispatched by the system as a
- * whole (i.e., until manager.event_seq_num() changes).
- *
- * @param event picked_by_event the event to return the pick_list for
- * @return pick_collector the pick collector whose contents are those
- * picked by the event
- */
- public static pick_collector current_pick_list(event picked_by_event)
- {
- /* give them the cached copy if its still valid */
- if (_pick_valid_seq_num != manager.event_seq_num())
- {
- /* if not reset */
- _pick_valid_seq_num = manager.event_seq_num();
- _current_pick_list.reset();
-
- /* and do a new pick */
- if (picked_by_event!=null && picked_by_event.root_interactor()!=null)
- picked_by_event.root_interactor().pick(
- picked_by_event.global_x(), picked_by_event.global_y(),
- _current_pick_list);
- }
-
- return _current_pick_list;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This is called by the event dispatch infrastructure to tell this
- * policy to handle an event.
- *
- * @param event evt the event to dispatch
- * @return boolean the policy returns true if it dispatches the event
- */
- public boolean dispatch_event(event evt)
- {
- pick_collector cur_pick;
- int i, agnt;
- interactor to_obj;
- dispatch_agent an_agent;
- user_info_holder user_info;
-
- /* do a pick with the event. */
- cur_pick = current_pick_list(evt);
-
- /* loop over all the objects "under" the event (i.e., picked) */
- for (i = 0; i < cur_pick.num_picks(); i++)
- {
- /* get the candidate object and its user_info */
- user_info = cur_pick.pick(i);
- to_obj = user_info.obj;
-
- /* sanity check */
- if (to_obj == null) continue;
-
- /* loop over all the agents and try to dispatch the event */
- for (agnt = 0; agnt < num_agents(); agnt++)
- {
- /* pull out the agent */
- an_agent = (dispatch_agent)_agent_list.elementAt(agnt);
-
- /* if the agent doesn't want this kind of event just move on */
- if (!an_agent.event_is_useful(evt))
- continue;
-
- /* try to dispatch the event to the object via the agent. if it
- * takes it we're done */
- if (an_agent.dispatch_event(evt, user_info.info, to_obj,
- manager.event_seq_num()))
- return true;
- }
- }
-
- /* nobody wanted it so return false */
- return false;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
- }
-
- /*=========================== 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/
-
- ========================================================================*/
-