Split up Sys.openURL into the platform specific DisplayImplementation

This commit is contained in:
Elias Naur 2004-11-22 21:22:30 +00:00
parent 23b6e400eb
commit 2577ffd377
7 changed files with 38 additions and 53 deletions

View File

@ -34,6 +34,7 @@ package org.lwjgl;
import java.io.IOException;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
/**
* $Id$
@ -238,36 +239,8 @@ public final class Sys {
* @return false if we are CERTAIN the call has failed
*/
public static boolean openURL(String url) {
String osName = System.getProperty("os.name");
if (osName.startsWith("Mac OS") || osName.startsWith("Windows")) {
// Mac and Windows both do this nicely from native code.
nOpenURL(url);
return true;
}
// Linux may as well resort to pure Java hackery, as there's no Linux native way of doing it
// right anyway.
String[] browsers = {"mozilla", "opera", "konqueror", "nautilus", "galeon", "netscape"};
for (int i = 0; i < browsers.length; i ++) {
try {
Runtime.getRuntime().exec(new String[] { browsers[i], url });
return true;
} catch (IOException e) {
// Ignore
e.printStackTrace(System.err);
}
}
// Seems to have failed
return false;
return Display.getImplementation().openURL(url);
}
/*
* Where necessary, we use a native implementation of openURL.
*/
private static native void nOpenURL(String url);
/**
* Get the contents of the system clipboard. The system might not have a clipboard

View File

@ -237,4 +237,6 @@ public interface DisplayImplementation {
/* Pbuffer caps */
public int getPbufferCaps();
public boolean openURL(String url);
}

View File

@ -41,6 +41,7 @@ package org.lwjgl.opengl;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.io.IOException;
import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException;
@ -102,4 +103,24 @@ final class LinuxDisplay implements DisplayImplementation {
public native void destroyCursor(Object cursorHandle);
public native int getPbufferCaps();
public boolean openURL(String url) {
// Linux may as well resort to pure Java hackery, as there's no Linux native way of doing it
// right anyway.
String[] browsers = {"mozilla", "opera", "konqueror", "nautilus", "galeon", "netscape"};
for (int i = 0; i < browsers.length; i ++) {
try {
Runtime.getRuntime().exec(new String[] { browsers[i], url });
return true;
} catch (IOException e) {
// Ignore
e.printStackTrace(System.err);
}
}
// Seems to have failed
return false;
}
}

View File

@ -375,6 +375,10 @@ final class MacOSXDisplay implements DisplayImplementation {
return GL11.glGetString(GL11.GL_EXTENSIONS).indexOf("GL_APPLE_pixel_buffer") != -1 ? Pbuffer.PBUFFER_SUPPORTED : 0;
}
public boolean openURL(String url) {
return false;
}
/**
* This class captures com.apple.eawt.ApplicationEvents through reflection
* to enable compilation on other platforms than Mac OS X

View File

@ -102,4 +102,10 @@ final class Win32Display implements DisplayImplementation {
public native void destroyCursor(Object cursorHandle);
public native int getPbufferCaps();
public boolean openURL(String url) {
nOpenURL(url);
return true;
}
private native void nOpenURL(String url);
}

View File

@ -94,28 +94,6 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Sys_nAlert(JNIEnv * env, jclass clazz, jst
{
}
JNIEXPORT void JNICALL Java_org_lwjgl_Sys_nOpenURL
(JNIEnv * env, jclass clazz, jstring url)
{
/* char * urlString = GetStringNativeChars(env, url);
OSStatus err;
ICInstance inst;
long startSel;
long endSel;
Str255 urlStr;
CopyCStringToPascal(urlString, urlStr);
free(urlString);
err = ICStart(&inst, '????'); // Use your creator code if you have one!
if (err == noErr) {
startSel = 0;
endSel = urlStr[0];
err = ICLaunchURL(inst, "\p", (char *) &urlStr[1], urlStr[0], &startSel, &endSel);
(void) ICStop(inst);
}*/
}
JNIEXPORT jstring JNICALL Java_org_lwjgl_Sys_nGetClipboard
(JNIEnv * env, jclass clazz)
{

View File

@ -41,6 +41,7 @@
#include "Window.h"
#include "org_lwjgl_Sys.h"
#include "org_lwjgl_opengl_Win32Display.h"
#include "common_tools.h"
#include <malloc.h>
@ -135,8 +136,8 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Sys_nAlert
* Method: openURL
* Signature: (Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_Sys_nOpenURL
(JNIEnv * env, jclass clazz, jstring url)
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_nOpenURL
(JNIEnv * env, jobject self, jstring url)
{
char * urlString = GetStringNativeChars(env, url);