KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > foxtrot > pumps > SunJDK14ConditionalEventPump


1 /**
2  * Copyright (c) 2002-2005, Simone Bordet
3  * All rights reserved.
4  *
5  * This software is distributable under the BSD license.
6  * See the terms of the BSD license in the documentation provided with this software.
7  */

8
9 package foxtrot.pumps;
10
11 import java.awt.AWTEvent JavaDoc;
12 import java.awt.EventQueue JavaDoc;
13
14 /**
15  * Specialized ConditionalEventPump for Sun's JDK 1.4 and 5.0.
16  * It fixes what I think is a misbehavior of {@link java.awt.EventQueue#peekEvent()},
17  * that does not flush pending events to the EventQueue before peeking for them.
18  * @version $Revision: 1.9 $
19  */

20 public class SunJDK14ConditionalEventPump extends ConditionalEventPump implements EventFilterable
21 {
22    /**
23     * Flushes pending events before peeking the EventQueue.
24     * There is a mismatch between the behavior of {@link java.awt.EventQueue#getNextEvent()}
25     * and {@link java.awt.EventQueue#peekEvent()}: the first always flushes pending events,
26     * the second does not. This missing flushing is the reason why peekEvent() returns null
27     * causing the proxy implementation of Conditional.evaluate() to never return
28     */

29    protected AWTEvent JavaDoc peekEvent(EventQueue JavaDoc queue)
30    {
31       sun.awt.SunToolkit.flushPendingEvents();
32       return super.peekEvent(queue);
33    }
34 }
35
Popular Tags