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 int percentageDone = 0;
private String getPrivilegedProperty(final String property) { private String getPrivilegedProperty(final String property) {
return (String) AccessController.doPrivileged(new PrivilegedAction() { return AccessController.doPrivileged((PrivilegedAction<String>) () -> System.getProperty(property));
public Object run() {
return System.getProperty(property);
}
});
} }
private String setPrivilegedProperty(final String property, final String value) { private String setPrivilegedProperty(final String property, final String value) {
return (String) AccessController.doPrivileged(new PrivilegedAction() { return AccessController.doPrivileged((PrivilegedAction<String>) () -> System.setProperty(property, value));
public Object run() {
return System.setProperty(property, value);
}
});
} }
public void loadResources(URL codeBase) throws IOException { public void loadResources(URL codeBase) throws IOException {
@ -94,13 +86,13 @@ public class JInputAppletResourceLoader {
JarFile localJarFile = new JarFile(new File(tempDir, nativeJar), true); JarFile localJarFile = new JarFile(new File(tempDir, nativeJar), true);
Enumeration jarEntries = localJarFile.entries(); Enumeration<JarEntry> jarEntries = localJarFile.entries();
int totalUncompressedBytes = 0; int totalUncompressedBytes = 0;
int totalUncompressedBytesWritten = 0; int totalUncompressedBytesWritten = 0;
List entriesToUse = new ArrayList(); List<JarEntry> entriesToUse = new ArrayList<>();
while(jarEntries.hasMoreElements()) { while(jarEntries.hasMoreElements()) {
JarEntry jarEntry = (JarEntry)jarEntries.nextElement(); JarEntry jarEntry = jarEntries.nextElement();
String entryName = jarEntry.getName(); String entryName = jarEntry.getName();
if(!entryName.startsWith("META-INF")) { if(!entryName.startsWith("META-INF")) {
totalUncompressedBytes+=jarEntry.getSize(); totalUncompressedBytes+=jarEntry.getSize();
@ -116,7 +108,7 @@ public class JInputAppletResourceLoader {
} }
for(int i=0;i<entriesToUse.size();i++) { 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())); InputStream inStream = localJarFile.getInputStream(localJarFile.getEntry(jarEntry.getName()));
File nativeFile = new File(tempNativesDir, jarEntry.getName()); File nativeFile = new File(tempNativesDir, jarEntry.getName());
FileOutputStream fos = new FileOutputStream(nativeFile); 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. * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * 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 * You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility * the design, construction, operation or maintenance of any nuclear facility
* *
*****************************************************************************/ */
package net.java.games.input; package net.java.games.input;
import java.util.Map; import java.util.Map;
import java.util.List;
import java.util.HashMap; import java.util.HashMap;
import java.util.ArrayList;
import java.io.IOException; import java.io.IOException;
@ -77,7 +69,7 @@ public abstract class AbstractController implements Controller {
/** /**
* Map from Component.Identifiers to Components * 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); 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. * if no component with the specified type could be found.
*/ */
public final Component getComponent(Component.Identifier id) { 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 * List of controller listeners
*/ */
protected final ArrayList controllerListeners = new ArrayList(); protected final ArrayList<ControllerListener> controllerListeners = new ArrayList<>();
/** /**
* Protected constructor for subclassing. * Protected constructor for subclassing.
@ -133,9 +133,9 @@ public abstract class ControllerEnvironment {
*/ */
protected void fireControllerAdded(Controller c) { protected void fireControllerAdded(Controller c) {
ControllerEvent ev = new ControllerEvent(c); ControllerEvent ev = new ControllerEvent(c);
Iterator it = controllerListeners.iterator(); Iterator<ControllerListener> it = controllerListeners.iterator();
while (it.hasNext()) { 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) { protected void fireControllerRemoved(Controller c) {
ControllerEvent ev = new ControllerEvent(c); ControllerEvent ev = new ControllerEvent(c);
Iterator it = controllerListeners.iterator(); Iterator<ControllerListener> it = controllerListeners.iterator();
while (it.hasNext()) { while (it.hasNext()) {
((ControllerListener)it.next()).controllerRemoved(ev); it.next().controllerRemoved(ev);
} }
} }
@ -158,4 +158,4 @@ public abstract class ControllerEnvironment {
public static ControllerEnvironment getDefaultEnvironment() { public static ControllerEnvironment getDefaultEnvironment() {
return defaultEnvironment; 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. * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * 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 * You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility * the design, construction, operation or maintenance of any nuclear facility
* *
*****************************************************************************/ */
package net.java.games.input; package net.java.games.input;
import net.java.games.util.plugins.Plugins;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.lang.reflect.Method;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.Properties;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.java.games.util.plugins.*;
/** /**
* The default controller environment. * The default controller environment.
* *
@ -72,42 +62,31 @@ class DefaultControllerEnvironment extends ControllerEnvironment {
* *
*/ */
static void loadLibrary(final String lib_name) { static void loadLibrary(final String lib_name) {
AccessController.doPrivileged( AccessController.doPrivileged((PrivilegedAction<String>) () -> {
new PrivilegedAction() {
public final Object run() {
String lib_path = System.getProperty("net.java.games.input.librarypath"); String lib_path = System.getProperty("net.java.games.input.librarypath");
if (lib_path != null) if (lib_path != null)
System.load(lib_path + File.separator + System.mapLibraryName(lib_name)); System.load(lib_path + File.separator + System.mapLibraryName(lib_name));
else else
System.loadLibrary(lib_name); System.loadLibrary(lib_name);
return null; return null;
}
}); });
} }
static String getPrivilegedProperty(final String property) { static String getPrivilegedProperty(final String property) {
return (String)AccessController.doPrivileged(new PrivilegedAction() { return AccessController.doPrivileged((PrivilegedAction<String>) () -> System.getProperty(property));
public Object run() {
return System.getProperty(property);
}
});
} }
static String getPrivilegedProperty(final String property, final String default_value) { static String getPrivilegedProperty(final String property, final String default_value) {
return (String)AccessController.doPrivileged(new PrivilegedAction() { return AccessController.doPrivileged((PrivilegedAction<String>) () -> System.getProperty(property, default_value));
public Object run() {
return System.getProperty(property, default_value);
}
});
} }
/** /**
* List of all controllers in this environment * 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. * Public no-arg constructor.
@ -122,13 +101,8 @@ class DefaultControllerEnvironment extends ControllerEnvironment {
public Controller[] getControllers() { public Controller[] getControllers() {
if (controllers == null) { if (controllers == null) {
// Controller list has not been scanned. // Controller list has not been scanned.
controllers = new ArrayList(); controllers = new ArrayList<>();
AccessController.doPrivileged(new PrivilegedAction() { AccessController.doPrivileged((PrivilegedAction<Void>) () -> scanControllers());
public Object run() {
scanControllers();
return null;
}
});
//Check the properties for specified controller classes //Check the properties for specified controller classes
String pluginClasses = getPrivilegedProperty("jinput.plugins", "") + " " + getPrivilegedProperty("net.java.games.input.plugins", ""); 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")) { 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()) { while(pluginClassTok.hasMoreTokens()) {
String className = pluginClassTok.nextToken(); String className = pluginClassTok.nextToken();
try { try {
if(!loadedPlugins.contains(className)) { if(!loadedPluginNames.contains(className)) {
log.fine("Loading: " + className); log.fine("Loading: " + className);
Class ceClass = Class.forName(className); Class<?> ceClass = Class.forName(className);
ControllerEnvironment ce = (ControllerEnvironment) ceClass.getDeclaredConstructor().newInstance(); ControllerEnvironment ce = (ControllerEnvironment) ceClass.getDeclaredConstructor().newInstance();
if(ce.isSupported()) { if(ce.isSupported()) {
addControllers(ce.getControllers()); addControllers(ce.getControllers());
loadedPlugins.add(ce.getClass().getName()); loadedPluginNames.add(ce.getClass().getName());
} else { } else {
log(ceClass.getName() + " is not supported"); log(ceClass.getName() + " is not supported");
} }
@ -171,17 +145,17 @@ class DefaultControllerEnvironment extends ControllerEnvironment {
} }
} }
Controller[] ret = new Controller[controllers.size()]; Controller[] ret = new Controller[controllers.size()];
Iterator it = controllers.iterator(); Iterator<Controller> it = controllers.iterator();
int i = 0; int i = 0;
while (it.hasNext()) { while (it.hasNext()) {
ret[i] = (Controller)it.next(); ret[i] = it.next();
i++; i++;
} }
return ret; return ret;
} }
/* This is jeff's new plugin code using Jeff's Plugin manager */ /* This is jeff's new plugin code using Jeff's Plugin manager */
private void scanControllers() { private Void scanControllers() {
String pluginPathName = getPrivilegedProperty("jinput.controllerPluginPath"); String pluginPathName = getPrivilegedProperty("jinput.controllerPluginPath");
if(pluginPathName == null) { if(pluginPathName == null) {
pluginPathName = "controller"; pluginPathName = "controller";
@ -191,6 +165,8 @@ class DefaultControllerEnvironment extends ControllerEnvironment {
File.separator + "lib"+File.separator + pluginPathName); File.separator + "lib"+File.separator + pluginPathName);
scanControllersAt(getPrivilegedProperty("user.dir")+ scanControllersAt(getPrivilegedProperty("user.dir")+
File.separator + pluginPathName); File.separator + pluginPathName);
return null;
} }
private void scanControllersAt(String path) { private void scanControllersAt(String path) {
@ -200,17 +176,17 @@ class DefaultControllerEnvironment extends ControllerEnvironment {
} }
try { try {
Plugins plugins = new Plugins(file); 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++){ for(int i=0;i<envClasses.length;i++){
try { try {
ControllerEnvironment.log("ControllerEnvironment "+ ControllerEnvironment.log("ControllerEnvironment "+
envClasses[i].getName() envClasses[i].getName()
+" loaded by "+envClasses[i].getClassLoader()); +" loaded by "+envClasses[i].getClassLoader());
ControllerEnvironment ce = (ControllerEnvironment) ControllerEnvironment ce = envClasses[i].getDeclaredConstructor().newInstance();
envClasses[i].getDeclaredConstructor().newInstance();
if(ce.isSupported()) { if(ce.isSupported()) {
addControllers(ce.getControllers()); addControllers(ce.getControllers());
loadedPlugins.add(ce.getClass().getName()); loadedPluginNames.add(ce.getClass().getName());
} else { } else {
log(envClasses[i].getName() + " is not supported"); 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. * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * 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 * You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility * the design, construction, operation or maintenance of any nuclear facility
* *
*****************************************************************************/ */
package net.java.games.input; package net.java.games.input;
import java.io.File; import java.io.File;
@ -77,7 +71,7 @@ class PluginClassLoader extends ClassLoader {
* Overrides findClass to first look in the parent class loader, * Overrides findClass to first look in the parent class loader,
* then try loading the class from the plugin file system. * then try loading the class from the plugin file system.
*/ */
protected Class findClass(String name) protected Class<?> findClass(String name)
throws ClassNotFoundException { throws ClassNotFoundException {
// Try loading the class from the file system. // Try loading the class from the file system.
byte[] b = loadClassData(name); byte[] b = loadClassData(name);

View file

@ -29,12 +29,6 @@
</plugin> </plugin>
<plugin> <plugin>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgs>
<arg>-h</arg>
<arg>${project.build.directory}/generated-sources/natives</arg>
</compilerArgs>
</configuration>
</plugin> </plugin>
<plugin> <plugin>
<artifactId>maven-antrun-plugin</artifactId> <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. * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * 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 * You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility * the design, construction, operation or maintenance of any nuclear facility
* *
*****************************************************************************/ */
package net.java.games.input; package net.java.games.input;
import java.util.Map; import java.util.Map;
@ -46,13 +40,13 @@ import java.util.HashMap;
* @version 1.0 * @version 1.0
*/ */
final class ButtonUsage implements Usage { 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; private final int button_id;
public final static ButtonUsage map(int button_id) { public final static ButtonUsage map(int button_id) {
Integer button_id_obj = new Integer(button_id); Integer button_id_obj = button_id;
ButtonUsage existing = (ButtonUsage)map.get(button_id_obj); ButtonUsage existing = map.get(button_id_obj);
if (existing != null) if (existing != null)
return existing; return existing;
ButtonUsage new_button = new ButtonUsage(button_id); ButtonUsage new_button = new ButtonUsage(button_id);

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. * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * 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 * You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility * the design, construction, operation or maintenance of any nuclear facility
* *
*****************************************************************************/ */
package net.java.games.input; package net.java.games.input;
/** Generic Desktop Usages /** Generic Desktop Usages

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. * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@ -35,12 +29,9 @@
* You acknowledge that this software is not designed or intended for us in * You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility * the design, construction, operation or maintenance of any nuclear facility
* *
*****************************************************************************/ */
package net.java.games.input; package net.java.games.input;
import java.util.Map;
import java.util.HashMap;
/** Mapping from Keyboard HID usages to Component.Identifier.Key /** Mapping from Keyboard HID usages to Component.Identifier.Key
* @author elias * @author elias
* @version 1.0 * @version 1.0

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. * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * 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 * You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility * the design, construction, operation or maintenance of any nuclear facility
* *
*****************************************************************************/ */
package net.java.games.input; package net.java.games.input;
import java.io.File; import java.io.File;
@ -67,9 +61,7 @@ public final class OSXEnvironmentPlugin extends ControllerEnvironment implements
* *
*/ */
static void loadLibrary(final String lib_name) { static void loadLibrary(final String lib_name) {
AccessController.doPrivileged( AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
new PrivilegedAction() {
public final Object run() {
try { try {
String lib_path = System.getProperty("net.java.games.input.librarypath"); String lib_path = System.getProperty("net.java.games.input.librarypath");
if (lib_path != null) if (lib_path != null)
@ -81,25 +73,16 @@ public final class OSXEnvironmentPlugin extends ControllerEnvironment implements
supported = false; supported = false;
} }
return null; return null;
}
}); });
} }
static String getPrivilegedProperty(final String property) { static String getPrivilegedProperty(final String property) {
return (String)AccessController.doPrivileged(new PrivilegedAction() { return AccessController.doPrivileged((PrivilegedAction<String>)() -> System.getProperty(property));
public Object run() {
return System.getProperty(property);
}
});
} }
static String getPrivilegedProperty(final String property, final String default_value) { static String getPrivilegedProperty(final String property, final String default_value) {
return (String)AccessController.doPrivileged(new PrivilegedAction() { return AccessController.doPrivileged((PrivilegedAction<String>)() -> System.getProperty(property, default_value));
public Object run() {
return System.getProperty(property, default_value);
}
});
} }
static { static {
@ -147,10 +130,10 @@ public final class OSXEnvironmentPlugin extends ControllerEnvironment implements
return supported; return supported;
} }
private final static void addElements(OSXHIDQueue queue, List elements, List components, boolean map_mouse_buttons) throws IOException { private final static void addElements(OSXHIDQueue queue, List<OSXHIDElement> elements, List<OSXComponent> components, boolean map_mouse_buttons) throws IOException {
Iterator it = elements.iterator(); Iterator<OSXHIDElement> it = elements.iterator();
while (it.hasNext()) { while (it.hasNext()) {
OSXHIDElement element = (OSXHIDElement)it.next(); OSXHIDElement element = it.next();
Component.Identifier id = element.getIdentifier(); Component.Identifier id = element.getIdentifier();
if (id == null) if (id == null)
continue; continue;
@ -169,8 +152,8 @@ public final class OSXEnvironmentPlugin extends ControllerEnvironment implements
} }
} }
private final static Keyboard createKeyboardFromDevice(OSXHIDDevice device, List elements) throws IOException { private final static Keyboard createKeyboardFromDevice(OSXHIDDevice device, List<OSXHIDElement> elements) throws IOException {
List components = new ArrayList(); List<OSXComponent> components = new ArrayList<>();
OSXHIDQueue queue = device.createQueue(AbstractController.EVENT_QUEUE_DEPTH); OSXHIDQueue queue = device.createQueue(AbstractController.EVENT_QUEUE_DEPTH);
try { try {
addElements(queue, elements, components, false); addElements(queue, elements, components, false);
@ -180,12 +163,11 @@ public final class OSXEnvironmentPlugin extends ControllerEnvironment implements
} }
Component[] components_array = new Component[components.size()]; Component[] components_array = new Component[components.size()];
components.toArray(components_array); components.toArray(components_array);
Keyboard keyboard = new OSXKeyboard(device, queue, components_array, new Controller[]{}, new Rumbler[]{}); return new OSXKeyboard(device, queue, components_array, new Controller[]{}, new Rumbler[]{});
return keyboard;
} }
private final static Mouse createMouseFromDevice(OSXHIDDevice device, List elements) throws IOException { private final static Mouse createMouseFromDevice(OSXHIDDevice device, List<OSXHIDElement> elements) throws IOException {
List components = new ArrayList(); List<OSXComponent> components = new ArrayList<>();
OSXHIDQueue queue = device.createQueue(AbstractController.EVENT_QUEUE_DEPTH); OSXHIDQueue queue = device.createQueue(AbstractController.EVENT_QUEUE_DEPTH);
try { try {
addElements(queue, elements, components, true); 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 { private final static AbstractController createControllerFromDevice(OSXHIDDevice device, List<OSXHIDElement> elements, Controller.Type type) throws IOException {
List components = new ArrayList(); List<OSXComponent> components = new ArrayList<>();
OSXHIDQueue queue = device.createQueue(AbstractController.EVENT_QUEUE_DEPTH); OSXHIDQueue queue = device.createQueue(AbstractController.EVENT_QUEUE_DEPTH);
try { try {
addElements(queue, elements, components, false); addElements(queue, elements, components, false);
@ -215,15 +197,14 @@ public final class OSXEnvironmentPlugin extends ControllerEnvironment implements
} }
Component[] components_array = new Component[components.size()]; Component[] components_array = new Component[components.size()];
components.toArray(components_array); components.toArray(components_array);
AbstractController controller = new OSXAbstractController(device, queue, components_array, new Controller[]{}, new Rumbler[]{}, type); return new OSXAbstractController(device, queue, components_array, new Controller[]{}, new Rumbler[]{}, type);
return controller;
} }
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(); UsagePair usage_pair = device.getUsagePair();
if (usage_pair == null) if (usage_pair == null)
return; return;
List elements = device.getElements(); List<OSXHIDElement> elements = device.getElements();
if (usage_pair.getUsagePage() == UsagePage.GENERIC_DESKTOP && (usage_pair.getUsage() == GenericDesktopUsage.MOUSE || if (usage_pair.getUsagePage() == UsagePage.GENERIC_DESKTOP && (usage_pair.getUsage() == GenericDesktopUsage.MOUSE ||
usage_pair.getUsage() == GenericDesktopUsage.POINTER)) { usage_pair.getUsage() == GenericDesktopUsage.POINTER)) {
Controller mouse = createMouseFromDevice(device, elements); Controller mouse = createMouseFromDevice(device, elements);
@ -231,26 +212,18 @@ public final class OSXEnvironmentPlugin extends ControllerEnvironment implements
controllers.add(mouse); controllers.add(mouse);
} else if (usage_pair.getUsagePage() == UsagePage.GENERIC_DESKTOP && (usage_pair.getUsage() == GenericDesktopUsage.KEYBOARD || } else if (usage_pair.getUsagePage() == UsagePage.GENERIC_DESKTOP && (usage_pair.getUsage() == GenericDesktopUsage.KEYBOARD ||
usage_pair.getUsage() == GenericDesktopUsage.KEYPAD)) { usage_pair.getUsage() == GenericDesktopUsage.KEYPAD)) {
Controller keyboard = createKeyboardFromDevice(device, elements); controllers.add(createKeyboardFromDevice(device, elements));
if (keyboard != null)
controllers.add(keyboard);
} else if (usage_pair.getUsagePage() == UsagePage.GENERIC_DESKTOP && usage_pair.getUsage() == GenericDesktopUsage.JOYSTICK) { } else if (usage_pair.getUsagePage() == UsagePage.GENERIC_DESKTOP && usage_pair.getUsage() == GenericDesktopUsage.JOYSTICK) {
Controller joystick = createControllerFromDevice(device, elements, Controller.Type.STICK); controllers.add(createControllerFromDevice(device, elements, Controller.Type.STICK));
if (joystick != null)
controllers.add(joystick);
} else if (usage_pair.getUsagePage() == UsagePage.GENERIC_DESKTOP && usage_pair.getUsage() == GenericDesktopUsage.MULTI_AXIS_CONTROLLER) { } else if (usage_pair.getUsagePage() == UsagePage.GENERIC_DESKTOP && usage_pair.getUsage() == GenericDesktopUsage.MULTI_AXIS_CONTROLLER) {
Controller multiaxis = createControllerFromDevice(device, elements, Controller.Type.STICK); controllers.add(createControllerFromDevice(device, elements, Controller.Type.STICK));
if (multiaxis != null)
controllers.add(multiaxis);
} else if (usage_pair.getUsagePage() == UsagePage.GENERIC_DESKTOP && usage_pair.getUsage() == GenericDesktopUsage.GAME_PAD) { } else if (usage_pair.getUsagePage() == UsagePage.GENERIC_DESKTOP && usage_pair.getUsage() == GenericDesktopUsage.GAME_PAD) {
Controller game_pad = createControllerFromDevice(device, elements, Controller.Type.GAMEPAD); controllers.add(createControllerFromDevice(device, elements, Controller.Type.GAMEPAD));
if (game_pad != null)
controllers.add(game_pad);
} }
} }
private final static Controller[] enumerateControllers() { private final static Controller[] enumerateControllers() {
List controllers = new ArrayList(); List<Controller> controllers = new ArrayList<>();
try { try {
OSXHIDDeviceIterator it = new OSXHIDDeviceIterator(); OSXHIDDeviceIterator it = new OSXHIDDeviceIterator();
try { try {

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. * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * 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 * You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility * the design, construction, operation or maintenance of any nuclear facility
* *
*****************************************************************************/ */
package net.java.games.input; package net.java.games.input;
import java.io.IOException; import java.io.IOException;
@ -104,7 +98,7 @@ final class OSXHIDDevice {
private final long device_address; private final long device_address;
private final long device_interface_address; private final long device_interface_address;
private final Map properties; private final Map<String,?> properties;
private boolean released; private boolean released;
@ -130,7 +124,7 @@ final class OSXHIDDevice {
return (String)properties.get(kIOHIDProductKey); 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); /* long size = getLongFromProperties(element_properties, kIOHIDElementSizeKey);
// ignore elements that can't fit into the 32 bit value field of a hid event // ignore elements that can't fit into the 32 bit value field of a hid event
if (size > 32) 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); Object[] elements_properties = (Object[])properties.get(kIOHIDElementKey);
if (elements_properties == null) if (elements_properties == null)
return; return;
for (int i = 0; i < elements_properties.length; i++) { 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); OSXHIDElement element = createElementFromElementProperties(element_properties);
if (element != null) { if (element != null) {
elements.add(element); elements.add(element);
@ -175,28 +170,28 @@ final class OSXHIDDevice {
} }
} }
public final List getElements() { public final List<OSXHIDElement> getElements() {
List elements = new ArrayList(); List<OSXHIDElement> elements = new ArrayList<>();
addElements(elements, properties); addElements(elements, properties);
return elements; 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); Long long_obj = (Long)properties.get(key);
if (long_obj == null) if (long_obj == null)
return default_value; return default_value;
return long_obj.longValue(); 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; 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); 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); Long long_obj = (Long)properties.get(key);
return long_obj.longValue(); return long_obj.longValue();
} }
@ -217,28 +212,6 @@ final class OSXHIDDevice {
return createUsagePair(usage_page_id, usage_id); 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() { private final void dumpProperties() {
log.info(toString()); log.info(toString());
dumpMap("", properties); dumpMap("", properties);
@ -253,8 +226,8 @@ final class OSXHIDDevice {
log.info(prefix + "}"); log.info(prefix + "}");
} }
private final static void dumpMap(String prefix, Map map) { private final static void dumpMap(String prefix, Map<String,?> map) {
Iterator keys = map.keySet().iterator(); Iterator<String> keys = map.keySet().iterator();
while (keys.hasNext()) { while (keys.hasNext()) {
Object key = keys.next(); Object key = keys.next();
Object value = map.get(key); Object value = map.get(key);
@ -263,22 +236,23 @@ final class OSXHIDDevice {
} }
} }
@SuppressWarnings("unchecked")
private final static void dumpObject(String prefix, Object obj) { private final static void dumpObject(String prefix, Object obj) {
if (obj instanceof Long) { if (obj instanceof Long) {
Long l = (Long)obj; Long l = (Long)obj;
log.info(prefix + "0x" + Long.toHexString(l.longValue())); log.info(prefix + "0x" + Long.toHexString(l.longValue()));
} else if (obj instanceof Map) } else if (obj instanceof Map)
dumpMap(prefix, (Map)obj); dumpMap(prefix, (Map<String,?>)obj);
else if (obj.getClass().isArray()) else if (obj.getClass().isArray())
dumpArray(prefix, (Object[])obj); dumpArray(prefix, (Object[])obj);
else else
log.info(prefix + obj); log.info(prefix + obj);
} }
private final Map getDeviceProperties() throws IOException { private final Map<String,?> getDeviceProperties() throws IOException {
return nGetDeviceProperties(device_address); 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 { public final synchronized void release() throws IOException {
try { try {

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. * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * 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 * You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility * the design, construction, operation or maintenance of any nuclear facility
* *
*****************************************************************************/ */
package net.java.games.input; package net.java.games.input;
import java.io.IOException; import java.io.IOException;
@ -47,7 +41,7 @@ import java.util.HashMap;
* @version 1.0 * @version 1.0
*/ */
final class OSXHIDQueue { final class OSXHIDQueue {
private final Map map = new HashMap(); private final Map<Long,OSXComponent> map = new HashMap<>();
private final long queue_address; private final long queue_address;
private boolean released; private boolean released;
@ -80,7 +74,7 @@ final class OSXHIDQueue {
} }
public final OSXComponent mapEvent(OSXEvent event) { 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 { 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 { public final void addElement(OSXHIDElement element, OSXComponent component) throws IOException {
nAddElement(queue_address, element.getCookie()); 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; private final static native void nAddElement(long queue_address, long cookie) throws IOException;
public final void removeElement(OSXHIDElement element) throws IOException { public final void removeElement(OSXHIDElement element) throws IOException {
nRemoveElement(queue_address, element.getCookie()); 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; private final static native void nRemoveElement(long queue_address, long cookie) throws IOException;

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. * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * 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 * You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility * the design, construction, operation or maintenance of any nuclear facility
* *
*****************************************************************************/ */
package net.java.games.input; package net.java.games.input;
/** Generic Desktop Usages /** Generic Desktop Usages

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. * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * 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 * You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility * the design, construction, operation or maintenance of any nuclear facility
* *
*****************************************************************************/ */
package net.java.games.input; package net.java.games.input;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -77,7 +71,7 @@ final class UsagePage {
/* ReservedPointofSalepages 0x8E - 0X8F */ /* ReservedPointofSalepages 0x8E - 0X8F */
public final static UsagePage CAMERACONTROL= new UsagePage(0x90); /* USB Device Class Definition for Image Class Devices */ 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 */ 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; private final int usage_page_id;
public final static UsagePage map(int page_id) { public final static UsagePage map(int page_id) {
@ -86,7 +80,7 @@ final class UsagePage {
return map[page_id]; 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; map[page_id] = this;
this.usage_class = usage_class; this.usage_class = usage_class;
this.usage_page_id = page_id; this.usage_page_id = page_id;
@ -104,8 +98,8 @@ final class UsagePage {
if (usage_class == null) if (usage_class == null)
return null; return null;
try { try {
Method map_method = usage_class.getMethod("map", new Class[]{int.class}); Method map_method = usage_class.getMethod("map", int.class);
Object result = map_method.invoke(null, new Object[]{new Integer(usage_id)}); Object result = map_method.invoke(null, usage_id);
return (Usage)result; return (Usage)result;
} catch (Exception e) { } catch (Exception e) {
throw new Error(e); throw new Error(e);

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,4 +1,4 @@
/** /*
* Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com) * Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
* *
* Redistribution and use in source and binary forms, with or without * 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); weak_magnitude = (int)(0xc000*intensity);
} else if (intensity > 0.3333333f) { } else if (intensity > 0.3333333f) {
strong_magnitude = (int)(0x8000*intensity); strong_magnitude = (int)(0x8000*intensity);
weak_magnitude = (int)(0xc000*0); weak_magnitude = 0;
} else { } else {
strong_magnitude = (int)(0x8000*0); strong_magnitude = 0;
weak_magnitude = (int)(0xc000*intensity); weak_magnitude = (int)(0xc000*intensity);
} }

View file

@ -29,12 +29,6 @@
</plugin> </plugin>
<plugin> <plugin>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgs>
<arg>-h</arg>
<arg>${project.build.directory}/generated-sources/natives</arg>
</compilerArgs>
</configuration>
</plugin> </plugin>
<plugin> <plugin>
<artifactId>maven-antrun-plugin</artifactId> <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. * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@ -38,23 +32,25 @@
*****************************************************************************/ *****************************************************************************/
package net.java.games.input; package net.java.games.input;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
/** /**
* @author elias * @author elias
* @version 1.0 * @version 1.0
*/ */
final class DataQueue { final class DataQueue<T> {
private final Object[] elements; private final T[] elements;
private int position; private int position;
private int limit; private int limit;
public DataQueue(int size, Class element_type) { @SuppressWarnings("unchecked")
this.elements= new Object[size]; public DataQueue(int size, Class<T> element_type) {
this.elements= (T[])Array.newInstance(element_type, size);
for (int i = 0; i < elements.length; i++) { for (int i = 0; i < elements.length; i++) {
try { try {
elements[i] = element_type.newInstance(); elements[i] = element_type.getDeclaredConstructor().newInstance();
} catch (InstantiationException e) { } catch (InstantiationException|IllegalAccessException|NoSuchMethodException|InvocationTargetException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
@ -74,12 +70,12 @@ final class DataQueue {
return limit; return limit;
} }
public final Object get(int index) { public final T get(int index) {
assert index < limit; assert index < limit;
return elements[index]; return elements[index];
} }
public final Object get() { public final T get() {
if (!hasRemaining()) if (!hasRemaining())
return null; return null;
return get(position++); return get(position++);
@ -97,7 +93,7 @@ final class DataQueue {
} }
private final void swap(int index1, int index2) { private final void swap(int index1, int index2) {
Object temp = elements[index1]; T temp = elements[index1];
elements[index1] = elements[index2]; elements[index1] = elements[index2];
elements[index2] = temp; elements[index2] = temp;
} }
@ -119,7 +115,7 @@ final class DataQueue {
this.position = position; this.position = position;
} }
public final Object[] getElements() { public final T[] getElements() {
return elements; return elements;
} }
} }

View file

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

View file

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

View file

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

View file

@ -58,7 +58,7 @@ final class IDirectInputEffect implements Rumbler {
try { try {
checkReleased(); checkReleased();
if (intensity > 0) { 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); setGain(int_gain);
start(1, 0); start(1, 0);
} else } else
@ -115,6 +115,7 @@ final class IDirectInputEffect implements Rumbler {
} }
private final static native int nStop(long address); private final static native int nStop(long address);
@SuppressWarnings("deprecation")
protected void finalize() { protected void finalize() {
release(); release();
} }

View file

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

View file

@ -64,9 +64,7 @@ public final class RawInputEnvironmentPlugin extends ControllerEnvironment imple
* *
*/ */
static void loadLibrary(final String lib_name) { static void loadLibrary(final String lib_name) {
AccessController.doPrivileged( AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
new PrivilegedAction() {
public final Object run() {
try { try {
String lib_path = System.getProperty("net.java.games.input.librarypath"); String lib_path = System.getProperty("net.java.games.input.librarypath");
if (lib_path != null) if (lib_path != null)
@ -78,25 +76,16 @@ public final class RawInputEnvironmentPlugin extends ControllerEnvironment imple
supported = false; supported = false;
} }
return null; return null;
}
}); });
} }
static String getPrivilegedProperty(final String property) { static String getPrivilegedProperty(final String property) {
return (String)AccessController.doPrivileged(new PrivilegedAction() { return AccessController.doPrivileged((PrivilegedAction<String>) () -> System.getProperty(property));
public Object run() {
return System.getProperty(property);
}
});
} }
static String getPrivilegedProperty(final String property, final String default_value) { static String getPrivilegedProperty(final String property, final String default_value) {
return (String)AccessController.doPrivileged(new PrivilegedAction() { return AccessController.doPrivileged((PrivilegedAction<String>) () -> System.getProperty(property, default_value));
public Object run() {
return System.getProperty(property, default_value);
}
});
} }
static { static {
@ -132,23 +121,23 @@ public final class RawInputEnvironmentPlugin extends ControllerEnvironment imple
return controllers; 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 /* First, replace # with / in the device name, since that
* seems to be the format in raw input device name * seems to be the format in raw input device name
*/ */
device_name = device_name.replaceAll("#", "\\\\").toUpperCase(); device_name = device_name.replaceAll("#", "\\\\").toUpperCase();
for (int i = 0; i < setupapi_devices.size(); i++) { for (int i = 0; i < setupapi_devices.size(); i++) {
SetupAPIDevice device = (SetupAPIDevice)setupapi_devices.get(i); SetupAPIDevice device = setupapi_devices.get(i);
if (device_name.indexOf(device.getInstanceId().toUpperCase()) != -1) if (device_name.contains(device.getInstanceId().toUpperCase()))
return device; return device;
} }
return null; return null;
} }
private final static void createControllersFromDevices(RawInputEventQueue queue, List controllers, List devices, List setupapi_devices) throws IOException { private final static void createControllersFromDevices(RawInputEventQueue queue, List<Controller> controllers, List<RawDevice> devices, List<SetupAPIDevice> setupapi_devices) throws IOException {
List active_devices = new ArrayList(); List<RawDevice> active_devices = new ArrayList<>();
for (int i = 0; i < devices.size(); i++) { 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); SetupAPIDevice setupapi_device = lookupSetupAPIDevice(device.getName(), setupapi_devices);
if (setupapi_device == null) { if (setupapi_device == null) {
/* Either the device is an RDP or we failed to locate the /* 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); 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 { private final Controller[] enumControllers(RawInputEventQueue queue) throws IOException {
List controllers = new ArrayList(); List<Controller> controllers = new ArrayList<>();
List devices = new ArrayList(); List<RawDevice> devices = new ArrayList<>();
enumerateDevices(queue, devices); enumerateDevices(queue, devices);
List setupapi_devices = enumSetupAPIDevices(); List<SetupAPIDevice> setupapi_devices = enumSetupAPIDevices();
createControllersFromDevices(queue, controllers, devices, setupapi_devices); createControllersFromDevices(queue, controllers, devices, setupapi_devices);
Controller[] controllers_array = new Controller[controllers.size()]; Controller[] controllers_array = new Controller[controllers.size()];
controllers.toArray(controllers_array); 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 * descriptive names and at the same time filter out the unwanted
* RDP devices. * RDP devices.
*/ */
private final static List enumSetupAPIDevices() throws IOException { private final static List<SetupAPIDevice> enumSetupAPIDevices() throws IOException {
List devices = new ArrayList(); List<SetupAPIDevice> devices = new ArrayList<>();
nEnumSetupAPIDevices(getKeyboardClassGUID(), devices); nEnumSetupAPIDevices(getKeyboardClassGUID(), devices);
nEnumSetupAPIDevices(getMouseClassGUID(), devices); nEnumSetupAPIDevices(getMouseClassGUID(), devices);
return 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[] getKeyboardClassGUID();
private final static native byte[] getMouseClassGUID(); 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. * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * 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 * You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility * the design, construction, operation or maintenance of any nuclear facility
* *
*****************************************************************************/ */
package net.java.games.input; package net.java.games.input;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.ArrayList;
import java.util.Set; import java.util.Set;
import java.util.HashSet; import java.util.HashSet;
@ -51,9 +44,9 @@ import java.util.HashSet;
final class RawInputEventQueue { final class RawInputEventQueue {
private final Object monitor = new Object(); 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; this.devices = devices;
QueueThread queue = new QueueThread(); QueueThread queue = new QueueThread();
synchronized (monitor) { synchronized (monitor) {
@ -71,7 +64,7 @@ final class RawInputEventQueue {
private final RawDevice lookupDevice(long handle) { private final RawDevice lookupDevice(long handle) {
for (int i = 0; i < devices.size(); i++) { for (int i = 0; i < devices.size(); i++) {
RawDevice device = (RawDevice)devices.get(i); RawDevice device = devices.get(i);
if (device.getHandle() == handle) if (device.getHandle() == handle)
return device; return device;
} }
@ -133,10 +126,10 @@ final class RawInputEventQueue {
} }
if (exception != null) if (exception != null)
return; return;
Set active_infos = new HashSet(); Set<RawDeviceInfo> active_infos = new HashSet<>();
try { try {
for (int i = 0; i < devices.size(); i++) { for (int i = 0; i < devices.size(); i++) {
RawDevice device = (RawDevice)devices.get(i); RawDevice device = devices.get(i);
active_infos.add(device.getInfo()); active_infos.add(device.getInfo());
} }
RawDeviceInfo[] active_infos_array = new RawDeviceInfo[active_infos.size()]; RawDeviceInfo[] active_infos_array = new RawDeviceInfo[active_infos.size()];

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. * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * 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 * You acknowledge that this software is not designed or intended for us in
* the design, construction, operation or maintenance of any nuclear facility * the design, construction, operation or maintenance of any nuclear facility
* *
*****************************************************************************/ */
package net.java.games.input; package net.java.games.input;
import java.io.IOException; import java.io.IOException;
@ -59,7 +53,7 @@ final class RawKeyboard extends Keyboard {
} }
private final static Component[] createKeyboardComponents(RawDevice device) { private final static Component[] createKeyboardComponents(RawDevice device) {
List components = new ArrayList(); List<Component> components = new ArrayList<>();
Field[] vkey_fields = RawIdentifierMap.class.getFields(); Field[] vkey_fields = RawIdentifierMap.class.getFields();
for (int i = 0; i < vkey_fields.length; i++) { for (int i = 0; i < vkey_fields.length; i++) {
Field vkey_field = vkey_fields[i]; Field vkey_field = vkey_fields[i];
@ -74,7 +68,7 @@ final class RawKeyboard extends Keyboard {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
return (Component[])components.toArray(new Component[]{}); return components.toArray(new Component[]{});
} }
protected final synchronized boolean getNextDeviceEvent(Event event) throws IOException { protected final synchronized boolean getNextDeviceEvent(Event event) throws IOException {

View file

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

View file

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

View file

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

View file

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

View file

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

10
pom.xml
View file

@ -39,8 +39,8 @@
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.6</maven.compiler.source> <maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target> <maven.compiler.target>8</maven.compiler.target>
</properties> </properties>
<dependencyManagement> <dependencyManagement>
@ -70,6 +70,12 @@
<configuration> <configuration>
<showDeprecation>true</showDeprecation> <showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings> <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> </configuration>
</plugin> </plugin>
<plugin> <plugin>

View file

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

View file

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

View file

@ -37,12 +37,6 @@
*****************************************************************************/ *****************************************************************************/
package net.java.games.input; package net.java.games.input;
/**
*
* @author administrator
*/
import net.java.games.input.*;
public class ControllerTextTest { public class ControllerTextTest {
ControllerEnvironment ce; ControllerEnvironment ce;
/** Creates a new instance of ControllerScanner */ /** 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; 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 { public class RumbleTest {
/** Creates a new instance of 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; package net.java.games.input;
import net.java.games.input.Version;
public class VersionTest { public class VersionTest {
/**
* @param args
*/
public static void main(String[] args) { public static void main(String[] args) {
System.out.println("JInput version: " + Version.getVersion()); System.out.println("JInput version: " + Version.getVersion());
} }

View file

@ -1,4 +1,4 @@
/** /*
* Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com) * Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -25,13 +25,14 @@
*/ */
package net.java.games.input.applet; package net.java.games.input.applet;
import java.applet.Applet;
import java.io.IOException; import java.io.IOException;
import net.java.games.input.ControllerEventTest; 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 {
private static final long serialVersionUID = 4250817143444220400L;
public void init() { public void init() {
try { try {

View file

@ -1,4 +1,4 @@
/** /*
* Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com) * Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com)
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -25,13 +25,14 @@
*/ */
package net.java.games.input.applet; package net.java.games.input.applet;
import java.applet.Applet;
import java.io.IOException; import java.io.IOException;
import net.java.games.input.ControllerReadTest; 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() { public void init() {
try { try {