Code Search for Developers
 
 
  

Sys.java from Lightweight Java Game Library at Krugle


Show Sys.java syntax highlighted

/*
 * Copyright (c) 2002-2006 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.io.File;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedExceptionAction;

import org.lwjgl.input.Mouse;

/**
 * <p>
 * System class (named Sys so as not to conflict with java.lang.System)
 * </p>
 * @author cix_foo <cix_foo@users.sourceforge.net>
 * @version $Revision: 2880 $
 * $Id: Sys.java 2880 2007-08-17 18:41:00Z matzon $
 */
public final class Sys {
	/** The native library name */
	private static final String JNI_LIBRARY_NAME = "lwjgl";

	/** Current version of library */
	private static final String VERSION = "1.1.2";

	/** Current version of the JNI library */
	static final int JNI_VERSION = 11;

	/** The implementation instance to delegate platform specific behavior to */
	private final static SysImplementation implementation;

	private final static String POSTFIX64BIT = "64";
  
	private static void doLoadLibrary(final String lib_name) {
		AccessController.doPrivileged(new PrivilegedAction() {
			public Object run() {
				String library_path = System.getProperty("org.lwjgl.librarypath");
				if (library_path != null) {
					System.load(library_path + File.separator + 
						System.mapLibraryName(lib_name));
				} else {
					System.loadLibrary(lib_name);
				}
				return null;
			}
		});
	}

	private static void loadLibrary(final String lib_name) {
		try {
			doLoadLibrary(lib_name);
		} catch (UnsatisfiedLinkError e) {
			if (implementation.has64Bit()) {
				try {
					doLoadLibrary(lib_name + POSTFIX64BIT);
					return;
				} catch (UnsatisfiedLinkError e2) {
					LWJGLUtil.log("Failed to load 64 bit library:" + e2.getMessage());
				}
			}
			// Throw original error
			throw e;
		}
	}	

	static {
		implementation = createImplementation();
		loadLibrary(JNI_LIBRARY_NAME);
		
		int native_jni_version = implementation.getJNIVersion();
		if (native_jni_version != JNI_VERSION)
			throw new LinkageError("Version mismatch: jar version is '" + JNI_VERSION +
                             "', native libary version is '" + native_jni_version + "'");
		implementation.setDebug(LWJGLUtil.DEBUG);
	}

	private static SysImplementation createImplementation() {
		switch (LWJGLUtil.getPlatform()) {
			case LWJGLUtil.PLATFORM_LINUX:
				return new LinuxSysImplementation();
			case LWJGLUtil.PLATFORM_WINDOWS:
				return new org.lwjgl.WindowsSysImplementation();
			case LWJGLUtil.PLATFORM_MACOSX:
				return new org.lwjgl.MacOSXSysImplementation();
			default:
				throw new IllegalStateException("Unsupported platform");
		}
	}

	/**
	 * No constructor for Sys.
	 */
	private Sys() {
	}

	/**
	 * Return the version of the core LWJGL libraries as a String.
	 */
	public static String getVersion() {
		return VERSION;
	}
	
	/**
	 * Initialization. This is just a dummy method to trigger the static constructor.
	 */
	public static void initialize() {
	}

	/**
	 * Obtains the number of ticks that the hires timer does in a second. This method is fast;
	 * it should be called as frequently as possible, as it recalibrates the timer.
	 *
	 * @return timer resolution in ticks per second or 0 if no timer is present.
	 */
	public static long getTimerResolution() {
		return implementation.getTimerResolution();
	}

	/**
	 * Gets the current value of the hires timer, in ticks. When the Sys class is first loaded
	 * the hires timer is reset to 0. If no hires timer is present then this method will always
	 * return 0.<p><strong>NOTEZ BIEN</strong> that the hires timer WILL wrap around.
	 *
	 * @return the current hires time, in ticks (always >= 0)
	 */
	public static long getTime() {
		return implementation.getTime() & 0x7FFFFFFFFFFFFFFFL;
	}

	/**
	 * Attempt to display a modal alert to the user. This method should be used
	 * when a game fails to initialize properly or crashes out losing its display
	 * in the process. It is provided because AWT may not be available on the target
	 * platform, although on Mac and Linux and other platforms supporting AWT we
	 * delegate the task to AWT instead of doing it ourselves.
	 * <p>
	 * The alert should display the title and the message and then the current
	 * thread should block until the user dismisses the alert - typically with an
	 * OK button click.
	 * <p>
	 * It may be that the user's system has no windowing system installed for some
	 * reason, in which case this method may do nothing at all, or attempt to provide
	 * some console output.
	 *
	 * @param title The title of the alert. We suggest using the title of your game.
	 * @param message The message text for the alert.
	 */
	public static void alert(String title, String message) {
		boolean grabbed = Mouse.isGrabbed();
		if (grabbed) {
			Mouse.setGrabbed(false);
		}
		if (title == null)
			title = "";
		if (message == null)
			message = "";
		implementation.alert(title, message);
		if (grabbed) {
			Mouse.setGrabbed(true);
		}
	}

