Merge pull request #37 from jinput/issue/32

Issue/32
This commit is contained in:
Endolf 2018-05-31 20:58:11 +01:00 committed by GitHub
commit 16202823b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
46 changed files with 639 additions and 858 deletions

View file

@ -50,19 +50,11 @@ public class JInputAppletResourceLoader {
private int percentageDone = 0;
private String getPrivilegedProperty(final String property) {
return (String) AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return System.getProperty(property);
}
});
return AccessController.doPrivileged((PrivilegedAction<String>) () -> System.getProperty(property));
}
private String setPrivilegedProperty(final String property, final String value) {
return (String) AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return System.setProperty(property, value);
}
});
return AccessController.doPrivileged((PrivilegedAction<String>) () -> System.setProperty(property, value));
}
public void loadResources(URL codeBase) throws IOException {
@ -94,13 +86,13 @@ public class JInputAppletResourceLoader {
JarFile localJarFile = new JarFile(new File(tempDir, nativeJar), true);
Enumeration jarEntries = localJarFile.entries();
Enumeration<JarEntry> jarEntries = localJarFile.entries();
int totalUncompressedBytes = 0;
int totalUncompressedBytesWritten = 0;
List entriesToUse = new ArrayList();
List<JarEntry> entriesToUse = new ArrayList<>();
while(jarEntries.hasMoreElements()) {
JarEntry jarEntry = (JarEntry)jarEntries.nextElement();
JarEntry jarEntry = jarEntries.nextElement();
String entryName = jarEntry.getName();
if(!entryName.startsWith("META-INF")) {
totalUncompressedBytes+=jarEntry.getSize();
@ -116,7 +108,7 @@ public class JInputAppletResourceLoader {
}
for(int i=0;i<entriesToUse.size();i++) {
JarEntry jarEntry = (JarEntry) entriesToUse.get(i);
JarEntry jarEntry = entriesToUse.get(i);
InputStream inStream = localJarFile.getInputStream(localJarFile.getEntry(jarEntry.getName()));
File nativeFile = new File(tempNativesDir, jarEntry.getName());
FileOutputStream fos = new FileOutputStream(nativeFile);

View file

@ -1,10 +1,4 @@
/*
* %W% %E%
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*****************************************************************************
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -35,13 +29,11 @@
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
*****************************************************************************/
*/
package net.java.games.input;
import java.util.Map;
import java.util.List;
import java.util.HashMap;
import java.util.ArrayList;
import java.io.IOException;
@ -77,7 +69,7 @@ public abstract class AbstractController implements Controller {
/**
* Map from Component.Identifiers to Components
*/
private final Map id_to_components = new HashMap();
private final Map<Component.Identifier, Component> id_to_components = new HashMap<>();
private EventQueue event_queue = new EventQueue(EVENT_QUEUE_DEPTH);
@ -128,7 +120,7 @@ public abstract class AbstractController implements Controller {
* if no component with the specified type could be found.
*/
public final Component getComponent(Component.Identifier id) {
return (Component)id_to_components.get(id);
return id_to_components.get(id);
}
/**

View file

@ -85,7 +85,7 @@ public abstract class ControllerEnvironment {
/**
* List of controller listeners
*/
protected final ArrayList controllerListeners = new ArrayList();
protected final ArrayList<ControllerListener> controllerListeners = new ArrayList<>();
/**
* Protected constructor for subclassing.
@ -133,9 +133,9 @@ public abstract class ControllerEnvironment {
*/
protected void fireControllerAdded(Controller c) {
ControllerEvent ev = new ControllerEvent(c);
Iterator it = controllerListeners.iterator();
Iterator<ControllerListener> it = controllerListeners.iterator();
while (it.hasNext()) {
((ControllerListener)it.next()).controllerAdded(ev);
it.next().controllerAdded(ev);
}
}
@ -145,9 +145,9 @@ public abstract class ControllerEnvironment {
*/
protected void fireControllerRemoved(Controller c) {
ControllerEvent ev = new ControllerEvent(c);
Iterator it = controllerListeners.iterator();
Iterator<ControllerListener> it = controllerListeners.iterator();
while (it.hasNext()) {
((ControllerListener)it.next()).controllerRemoved(ev);
it.next().controllerRemoved(ev);
}
}
@ -158,4 +158,4 @@ public abstract class ControllerEnvironment {
public static ControllerEnvironment getDefaultEnvironment() {
return defaultEnvironment;
}
} // ControllerEnvironment
}

View file

@ -1,10 +1,4 @@
/*
* %W% %E%
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*****************************************************************************
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -35,24 +29,20 @@
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
*****************************************************************************/
*/
package net.java.games.input;
import net.java.games.util.plugins.Plugins;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Properties;
import java.util.StringTokenizer;
import java.util.logging.Logger;
import net.java.games.util.plugins.*;
/**
* The default controller environment.
*
@ -72,42 +62,31 @@ class DefaultControllerEnvironment extends ControllerEnvironment {
*
*/
static void loadLibrary(final String lib_name) {
AccessController.doPrivileged(
new PrivilegedAction() {
public final Object run() {
AccessController.doPrivileged((PrivilegedAction<String>) () -> {
String lib_path = System.getProperty("net.java.games.input.librarypath");
if (lib_path != null)
System.load(lib_path + File.separator + System.mapLibraryName(lib_name));
else
System.loadLibrary(lib_name);
return null;
}
});
}
static String getPrivilegedProperty(final String property) {
return (String)AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return System.getProperty(property);
}
});
return AccessController.doPrivileged((PrivilegedAction<String>) () -> System.getProperty(property));
}
static String getPrivilegedProperty(final String property, final String default_value) {
return (String)AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return System.getProperty(property, default_value);
}
});
return AccessController.doPrivileged((PrivilegedAction<String>) () -> System.getProperty(property, default_value));
}
/**
* List of all controllers in this environment
*/
private ArrayList controllers;
private ArrayList<Controller> controllers;
private Collection loadedPlugins = new ArrayList();
private Collection<String> loadedPluginNames = new ArrayList<>();
/**
* Public no-arg constructor.
@ -122,13 +101,8 @@ class DefaultControllerEnvironment extends ControllerEnvironment {
public Controller[] getControllers() {
if (controllers == null) {
// Controller list has not been scanned.
controllers = new ArrayList();
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
scanControllers();
return null;
}
});
controllers = new ArrayList<>();
AccessController.doPrivileged((PrivilegedAction<Void>) () -> scanControllers());
//Check the properties for specified controller classes
String pluginClasses = getPrivilegedProperty("jinput.plugins", "") + " " + getPrivilegedProperty("net.java.games.input.plugins", "");
if(!getPrivilegedProperty("jinput.useDefaultPlugin", "true").toLowerCase().trim().equals("false") && !getPrivilegedProperty("net.java.games.input.useDefaultPlugin", "true").toLowerCase().trim().equals("false")) {
@ -154,13 +128,13 @@ class DefaultControllerEnvironment extends ControllerEnvironment {
while(pluginClassTok.hasMoreTokens()) {
String className = pluginClassTok.nextToken();
try {
if(!loadedPlugins.contains(className)) {
if(!loadedPluginNames.contains(className)) {
log.fine("Loading: " + className);
Class ceClass = Class.forName(className);
Class<?> ceClass = Class.forName(className);
ControllerEnvironment ce = (ControllerEnvironment) ceClass.getDeclaredConstructor().newInstance();
if(ce.isSupported()) {
addControllers(ce.getControllers());
loadedPlugins.add(ce.getClass().getName());
loadedPluginNames.add(ce.getClass().getName());
} else {
log(ceClass.getName() + " is not supported");
}
@ -171,17 +145,17 @@ class DefaultControllerEnvironment extends ControllerEnvironment {
}
}
Controller[] ret = new Controller[controllers.size()];
Iterator it = controllers.iterator();
Iterator<Controller> it = controllers.iterator();
int i = 0;
while (it.hasNext()) {
ret[i] = (Controller)it.next();
ret[i] = it.next();
i++;
}
return ret;
}
/* This is jeff's new plugin code using Jeff's Plugin manager */
private void scanControllers() {
private Void scanControllers() {
String pluginPathName = getPrivilegedProperty("jinput.controllerPluginPath");
if(pluginPathName == null) {
pluginPathName = "controller";
@ -191,6 +165,8 @@ class DefaultControllerEnvironment extends ControllerEnvironment {
File.separator + "lib"+File.separator + pluginPathName);
scanControllersAt(getPrivilegedProperty("user.dir")+
File.separator + pluginPathName);
return null;
}
private void scanControllersAt(String path) {
@ -200,17 +176,17 @@ class DefaultControllerEnvironment extends ControllerEnvironment {
}
try {
Plugins plugins = new Plugins(file);
Class[] envClasses = plugins.getExtends(ControllerEnvironment.class);
@SuppressWarnings("unchecked")
Class<ControllerEnvironment>[] envClasses = plugins.getExtends(ControllerEnvironment.class);
for(int i=0;i<envClasses.length;i++){
try {
ControllerEnvironment.log("ControllerEnvironment "+
envClasses[i].getName()
+" loaded by "+envClasses[i].getClassLoader());
ControllerEnvironment ce = (ControllerEnvironment)
envClasses[i].getDeclaredConstructor().newInstance();
ControllerEnvironment ce = envClasses[i].getDeclaredConstructor().newInstance();
if(ce.isSupported()) {
addControllers(ce.getControllers());
loadedPlugins.add(ce.getClass().getName());
loadedPluginNames.add(ce.getClass().getName());
} else {
log(envClasses[i].getName() + " is not supported");
}

View file

@ -1,10 +1,4 @@
/*
* %W% %E%
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*****************************************************************************
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -35,7 +29,7 @@
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
*****************************************************************************/
*/
package net.java.games.input;
import java.io.File;
@ -77,7 +71,7 @@ class PluginClassLoader extends ClassLoader {
* Overrides findClass to first look in the parent class loader,
* then try loading the class from the plugin file system.
*/
protected Class findClass(String name)
protected Class<?> findClass(String name)
throws ClassNotFoundException {
// Try loading the class from the file system.
byte[] b = loadClassData(name);

View file

@ -29,12 +29,6 @@
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgs>
<arg>-h</arg>
<arg>${project.build.directory}/generated-sources/natives</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>

View file

@ -1,41 +1,35 @@
/*
* %W% %E%
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materails provided with the distribution.
*
* Neither the name Sun Microsystems, Inc. or the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*****************************************************************************
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materails provided with the distribution.
*
* Neither the name Sun Microsystems, Inc. or the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
*****************************************************************************/
package net.java.games.input;
import java.util.Map;
@ -46,13 +40,13 @@ import java.util.HashMap;
* @version 1.0
*/
final class ButtonUsage implements Usage {
private final static Map map = new HashMap();
private final static Map<Integer, ButtonUsage> map = new HashMap<>();
private final int button_id;
public final static ButtonUsage map(int button_id) {
Integer button_id_obj = new Integer(button_id);
ButtonUsage existing = (ButtonUsage)map.get(button_id_obj);
Integer button_id_obj = button_id;
ButtonUsage existing = map.get(button_id_obj);
if (existing != null)
return existing;
ButtonUsage new_button = new ButtonUsage(button_id);

View file

@ -1,41 +1,35 @@
/*
* %W% %E%
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materails provided with the distribution.
*
* Neither the name Sun Microsystems, Inc. or the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*****************************************************************************
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materails provided with the distribution.
*
* Neither the name Sun Microsystems, Inc. or the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
*****************************************************************************/
package net.java.games.input;
/** Generic Desktop Usages

View file

@ -1,46 +1,37 @@
/*
* %W% %E%
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materails provided with the distribution.
*
* Neither the name Sun Microsystems, Inc. or the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*****************************************************************************
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materails provided with the distribution.
*
* Neither the name Sun Microsystems, Inc. or the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
*****************************************************************************/
package net.java.games.input;
import java.util.Map;
import java.util.HashMap;
/** Mapping from Keyboard HID usages to Component.Identifier.Key
* @author elias
* @version 1.0

View file

@ -1,41 +1,35 @@
/*
* %W% %E%
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materails provided with the distribution.
*
* Neither the name Sun Microsystems, Inc. or the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*****************************************************************************
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materails provided with the distribution.
*
* Neither the name Sun Microsystems, Inc. or the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
*****************************************************************************/
package net.java.games.input;
import java.io.File;
@ -67,9 +61,7 @@ public final class OSXEnvironmentPlugin extends ControllerEnvironment implements
*
*/
static void loadLibrary(final String lib_name) {
AccessController.doPrivileged(
new PrivilegedAction() {
public final Object run() {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
try {
String lib_path = System.getProperty("net.java.games.input.librarypath");
if (lib_path != null)
@ -81,25 +73,16 @@ public final class OSXEnvironmentPlugin extends ControllerEnvironment implements
supported = false;
}
return null;
}
});
}
static String getPrivilegedProperty(final String property) {
return (String)AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return System.getProperty(property);
}
});
return AccessController.doPrivileged((PrivilegedAction<String>)() -> System.getProperty(property));
}
static String getPrivilegedProperty(final String property, final String default_value) {
return (String)AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return System.getProperty(property, default_value);
}
});
return AccessController.doPrivileged((PrivilegedAction<String>)() -> System.getProperty(property, default_value));
}
static {
@ -147,10 +130,10 @@ public final class OSXEnvironmentPlugin extends ControllerEnvironment implements
return supported;
}
private final static void addElements(OSXHIDQueue queue, List elements, List components, boolean map_mouse_buttons) throws IOException {
Iterator it = elements.iterator();
private final static void addElements(OSXHIDQueue queue, List<OSXHIDElement> elements, List<OSXComponent> components, boolean map_mouse_buttons) throws IOException {
Iterator<OSXHIDElement> it = elements.iterator();
while (it.hasNext()) {
OSXHIDElement element = (OSXHIDElement)it.next();
OSXHIDElement element = it.next();
Component.Identifier id = element.getIdentifier();
if (id == null)
continue;
@ -169,8 +152,8 @@ public final class OSXEnvironmentPlugin extends ControllerEnvironment implements
}
}
private final static Keyboard createKeyboardFromDevice(OSXHIDDevice device, List elements) throws IOException {
List components = new ArrayList();
private final static Keyboard createKeyboardFromDevice(OSXHIDDevice device, List<OSXHIDElement> elements) throws IOException {
List<OSXComponent> components = new ArrayList<>();
OSXHIDQueue queue = device.createQueue(AbstractController.EVENT_QUEUE_DEPTH);
try {
addElements(queue, elements, components, false);
@ -180,12 +163,11 @@ public final class OSXEnvironmentPlugin extends ControllerEnvironment implements
}
Component[] components_array = new Component[components.size()];
components.toArray(components_array);
Keyboard keyboard = new OSXKeyboard(device, queue, components_array, new Controller[]{}, new Rumbler[]{});
return keyboard;
return new OSXKeyboard(device, queue, components_array, new Controller[]{}, new Rumbler[]{});
}
private final static Mouse createMouseFromDevice(OSXHIDDevice device, List elements) throws IOException {
List components = new ArrayList();
private final static Mouse createMouseFromDevice(OSXHIDDevice device, List<OSXHIDElement> elements) throws IOException {
List<OSXComponent> components = new ArrayList<>();
OSXHIDQueue queue = device.createQueue(AbstractController.EVENT_QUEUE_DEPTH);
try {
addElements(queue, elements, components, true);
@ -204,8 +186,8 @@ public final class OSXEnvironmentPlugin extends ControllerEnvironment implements
}
}
private final static AbstractController createControllerFromDevice(OSXHIDDevice device, List elements, Controller.Type type) throws IOException {
List components = new ArrayList();
private final static AbstractController createControllerFromDevice(OSXHIDDevice device, List<OSXHIDElement> elements, Controller.Type type) throws IOException {
List<OSXComponent> components = new ArrayList<>();
OSXHIDQueue queue = device.createQueue(AbstractController.EVENT_QUEUE_DEPTH);
try {
addElements(queue, elements, components, false);
@ -215,15 +197,14 @@ public final class OSXEnvironmentPlugin extends ControllerEnvironment implements
}
Component[] components_array = new Component[components.size()];
components.toArray(components_array);
AbstractController controller = new OSXAbstractController(device, queue, components_array, new Controller[]{}, new Rumbler[]{}, type);
return controller;
return new OSXAbstractController(device, queue, components_array, new Controller[]{}, new Rumbler[]{}, type);
}
private final static void createControllersFromDevice(OSXHIDDevice device, List controllers) throws IOException {
private final static void createControllersFromDevice(OSXHIDDevice device, List<Controller> controllers) throws IOException {
UsagePair usage_pair = device.getUsagePair();
if (usage_pair == null)
return;
List elements = device.getElements();
List<OSXHIDElement> elements = device.getElements();
if (usage_pair.getUsagePage() == UsagePage.GENERIC_DESKTOP && (usage_pair.getUsage() == GenericDesktopUsage.MOUSE ||
usage_pair.getUsage() == GenericDesktopUsage.POINTER)) {
Controller mouse = createMouseFromDevice(device, elements);
@ -231,26 +212,18 @@ public final class OSXEnvironmentPlugin extends ControllerEnvironment implements
controllers.add(mouse);
} else if (usage_pair.getUsagePage() == UsagePage.GENERIC_DESKTOP && (usage_pair.getUsage() == GenericDesktopUsage.KEYBOARD ||
usage_pair.getUsage() == GenericDesktopUsage.KEYPAD)) {
Controller keyboard = createKeyboardFromDevice(device, elements);
if (keyboard != null)
controllers.add(keyboard);
controllers.add(createKeyboardFromDevice(device, elements));
} else if (usage_pair.getUsagePage() == UsagePage.GENERIC_DESKTOP && usage_pair.getUsage() == GenericDesktopUsage.JOYSTICK) {
Controller joystick = createControllerFromDevice(device, elements, Controller.Type.STICK);
if (joystick != null)
controllers.add(joystick);
controllers.add(createControllerFromDevice(device, elements, Controller.Type.STICK));
} else if (usage_pair.getUsagePage() == UsagePage.GENERIC_DESKTOP && usage_pair.getUsage() == GenericDesktopUsage.MULTI_AXIS_CONTROLLER) {
Controller multiaxis = createControllerFromDevice(device, elements, Controller.Type.STICK);
if (multiaxis != null)
controllers.add(multiaxis);
controllers.add(createControllerFromDevice(device, elements, Controller.Type.STICK));
} else if (usage_pair.getUsagePage() == UsagePage.GENERIC_DESKTOP && usage_pair.getUsage() == GenericDesktopUsage.GAME_PAD) {
Controller game_pad = createControllerFromDevice(device, elements, Controller.Type.GAMEPAD);
if (game_pad != null)
controllers.add(game_pad);
controllers.add(createControllerFromDevice(device, elements, Controller.Type.GAMEPAD));
}
}
private final static Controller[] enumerateControllers() {
List controllers = new ArrayList();
List<Controller> controllers = new ArrayList<>();
try {
OSXHIDDeviceIterator it = new OSXHIDDeviceIterator();
try {

View file

@ -1,41 +1,35 @@
/*
* %W% %E%
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materails provided with the distribution.
*
* Neither the name Sun Microsystems, Inc. or the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*****************************************************************************
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materails provided with the distribution.
*
* Neither the name Sun Microsystems, Inc. or the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
*****************************************************************************/
package net.java.games.input;
import java.io.IOException;
@ -104,7 +98,7 @@ final class OSXHIDDevice {
private final long device_address;
private final long device_interface_address;
private final Map properties;
private final Map<String,?> properties;
private boolean released;
@ -130,7 +124,7 @@ final class OSXHIDDevice {
return (String)properties.get(kIOHIDProductKey);
}
private final OSXHIDElement createElementFromElementProperties(Map element_properties) {
private final OSXHIDElement createElementFromElementProperties(Map<String,?> element_properties) {
/* long size = getLongFromProperties(element_properties, kIOHIDElementSizeKey);
// ignore elements that can't fit into the 32 bit value field of a hid event
if (size > 32)
@ -161,12 +155,13 @@ final class OSXHIDDevice {
}
}
private final void addElements(List elements, Map properties) {
@SuppressWarnings("unchecked")
private final void addElements(List<OSXHIDElement> elements, Map<String,?> properties) {
Object[] elements_properties = (Object[])properties.get(kIOHIDElementKey);
if (elements_properties == null)
return;
for (int i = 0; i < elements_properties.length; i++) {
Map element_properties = (Map)elements_properties[i];
Map<String,?> element_properties = (Map<String,?>)elements_properties[i];
OSXHIDElement element = createElementFromElementProperties(element_properties);
if (element != null) {
elements.add(element);
@ -175,28 +170,28 @@ final class OSXHIDDevice {
}
}
public final List getElements() {
List elements = new ArrayList();
public final List<OSXHIDElement> getElements() {
List<OSXHIDElement> elements = new ArrayList<>();
addElements(elements, properties);
return elements;
}
private final static long getLongFromProperties(Map properties, String key, long default_value) {
private final static long getLongFromProperties(Map<String,?> properties, String key, long default_value) {
Long long_obj = (Long)properties.get(key);
if (long_obj == null)
return default_value;
return long_obj.longValue();
}
private final static boolean getBooleanFromProperties(Map properties, String key, boolean default_value) {
private final static boolean getBooleanFromProperties(Map<String,?> properties, String key, boolean default_value) {
return getLongFromProperties(properties, key, default_value ? 1 : 0) != 0;
}
private final static int getIntFromProperties(Map properties, String key) {
private final static int getIntFromProperties(Map<String,?> properties, String key) {
return (int)getLongFromProperties(properties, key);
}
private final static long getLongFromProperties(Map properties, String key) {
private final static long getLongFromProperties(Map<String,?> properties, String key) {
Long long_obj = (Long)properties.get(key);
return long_obj.longValue();
}
@ -217,28 +212,6 @@ final class OSXHIDDevice {
return createUsagePair(usage_page_id, usage_id);
}
/*
public final List getUsagePairs() {
List usage_pairs_list = new ArrayList();
Object[] usage_pairs = (Object[])properties.get(kIOHIDDeviceUsagePairsKey);
if (usage_pairs == null) {
int usage_page_id = getIntFromProperties(properties, kIOHIDPrimaryUsagePageKey);
int usage_id = getIntFromProperties(properties, kIOHIDPrimaryUsageKey);
UsagePair pair = createUsagePair(usage_page_id, usage_id);
if (pair != null)
usage_pairs_list.add(pair);
}
for (int i = 0; i < usage_pairs.length; i++) {
Map usage_pair = (Map)usage_pairs[i];
int usage_page_id = getIntFromProperties(usage_pair, kIOHIDDeviceUsagePageKey);
int usage_id = getIntFromProperties(usage_pair, kIOHIDDeviceUsageKey);
UsagePair pair = createUsagePair(usage_page_id, usage_id);
if (pair != null)
usage_pairs_list.add(pair);
}
return usage_pairs_list;
}
*/
private final void dumpProperties() {
log.info(toString());
dumpMap("", properties);
@ -253,8 +226,8 @@ final class OSXHIDDevice {
log.info(prefix + "}");
}
private final static void dumpMap(String prefix, Map map) {
Iterator keys = map.keySet().iterator();
private final static void dumpMap(String prefix, Map<String,?> map) {
Iterator<String> keys = map.keySet().iterator();
while (keys.hasNext()) {
Object key = keys.next();
Object value = map.get(key);
@ -262,23 +235,24 @@ final class OSXHIDDevice {
dumpObject(prefix + "\t", value);
}
}
@SuppressWarnings("unchecked")
private final static void dumpObject(String prefix, Object obj) {
if (obj instanceof Long) {
Long l = (Long)obj;
log.info(prefix + "0x" + Long.toHexString(l.longValue()));
} else if (obj instanceof Map)
dumpMap(prefix, (Map)obj);
dumpMap(prefix, (Map<String,?>)obj);
else if (obj.getClass().isArray())
dumpArray(prefix, (Object[])obj);
else
log.info(prefix + obj);
}
private final Map getDeviceProperties() throws IOException {
private final Map<String,?> getDeviceProperties() throws IOException {
return nGetDeviceProperties(device_address);
}
private final static native Map nGetDeviceProperties(long device_address) throws IOException;
private final static native Map<String,?> nGetDeviceProperties(long device_address) throws IOException;
public final synchronized void release() throws IOException {
try {

View file

@ -1,41 +1,35 @@
/*
* %W% %E%
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materails provided with the distribution.
*
* Neither the name Sun Microsystems, Inc. or the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*****************************************************************************
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materails provided with the distribution.
*
* Neither the name Sun Microsystems, Inc. or the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
*****************************************************************************/
package net.java.games.input;
import java.io.IOException;
@ -47,7 +41,7 @@ import java.util.HashMap;
* @version 1.0
*/
final class OSXHIDQueue {
private final Map map = new HashMap();
private final Map<Long,OSXComponent> map = new HashMap<>();
private final long queue_address;
private boolean released;
@ -80,7 +74,7 @@ final class OSXHIDQueue {
}
public final OSXComponent mapEvent(OSXEvent event) {
return (OSXComponent)map.get(new Long(event.getCookie()));
return map.get(event.getCookie());
}
private final void open(int queue_depth) throws IOException {
@ -118,13 +112,13 @@ final class OSXHIDQueue {
public final void addElement(OSXHIDElement element, OSXComponent component) throws IOException {
nAddElement(queue_address, element.getCookie());
map.put(new Long(element.getCookie()), component);
map.put(element.getCookie(), component);
}
private final static native void nAddElement(long queue_address, long cookie) throws IOException;
public final void removeElement(OSXHIDElement element) throws IOException {
nRemoveElement(queue_address, element.getCookie());
map.remove(new Long(element.getCookie()));
map.remove(element.getCookie());
}
private final static native void nRemoveElement(long queue_address, long cookie) throws IOException;

View file

@ -1,41 +1,35 @@
/*
* %W% %E%
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materails provided with the distribution.
*
* Neither the name Sun Microsystems, Inc. or the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*****************************************************************************
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materails provided with the distribution.
*
* Neither the name Sun Microsystems, Inc. or the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
*****************************************************************************/
package net.java.games.input;
/** Generic Desktop Usages

View file

@ -1,41 +1,35 @@
/*
* %W% %E%
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materails provided with the distribution.
*
* Neither the name Sun Microsystems, Inc. or the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*****************************************************************************
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materails provided with the distribution.
*
* Neither the name Sun Microsystems, Inc. or the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
*****************************************************************************/
package net.java.games.input;
import java.lang.reflect.Method;
@ -77,7 +71,7 @@ final class UsagePage {
/* ReservedPointofSalepages 0x8E - 0X8F */
public final static UsagePage CAMERACONTROL= new UsagePage(0x90); /* USB Device Class Definition for Image Class Devices */
public final static UsagePage ARCADE = new UsagePage(0x91); /* OAAF Definitions for arcade and coinop related Devices */
private final Class usage_class;
private final Class<? extends Usage> usage_class;
private final int usage_page_id;
public final static UsagePage map(int page_id) {
@ -86,7 +80,7 @@ final class UsagePage {
return map[page_id];
}
private UsagePage(int page_id, Class usage_class) {
private UsagePage(int page_id, Class<? extends Usage> usage_class) {
map[page_id] = this;
this.usage_class = usage_class;
this.usage_page_id = page_id;
@ -104,8 +98,8 @@ final class UsagePage {
if (usage_class == null)
return null;
try {
Method map_method = usage_class.getMethod("map", new Class[]{int.class});
Object result = map_method.invoke(null, new Object[]{new Integer(usage_id)});
Method map_method = usage_class.getMethod("map", int.class);
Object result = map_method.invoke(null, usage_id);
return (Usage)result;
} catch (Exception e) {
throw new Error(e);

View file

@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2004 Jeremy Booth (jeremy@newdawnsoftware.com)
*
* Redistribution and use in source and binary forms, with or without
@ -43,7 +43,7 @@ import java.lang.reflect.Modifier;
* @author elias
*/
final class AWTKeyboard extends Keyboard implements AWTEventListener {
private final List awt_events = new ArrayList();
private final List<KeyEvent> awt_events = new ArrayList<>();
private Event[] processed_events;
private int processed_events_index;
@ -54,7 +54,7 @@ final class AWTKeyboard extends Keyboard implements AWTEventListener {
}
private final static Component[] createComponents() {
List components = new ArrayList();
List<Component> components = new ArrayList<>();
Field[] vkey_fields = KeyEvent.class.getFields();
for (int i = 0; i < vkey_fields.length; i++) {
Field vkey_field = vkey_fields[i];
@ -80,7 +80,7 @@ final class AWTKeyboard extends Keyboard implements AWTEventListener {
components.add(new Key(Component.Identifier.Key.RETURN));
components.add(new Key(Component.Identifier.Key.NUMPADCOMMA));
components.add(new Key(Component.Identifier.Key.COMMA));
return (Component[])components.toArray(new Component[]{});
return components.toArray(new Component[]{});
}
private final void resizeEventQueue(int size) {
@ -96,13 +96,12 @@ final class AWTKeyboard extends Keyboard implements AWTEventListener {
public final synchronized void eventDispatched(AWTEvent event) {
if (event instanceof KeyEvent)
awt_events.add(event);
awt_events.add((KeyEvent)event);
}
public final synchronized void pollDevice() throws IOException {
for (int i = 0; i < awt_events.size(); i++) {
KeyEvent event = (KeyEvent)awt_events.get(i);
processEvent(event);
processEvent(awt_events.get(i));
}
awt_events.clear();
}

View file

@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2004 Jeremy Booth (jeremy@newdawnsoftware.com)
*
* Redistribution and use in source and binary forms, with or without
@ -27,7 +27,6 @@
package net.java.games.input;
import java.awt.AWTEvent;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.AWTEventListener;
import java.awt.event.MouseEvent;
@ -47,8 +46,8 @@ final class AWTMouse extends Mouse implements AWTEventListener {
private final static int EVENT_Y = 2;
private final static int EVENT_BUTTON = 4;
private final List awt_events = new ArrayList();
private final List processed_awt_events = new ArrayList();
private final List<AWTEvent> awt_events = new ArrayList<>();
private final List<AWTEvent> processed_awt_events = new ArrayList<>();
private int event_state = EVENT_X;
@ -115,7 +114,7 @@ final class AWTMouse extends Mouse implements AWTEventListener {
Axis wheel = (Axis)getWheel();
wheel.setValue(0);
for (int i = 0; i < awt_events.size(); i++) {
AWTEvent event = (AWTEvent)awt_events.get(i);
AWTEvent event = awt_events.get(i);
processEvent(event);
processed_awt_events.add(event);
}
@ -126,7 +125,7 @@ final class AWTMouse extends Mouse implements AWTEventListener {
while (true) {
if (processed_awt_events.isEmpty())
return false;
AWTEvent awt_event = (AWTEvent)processed_awt_events.get(0);
AWTEvent awt_event = processed_awt_events.get(0);
if (awt_event instanceof MouseWheelEvent) {
MouseWheelEvent awt_wheel_event = (MouseWheelEvent)awt_event;
long nanos = awt_wheel_event.getWhen()*1000000L;

View file

@ -29,12 +29,6 @@
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgs>
<arg>-h</arg>
<arg>${project.build.directory}/generated-sources/natives</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>

View file

@ -40,7 +40,7 @@ import java.util.ArrayList;
* is run on a single thread.
*/
final class LinuxDeviceThread extends Thread {
private final List tasks = new ArrayList();
private final List<LinuxDeviceTask> tasks = new ArrayList<>();
public LinuxDeviceThread() {
setDaemon(true);
@ -50,7 +50,7 @@ final class LinuxDeviceThread extends Thread {
public synchronized final void run() {
while (true) {
if (!tasks.isEmpty()) {
LinuxDeviceTask task = (LinuxDeviceTask)tasks.remove(0);
LinuxDeviceTask task = tasks.remove(0);
task.doExecute();
synchronized (task) {
task.notify();

View file

@ -47,7 +47,7 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen
private static boolean supported = false;
private final Controller[] controllers;
private final List devices = new ArrayList();
private final List<LinuxDevice> devices = new ArrayList<LinuxDevice>();
private final static LinuxDeviceThread device_thread = new LinuxDeviceThread();
/**
@ -58,9 +58,7 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen
*
*/
static void loadLibrary(final String lib_name) {
AccessController.doPrivileged(
new PrivilegedAction() {
public final Object run() {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
String lib_path = System.getProperty("net.java.games.input.librarypath");
try {
if(lib_path != null)
@ -73,25 +71,16 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen
supported = false;
}
return null;
}
});
}
static String getPrivilegedProperty(final String property) {
return (String) AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return System.getProperty(property);
}
});
return AccessController.doPrivileged((PrivilegedAction<String>)() -> System.getProperty(property));
}
static String getPrivilegedProperty(final String property, final String default_value) {
return (String) AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return System.getProperty(property, default_value);
}
});
return AccessController.doPrivileged((PrivilegedAction<String>)() -> System.getProperty(property, default_value));
}
static {
@ -114,12 +103,9 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen
if(isSupported()) {
this.controllers = enumerateControllers();
log("Linux plugin claims to have found " + controllers.length + " controllers");
AccessController.doPrivileged(
new PrivilegedAction() {
public final Object run() {
AccessController.doPrivileged((PrivilegedAction<Void>)() -> {
Runtime.getRuntime().addShutdownHook(new ShutdownHook());
return null;
}
});
} else {
controllers = new Controller[0];
@ -135,11 +121,11 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen
return controllers;
}
private final static Component[] createComponents(List event_components, LinuxEventDevice device) {
private final static Component[] createComponents(List<LinuxEventComponent> event_components, LinuxEventDevice device) {
LinuxEventComponent[][] povs = new LinuxEventComponent[4][2];
List components = new ArrayList();
List<LinuxComponent> components = new ArrayList<>();
for(int i = 0; i < event_components.size(); i++) {
LinuxEventComponent event_component = (LinuxEventComponent) event_components.get(i);
LinuxEventComponent event_component = event_components.get(i);
Component.Identifier identifier = event_component.getIdentifier();
if(identifier == Component.Identifier.Axis.POV) {
@ -213,7 +199,7 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen
}
private final static Controller createControllerFromDevice(LinuxEventDevice device) throws IOException {
List event_components = device.getComponents();
List<LinuxEventComponent> event_components = device.getComponents();
Component[] components = createComponents(event_components, device);
Controller.Type type = device.getType();
@ -228,16 +214,16 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen
}
private final Controller[] enumerateControllers() {
List controllers = new ArrayList();
List eventControllers = new ArrayList();
List jsControllers = new ArrayList();
List<Controller> controllers = new ArrayList<>();
List<Controller> eventControllers = new ArrayList<>();
List<Controller> jsControllers = new ArrayList<>();
enumerateEventControllers(eventControllers);
enumerateJoystickControllers(jsControllers);
for(int i = 0; i < eventControllers.size(); i++) {
for(int j = 0; j < jsControllers.size(); j++) {
Controller evController = (Controller) eventControllers.get(i);
Controller jsController = (Controller) jsControllers.get(j);
Controller evController = eventControllers.get(i);
Controller jsController = jsControllers.get(j);
// compare
// Check if the nodes have the same name
@ -345,13 +331,13 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen
}
private final static Controller createJoystickFromJoystickDevice(LinuxJoystickDevice device) {
List components = new ArrayList();
List<AbstractComponent> components = new ArrayList<>();
byte[] axisMap = device.getAxisMap();
char[] buttonMap = device.getButtonMap();
LinuxJoystickAxis[] hatBits = new LinuxJoystickAxis[6];
for(int i = 0; i < device.getNumButtons(); i++) {
Component.Identifier button_id = (Component.Identifier) LinuxNativeTypesMap.getButtonID(buttonMap[i]);
Component.Identifier button_id = LinuxNativeTypesMap.getButtonID(buttonMap[i]);
if(button_id != null) {
LinuxJoystickButton button = new LinuxJoystickButton(button_id);
device.registerButton(i, button);
@ -391,10 +377,10 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen
}
}
return new LinuxJoystickAbstractController(device, (Component[]) components.toArray(new Component[]{}), new Controller[]{}, new Rumbler[]{});
return new LinuxJoystickAbstractController(device, components.toArray(new Component[]{}), new Controller[]{}, new Rumbler[]{});
}
private final void enumerateJoystickControllers(List controllers) {
private final void enumerateJoystickControllers(List<Controller> controllers) {
File[] joystick_device_files = enumerateJoystickDeviceFiles("/dev/input");
if(joystick_device_files == null || joystick_device_files.length == 0) {
joystick_device_files = enumerateJoystickDeviceFiles("/dev");
@ -428,39 +414,26 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen
}
private static String getAbsolutePathPrivileged(final File file) {
return (String) AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return file.getAbsolutePath();
}
});
return AccessController.doPrivileged((PrivilegedAction<String>) () -> file.getAbsolutePath());
}
private static File[] listFilesPrivileged(final File dir, final FilenameFilter filter) {
return (File[]) AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return AccessController.doPrivileged((PrivilegedAction<File[]>) () -> {
File[] files = dir.listFiles(filter);
if(files == null) {
log("dir " + dir.getName() + " exists: " + dir.exists() + ", is writable: " + dir.isDirectory());
files = new File[]{};
} else {
Arrays.sort(files, new Comparator() {
public int compare(Object f1, Object f2) {
return ((File) f1).getName().compareTo(((File) f2).getName());
}
});
Arrays.sort(files, Comparator.comparing(File::getName));
}
return files;
}
});
}
private final void enumerateEventControllers(List controllers) {
private final void enumerateEventControllers(List<Controller> controllers) {
final File dev = new File("/dev/input");
File[] event_device_files = listFilesPrivileged(dev, new FilenameFilter() {
public final boolean accept(File dir, String name) {
return name.startsWith("event");
}
});
File[] event_device_files = listFilesPrivileged(dev, (File dir, String name) -> name.startsWith("event"));
if(event_device_files == null)
return;
for(int i = 0; i < event_device_files.length; i++) {
@ -489,7 +462,7 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen
public final void run() {
for(int i = 0; i < devices.size(); i++) {
try {
LinuxDevice device = (LinuxDevice) devices.get(i);
LinuxDevice device = devices.get(i);
device.close();
} catch(IOException e) {
log("Failed to close device: " + e.getMessage());

View file

@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
*
* Redistribution and use in source and binary forms, with or without
@ -35,12 +35,12 @@ import java.util.ArrayList;
* @author elias
*/
final class LinuxEventDevice implements LinuxDevice {
private final Map component_map = new HashMap();
private final Map<LinuxAxisDescriptor, LinuxComponent> component_map = new HashMap<>();
private final Rumbler[] rumblers;
private final long fd;
private final String name;
private final LinuxInputID input_id;
private final List components;
private final List<LinuxEventComponent> components;
private final Controller.Type type;
/* Closed state variable that protects the validity of the file descriptor.
@ -83,10 +83,10 @@ final class LinuxEventDevice implements LinuxDevice {
return type;
}
private final static int countComponents(List components, Class id_type, boolean relative) {
private final static int countComponents(List<LinuxEventComponent> components, Class<?> id_type, boolean relative) {
int count = 0;
for (int i = 0; i < components.size(); i++) {
LinuxEventComponent component = (LinuxEventComponent)components.get(i);
LinuxEventComponent component = components.get(i);
if (id_type.isInstance(component.getIdentifier()) && relative == component.isRelative())
count++;
}
@ -94,7 +94,7 @@ final class LinuxEventDevice implements LinuxDevice {
}
private final Controller.Type guessType() throws IOException {
List components = getComponents();
List<LinuxEventComponent> components = getComponents();
if (components.size() == 0)
return Controller.Type.UNKNOWN;
int num_rel_axes = countComponents(components, Component.Identifier.Axis.class, true);
@ -118,7 +118,7 @@ final class LinuxEventDevice implements LinuxDevice {
int num_gamepad_button_traits = 0;
// count button traits
for (int i = 0; i < components.size(); i++) {
LinuxEventComponent component = (LinuxEventComponent)components.get(i);
LinuxEventComponent component = components.get(i);
if (component.getButtonTrait() == Controller.Type.MOUSE)
num_mouse_button_traits++;
else if (component.getButtonTrait() == Controller.Type.KEYBOARD)
@ -158,11 +158,11 @@ final class LinuxEventDevice implements LinuxDevice {
}
private final Rumbler[] enumerateRumblers() {
List rumblers = new ArrayList();
List<Rumbler> rumblers = new ArrayList<>();
try {
int num_effects = getNumEffects();
if (num_effects <= 0)
return (Rumbler[])rumblers.toArray(new Rumbler[]{});
return rumblers.toArray(new Rumbler[]{});
byte[] ff_bits = getForceFeedbackBits();
if (isBitSet(ff_bits, NativeDefinitions.FF_RUMBLE) && num_effects > rumblers.size()) {
rumblers.add(new LinuxRumbleFF(this));
@ -170,7 +170,7 @@ final class LinuxEventDevice implements LinuxDevice {
} catch (IOException e) {
LinuxEnvironmentPlugin.log("Failed to enumerate rumblers: " + e.getMessage());
}
return (Rumbler[])rumblers.toArray(new Rumbler[]{});
return rumblers.toArray(new Rumbler[]{});
}
public final Rumbler[] getRumblers() {
@ -205,7 +205,7 @@ final class LinuxEventDevice implements LinuxDevice {
}
public final LinuxComponent mapDescriptor(LinuxAxisDescriptor desc) {
return (LinuxComponent)component_map.get(desc);
return component_map.get(desc);
}
public final Controller.PortType getPortType() throws IOException {
@ -243,7 +243,7 @@ final class LinuxEventDevice implements LinuxDevice {
}
private final static native void nGetAbsInfo(long fd, int abs_axis, LinuxAbsInfo abs_info) throws IOException;
private final void addKeys(List components) throws IOException {
private final void addKeys(List<LinuxEventComponent> components) throws IOException {
byte[] bits = getKeysBits();
for (int i = 0; i < bits.length*8; i++) {
if (isBitSet(bits, i)) {
@ -253,7 +253,7 @@ final class LinuxEventDevice implements LinuxDevice {
}
}
private final void addAbsoluteAxes(List components) throws IOException {
private final void addAbsoluteAxes(List<LinuxEventComponent> components) throws IOException {
byte[] bits = getAbsoluteAxesBits();
for (int i = 0; i < bits.length*8; i++) {
if (isBitSet(bits, i)) {
@ -263,7 +263,7 @@ final class LinuxEventDevice implements LinuxDevice {
}
}
private final void addRelativeAxes(List components) throws IOException {
private final void addRelativeAxes(List<LinuxEventComponent> components) throws IOException {
byte[] bits = getRelativeAxesBits();
for (int i = 0; i < bits.length*8; i++) {
if (isBitSet(bits, i)) {
@ -273,12 +273,12 @@ final class LinuxEventDevice implements LinuxDevice {
}
}
public final List getComponents() {
public final List<LinuxEventComponent> getComponents() {
return components;
}
private final List getDeviceComponents() throws IOException {
List components = new ArrayList();
private final List<LinuxEventComponent> getDeviceComponents() throws IOException {
List<LinuxEventComponent> components = new ArrayList<>();
byte[] evtype_bits = getEventTypeBits();
if (isBitSet(evtype_bits, NativeDefinitions.EV_KEY))
addKeys(components);
@ -360,6 +360,7 @@ final class LinuxEventDevice implements LinuxDevice {
throw new IOException("Device is closed");
}
@SuppressWarnings("deprecation")
protected void finalize() throws IOException {
close();
}

View file

@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
*
* Redistribution and use in source and binary forms, with or without
@ -28,8 +28,6 @@ package net.java.games.input;
import java.io.IOException;
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
/**
* @author elias
@ -48,8 +46,8 @@ final class LinuxJoystickDevice implements LinuxDevice {
private final Event event = new Event();
private final LinuxJoystickButton[] buttons;
private final LinuxJoystickAxis[] axes;
private final Map povXs = new HashMap();
private final Map povYs = new HashMap();
private final Map<Integer, LinuxJoystickPOV> povXs = new HashMap<>();
private final Map<Integer, LinuxJoystickPOV> povYs = new HashMap<>();
private final byte[] axisMap;
private final char[] buttonMap;
@ -102,12 +100,12 @@ final class LinuxJoystickDevice implements LinuxDevice {
if (axis != null) {
float value = (float)joystick_event.getValue()/AXIS_MAX_VALUE;
axis.setValue(value);
if(povXs.containsKey(new Integer(index))) {
LinuxJoystickPOV pov = (LinuxJoystickPOV)(povXs.get(new Integer(index)));
if(povXs.containsKey(index)) {
LinuxJoystickPOV pov = povXs.get(index);
pov.updateValue();
event.set(pov, pov.getPollData(), joystick_event.getNanos());
} else if(povYs.containsKey(new Integer(index))) {
LinuxJoystickPOV pov = (LinuxJoystickPOV)(povYs.get(new Integer(index)));
} else if(povYs.containsKey(index)) {
LinuxJoystickPOV pov = povYs.get(index);
pov.updateValue();
event.set(pov, pov.getPollData(), joystick_event.getNanos());
} else {
@ -150,8 +148,8 @@ final class LinuxJoystickDevice implements LinuxDevice {
break;
}
}
povXs.put(new Integer(xIndex),pov);
povYs.put(new Integer(yIndex),pov);
povXs.put(xIndex,pov);
povYs.put(yIndex,pov);
}
public final synchronized boolean getNextEvent(Event event) throws IOException {
@ -233,6 +231,7 @@ final class LinuxJoystickDevice implements LinuxDevice {
throw new IOException("Device is closed");
}
@SuppressWarnings("deprecation")
protected void finalize() throws IOException {
close();
}

View file

@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
*
* Redistribution and use in source and binary forms, with or without
@ -43,9 +43,9 @@ final class LinuxRumbleFF extends LinuxForceFeedbackEffect {
weak_magnitude = (int)(0xc000*intensity);
} else if (intensity > 0.3333333f) {
strong_magnitude = (int)(0x8000*intensity);
weak_magnitude = (int)(0xc000*0);
weak_magnitude = 0;
} else {
strong_magnitude = (int)(0x8000*0);
strong_magnitude = 0;
weak_magnitude = (int)(0xc000*intensity);
}

View file

@ -29,12 +29,6 @@
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgs>
<arg>-h</arg>
<arg>${project.build.directory}/generated-sources/natives</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>

View file

@ -1,10 +1,4 @@
/*
* %W% %E%
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*****************************************************************************
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -38,23 +32,25 @@
*****************************************************************************/
package net.java.games.input;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
/**
* @author elias
* @version 1.0
*/
final class DataQueue {
private final Object[] elements;
final class DataQueue<T> {
private final T[] elements;
private int position;
private int limit;
public DataQueue(int size, Class element_type) {
this.elements= new Object[size];
@SuppressWarnings("unchecked")
public DataQueue(int size, Class<T> element_type) {
this.elements= (T[])Array.newInstance(element_type, size);
for (int i = 0; i < elements.length; i++) {
try {
elements[i] = element_type.newInstance();
} catch (InstantiationException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
elements[i] = element_type.getDeclaredConstructor().newInstance();
} catch (InstantiationException|IllegalAccessException|NoSuchMethodException|InvocationTargetException e) {
throw new RuntimeException(e);
}
}
@ -74,12 +70,12 @@ final class DataQueue {
return limit;
}
public final Object get(int index) {
public final T get(int index) {
assert index < limit;
return elements[index];
}
public final Object get() {
public final T get() {
if (!hasRemaining())
return null;
return get(position++);
@ -97,7 +93,7 @@ final class DataQueue {
}
private final void swap(int index1, int index2) {
Object temp = elements[index1];
T temp = elements[index1];
elements[index1] = elements[index2];
elements[index2] = temp;
}
@ -119,7 +115,7 @@ final class DataQueue {
this.position = position;
}
public final Object[] getElements() {
public final T[] getElements() {
return elements;
}
}

View file

@ -53,7 +53,7 @@ public class DirectAndRawInputEnvironmentPlugin extends ControllerEnvironment {
if(controllers == null) {
boolean rawKeyboardFound = false;
boolean rawMouseFound = false;
List tempControllers = new ArrayList();
List<Controller> tempControllers = new ArrayList<>();
Controller[] dinputControllers = dinputPlugin.getControllers();
Controller[] rawControllers = rawPlugin.getControllers();
for(int i=0;i<rawControllers.length;i++) {
@ -78,7 +78,7 @@ public class DirectAndRawInputEnvironmentPlugin extends ControllerEnvironment {
}
}
controllers = (Controller[]) tempControllers.toArray(new Controller[]{});
controllers = tempControllers.toArray(new Controller[]{});
}
return controllers;

View file

@ -64,10 +64,8 @@ public final class DirectInputEnvironmentPlugin extends ControllerEnvironment im
*
*/
static void loadLibrary(final String lib_name) {
AccessController.doPrivileged(
new PrivilegedAction() {
public final Object run() {
try {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
try {
String lib_path = System.getProperty("net.java.games.input.librarypath");
if (lib_path != null)
System.load(lib_path + File.separator + System.mapLibraryName(lib_name));
@ -78,25 +76,16 @@ public final class DirectInputEnvironmentPlugin extends ControllerEnvironment im
supported = false;
}
return null;
}
});
}
static String getPrivilegedProperty(final String property) {
return (String)AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return System.getProperty(property);
}
});
return AccessController.doPrivileged((PrivilegedAction<String>) () -> System.getProperty(property));
}
static String getPrivilegedProperty(final String property, final String default_value) {
return (String)AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return System.getProperty(property, default_value);
}
});
return AccessController.doPrivileged((PrivilegedAction<String>) () -> System.getProperty(property, default_value));
}
static {
@ -112,7 +101,7 @@ public final class DirectInputEnvironmentPlugin extends ControllerEnvironment im
}
private final Controller[] controllers;
private final List active_devices = new ArrayList();
private final List<IDirectInputDevice> active_devices = new ArrayList<>();
private final DummyWindow window;
/** Creates new DirectInputEnvironment */
@ -133,12 +122,9 @@ public final class DirectInputEnvironmentPlugin extends ControllerEnvironment im
}
this.window = window;
this.controllers = controllers;
AccessController.doPrivileged(
new PrivilegedAction() {
public final Object run() {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
Runtime.getRuntime().addShutdownHook(new ShutdownHook());
return null;
}
});
} else {
// These are final fields, so can't set them, then over ride
@ -153,10 +139,10 @@ public final class DirectInputEnvironmentPlugin extends ControllerEnvironment im
}
private final Component[] createComponents(IDirectInputDevice device, boolean map_mouse_buttons) {
List device_objects = device.getObjects();
List controller_components = new ArrayList();
List<DIDeviceObject> device_objects = device.getObjects();
List<DIComponent> controller_components = new ArrayList<>();
for (int i = 0; i < device_objects.size(); i++) {
DIDeviceObject device_object = (DIDeviceObject)device_objects.get(i);
DIDeviceObject device_object = device_objects.get(i);
Component.Identifier identifier = device_object.getIdentifier();
if (identifier == null)
continue;
@ -214,12 +200,12 @@ public final class DirectInputEnvironmentPlugin extends ControllerEnvironment im
}
private final Controller[] enumControllers(DummyWindow window) throws IOException {
List controllers = new ArrayList();
List<Controller> controllers = new ArrayList<>();
IDirectInput dinput = new IDirectInput(window);
try {
List devices = dinput.getDevices();
List<IDirectInputDevice> devices = dinput.getDevices();
for (int i = 0; i < devices.size(); i++) {
IDirectInputDevice device = (IDirectInputDevice)devices.get(i);
IDirectInputDevice device = devices.get(i);
Controller controller = createControllerFromDevice(device);
if (controller != null) {
controllers.add(controller);
@ -239,7 +225,7 @@ public final class DirectInputEnvironmentPlugin extends ControllerEnvironment im
public final void run() {
/* Release the devices to kill off active force feedback effects */
for (int i = 0; i < active_devices.size(); i++) {
IDirectInputDevice device = (IDirectInputDevice)active_devices.get(i);
IDirectInputDevice device = active_devices.get(i);
device.release();
}
/* We won't release the window since it is
@ -251,4 +237,4 @@ public final class DirectInputEnvironmentPlugin extends ControllerEnvironment im
public boolean isSupported() {
return supported;
}
} // class DirectInputEnvironment
}

View file

@ -48,7 +48,7 @@ import java.util.ArrayList;
* @version 1.0
*/
final class IDirectInput {
private final List devices = new ArrayList();
private final List<IDirectInputDevice> devices = new ArrayList<>();
private final long idirectinput_address;
private final DummyWindow window;
@ -65,7 +65,7 @@ final class IDirectInput {
}
private final static native long createIDirectInput() throws IOException;
public final List getDevices() {
public final List<IDirectInputDevice> getDevices() {
return devices;
}
@ -88,7 +88,7 @@ final class IDirectInput {
public final void releaseDevices() {
for (int i = 0; i < devices.size(); i++) {
IDirectInputDevice device = (IDirectInputDevice)devices.get(i);
IDirectInputDevice device = devices.get(i);
device.release();
}
}

View file

@ -1,10 +1,4 @@
/*
* %W% %E%
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*****************************************************************************
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -201,16 +195,16 @@ final class IDirectInputDevice {
private final int dev_subtype;
private final String instance_name;
private final String product_name;
private final List objects = new ArrayList();
private final List effects = new ArrayList();
private final List rumblers = new ArrayList();
private final List<DIDeviceObject> objects = new ArrayList<>();
private final List<DIEffectInfo> effects = new ArrayList<>();
private final List<Rumbler> rumblers = new ArrayList<>();
private final int[] device_state;
private final Map object_to_component = new HashMap();
private final Map<DIDeviceObject,DIComponent> object_to_component = new HashMap<>();
private final boolean axes_in_relative_mode;
private boolean released;
private DataQueue queue;
private DataQueue<DIDeviceObjectData> queue;
private int button_counter;
private int current_format_offset;
@ -242,7 +236,7 @@ final class IDirectInputDevice {
boolean all_relative = true;
boolean has_axis = false;
for (int i = 0; i < objects.size(); i++) {
DIDeviceObject obj = (DIDeviceObject)objects.get(i);
DIDeviceObject obj = objects.get(i);
if (obj.isAxis()) {
has_axis = true;
if (!obj.isRelative()) {
@ -272,10 +266,10 @@ final class IDirectInputDevice {
}
public final Rumbler[] getRumblers() {
return (Rumbler[])rumblers.toArray(new Rumbler[]{});
return rumblers.toArray(new Rumbler[]{});
}
private final List createRumblers() throws IOException {
private final List<Rumbler> createRumblers() throws IOException {
DIDeviceObject x_axis = lookupObjectByGUID(GUID_XAxis);
// DIDeviceObject y_axis = lookupObjectByGUID(GUID_YAxis);
if(x_axis == null/* || y_axis == null*/)
@ -283,7 +277,7 @@ final class IDirectInputDevice {
DIDeviceObject[] axes = {x_axis/*, y_axis*/};
long[] directions = {0/*, 0*/};
for (int i = 0; i < effects.size(); i++) {
DIEffectInfo info = (DIEffectInfo)effects.get(i);
DIEffectInfo info = effects.get(i);
if ((info.getEffectType() & 0xff) == DIEFT_PERIODIC &&
(info.getDynamicParams() & DIEP_GAIN) != 0) {
rumblers.add(createPeriodicRumbler(axes, directions, info));
@ -304,7 +298,7 @@ final class IDirectInputDevice {
private final DIDeviceObject lookupObjectByGUID(int guid_id) {
for (int i = 0; i < objects.size(); i++) {
DIDeviceObject object = (DIDeviceObject)objects.get(i);
DIDeviceObject object = objects.get(i);
if (guid_id == object.getGUIDType())
return object;
}
@ -321,11 +315,11 @@ final class IDirectInputDevice {
* for the int size (4 bytes)
*/
int format_offset = event.getFormatOffset()/4;
return (DIDeviceObject)objects.get(format_offset);
return objects.get(format_offset);
}
public final DIComponent mapObject(DIDeviceObject object) {
return (DIComponent)object_to_component.get(object);
return object_to_component.get(object);
}
public final void registerComponent(DIDeviceObject object, DIComponent component) {
@ -342,7 +336,7 @@ final class IDirectInputDevice {
}
public synchronized final boolean getNextEvent(DIDeviceObjectData data) {
DIDeviceObjectData next_event = (DIDeviceObjectData)queue.get();
DIDeviceObjectData next_event = queue.get();
if (next_event == null)
return false;
data.set(next_event);
@ -375,7 +369,7 @@ final class IDirectInputDevice {
}
private final static native int nUnacquire(long address);
private final boolean getDeviceData(DataQueue queue) throws IOException {
private final boolean getDeviceData(DataQueue<DIDeviceObjectData> queue) throws IOException {
int res = nGetDeviceData(address, 0, queue, queue.getElements(), queue.position(), queue.remaining());
if (res != DI_OK && res != DI_BUFFEROVERFLOW) {
if (res == DIERR_NOTACQUIRED) {
@ -386,7 +380,7 @@ final class IDirectInputDevice {
}
return true;
}
private final static native int nGetDeviceData(long address, int flags, DataQueue queue, Object[] queue_elements, int position, int remaining);
private final static native int nGetDeviceData(long address, int flags, DataQueue<DIDeviceObjectData> queue, Object[] queue_elements, int position, int remaining);
private final void getDeviceState(int[] device_state) throws IOException {
int res = nGetDeviceState(address, device_state);
@ -420,7 +414,7 @@ final class IDirectInputDevice {
return dev_type;
}
public final List getObjects() {
public final List<DIDeviceObject> getObjects() {
return objects;
}
@ -509,7 +503,7 @@ final class IDirectInputDevice {
int res = nSetBufferSize(address, size);
if (res != DI_OK && res != DI_PROPNOEFFECT && res != DI_POLLEDDEVICE)
throw new IOException("Failed to set buffer size (" + Integer.toHexString(res) + ")");
queue = new DataQueue(size, DIDeviceObjectData.class);
queue = new DataQueue<>(size, DIDeviceObjectData.class);
queue.position(queue.limit());
acquire();
}
@ -540,6 +534,7 @@ final class IDirectInputDevice {
throw new IOException("Device is released");
}
@SuppressWarnings("deprecation")
protected void finalize() {
release();
}

View file

@ -58,7 +58,7 @@ final class IDirectInputEffect implements Rumbler {
try {
checkReleased();
if (intensity > 0) {
int int_gain = (int)Math.round(intensity*IDirectInputDevice.DI_FFNOMINALMAX);
int int_gain = Math.round(intensity*IDirectInputDevice.DI_FFNOMINALMAX);
setGain(int_gain);
start(1, 0);
} else
@ -115,6 +115,7 @@ final class IDirectInputEffect implements Rumbler {
}
private final static native int nStop(long address);
@SuppressWarnings("deprecation")
protected void finalize() {
release();
}

View file

@ -89,12 +89,12 @@ final class RawDevice {
private final int type;
/* Events from the event queue thread end here */
private DataQueue keyboard_events;
private DataQueue mouse_events;
private DataQueue<RawKeyboardEvent> keyboard_events;
private DataQueue<RawMouseEvent> mouse_events;
/* After processing in poll*(), the events are placed here */
private DataQueue processed_keyboard_events;
private DataQueue processed_mouse_events;
private DataQueue<RawKeyboardEvent> processed_keyboard_events;
private DataQueue<RawMouseEvent> processed_mouse_events;
/* mouse state */
private final boolean[] button_states = new boolean[5];
@ -123,7 +123,7 @@ final class RawDevice {
/* Careful, this is called from the event queue thread */
public final synchronized void addMouseEvent(long millis, int flags, int button_flags, int button_data, long raw_buttons, long last_x, long last_y, long extra_information) {
if (mouse_events.hasRemaining()) {
RawMouseEvent event = (RawMouseEvent)mouse_events.get();
RawMouseEvent event = mouse_events.get();
event.set(millis, flags, button_flags, button_data, raw_buttons, last_x, last_y, extra_information);
}
}
@ -131,7 +131,7 @@ final class RawDevice {
/* Careful, this is called from the event queue thread */
public final synchronized void addKeyboardEvent(long millis, int make_code, int flags, int vkey, int message, long extra_information) {
if (keyboard_events.hasRemaining()) {
RawKeyboardEvent event = (RawKeyboardEvent)keyboard_events.get();
RawKeyboardEvent event = keyboard_events.get();
event.set(millis, make_code, flags, vkey, message, extra_information);
}
}
@ -140,10 +140,10 @@ final class RawDevice {
relative_x = relative_y = wheel = 0;
mouse_events.flip();
while (mouse_events.hasRemaining()) {
RawMouseEvent event = (RawMouseEvent)mouse_events.get();
RawMouseEvent event = mouse_events.get();
boolean has_update = processMouseEvent(event);
if (has_update && processed_mouse_events.hasRemaining()) {
RawMouseEvent processed_event = (RawMouseEvent)processed_mouse_events.get();
RawMouseEvent processed_event = processed_mouse_events.get();
processed_event.set(event);
}
}
@ -153,10 +153,10 @@ final class RawDevice {
public final synchronized void pollKeyboard() {
keyboard_events.flip();
while (keyboard_events.hasRemaining()) {
RawKeyboardEvent event = (RawKeyboardEvent)keyboard_events.get();
RawKeyboardEvent event = keyboard_events.get();
boolean has_update = processKeyboardEvent(event);
if (has_update && processed_keyboard_events.hasRemaining()) {
RawKeyboardEvent processed_event = (RawKeyboardEvent)processed_keyboard_events.get();
RawKeyboardEvent processed_event = processed_keyboard_events.get();
processed_event.set(event);
}
}
@ -250,7 +250,7 @@ final class RawDevice {
processed_keyboard_events.compact();
return false;
}
RawKeyboardEvent next_event = (RawKeyboardEvent)processed_keyboard_events.get();
RawKeyboardEvent next_event = processed_keyboard_events.get();
event.set(next_event);
processed_keyboard_events.compact();
return true;
@ -262,7 +262,7 @@ final class RawDevice {
processed_mouse_events.compact();
return false;
}
RawMouseEvent next_event = (RawMouseEvent)processed_mouse_events.get();
RawMouseEvent next_event = processed_mouse_events.get();
if ((next_event.getFlags() & MOUSE_MOVE_ABSOLUTE) != 0) {
event_relative_x = next_event.getLastX() - event_last_x;
event_relative_y = next_event.getLastY() - event_last_y;
@ -284,10 +284,10 @@ final class RawDevice {
}
public final void setBufferSize(int size) {
keyboard_events = new DataQueue(size, RawKeyboardEvent.class);
mouse_events = new DataQueue(size, RawMouseEvent.class);
processed_keyboard_events = new DataQueue(size, RawKeyboardEvent.class);
processed_mouse_events = new DataQueue(size, RawMouseEvent.class);
keyboard_events = new DataQueue<>(size, RawKeyboardEvent.class);
mouse_events = new DataQueue<>(size, RawMouseEvent.class);
processed_keyboard_events = new DataQueue<>(size, RawKeyboardEvent.class);
processed_mouse_events = new DataQueue<>(size, RawMouseEvent.class);
}
public final int getType() {

View file

@ -64,9 +64,7 @@ public final class RawInputEnvironmentPlugin extends ControllerEnvironment imple
*
*/
static void loadLibrary(final String lib_name) {
AccessController.doPrivileged(
new PrivilegedAction() {
public final Object run() {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
try {
String lib_path = System.getProperty("net.java.games.input.librarypath");
if (lib_path != null)
@ -78,25 +76,16 @@ public final class RawInputEnvironmentPlugin extends ControllerEnvironment imple
supported = false;
}
return null;
}
});
}
static String getPrivilegedProperty(final String property) {
return (String)AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return System.getProperty(property);
}
});
return AccessController.doPrivileged((PrivilegedAction<String>) () -> System.getProperty(property));
}
static String getPrivilegedProperty(final String property, final String default_value) {
return (String)AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return System.getProperty(property, default_value);
}
});
return AccessController.doPrivileged((PrivilegedAction<String>) () -> System.getProperty(property, default_value));
}
static {
@ -132,23 +121,23 @@ public final class RawInputEnvironmentPlugin extends ControllerEnvironment imple
return controllers;
}
private final static SetupAPIDevice lookupSetupAPIDevice(String device_name, List setupapi_devices) {
private final static SetupAPIDevice lookupSetupAPIDevice(String device_name, List<SetupAPIDevice> setupapi_devices) {
/* First, replace # with / in the device name, since that
* seems to be the format in raw input device name
*/
device_name = device_name.replaceAll("#", "\\\\").toUpperCase();
for (int i = 0; i < setupapi_devices.size(); i++) {
SetupAPIDevice device = (SetupAPIDevice)setupapi_devices.get(i);
if (device_name.indexOf(device.getInstanceId().toUpperCase()) != -1)
SetupAPIDevice device = setupapi_devices.get(i);
if (device_name.contains(device.getInstanceId().toUpperCase()))
return device;
}
return null;
}
private final static void createControllersFromDevices(RawInputEventQueue queue, List controllers, List devices, List setupapi_devices) throws IOException {
List active_devices = new ArrayList();
private final static void createControllersFromDevices(RawInputEventQueue queue, List<Controller> controllers, List<RawDevice> devices, List<SetupAPIDevice> setupapi_devices) throws IOException {
List<RawDevice> active_devices = new ArrayList<>();
for (int i = 0; i < devices.size(); i++) {
RawDevice device = (RawDevice)devices.get(i);
RawDevice device = devices.get(i);
SetupAPIDevice setupapi_device = lookupSetupAPIDevice(device.getName(), setupapi_devices);
if (setupapi_device == null) {
/* Either the device is an RDP or we failed to locate the
@ -166,13 +155,13 @@ public final class RawInputEnvironmentPlugin extends ControllerEnvironment imple
queue.start(active_devices);
}
private final static native void enumerateDevices(RawInputEventQueue queue, List devices) throws IOException;
private final static native void enumerateDevices(RawInputEventQueue queue, List<RawDevice> devices) throws IOException;
private final Controller[] enumControllers(RawInputEventQueue queue) throws IOException {
List controllers = new ArrayList();
List devices = new ArrayList();
List<Controller> controllers = new ArrayList<>();
List<RawDevice> devices = new ArrayList<>();
enumerateDevices(queue, devices);
List setupapi_devices = enumSetupAPIDevices();
List<SetupAPIDevice> setupapi_devices = enumSetupAPIDevices();
createControllersFromDevices(queue, controllers, devices, setupapi_devices);
Controller[] controllers_array = new Controller[controllers.size()];
controllers.toArray(controllers_array);
@ -202,13 +191,13 @@ public final class RawInputEnvironmentPlugin extends ControllerEnvironment imple
* descriptive names and at the same time filter out the unwanted
* RDP devices.
*/
private final static List enumSetupAPIDevices() throws IOException {
List devices = new ArrayList();
private final static List<SetupAPIDevice> enumSetupAPIDevices() throws IOException {
List<SetupAPIDevice> devices = new ArrayList<>();
nEnumSetupAPIDevices(getKeyboardClassGUID(), devices);
nEnumSetupAPIDevices(getMouseClassGUID(), devices);
return devices;
}
private final static native void nEnumSetupAPIDevices(byte[] guid, List devices) throws IOException;
private final static native void nEnumSetupAPIDevices(byte[] guid, List<SetupAPIDevice> devices) throws IOException;
private final static native byte[] getKeyboardClassGUID();
private final static native byte[] getMouseClassGUID();

View file

@ -1,10 +1,4 @@
/*
* %W% %E%
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*****************************************************************************
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -35,12 +29,11 @@
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
*****************************************************************************/
*/
package net.java.games.input;
import java.io.IOException;
import java.util.List;
import java.util.ArrayList;
import java.util.Set;
import java.util.HashSet;
@ -51,9 +44,9 @@ import java.util.HashSet;
final class RawInputEventQueue {
private final Object monitor = new Object();
private List devices;
private List<RawDevice> devices;
public final void start(List devices) throws IOException {
public final void start(List<RawDevice> devices) throws IOException {
this.devices = devices;
QueueThread queue = new QueueThread();
synchronized (monitor) {
@ -71,7 +64,7 @@ final class RawInputEventQueue {
private final RawDevice lookupDevice(long handle) {
for (int i = 0; i < devices.size(); i++) {
RawDevice device = (RawDevice)devices.get(i);
RawDevice device = devices.get(i);
if (device.getHandle() == handle)
return device;
}
@ -133,10 +126,10 @@ final class RawInputEventQueue {
}
if (exception != null)
return;
Set active_infos = new HashSet();
Set<RawDeviceInfo> active_infos = new HashSet<>();
try {
for (int i = 0; i < devices.size(); i++) {
RawDevice device = (RawDevice)devices.get(i);
RawDevice device = devices.get(i);
active_infos.add(device.getInfo());
}
RawDeviceInfo[] active_infos_array = new RawDeviceInfo[active_infos.size()];

View file

@ -1,41 +1,35 @@
/*
* %W% %E%
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materails provided with the distribution.
*
* Neither the name Sun Microsystems, Inc. or the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
* Copyright 2002 Sun Microsystems, Inc. All rights reserved.
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*****************************************************************************
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materails provided with the distribution.
*
* Neither the name Sun Microsystems, Inc. or the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND
* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS
* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS
* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY
* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility
*
*****************************************************************************/
package net.java.games.input;
import java.io.IOException;
@ -59,7 +53,7 @@ final class RawKeyboard extends Keyboard {
}
private final static Component[] createKeyboardComponents(RawDevice device) {
List components = new ArrayList();
List<Component> components = new ArrayList<>();
Field[] vkey_fields = RawIdentifierMap.class.getFields();
for (int i = 0; i < vkey_fields.length; i++) {
Field vkey_field = vkey_fields[i];
@ -74,7 +68,7 @@ final class RawKeyboard extends Keyboard {
throw new RuntimeException(e);
}
}
return (Component[])components.toArray(new Component[]{});
return components.toArray(new Component[]{});
}
protected final synchronized boolean getNextDeviceEvent(Event event) throws IOException {

View file

@ -29,12 +29,6 @@
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgs>
<arg>-h</arg>
<arg>${project.build.directory}/generated-sources/natives</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>

View file

@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2006 Jeremy Booth (jeremy@newdawnsoftware.com)
*
* Redistribution and use in source and binary forms, with or without
@ -65,8 +65,8 @@ public class WinTabComponent extends AbstractComponent {
return false;
}
public static List createComponents(WinTabContext context, int parentDevice, int axisId, int[] axisRanges) {
List components = new ArrayList();
public static List<WinTabComponent> createComponents(WinTabContext context, int parentDevice, int axisId, int[] axisRanges) {
List<WinTabComponent> components = new ArrayList<>();
Identifier id;
switch(axisId) {
case WinTabDevice.XAxis:
@ -110,26 +110,17 @@ public class WinTabComponent extends AbstractComponent {
return components;
}
public static Collection createButtons(WinTabContext context, int deviceIndex, int numberOfButtons) {
List buttons = new ArrayList();
public static Collection<WinTabButtonComponent> createButtons(WinTabContext context, int deviceIndex, int numberOfButtons) {
List<WinTabButtonComponent> buttons = new ArrayList<>();
Identifier id;
for(int i=0;i<numberOfButtons;i++) {
try {
Class buttonIdClass = Identifier.Button.class;
Class<Identifier.Button> buttonIdClass = Identifier.Button.class;
Field idField = buttonIdClass.getField("_" + i);
id = (Identifier)idField.get(null);
buttons.add(new WinTabButtonComponent(context, deviceIndex, id.getName(), id, i));
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchFieldException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
} catch (SecurityException|NoSuchFieldException|IllegalArgumentException|IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
@ -184,9 +175,9 @@ public class WinTabComponent extends AbstractComponent {
return (value - min)/bottom;
}
public static Collection createCursors(WinTabContext context, int deviceIndex, String[] cursorNames) {
public static Collection<WinTabCursorComponent> createCursors(WinTabContext context, int deviceIndex, String[] cursorNames) {
Identifier id;
List cursors = new ArrayList();
List<WinTabCursorComponent> cursors = new ArrayList<>();
for(int i=0;i<cursorNames.length;i++) {
if(cursorNames[i].matches("Puck")) {

View file

@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2006 Jeremy Booth (jeremy@newdawnsoftware.com)
*
* Redistribution and use in source and binary forms, with or without
@ -47,17 +47,14 @@ public class WinTabContext {
public synchronized void open() {
this.hCTX = nOpen(window.getHwnd());
List devices = new ArrayList();
List<WinTabDevice> devices = new ArrayList<>();
int numSupportedDevices = nGetNumberOfSupportedDevices();
for(int i=0;i<numSupportedDevices;i++) {
WinTabDevice newDevice = WinTabDevice.createDevice(this,i);
if(newDevice!=null) {
devices.add(newDevice);
}
devices.add(WinTabDevice.createDevice(this,i));
}
controllers = (Controller[])devices.toArray(new Controller[0]);
controllers = devices.toArray(new Controller[0]);
}
public synchronized void close() {

View file

@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2006 Jeremy Booth (jeremy@newdawnsoftware.com)
*
* Redistribution and use in source and binary forms, with or without
@ -39,7 +39,7 @@ public class WinTabDevice extends AbstractController {
public final static int RotationAxis = 7;
private WinTabContext context;
private List eventList = new ArrayList();
private List<Event> eventList = new ArrayList<>();
private WinTabDevice(WinTabContext context, int index, String name, Component[] components) {
super(name, components, new Controller[0], new Rumbler[0]);
@ -48,7 +48,7 @@ public class WinTabDevice extends AbstractController {
protected boolean getNextDeviceEvent(Event event) throws IOException {
if(eventList.size()>0) {
Event ourEvent = (Event)eventList.remove(0);
Event ourEvent = eventList.remove(0);
event.set(ourEvent);
return true;
} else {
@ -80,7 +80,7 @@ public class WinTabDevice extends AbstractController {
public static WinTabDevice createDevice(WinTabContext context, int deviceIndex) {
String name = nGetName(deviceIndex);
WinTabEnvironmentPlugin.log("Device " + deviceIndex + ", name: " + name);
List componentsList = new ArrayList();
List<WinTabComponent> componentsList = new ArrayList<>();
int[] axisDetails = nGetAxisDetails(deviceIndex, XAxis);
if(axisDetails.length==0) {
@ -148,7 +148,7 @@ public class WinTabDevice extends AbstractController {
WinTabEnvironmentPlugin.log("Device has " + numberOfButtons + " buttons");
componentsList.addAll(WinTabComponent.createButtons(context, deviceIndex, numberOfButtons));
Component[] components = (Component[])componentsList.toArray(new Component[0]);
Component[] components = componentsList.toArray(new Component[0]);
return new WinTabDevice(context, deviceIndex, name, components);
}

View file

@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2006 Jeremy Booth (jeremy@newdawnsoftware.com)
*
* Redistribution and use in source and binary forms, with or without
@ -44,9 +44,7 @@ public class WinTabEnvironmentPlugin extends ControllerEnvironment implements Pl
*
*/
static void loadLibrary(final String lib_name) {
AccessController.doPrivileged(
new PrivilegedAction() {
public final Object run() {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
try {
String lib_path = System.getProperty("net.java.games.input.librarypath");
if (lib_path != null)
@ -58,25 +56,16 @@ public class WinTabEnvironmentPlugin extends ControllerEnvironment implements Pl
supported = false;
}
return null;
}
});
}
static String getPrivilegedProperty(final String property) {
return (String)AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return System.getProperty(property);
}
});
}
return AccessController.doPrivileged((PrivilegedAction<String>)() -> System.getProperty(property));
}
static String getPrivilegedProperty(final String property, final String default_value) {
return (String)AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return System.getProperty(property, default_value);
}
});
return AccessController.doPrivileged((PrivilegedAction<String>)() -> System.getProperty(property, default_value));
}
static {
@ -88,13 +77,13 @@ public class WinTabEnvironmentPlugin extends ControllerEnvironment implements Pl
}
private final Controller[] controllers;
private final List active_devices = new ArrayList();
private final List<WinTabDevice> active_devices = new ArrayList<>();
private final WinTabContext winTabContext;
/** Creates new DirectInputEnvironment */
public WinTabEnvironmentPlugin() {
if(isSupported()) {
DummyWindow window = null;
DummyWindow window;
WinTabContext winTabContext = null;
Controller[] controllers = new Controller[]{};
try {
@ -113,12 +102,9 @@ public class WinTabEnvironmentPlugin extends ControllerEnvironment implements Pl
}
this.controllers = controllers;
this.winTabContext = winTabContext;
AccessController.doPrivileged(
new PrivilegedAction() {
public final Object run() {
AccessController.doPrivileged((PrivilegedAction<Void>)() -> {
Runtime.getRuntime().addShutdownHook(new ShutdownHook());
return null;
}
});
} else {
winTabContext = null;

10
pom.xml
View file

@ -39,8 +39,8 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencyManagement>
@ -70,6 +70,12 @@
<configuration>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
<compilerArgs>
<arg>-Werror</arg>
<arg>-Xlint:all,-options</arg>
<arg>-h</arg>
<arg>${project.build.directory}/generated-sources/natives</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>

View file

@ -46,6 +46,7 @@ import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.WindowConstants;
import net.java.games.input.Component;
import net.java.games.input.Controller;
@ -55,7 +56,10 @@ import net.java.games.input.Event;
import net.java.games.input.Version;
public class ControllerEventTest extends JFrame{
private static final long serialVersionUID = -8266185848160199092L;
private static abstract class AxisPanel extends JPanel{
private static final long serialVersionUID = -6200599064870672000L;
Component axis;
float data;
@ -79,6 +83,7 @@ public class ControllerEventTest extends JFrame{
}
private static class DigitalAxisPanel extends AxisPanel {
private static final long serialVersionUID = -4729666037860134626L;
JLabel digitalState = new JLabel("<unread>");
public DigitalAxisPanel(Component ax) {
@ -102,6 +107,7 @@ public class ControllerEventTest extends JFrame{
}
private static class DigitalHatPanel extends AxisPanel {
private static final long serialVersionUID = -6582605379682496832L;
JLabel digitalState = new JLabel("<unread>");
public DigitalHatPanel(Component ax) {
@ -145,6 +151,7 @@ public class ControllerEventTest extends JFrame{
}
}
private static class AnalogAxisPanel extends AxisPanel {
private static final long serialVersionUID = 7536173405896285590L;
JLabel analogState = new JLabel("<unread>");
public AnalogAxisPanel(Component ax) {
@ -164,8 +171,9 @@ public class ControllerEventTest extends JFrame{
private static class ControllerWindow extends JFrame {
private static final long serialVersionUID = 8623977198558568961L;
Controller ca;
Map axes_to_panels = new HashMap();
Map<Component, AxisPanel> axes_to_panels = new HashMap<>();
boolean disabled = false;
public ControllerWindow(JFrame frame,Controller ca){
@ -207,7 +215,7 @@ public class ControllerEventTest extends JFrame{
}
private void addAxis(JPanel p, Component ax){
JPanel p2;
AxisPanel p2;
if (ax.isAnalog()) {
p2 = new AnalogAxisPanel(ax);
} else {
@ -234,14 +242,14 @@ public class ControllerEventTest extends JFrame{
EventQueue event_queue = ca.getEventQueue();
Event event = new Event();
while (event_queue.getNextEvent(event)) {
AxisPanel panel = (AxisPanel)axes_to_panels.get(event.getComponent());
AxisPanel panel = axes_to_panels.get(event.getComponent());
panel.setPollData(event.getValue());
}
}
}
static final long HEARTBEATMS =100; // 10th of a second
List controllers = new ArrayList();
List<ControllerWindow> controllers = new ArrayList<>();
public ControllerEventTest() {
super("Controller Event Test. Version: " + Version.getVersion());
@ -251,14 +259,12 @@ public class ControllerEventTest extends JFrame{
makeController(ca[i]);
}
new Thread(new Runnable() {
public void run(){
new Thread(() -> {
try {
while(true){
for(Iterator i=controllers.iterator();i.hasNext();){
for(Iterator<ControllerWindow> i=controllers.iterator();i.hasNext();){
try {
ControllerWindow cw = (ControllerWindow)i.next();
cw.poll();
i.next().poll();
} catch (Exception e) {
e.printStackTrace();
}
@ -268,11 +274,10 @@ public class ControllerEventTest extends JFrame{
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
pack();
setSize(400,400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setVisible(true);
}

View file

@ -49,13 +49,17 @@ import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.WindowConstants;
import net.java.games.input.Component;
import net.java.games.input.Controller;
import net.java.games.input.ControllerEnvironment;
public class ControllerReadTest extends JFrame{
private static final long serialVersionUID = -7129976919159465311L;
private abstract static class AxisPanel extends JPanel{
private static final long serialVersionUID = -2117191506803328790L;
Component axis;
float data;
@ -79,6 +83,7 @@ public class ControllerReadTest extends JFrame{
}
private static class DigitalAxisPanel extends AxisPanel {
private static final long serialVersionUID = -4006900519933869168L;
JLabel digitalState = new JLabel("<unread>");
public DigitalAxisPanel(Component ax) {
@ -102,6 +107,7 @@ public class ControllerReadTest extends JFrame{
}
private static class DigitalHatPanel extends AxisPanel {
private static final long serialVersionUID = -3293100130201231029L;
JLabel digitalState = new JLabel("<unread>");
public DigitalHatPanel(Component ax) {
@ -145,6 +151,7 @@ public class ControllerReadTest extends JFrame{
}
}
private static class AnalogAxisPanel extends AxisPanel {
private static final long serialVersionUID = -3220244985697453835L;
JLabel analogState = new JLabel("<unread>");
public AnalogAxisPanel(Component ax) {
@ -164,8 +171,9 @@ public class ControllerReadTest extends JFrame{
private static class ControllerWindow extends JFrame {
private static final long serialVersionUID = 5812903945250431578L;
Controller ca;
List axisList = new ArrayList();
List<AxisPanel> axisList = new ArrayList<>();
boolean disabled = false;
public ControllerWindow(JFrame frame,Controller ca){
@ -207,7 +215,7 @@ public class ControllerReadTest extends JFrame{
}
private void addAxis(JPanel p, Component ax){
JPanel p2;
AxisPanel p2;
if (ax.isAnalog()) {
p2 = new AnalogAxisPanel(ax);
} else {
@ -233,9 +241,9 @@ public class ControllerReadTest extends JFrame{
setDisabled(false);
}
//System.out.println("Polled "+ca.getName());
for(Iterator i =axisList.iterator();i.hasNext();){
for(Iterator<AxisPanel> i =axisList.iterator();i.hasNext();){
try {
((AxisPanel)i.next()).poll();
i.next().poll();
}catch (Exception e) {
e.printStackTrace();
}
@ -244,7 +252,7 @@ public class ControllerReadTest extends JFrame{
}
static final long HEARTBEATMS =100; // 10th of a second
List controllers = new ArrayList();
List<ControllerWindow> controllers = new ArrayList<>();
public ControllerReadTest() {
super("Controller Read Test. Version: " + Version.getVersion());
@ -254,13 +262,12 @@ public class ControllerReadTest extends JFrame{
makeController(ca[i]);
}
new Thread(new Runnable() {
public void run(){
new Thread(() ->{
try {
while(true){
for(Iterator i=controllers.iterator();i.hasNext();){
for(Iterator<ControllerWindow> i=controllers.iterator();i.hasNext();){
try {
ControllerWindow cw = (ControllerWindow)i.next();
ControllerWindow cw = i.next();
cw.poll();
} catch (Exception e) {
e.printStackTrace();
@ -271,11 +278,10 @@ public class ControllerReadTest extends JFrame{
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
pack();
setSize(400,400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setVisible(true);
}

View file

@ -37,12 +37,6 @@
*****************************************************************************/
package net.java.games.input;
/**
*
* @author administrator
*/
import net.java.games.input.*;
public class ControllerTextTest {
ControllerEnvironment ce;
/** Creates a new instance of ControllerScanner */

View file

@ -1,19 +1,30 @@
/*
* RumbleTest.java
* Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
*
* Created on 01 December 2003, 23:02
* 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.
* The name of the author may not be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 net.java.games.input;
import net.java.games.input.ControllerEnvironment;
import net.java.games.input.Controller;
import net.java.games.input.Rumbler;
import net.java.games.input.Version;
/**
*
* @author Jeremy
*/
public class RumbleTest {
/** Creates a new instance of RumbleTest */

View file

@ -1,12 +1,32 @@
/*
* Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
*
* 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.
* The name of the author may not be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 net.java.games.input;
import net.java.games.input.Version;
public class VersionTest {
/**
* @param args
*/
public static void main(String[] args) {
System.out.println("JInput version: " + Version.getVersion());
}

View file

@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
*
* Redistribution and use in source and binary forms, with or without
@ -25,15 +25,16 @@
*/
package net.java.games.input.applet;
import java.applet.Applet;
import java.io.IOException;
import net.java.games.input.ControllerEventTest;
import net.java.games.input.applet.JInputAppletResourceLoader;
public class ControllerEventTestApplet extends Applet {
@SuppressWarnings("deprecation")
public class ControllerEventTestApplet extends java.applet.Applet {
public void init() {
private static final long serialVersionUID = 4250817143444220400L;
public void init() {
try {
new JInputAppletResourceLoader().loadResources(getCodeBase());
} catch (IOException e) {

View file

@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
*
* Redistribution and use in source and binary forms, with or without
@ -25,13 +25,14 @@
*/
package net.java.games.input.applet;
import java.applet.Applet;
import java.io.IOException;
import net.java.games.input.ControllerReadTest;
import net.java.games.input.applet.JInputAppletResourceLoader;
public class ControllerReadTestApplet extends Applet {
@SuppressWarnings("deprecation")
public class ControllerReadTestApplet extends java.applet.Applet {
private static final long serialVersionUID = -2558493887683964119L;
public void init() {
try {