/[classpath]/classpath/java/awt/EventQueue.java
ViewVC logotype

Diff of /classpath/java/awt/EventQueue.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.18 by mkoch, Tue Nov 16 09:59:11 2004 UTC revision 1.19 by mkoch, Tue Jan 11 15:06:04 2005 UTC
# Line 40  package java.awt; Line 40  package java.awt;
40  import java.awt.event.ActionEvent;  import java.awt.event.ActionEvent;
41  import java.awt.event.InputEvent;  import java.awt.event.InputEvent;
42  import java.awt.event.InvocationEvent;  import java.awt.event.InvocationEvent;
43    import java.awt.event.WindowEvent;
44  import java.lang.reflect.InvocationTargetException;  import java.lang.reflect.InvocationTargetException;
45  import java.util.EmptyStackException;  import java.util.EmptyStackException;
46    
47    import gnu.java.awt.ClasspathToolkit;
48    
49  /* Written using on-line Java 2 Platform Standard Edition v1.3 API  /* Written using on-line Java 2 Platform Standard Edition v1.3 API
50   * Specification, as well as "The Java Class Libraries", 2nd edition   * Specification, as well as "The Java Class Libraries", 2nd edition
51   * (Addison-Wesley, 1998).   * (Addison-Wesley, 1998).
# Line 71  public class EventQueue Line 74  public class EventQueue
74    private long lastWhen = System.currentTimeMillis();    private long lastWhen = System.currentTimeMillis();
75    
76    private EventDispatchThread dispatchThread = new EventDispatchThread(this);    private EventDispatchThread dispatchThread = new EventDispatchThread(this);
77      private boolean shutdown = false;
78    
79      synchronized void setShutdown (boolean b)
80      {
81        shutdown = b;
82      }
83    
84      synchronized boolean isShutdown ()
85      {
86        if (shutdown)
87          return true;
88    
89        // This is the exact self-shutdown condition specified in J2SE:
90        // http://java.sun.com/j2se/1.4.2/docs/api/java/awt/doc-files/AWTThreadIssues.html
91        
92        if (peekEvent() == null
93            && ((ClasspathToolkit) Toolkit.getDefaultToolkit()).nativeQueueEmpty())
94          {
95            Frame[] frames = Frame.getFrames();
96            for (int i = 0; i < frames.length; ++i)
97              if (frames[i].isDisplayable())
98                return false;
99            return true;
100          }
101        return false;
102      }
103    
104    /**    /**
105     * Initializes a new instance of <code>EventQueue</code>.     * Initializes a new instance of <code>EventQueue</code>.
# Line 95  public class EventQueue Line 124  public class EventQueue
124        return next.getNextEvent();        return next.getNextEvent();
125    
126      while (next_in == next_out)      while (next_in == next_out)
127        wait();        {
128            // Only the EventDispatchThread associated with the top of the stack is
129            // allowed to get events from the native source; everyone else just
130            // waits on the head of the queue.
131    
132            if (isDispatchThread())
133              {
134                // We are not allowed to return null from this method, yet it
135                // is possible that we actually have run out of native events
136                // in the enclosing while() loop, and none of the native events
137                // happened to cause AWT events. We therefore ought to check
138                // the isShutdown() condition here, before risking a "native
139                // wait". If we check it before entering this function we may
140                // wait forever for events after the shutdown condition has
141                // arisen.
142    
143                if (isShutdown())
144                  throw new InterruptedException();
145    
146                ((ClasspathToolkit) Toolkit.getDefaultToolkit()).iterateNativeQueue(this);
147              }
148            else
149              {
150                try
151                  {
152                    wait();
153                  }
154                catch (InterruptedException ie)
155                  {
156                  }
157              }
158          }
159    
160      AWTEvent res = queue[next_out];      AWTEvent res = queue[next_out];
161    
# Line 215  public class EventQueue Line 275  public class EventQueue
275          next_out = 0;          next_out = 0;
276          next_in = oldQueue.length;          next_in = oldQueue.length;
277        }        }
278        
279        if (dispatchThread == null || !dispatchThread.isAlive())
280          {
281            dispatchThread = new EventDispatchThread(this);
282            dispatchThread.start();
283          }
284    
285        // Window events might represent the closing of a window, which
286        // might cause the end of the dispatch thread's life, so we'll wake
287        // it up here to give it a chance to check for shutdown.
288    
289        if (!isDispatchThread()
290            || (evt.getID() == WindowEvent.WINDOW_CLOSED)
291            || (evt.getID() == WindowEvent.WINDOW_CLOSING))
292          ((ClasspathToolkit) Toolkit.getDefaultToolkit()).wakeNativeQueue();
293    
294      notify();      notify();
295    }    }
296    
# Line 386  public class EventQueue Line 462  public class EventQueue
462              next_in = 0;              next_in = 0;
463              next_out = 0;              next_out = 0;
464    
465              // Tell our EventDispatchThread that it can end execution              ((ClasspathToolkit) Toolkit.getDefaultToolkit()).wakeNativeQueue();
466              dispatchThread.interrupt ();              setShutdown(true);
467              dispatchThread = null;              dispatchThread = null;
468                this.notifyAll();
469            }            }
470        }        }
471    }    }

Legend:
Removed from v.1.18  
changed lines
  Added in v.1.19

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26