KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > foxtrot > pumps > SunJDK140ConditionalEventPump


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.lang.reflect.Field JavaDoc;
13 import java.security.AccessController JavaDoc;
14 import java.security.PrivilegedExceptionAction JavaDoc;
15 import java.util.LinkedList JavaDoc;
16
17 /**
18  * Specialized ConditionalEventPump for Sun's JDK 1.4.0.
19  * @deprecated This class implements a workaround for bug #4531693 that has been fixed
20  * in JDK 1.4.2 and backported to 1.4.1. Therefore it is recommended to upgrade to those
21  * fixed JDK versions, as the bug not only affects Foxtrot but also the usage of dialogs.
22  * @version $Revision: 1.4 $
23  */

24 public class SunJDK140ConditionalEventPump extends SunJDK14ConditionalEventPump
25 {
26    private static Class JavaDoc sequencedEventClass;
27    private static Field JavaDoc listField;
28
29    static
30    {
31       try
32       {
33          AccessController.doPrivileged(new PrivilegedExceptionAction JavaDoc()
34          {
35             public Object JavaDoc run() throws Exception JavaDoc
36             {
37                ClassLoader JavaDoc loader = ClassLoader.getSystemClassLoader();
38                sequencedEventClass = loader.loadClass("java.awt.SequencedEvent");
39                listField = sequencedEventClass.getDeclaredField("list");
40                listField.setAccessible(true);
41                return null;
42             }
43          });
44       }
45       catch (Throwable JavaDoc x)
46       {
47          if (debug) x.printStackTrace();
48          throw new Error JavaDoc(x.toString());
49       }
50    }
51
52    protected boolean canPumpEvent(AWTEvent JavaDoc event)
53    {
54       try
55       {
56          LinkedList JavaDoc list = (LinkedList JavaDoc)listField.get(event);
57          synchronized (sequencedEventClass)
58          {
59             if (list.getFirst() == event) return true;
60          }
61       }
62       catch (Exception JavaDoc x)
63       {
64       }
65       return false;
66    }
67 }
68
Popular Tags