From: <eli...@us...> - 2008-04-22 16:52:24
|
Revision: 3037 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3037&view=rev Author: elias_naur Date: 2008-04-22 09:52:16 -0700 (Tue, 22 Apr 2008) Log Message: ----------- Added ApplejavaExtensions.jar to be able to use apple extensions without reflection Modified Paths: -------------- trunk/LWJGL/build.xml trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java Added Paths: ----------- trunk/LWJGL/libs/AppleJavaExtensions.jar Modified: trunk/LWJGL/build.xml =================================================================== --- trunk/LWJGL/build.xml 2008-04-21 20:53:18 UTC (rev 3036) +++ trunk/LWJGL/build.xml 2008-04-22 16:52:16 UTC (rev 3037) @@ -224,7 +224,7 @@ <!-- Compiles the Java source code --> <target name="compile" description="Compiles the java source code" depends="-initialize"> - <javac debug="yes" destdir="${lwjgl.bin}" source="1.4" target="1.4" classpath="${lwjgl.lib}/jinput.jar" taskname="core"> + <javac debug="yes" destdir="${lwjgl.bin}" source="1.4" target="1.4" classpath="${lwjgl.lib}/jinput.jar:${lwjgl.lib}/AppleJavaExtensions.jar" taskname="core"> <src path="${lwjgl.src}/java/"/> <src path="${lwjgl.src}/generated/"/> <include name="org/lwjgl/*.java"/> Added: trunk/LWJGL/libs/AppleJavaExtensions.jar =================================================================== (Binary files differ) Property changes on: trunk/LWJGL/libs/AppleJavaExtensions.jar ___________________________________________________________________ Name: svn:executable + * Name: svn:mime-type + application/octet-stream Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java 2008-04-21 20:53:18 UTC (rev 3036) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java 2008-04-22 16:52:16 UTC (rev 3037) @@ -57,6 +57,8 @@ import org.lwjgl.LWJGLException; import org.lwjgl.LWJGLUtil; +import com.apple.eawt.*; + final class MacOSXDisplay implements DisplayImplementation { private static final int PBUFFER_HANDLE_SIZE = 24; private static final int GAMMA_LENGTH = 256; @@ -73,7 +75,24 @@ private boolean close_requested; MacOSXDisplay() { - new MacOSXApplicationListener(); + try { + AccessController.doPrivileged(new PrivilegedExceptionAction() { + public Object run() throws Exception { + Application.getApplication().addApplicationListener(new ApplicationAdapter() { + public final void handleQuit(ApplicationEvent event) { + doHandleQuit(); + } + }); + return null; + } + }); + } catch (Throwable e) { + /** + * In an applet environment, referencing com.apple.eawt.Application can fail with + * a native exception. So log any exceptions instead of re-throwing. + */ + LWJGLUtil.log("Failed to register quit handler: " + e.getMessage()); + } } public void createWindow(DisplayMode mode, boolean fullscreen, Canvas parent, int x, int y) throws LWJGLException { @@ -96,7 +115,7 @@ } } - private void handleQuit() { + private void doHandleQuit() { synchronized (this) { close_requested = true; } @@ -407,51 +426,6 @@ return 0; } - /** - * This class captures com.apple.eawt.ApplicationEvents through reflection - * to enable compilation on other platforms than Mac OS X - */ - private class MacOSXApplicationListener implements InvocationHandler { - private final Method handleQuit; - - public MacOSXApplicationListener() { - Method m = null; - try { - m = (Method)AccessController.doPrivileged(new PrivilegedExceptionAction() { - public Object run() throws Exception { - /* Get the com.apple.eawt.Application class */ - Class com_apple_eawt_Application = Class.forName("com.apple.eawt.Application"); - /* Call the static Application.getApplication() method */ - Object application = com_apple_eawt_Application.getMethod("getApplication", null).invoke(null, null); - /* Create a proxy implementing com.apple.eawt.ApplicationListener */ - Class com_apple_eawt_ApplicationListener = Class.forName("com.apple.eawt.ApplicationListener"); - Object listener_proxy = Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] {com_apple_eawt_ApplicationListener}, MacOSXApplicationListener.this); - /* Invoke the method application.addApplicationListener(proxy) */ - Method addApplicationListener = com_apple_eawt_Application.getMethod("addApplicationListener", new Class[]{com_apple_eawt_ApplicationListener}); - addApplicationListener.invoke(application, new Object[]{listener_proxy}); - /* Finally, get the handleQuit method we want to react to */ - Class com_apple_eawt_ApplicationEvent = Class.forName("com.apple.eawt.ApplicationEvent"); - return com_apple_eawt_ApplicationListener.getMethod("handleQuit", new Class[]{com_apple_eawt_ApplicationEvent}); - } - }); - } catch (Throwable e) { - /** - * In an applet environment, referencing com.apple.eawt.Application can fail with - * a native exception. So log any exceptions instead of re-throwing. - */ - LWJGLUtil.log("Failed to register quit handler: " + e.getMessage()); -// throw new RuntimeException(e); - } - handleQuit = m; - } - - public Object invoke(Object proxy, Method method, Object[] args) { - if (method.equals(handleQuit)) - handleQuit(); - return null; - } - } - public boolean isBufferLost(PeerInfo handle) { return false; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |