KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > foxtrot > pumps > SunJDK141ConditionalEventPump


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

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