	/**
	 * Open the system web browser and point it at the specified URL. It is recommended
	 * that this not be called whilst your game is running, but on application exit in
	 * a shutdown hook, as the screen resolution will not be reset when the browser is
	 * brought into view.
	 * <p>
	 * There is no guarantee that this will work, nor that we can detect if it has
	 * failed - hence we don't return success code or throw an Exception. This is just a
	 * best attempt at opening the URL given - don't rely on it to work!
	 * <p>
	 * @param url The URL. Ensure that the URL is properly encoded.
	 * @return false if we are CERTAIN the call has failed
	 */
	public static boolean openURL(String url) {
		// Attempt to use Webstart if we have it available
		try {
			// Lookup the javax.jnlp.BasicService object
			final Class serviceManagerClass = Class.forName("javax.jnlp.ServiceManager");
			Method lookupMethod = (Method)AccessController.doPrivileged(new PrivilegedExceptionAction() {
				public Object run() throws Exception {
					return serviceManagerClass.getMethod("lookup", new Class[] {String.class});
				}
			});
			Object basicService = lookupMethod.invoke(serviceManagerClass, new Object[] {"javax.jnlp.BasicService"});
			final Class basicServiceClass = Class.forName("javax.jnlp.BasicService");
			Method showDocumentMethod = (Method)AccessController.doPrivileged(new PrivilegedExceptionAction() {
				public Object run() throws Exception {
					return basicServiceClass.getMethod("showDocument", new Class[] {URL.class});
				}
			});
			try {
				Boolean ret = (Boolean) showDocumentMethod.invoke(basicService, new Object[] {new URL(url)});
				return ret.booleanValue();
			} catch (MalformedURLException e) {
				e.printStackTrace(System.err);
				return false;
			}
		} catch (Exception ue) {
			return implementation.openURL(url);
		}
	}

	/**
	 * Get the contents of the system clipboard. The system might not have a
	 * clipboard (particularly if it doesn't even have a keyboard) in which case
	 * we return null. Otherwise we return a String, which may be the empty
	 * string "".
	 *
	 * @return a String, or null if there is no system clipboard.
	 */
	public static String getClipboard() {
		return implementation.getClipboard();
	}
}




See more files for this project here

Lightweight Java Game Library

A Java Game Library extension: 1. Handles the graphics, sound, and input simply 2. Wraps OpenGL, OpenAL, fmod3 and DevIL 3. Hires timers LWJGL currently supports Linux, Mac OS X (10.2 and above) and Windows (98 and above).

Project homepage: http://sourceforge.net/projects/java-game-lib
Programming language(s): C,Java
License: other

  d3d/
    Context.java
    ContextImplementation.java
    D3DAdapterIdentifier9.java
    D3DBox.java
    D3DCaps9.java
    D3DClipStatus9.java
    D3DColorValue.java
    D3DDeviceCreationParameters.java
    D3DDisplaymode.java
    D3DDisplaymodeEx.java
    D3DDisplaymodeFilter.java
    D3DGammaRamp.java
    D3DIndexBufferDesc.java
    D3DLight9.java
    D3DLockedBox.java
    D3DLockedRect.java
    D3DMaterial9.java
    D3DMatrix.java
    D3DPShaderCaps2_0.java
    D3DPresentParameters.java
    D3DPresentStats.java
    D3DRasterStatus.java
    D3DRectPatchInfo.java
    D3DRegionData.java
    D3DRegionDataHeader.java
    D3DSsurfaceDesc.java
    D3DSurfaceDesc.java
    D3DTriPatchInfo.java
    D3DUtil.java
    D3DVShaderCaps2_0.java
    D3DVector.java
    D3DVertexBufferDesc.java
    D3DVertexElement9.java
    D3DViewport9.java
    D3DVolumeDesc.java
    Direct3DConstants.java
    Display.java
    DisplayImplementation.java
    DisplayMode.java
    Drawable.java
    EventQueue.java
    GUID.java
    GlobalLock.java
    IDirect3D9.java
    IDirect3D9Ex.java
    IDirect3DBaseTexture9.java
    IDirect3DCubeTexture9.java
    IDirect3DDevice9.java
    IDirect3DDevice9Ex.java
    IDirect3DIndexBuffer9.java
    IDirect3DPixelShader9.java
    IDirect3DQuery9.java
    IDirect3DResource9.java
    IDirect3DStateBlock9.java
    IDirect3DSurface9.java
    IDirect3DSwapChain9.java
    IDirect3DSwapChain9Ex.java
    IDirect3DTexture9.java
    IDirect3DVertexBuffer9.java
    IDirect3DVertexDeclaration9.java
    IDirect3DVertexShader9.java
    IDirect3DVolume9.java
    IDirect3DVolumeTexture9.java
    InputImplementation.java
    LUID.java
    NewDisplay.java
    PaletteEntry.java
    PeerInfo.java
    PixelFormat.java
    Point.java
    Rectangle.java
    RegionData.java
    RegionDataHeader.java
    WindowsContextImplementation.java
    WindowsDirectInput.java
    WindowsDirectInput3.java
    WindowsDirectInput8.java
    WindowsDirectInputDevice.java
    WindowsDirectInputDevice3.java
    WindowsDirectInputDevice8.java
  devil/
  examples/
  fmod3/
  input/
  openal/
  opengl/
  test/
  util/
  BufferChecks.java
  BufferUtils.java
  DefaultSysImplementation.java
  J2SESysImplementation.java
  LWJGLException.java
  LWJGLUtil.java
  LinuxSysImplementation.java
  MacOSXSysImplementation.java
  NondirectBufferWrapper.java
  Sys.java
  SysImplementation.java
  WindowsSysImplementation.java