Added ApplejavaExtensions.jar to be able to use apple extensions without reflection

This commit is contained in:
Elias Naur 2008-04-22 16:52:16 +00:00
parent da172b29c6
commit 4e432b9e3e
3 changed files with 22 additions and 48 deletions

View File

@ -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"/>

BIN
libs/AppleJavaExtensions.jar Executable file

Binary file not shown.

View File

@ -57,6 +57,8 @@ import org.lwjgl.BufferUtils;
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 @@ final class MacOSXDisplay implements DisplayImplementation {
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 @@ final class MacOSXDisplay implements DisplayImplementation {
}
}
private void handleQuit() {
private void doHandleQuit() {
synchronized (this) {
close_requested = true;
}
@ -407,51 +426,6 @@ final class MacOSXDisplay implements DisplayImplementation {
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;
}