You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2009/05/08 16:46:35 UTC
svn commit: r773014 -
/incubator/pivot/trunk/wtk/src/pivot/wtk/DesktopApplicationContext.java
Author: gbrown
Date: Fri May 8 14:46:34 2009
New Revision: 773014
URL: http://svn.apache.org/viewvc?rev=773014&view=rev
Log:
Re-enable OSX application handler using dynamic proxy invocation API.
Modified:
incubator/pivot/trunk/wtk/src/pivot/wtk/DesktopApplicationContext.java
Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/DesktopApplicationContext.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/DesktopApplicationContext.java?rev=773014&r1=773013&r2=773014&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/DesktopApplicationContext.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/DesktopApplicationContext.java Fri May 8 14:46:34 2009
@@ -23,7 +23,9 @@
import java.awt.event.KeyEvent;
import java.awt.event.WindowEvent;
import java.io.File;
+import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
import java.net.MalformedURLException;
import java.net.URL;
@@ -56,24 +58,45 @@
// Hook into OSX application menu
if (System.getProperty("mrj.version") != null) {
- /*
- new com.apple.eawt.Application() {
- { addApplicationListener(new com.apple.eawt.ApplicationAdapter() {
- @Override
- public void handleAbout(com.apple.eawt.ApplicationEvent event) {
+ try {
+ // Get the EAWT classes and methods
+ Class<?> eawtApplicationClass = Class.forName("com.apple.eawt.Application");
+ Class<?> eawtApplicationListenerClass = Class.forName("com.apple.eawt.ApplicationListener");
+ Class<?> eawtApplicationEventClass = Class.forName("com.apple.eawt.ApplicationEvent");
+
+ Method addApplicationListenerMethod = eawtApplicationClass.getMethod("addApplicationListener",
+ new Class<?>[] {eawtApplicationListenerClass});
+
+ final Method setHandledMethod = eawtApplicationEventClass.getMethod("setHandled",
+ new Class<?>[] {Boolean.TYPE});
+
+ // Create the proxy handler
+ InvocationHandler handler = new InvocationHandler() {
+ public Object invoke(Object proxy, Method method, Object[] args)
+ throws Throwable {
+ String methodName = method.getName();
+ if (methodName.equals("handleAbout")) {
showAboutDialog();
- event.setHandled(true);
- }
-
- @Override
- public void handleQuit(com.apple.eawt.ApplicationEvent event) {
+ } else if (methodName.equals("handleQuit")) {
exit();
- event.setHandled(true);
}
- });
- }
- };
- */
+
+ // Invoke setHandled(true)
+ setHandledMethod.invoke(args[0], new Object[] {true});
+
+ return null;
+ }
+ };
+
+ Object eawtApplication = eawtApplicationClass.newInstance();
+ Object eawtApplicationListener = Proxy.newProxyInstance(getClass().getClassLoader(),
+ new Class[]{eawtApplicationListenerClass}, handler);
+
+ // Invoke the addApplicationListener() method with the proxy listener
+ addApplicationListenerMethod.invoke(eawtApplication, new Object[] {eawtApplicationListener});
+ } catch(Exception exception) {
+ System.err.println(exception);
+ }
}
}