home *** CD-ROM | disk | FTP | other *** search
- package sub_arctic.anim;
- import sub_arctic.lib.manager;
-
- import java.awt.Component;
- import java.awt.Event;
-
- /**
- * This is the object which generates the animation events. It works by
- * delivering a "fake" animation event (also known as a "tick"), then
- * sleeping for a short period of time. Normally exactly one object of
- * this class is created by the static initializer at the end of this class
- * and forked as a thread.<p>
- *
- * Note: this class currently doesn't have any throttling behavior, and that
- * needs to be fixed. <P>
- *
- * @author Ian Smith
- */
- public class anim_generator implements Runnable {
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This is how long we sleep between animation event generations
- * (in milliseconds). This defaults to 60.
- */
- protected static int _sleep_time=60;
-
- /**
- * The thread which is providing the animation ticks
- */
- protected static Thread _anim_thread = null;
-
- /**
- * Retrieve the amount of time between animation events.
- * @return int number of milliseconds between event generations
- */
- public static int sleep_time() { return _sleep_time;};
-
- /**
- * Set the current amount of sleep time between animation events.
- * The rate of animation events sets a lower bound on the accuracy
- * of the animations (i.e. the size of the time intervals provided
- * to animations.)
- *
- * @int x the new amount of sleep time between animation events (in
- * milliseconds)
- */
- public static void set_sleep_time(int x) { _sleep_time=x;};
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Indication of whether we need the pulses at all. The agent sets this value.
- */
- protected static boolean _need_ticks=false;
-
- /**
- * Return whether we need the animation events (ticks) or not.
- * If not, we don't bother delivering animation inputs to the
- * event dispatch system. <P>
- *
- * The animation agent will turn on ticks when it has objects
- * in its queues, and turn off ticks when it has no objects
- * to consider.
- *
- * @return boolean true if we currently need ticks.
- */
- public static boolean need_ticks() { return _need_ticks;}
-
- /**
- * Set the state of tick (animation event) generation.
- * @param boolean b true if we need to be generating ticks to the event
- * dispatch code.
- */
- public synchronized static void set_need_ticks(boolean b) {
- _need_ticks=b;
- if (_anim_thread == null) {
- if (_need_ticks) {
- /* create a thread running on this class */
- _anim_thread = new Thread(new anim_generator());
- _anim_thread.start();
- }
- } else {
- //xx SEH doesn't look like we ever call suspend(), so I'm taking this
- // out since it causes NS3.0 fits
- //if (_need_ticks)
- // _anim_thread.resume();
- /* setting _need_ticks to false will cause the thread to suspend itself */
- }
- }
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * This is the method that gets run on the thread. It delivers an
- * ANIMATION_EVENT event to some AWT component with a subArctic interface
- * installed under it (which one doesn't matter since the animation agent
- * will deliver it to the focus regardless), then sleeps from a short
- * period of time.
- */
- public void run() {
- Component c;
-
- /* do this forever */
- while (true) {
-
- /* if we don't need ticks, don't bother */
- if (_need_ticks) {
-
- /* get an awt component from the manager */
- c=manager.an_awt_component();
-
- if (c!=null) {
- /* send it the message ...with the current time in the event */
- c.postEvent(new Event(c,animation_agent.ANIMATION_EVENT,
- new Long(System.currentTimeMillis())));
- }
- }
-
- try {
- Thread.currentThread().sleep(_sleep_time);
- } catch (InterruptedException e) {
- /* go ahead and deliver events... this will only happen on
- EARLY exit, so it won't hurt */
- }
-
- }
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
- }
-
- /*=========================== 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/
-
- ========================================================================*/
-