From: <eli...@us...> - 2006-07-15 19:45:57
|
Revision: 2521 Author: elias_naur Date: 2006-07-15 12:45:36 -0700 (Sat, 15 Jul 2006) ViewCVS: http://svn.sourceforge.net/java-game-lib/?rev=2521&view=rev Log Message: ----------- Windows: Moved NativeSysImplementation.java to WindowsSysImplementation.java and moved some native code to java. Modified Paths: -------------- trunk/LWJGL/build.xml trunk/LWJGL/src/java/org/lwjgl/Sys.java trunk/LWJGL/src/java/org/lwjgl/test/DisplayTest.java trunk/LWJGL/src/native/windows/org_lwjgl_Sys.c Added Paths: ----------- trunk/LWJGL/src/java/org/lwjgl/WindowsSysImplementation.java Removed Paths: ------------- trunk/LWJGL/src/java/org/lwjgl/NativeSysImplementation.java trunk/LWJGL/src/java/org/lwjgl/Win32SysImplementation.java Modified: trunk/LWJGL/build.xml =================================================================== --- trunk/LWJGL/build.xml 2006-07-15 19:25:13 UTC (rev 2520) +++ trunk/LWJGL/build.xml 2006-07-15 19:45:36 UTC (rev 2521) @@ -514,7 +514,7 @@ <class name="org.lwjgl.opengl.WindowsPbufferPeerInfo" /> <class name="org.lwjgl.opengl.WindowsDisplay" /> <class name="org.lwjgl.opengl.WindowsRegistry" /> - <class name="org.lwjgl.NativeSysImplementation" /> + <class name="org.lwjgl.WindowsSysImplementation" /> <class name="org.lwjgl.opengl.WindowsAWTGLCanvasPeerInfo" /> <class name="org.lwjgl.opengl.WindowsPeerInfo" /> <class name="org.lwjgl.opengl.WindowsDisplayPeerInfo" /> Deleted: trunk/LWJGL/src/java/org/lwjgl/NativeSysImplementation.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/NativeSysImplementation.java 2006-07-15 19:25:13 UTC (rev 2520) +++ trunk/LWJGL/src/java/org/lwjgl/NativeSysImplementation.java 2006-07-15 19:45:36 UTC (rev 2521) @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2002-2004 LWJGL Project - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.lwjgl; - -/** - * A SysImplementation that uses native calls only. - * <p> - * @author $Author$ - * @version $Revision$ - * $Id$ - */ -class NativeSysImplementation extends DefaultSysImplementation { - - static { - Sys.initialize(); - } - - public native long getTimerResolution(); - - public native long getTime(); - - public native void alert(String title, String message); - - public native boolean openURL(String url); - - public native String getClipboard(); -} Modified: trunk/LWJGL/src/java/org/lwjgl/Sys.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/Sys.java 2006-07-15 19:25:13 UTC (rev 2520) +++ trunk/LWJGL/src/java/org/lwjgl/Sys.java 2006-07-15 19:45:36 UTC (rev 2521) @@ -57,7 +57,7 @@ private static final String VERSION = "1.0beta2"; /** Current version of the JNI library */ - static final int JNI_VERSION = 2; + static final int JNI_VERSION = 3; /** The implementation instance to delegate platform specific behavior to */ private final static SysImplementation implementation; @@ -114,7 +114,7 @@ class_name = "org.lwjgl.LinuxSysImplementation"; break; case LWJGLUtil.PLATFORM_WINDOWS: - class_name = "org.lwjgl.Win32SysImplementation"; + class_name = "org.lwjgl.WindowsSysImplementation"; break; case LWJGLUtil.PLATFORM_MACOSX: class_name = "org.lwjgl.MacOSXSysImplementation"; Deleted: trunk/LWJGL/src/java/org/lwjgl/Win32SysImplementation.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/Win32SysImplementation.java 2006-07-15 19:25:13 UTC (rev 2520) +++ trunk/LWJGL/src/java/org/lwjgl/Win32SysImplementation.java 2006-07-15 19:45:36 UTC (rev 2521) @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2002-2004 LWJGL Project - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.lwjgl; - -/** - * <p> - * Win32 SysImplementation. This is just a straightforward NativsSysImplementation. - * </p> - * @author $Author$ - * @version $Revision$ - * $Id$ - */ -class Win32SysImplementation extends NativeSysImplementation { -} Copied: trunk/LWJGL/src/java/org/lwjgl/WindowsSysImplementation.java (from rev 2520, trunk/LWJGL/src/java/org/lwjgl/NativeSysImplementation.java) =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/WindowsSysImplementation.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/WindowsSysImplementation.java 2006-07-15 19:45:36 UTC (rev 2521) @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.lwjgl; + +import java.security.AccessController; +import java.security.PrivilegedExceptionAction; +import java.security.PrivilegedActionException; + +/** + * <p> + * @author $Author$ + * @version $Revision$ + * $Id$ + */ +class WindowsSysImplementation extends DefaultSysImplementation { + static { + Sys.initialize(); + } + + public long getTimerResolution() { + return 1000; + } + + public native long getTime(); + + public native void alert(String title, String message); + + public boolean openURL(final String url) { + try { + AccessController.doPrivileged(new PrivilegedExceptionAction() { + public Object run() throws Exception { + Runtime.getRuntime().exec(new String[]{"rundll32", "url.dll,FileProtocolHandler", url}); + return null; + } + }); + return true; + } catch (PrivilegedActionException e) { + LWJGLUtil.log("Failed to open url (" + url + "): " + e.getCause().getMessage()); + return false; + } + } + + public native String getClipboard(); +} Modified: trunk/LWJGL/src/java/org/lwjgl/test/DisplayTest.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/DisplayTest.java 2006-07-15 19:25:13 UTC (rev 2520) +++ trunk/LWJGL/src/java/org/lwjgl/test/DisplayTest.java 2006-07-15 19:45:36 UTC (rev 2521) @@ -69,6 +69,7 @@ System.out.println("Info about current:"); System.out.println("Graphics card: " + Display.getAdapter() + ", version: " + Display.getVersion()); +System.exit(1); System.out.println("Resolution: " + Display.getDisplayMode().getWidth() + "x" + Display.getDisplayMode().getHeight() + "x" + Modified: trunk/LWJGL/src/native/windows/org_lwjgl_Sys.c =================================================================== --- trunk/LWJGL/src/native/windows/org_lwjgl_Sys.c 2006-07-15 19:25:13 UTC (rev 2520) +++ trunk/LWJGL/src/native/windows/org_lwjgl_Sys.c 2006-07-15 19:45:36 UTC (rev 2521) @@ -41,48 +41,21 @@ #include "Window.h" #include "mmsystem.h" -#include "org_lwjgl_NativeSysImplementation.h" +#include "org_lwjgl_WindowsSysImplementation.h" #include "common_tools.h" #include <malloc.h> -/* - * Class: org_lwjgl_Sys - * Method: getTimerResolution - * Signature: ()J - */ -JNIEXPORT jlong JNICALL Java_org_lwjgl_NativeSysImplementation_getTimerResolution - (JNIEnv * env, jobject ignored) -{ - return (jlong) 1000L; -} - -/* - * Class: org_lwjgl_Sys - * Method: ngetTime - * Signature: ()J - */ -JNIEXPORT jlong JNICALL Java_org_lwjgl_NativeSysImplementation_getTime - (JNIEnv * env, jobject ignored) -{ - - MMRESULT result; +JNIEXPORT jlong JNICALL Java_org_lwjgl_WindowsSysImplementation_getTime(JNIEnv * env, jobject ignored) { DWORD time; - result = timeBeginPeriod(1); + timeBeginPeriod(1); time = timeGetTime(); - result = timeEndPeriod(1); + timeEndPeriod(1); return time; } -/* - * Class: org_lwjgl_Sys - * Method: alert - * Signature: (Ljava/lang/String;Ljava/lang/String;)V - */ -JNIEXPORT void JNICALL Java_org_lwjgl_NativeSysImplementation_alert - (JNIEnv * env, jobject ignored, jstring title, jstring message) -{ +JNIEXPORT void JNICALL Java_org_lwjgl_WindowsSysImplementation_alert(JNIEnv * env, jobject ignored, jstring title, jstring message) { char * eMessageText = GetStringNativeChars(env, message); char * cTitleBarText = GetStringNativeChars(env, title); MessageBox(getCurrentHWND(), eMessageText, cTitleBarText, MB_OK | MB_TOPMOST); @@ -93,56 +66,7 @@ free(cTitleBarText); } -/* - * Class: org_lwjgl_Sys - * Method: openURL - * Signature: (Ljava/lang/String;)V - */ -JNIEXPORT jboolean JNICALL Java_org_lwjgl_NativeSysImplementation_openURL - (JNIEnv * env, jobject ignored, jstring url) -{ -#define BUFFER_SIZE 1024 - const char *std_args = "rundll32 url.dll,FileProtocolHandler "; - STARTUPINFO si; - PROCESS_INFORMATION pi; - - char * urlString = GetStringNativeChars(env, url); - - char command[BUFFER_SIZE]; - strncpy_s(command, BUFFER_SIZE, "", 1); - strncat_s(command, BUFFER_SIZE, std_args, _TRUNCATE); - strncat_s(command, BUFFER_SIZE, urlString, _TRUNCATE); - free(urlString); - - ZeroMemory( &si, sizeof(si) ); - si.cb = sizeof(si); - ZeroMemory( &pi, sizeof(pi) ); - - // Start the child process. - if( !CreateProcess( NULL, // No module name (use command line). - command, // Command line. - NULL, // Process handle not inheritable. - NULL, // Thread handle not inheritable. - FALSE, // Set handle inheritance to FALSE. - 0, // No creation flags. - NULL, // Use parent's environment block. - NULL, // Use parent's starting directory. - &si, // Pointer to STARTUPINFO structure. - &pi ) // Pointer to PROCESS_INFORMATION structure. - ) - { - printfDebugJava(env, "Failed to open URL %s", urlString); - return JNI_FALSE; - } - - // Close process and thread handles. - CloseHandle( pi.hProcess ); - CloseHandle( pi.hThread ); - - return JNI_TRUE; -} - -JNIEXPORT jstring JNICALL Java_org_lwjgl_NativeSysImplementation_getClipboard +JNIEXPORT jstring JNICALL Java_org_lwjgl_WindowsSysImplementation_getClipboard (JNIEnv * env, jobject ignored) { // Check to see if there's text available in the clipboard This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |