diff --git a/applet/src/main/java/net/java/games/input/applet/JInputAppletResourceLoader.java b/applet/src/main/java/net/java/games/input/applet/JInputAppletResourceLoader.java index 63a18b5..4d2e63e 100644 --- a/applet/src/main/java/net/java/games/input/applet/JInputAppletResourceLoader.java +++ b/applet/src/main/java/net/java/games/input/applet/JInputAppletResourceLoader.java @@ -50,19 +50,11 @@ public class JInputAppletResourceLoader { private int percentageDone = 0; private String getPrivilegedProperty(final String property) { - return (String) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - return System.getProperty(property); - } - }); + return AccessController.doPrivileged((PrivilegedAction) () -> System.getProperty(property)); } private String setPrivilegedProperty(final String property, final String value) { - return (String) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - return System.setProperty(property, value); - } - }); + return AccessController.doPrivileged((PrivilegedAction) () -> System.setProperty(property, value)); } public void loadResources(URL codeBase) throws IOException { @@ -94,13 +86,13 @@ public class JInputAppletResourceLoader { JarFile localJarFile = new JarFile(new File(tempDir, nativeJar), true); - Enumeration jarEntries = localJarFile.entries(); + Enumeration jarEntries = localJarFile.entries(); int totalUncompressedBytes = 0; int totalUncompressedBytesWritten = 0; - List entriesToUse = new ArrayList(); + List entriesToUse = new ArrayList<>(); while(jarEntries.hasMoreElements()) { - JarEntry jarEntry = (JarEntry)jarEntries.nextElement(); + JarEntry jarEntry = jarEntries.nextElement(); String entryName = jarEntry.getName(); if(!entryName.startsWith("META-INF")) { totalUncompressedBytes+=jarEntry.getSize(); @@ -116,7 +108,7 @@ public class JInputAppletResourceLoader { } for(int i=0;i id_to_components = new HashMap<>(); private EventQueue event_queue = new EventQueue(EVENT_QUEUE_DEPTH); @@ -128,7 +120,7 @@ public abstract class AbstractController implements Controller { * if no component with the specified type could be found. */ public final Component getComponent(Component.Identifier id) { - return (Component)id_to_components.get(id); + return id_to_components.get(id); } /** diff --git a/coreAPI/src/main/java/net/java/games/input/ControllerEnvironment.java b/coreAPI/src/main/java/net/java/games/input/ControllerEnvironment.java index 795c9f1..6aa9ad8 100644 --- a/coreAPI/src/main/java/net/java/games/input/ControllerEnvironment.java +++ b/coreAPI/src/main/java/net/java/games/input/ControllerEnvironment.java @@ -85,7 +85,7 @@ public abstract class ControllerEnvironment { /** * List of controller listeners */ - protected final ArrayList controllerListeners = new ArrayList(); + protected final ArrayList controllerListeners = new ArrayList<>(); /** * Protected constructor for subclassing. @@ -133,9 +133,9 @@ public abstract class ControllerEnvironment { */ protected void fireControllerAdded(Controller c) { ControllerEvent ev = new ControllerEvent(c); - Iterator it = controllerListeners.iterator(); + Iterator it = controllerListeners.iterator(); while (it.hasNext()) { - ((ControllerListener)it.next()).controllerAdded(ev); + it.next().controllerAdded(ev); } } @@ -145,9 +145,9 @@ public abstract class ControllerEnvironment { */ protected void fireControllerRemoved(Controller c) { ControllerEvent ev = new ControllerEvent(c); - Iterator it = controllerListeners.iterator(); + Iterator it = controllerListeners.iterator(); while (it.hasNext()) { - ((ControllerListener)it.next()).controllerRemoved(ev); + it.next().controllerRemoved(ev); } } @@ -158,4 +158,4 @@ public abstract class ControllerEnvironment { public static ControllerEnvironment getDefaultEnvironment() { return defaultEnvironment; } -} // ControllerEnvironment +} \ No newline at end of file diff --git a/coreAPI/src/main/java/net/java/games/input/DefaultControllerEnvironment.java b/coreAPI/src/main/java/net/java/games/input/DefaultControllerEnvironment.java index 468f24c..4aa3521 100644 --- a/coreAPI/src/main/java/net/java/games/input/DefaultControllerEnvironment.java +++ b/coreAPI/src/main/java/net/java/games/input/DefaultControllerEnvironment.java @@ -1,10 +1,4 @@ /* - * %W% %E% - * - * Copyright 2002 Sun Microsystems, Inc. All rights reserved. - * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. - */ -/***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -35,24 +29,20 @@ * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * - *****************************************************************************/ + */ package net.java.games.input; +import net.java.games.util.plugins.Plugins; + import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.lang.reflect.Method; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; -import java.util.Properties; import java.util.StringTokenizer; import java.util.logging.Logger; -import net.java.games.util.plugins.*; - /** * The default controller environment. * @@ -72,42 +62,31 @@ class DefaultControllerEnvironment extends ControllerEnvironment { * */ static void loadLibrary(final String lib_name) { - AccessController.doPrivileged( - new PrivilegedAction() { - public final Object run() { + AccessController.doPrivileged((PrivilegedAction) () -> { String lib_path = System.getProperty("net.java.games.input.librarypath"); if (lib_path != null) System.load(lib_path + File.separator + System.mapLibraryName(lib_name)); else System.loadLibrary(lib_name); return null; - } }); } static String getPrivilegedProperty(final String property) { - return (String)AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - return System.getProperty(property); - } - }); + return AccessController.doPrivileged((PrivilegedAction) () -> System.getProperty(property)); } static String getPrivilegedProperty(final String property, final String default_value) { - return (String)AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - return System.getProperty(property, default_value); - } - }); + return AccessController.doPrivileged((PrivilegedAction) () -> System.getProperty(property, default_value)); } /** * List of all controllers in this environment */ - private ArrayList controllers; + private ArrayList controllers; - private Collection loadedPlugins = new ArrayList(); + private Collection loadedPluginNames = new ArrayList<>(); /** * Public no-arg constructor. @@ -122,13 +101,8 @@ class DefaultControllerEnvironment extends ControllerEnvironment { public Controller[] getControllers() { if (controllers == null) { // Controller list has not been scanned. - controllers = new ArrayList(); - AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - scanControllers(); - return null; - } - }); + controllers = new ArrayList<>(); + AccessController.doPrivileged((PrivilegedAction) () -> scanControllers()); //Check the properties for specified controller classes String pluginClasses = getPrivilegedProperty("jinput.plugins", "") + " " + getPrivilegedProperty("net.java.games.input.plugins", ""); if(!getPrivilegedProperty("jinput.useDefaultPlugin", "true").toLowerCase().trim().equals("false") && !getPrivilegedProperty("net.java.games.input.useDefaultPlugin", "true").toLowerCase().trim().equals("false")) { @@ -154,13 +128,13 @@ class DefaultControllerEnvironment extends ControllerEnvironment { while(pluginClassTok.hasMoreTokens()) { String className = pluginClassTok.nextToken(); try { - if(!loadedPlugins.contains(className)) { + if(!loadedPluginNames.contains(className)) { log.fine("Loading: " + className); - Class ceClass = Class.forName(className); + Class ceClass = Class.forName(className); ControllerEnvironment ce = (ControllerEnvironment) ceClass.getDeclaredConstructor().newInstance(); if(ce.isSupported()) { addControllers(ce.getControllers()); - loadedPlugins.add(ce.getClass().getName()); + loadedPluginNames.add(ce.getClass().getName()); } else { log(ceClass.getName() + " is not supported"); } @@ -171,17 +145,17 @@ class DefaultControllerEnvironment extends ControllerEnvironment { } } Controller[] ret = new Controller[controllers.size()]; - Iterator it = controllers.iterator(); + Iterator it = controllers.iterator(); int i = 0; while (it.hasNext()) { - ret[i] = (Controller)it.next(); + ret[i] = it.next(); i++; } return ret; } /* This is jeff's new plugin code using Jeff's Plugin manager */ - private void scanControllers() { + private Void scanControllers() { String pluginPathName = getPrivilegedProperty("jinput.controllerPluginPath"); if(pluginPathName == null) { pluginPathName = "controller"; @@ -191,6 +165,8 @@ class DefaultControllerEnvironment extends ControllerEnvironment { File.separator + "lib"+File.separator + pluginPathName); scanControllersAt(getPrivilegedProperty("user.dir")+ File.separator + pluginPathName); + + return null; } private void scanControllersAt(String path) { @@ -200,17 +176,17 @@ class DefaultControllerEnvironment extends ControllerEnvironment { } try { Plugins plugins = new Plugins(file); - Class[] envClasses = plugins.getExtends(ControllerEnvironment.class); + @SuppressWarnings("unchecked") + Class[] envClasses = plugins.getExtends(ControllerEnvironment.class); for(int i=0;i findClass(String name) throws ClassNotFoundException { // Try loading the class from the file system. byte[] b = loadClassData(name); diff --git a/plugins/OSX/pom.xml b/plugins/OSX/pom.xml index de41b19..bc30b9d 100644 --- a/plugins/OSX/pom.xml +++ b/plugins/OSX/pom.xml @@ -29,12 +29,6 @@ maven-compiler-plugin - - - -h - ${project.build.directory}/generated-sources/natives - - maven-antrun-plugin diff --git a/plugins/OSX/src/main/java/net/java/games/input/ButtonUsage.java b/plugins/OSX/src/main/java/net/java/games/input/ButtonUsage.java index d83dcb8..8114805 100644 --- a/plugins/OSX/src/main/java/net/java/games/input/ButtonUsage.java +++ b/plugins/OSX/src/main/java/net/java/games/input/ButtonUsage.java @@ -1,41 +1,35 @@ /* - * %W% %E% + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistribution of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materails provided with the distribution. + * + * Neither the name Sun Microsystems, Inc. or the names of the contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. + * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING + * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR + * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND + * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS + * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS + * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST + * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, + * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY + * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, + * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for us in + * the design, construction, operation or maintenance of any nuclear facility * - * Copyright 2002 Sun Microsystems, Inc. All rights reserved. - * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ -/***************************************************************************** -* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* -* - Redistribution of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* - Redistribution in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation -* and/or other materails provided with the distribution. -* -* Neither the name Sun Microsystems, Inc. or the names of the contributors -* may be used to endorse or promote products derived from this software -* without specific prior written permission. -* -* This software is provided "AS IS," without a warranty of any kind. -* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING -* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR -* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND -* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS -* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS -* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST -* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, -* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY -* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, -* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. -* -* You acknowledge that this software is not designed or intended for us in -* the design, construction, operation or maintenance of any nuclear facility -* -*****************************************************************************/ package net.java.games.input; import java.util.Map; @@ -46,13 +40,13 @@ import java.util.HashMap; * @version 1.0 */ final class ButtonUsage implements Usage { - private final static Map map = new HashMap(); + private final static Map map = new HashMap<>(); private final int button_id; public final static ButtonUsage map(int button_id) { - Integer button_id_obj = new Integer(button_id); - ButtonUsage existing = (ButtonUsage)map.get(button_id_obj); + Integer button_id_obj = button_id; + ButtonUsage existing = map.get(button_id_obj); if (existing != null) return existing; ButtonUsage new_button = new ButtonUsage(button_id); diff --git a/plugins/OSX/src/main/java/net/java/games/input/GenericDesktopUsage.java b/plugins/OSX/src/main/java/net/java/games/input/GenericDesktopUsage.java index 4c45fa4..4049d68 100644 --- a/plugins/OSX/src/main/java/net/java/games/input/GenericDesktopUsage.java +++ b/plugins/OSX/src/main/java/net/java/games/input/GenericDesktopUsage.java @@ -1,41 +1,35 @@ /* - * %W% %E% + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistribution of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materails provided with the distribution. + * + * Neither the name Sun Microsystems, Inc. or the names of the contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. + * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING + * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR + * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND + * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS + * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS + * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST + * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, + * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY + * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, + * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for us in + * the design, construction, operation or maintenance of any nuclear facility * - * Copyright 2002 Sun Microsystems, Inc. All rights reserved. - * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ -/***************************************************************************** -* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* -* - Redistribution of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* - Redistribution in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation -* and/or other materails provided with the distribution. -* -* Neither the name Sun Microsystems, Inc. or the names of the contributors -* may be used to endorse or promote products derived from this software -* without specific prior written permission. -* -* This software is provided "AS IS," without a warranty of any kind. -* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING -* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR -* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND -* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS -* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS -* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST -* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, -* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY -* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, -* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. -* -* You acknowledge that this software is not designed or intended for us in -* the design, construction, operation or maintenance of any nuclear facility -* -*****************************************************************************/ package net.java.games.input; /** Generic Desktop Usages diff --git a/plugins/OSX/src/main/java/net/java/games/input/KeyboardUsage.java b/plugins/OSX/src/main/java/net/java/games/input/KeyboardUsage.java index 7621032..30f2383 100644 --- a/plugins/OSX/src/main/java/net/java/games/input/KeyboardUsage.java +++ b/plugins/OSX/src/main/java/net/java/games/input/KeyboardUsage.java @@ -1,46 +1,37 @@ /* - * %W% %E% + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistribution of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materails provided with the distribution. + * + * Neither the name Sun Microsystems, Inc. or the names of the contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. + * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING + * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR + * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND + * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS + * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS + * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST + * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, + * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY + * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, + * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for us in + * the design, construction, operation or maintenance of any nuclear facility * - * Copyright 2002 Sun Microsystems, Inc. All rights reserved. - * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ -/***************************************************************************** -* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* -* - Redistribution of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* - Redistribution in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation -* and/or other materails provided with the distribution. -* -* Neither the name Sun Microsystems, Inc. or the names of the contributors -* may be used to endorse or promote products derived from this software -* without specific prior written permission. -* -* This software is provided "AS IS," without a warranty of any kind. -* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING -* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR -* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND -* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS -* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS -* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST -* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, -* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY -* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, -* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. -* -* You acknowledge that this software is not designed or intended for us in -* the design, construction, operation or maintenance of any nuclear facility -* -*****************************************************************************/ package net.java.games.input; -import java.util.Map; -import java.util.HashMap; - /** Mapping from Keyboard HID usages to Component.Identifier.Key * @author elias * @version 1.0 diff --git a/plugins/OSX/src/main/java/net/java/games/input/OSXEnvironmentPlugin.java b/plugins/OSX/src/main/java/net/java/games/input/OSXEnvironmentPlugin.java index 38f59b8..2278313 100755 --- a/plugins/OSX/src/main/java/net/java/games/input/OSXEnvironmentPlugin.java +++ b/plugins/OSX/src/main/java/net/java/games/input/OSXEnvironmentPlugin.java @@ -1,41 +1,35 @@ /* - * %W% %E% + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistribution of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materails provided with the distribution. + * + * Neither the name Sun Microsystems, Inc. or the names of the contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. + * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING + * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR + * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND + * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS + * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS + * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST + * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, + * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY + * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, + * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for us in + * the design, construction, operation or maintenance of any nuclear facility * - * Copyright 2002 Sun Microsystems, Inc. All rights reserved. - * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ -/***************************************************************************** -* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* -* - Redistribution of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* - Redistribution in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation -* and/or other materails provided with the distribution. -* -* Neither the name Sun Microsystems, Inc. or the names of the contributors -* may be used to endorse or promote products derived from this software -* without specific prior written permission. -* -* This software is provided "AS IS," without a warranty of any kind. -* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING -* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR -* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND -* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS -* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS -* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST -* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, -* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY -* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, -* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. -* -* You acknowledge that this software is not designed or intended for us in -* the design, construction, operation or maintenance of any nuclear facility -* -*****************************************************************************/ package net.java.games.input; import java.io.File; @@ -67,9 +61,7 @@ public final class OSXEnvironmentPlugin extends ControllerEnvironment implements * */ static void loadLibrary(final String lib_name) { - AccessController.doPrivileged( - new PrivilegedAction() { - public final Object run() { + AccessController.doPrivileged((PrivilegedAction) () -> { try { String lib_path = System.getProperty("net.java.games.input.librarypath"); if (lib_path != null) @@ -81,25 +73,16 @@ public final class OSXEnvironmentPlugin extends ControllerEnvironment implements supported = false; } return null; - } }); } static String getPrivilegedProperty(final String property) { - return (String)AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - return System.getProperty(property); - } - }); + return AccessController.doPrivileged((PrivilegedAction)() -> System.getProperty(property)); } static String getPrivilegedProperty(final String property, final String default_value) { - return (String)AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - return System.getProperty(property, default_value); - } - }); + return AccessController.doPrivileged((PrivilegedAction)() -> System.getProperty(property, default_value)); } static { @@ -147,10 +130,10 @@ public final class OSXEnvironmentPlugin extends ControllerEnvironment implements return supported; } - private final static void addElements(OSXHIDQueue queue, List elements, List components, boolean map_mouse_buttons) throws IOException { - Iterator it = elements.iterator(); + private final static void addElements(OSXHIDQueue queue, List elements, List components, boolean map_mouse_buttons) throws IOException { + Iterator it = elements.iterator(); while (it.hasNext()) { - OSXHIDElement element = (OSXHIDElement)it.next(); + OSXHIDElement element = it.next(); Component.Identifier id = element.getIdentifier(); if (id == null) continue; @@ -169,8 +152,8 @@ public final class OSXEnvironmentPlugin extends ControllerEnvironment implements } } - private final static Keyboard createKeyboardFromDevice(OSXHIDDevice device, List elements) throws IOException { - List components = new ArrayList(); + private final static Keyboard createKeyboardFromDevice(OSXHIDDevice device, List elements) throws IOException { + List components = new ArrayList<>(); OSXHIDQueue queue = device.createQueue(AbstractController.EVENT_QUEUE_DEPTH); try { addElements(queue, elements, components, false); @@ -180,12 +163,11 @@ public final class OSXEnvironmentPlugin extends ControllerEnvironment implements } Component[] components_array = new Component[components.size()]; components.toArray(components_array); - Keyboard keyboard = new OSXKeyboard(device, queue, components_array, new Controller[]{}, new Rumbler[]{}); - return keyboard; + return new OSXKeyboard(device, queue, components_array, new Controller[]{}, new Rumbler[]{}); } - private final static Mouse createMouseFromDevice(OSXHIDDevice device, List elements) throws IOException { - List components = new ArrayList(); + private final static Mouse createMouseFromDevice(OSXHIDDevice device, List elements) throws IOException { + List components = new ArrayList<>(); OSXHIDQueue queue = device.createQueue(AbstractController.EVENT_QUEUE_DEPTH); try { addElements(queue, elements, components, true); @@ -204,8 +186,8 @@ public final class OSXEnvironmentPlugin extends ControllerEnvironment implements } } - private final static AbstractController createControllerFromDevice(OSXHIDDevice device, List elements, Controller.Type type) throws IOException { - List components = new ArrayList(); + private final static AbstractController createControllerFromDevice(OSXHIDDevice device, List elements, Controller.Type type) throws IOException { + List components = new ArrayList<>(); OSXHIDQueue queue = device.createQueue(AbstractController.EVENT_QUEUE_DEPTH); try { addElements(queue, elements, components, false); @@ -215,15 +197,14 @@ public final class OSXEnvironmentPlugin extends ControllerEnvironment implements } Component[] components_array = new Component[components.size()]; components.toArray(components_array); - AbstractController controller = new OSXAbstractController(device, queue, components_array, new Controller[]{}, new Rumbler[]{}, type); - return controller; + return new OSXAbstractController(device, queue, components_array, new Controller[]{}, new Rumbler[]{}, type); } - private final static void createControllersFromDevice(OSXHIDDevice device, List controllers) throws IOException { + private final static void createControllersFromDevice(OSXHIDDevice device, List controllers) throws IOException { UsagePair usage_pair = device.getUsagePair(); if (usage_pair == null) return; - List elements = device.getElements(); + List elements = device.getElements(); if (usage_pair.getUsagePage() == UsagePage.GENERIC_DESKTOP && (usage_pair.getUsage() == GenericDesktopUsage.MOUSE || usage_pair.getUsage() == GenericDesktopUsage.POINTER)) { Controller mouse = createMouseFromDevice(device, elements); @@ -231,26 +212,18 @@ public final class OSXEnvironmentPlugin extends ControllerEnvironment implements controllers.add(mouse); } else if (usage_pair.getUsagePage() == UsagePage.GENERIC_DESKTOP && (usage_pair.getUsage() == GenericDesktopUsage.KEYBOARD || usage_pair.getUsage() == GenericDesktopUsage.KEYPAD)) { - Controller keyboard = createKeyboardFromDevice(device, elements); - if (keyboard != null) - controllers.add(keyboard); + controllers.add(createKeyboardFromDevice(device, elements)); } else if (usage_pair.getUsagePage() == UsagePage.GENERIC_DESKTOP && usage_pair.getUsage() == GenericDesktopUsage.JOYSTICK) { - Controller joystick = createControllerFromDevice(device, elements, Controller.Type.STICK); - if (joystick != null) - controllers.add(joystick); + controllers.add(createControllerFromDevice(device, elements, Controller.Type.STICK)); } else if (usage_pair.getUsagePage() == UsagePage.GENERIC_DESKTOP && usage_pair.getUsage() == GenericDesktopUsage.MULTI_AXIS_CONTROLLER) { - Controller multiaxis = createControllerFromDevice(device, elements, Controller.Type.STICK); - if (multiaxis != null) - controllers.add(multiaxis); + controllers.add(createControllerFromDevice(device, elements, Controller.Type.STICK)); } else if (usage_pair.getUsagePage() == UsagePage.GENERIC_DESKTOP && usage_pair.getUsage() == GenericDesktopUsage.GAME_PAD) { - Controller game_pad = createControllerFromDevice(device, elements, Controller.Type.GAMEPAD); - if (game_pad != null) - controllers.add(game_pad); + controllers.add(createControllerFromDevice(device, elements, Controller.Type.GAMEPAD)); } } private final static Controller[] enumerateControllers() { - List controllers = new ArrayList(); + List controllers = new ArrayList<>(); try { OSXHIDDeviceIterator it = new OSXHIDDeviceIterator(); try { diff --git a/plugins/OSX/src/main/java/net/java/games/input/OSXHIDDevice.java b/plugins/OSX/src/main/java/net/java/games/input/OSXHIDDevice.java index 40024c3..7ac4831 100644 --- a/plugins/OSX/src/main/java/net/java/games/input/OSXHIDDevice.java +++ b/plugins/OSX/src/main/java/net/java/games/input/OSXHIDDevice.java @@ -1,41 +1,35 @@ /* - * %W% %E% + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistribution of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materails provided with the distribution. + * + * Neither the name Sun Microsystems, Inc. or the names of the contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. + * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING + * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR + * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND + * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS + * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS + * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST + * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, + * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY + * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, + * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for us in + * the design, construction, operation or maintenance of any nuclear facility * - * Copyright 2002 Sun Microsystems, Inc. All rights reserved. - * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ -/***************************************************************************** -* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* -* - Redistribution of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* - Redistribution in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation -* and/or other materails provided with the distribution. -* -* Neither the name Sun Microsystems, Inc. or the names of the contributors -* may be used to endorse or promote products derived from this software -* without specific prior written permission. -* -* This software is provided "AS IS," without a warranty of any kind. -* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING -* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR -* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND -* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS -* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS -* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST -* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, -* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY -* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, -* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. -* -* You acknowledge that this software is not designed or intended for us in -* the design, construction, operation or maintenance of any nuclear facility -* -*****************************************************************************/ package net.java.games.input; import java.io.IOException; @@ -104,7 +98,7 @@ final class OSXHIDDevice { private final long device_address; private final long device_interface_address; - private final Map properties; + private final Map properties; private boolean released; @@ -130,7 +124,7 @@ final class OSXHIDDevice { return (String)properties.get(kIOHIDProductKey); } - private final OSXHIDElement createElementFromElementProperties(Map element_properties) { + private final OSXHIDElement createElementFromElementProperties(Map element_properties) { /* long size = getLongFromProperties(element_properties, kIOHIDElementSizeKey); // ignore elements that can't fit into the 32 bit value field of a hid event if (size > 32) @@ -161,12 +155,13 @@ final class OSXHIDDevice { } } - private final void addElements(List elements, Map properties) { + @SuppressWarnings("unchecked") + private final void addElements(List elements, Map properties) { Object[] elements_properties = (Object[])properties.get(kIOHIDElementKey); if (elements_properties == null) return; for (int i = 0; i < elements_properties.length; i++) { - Map element_properties = (Map)elements_properties[i]; + Map element_properties = (Map)elements_properties[i]; OSXHIDElement element = createElementFromElementProperties(element_properties); if (element != null) { elements.add(element); @@ -175,28 +170,28 @@ final class OSXHIDDevice { } } - public final List getElements() { - List elements = new ArrayList(); + public final List getElements() { + List elements = new ArrayList<>(); addElements(elements, properties); return elements; } - private final static long getLongFromProperties(Map properties, String key, long default_value) { + private final static long getLongFromProperties(Map properties, String key, long default_value) { Long long_obj = (Long)properties.get(key); if (long_obj == null) return default_value; return long_obj.longValue(); } - private final static boolean getBooleanFromProperties(Map properties, String key, boolean default_value) { + private final static boolean getBooleanFromProperties(Map properties, String key, boolean default_value) { return getLongFromProperties(properties, key, default_value ? 1 : 0) != 0; } - private final static int getIntFromProperties(Map properties, String key) { + private final static int getIntFromProperties(Map properties, String key) { return (int)getLongFromProperties(properties, key); } - private final static long getLongFromProperties(Map properties, String key) { + private final static long getLongFromProperties(Map properties, String key) { Long long_obj = (Long)properties.get(key); return long_obj.longValue(); } @@ -217,28 +212,6 @@ final class OSXHIDDevice { return createUsagePair(usage_page_id, usage_id); } -/* - public final List getUsagePairs() { - List usage_pairs_list = new ArrayList(); - Object[] usage_pairs = (Object[])properties.get(kIOHIDDeviceUsagePairsKey); - if (usage_pairs == null) { - int usage_page_id = getIntFromProperties(properties, kIOHIDPrimaryUsagePageKey); - int usage_id = getIntFromProperties(properties, kIOHIDPrimaryUsageKey); - UsagePair pair = createUsagePair(usage_page_id, usage_id); - if (pair != null) - usage_pairs_list.add(pair); - } - for (int i = 0; i < usage_pairs.length; i++) { - Map usage_pair = (Map)usage_pairs[i]; - int usage_page_id = getIntFromProperties(usage_pair, kIOHIDDeviceUsagePageKey); - int usage_id = getIntFromProperties(usage_pair, kIOHIDDeviceUsageKey); - UsagePair pair = createUsagePair(usage_page_id, usage_id); - if (pair != null) - usage_pairs_list.add(pair); - } - return usage_pairs_list; - } -*/ private final void dumpProperties() { log.info(toString()); dumpMap("", properties); @@ -253,8 +226,8 @@ final class OSXHIDDevice { log.info(prefix + "}"); } - private final static void dumpMap(String prefix, Map map) { - Iterator keys = map.keySet().iterator(); + private final static void dumpMap(String prefix, Map map) { + Iterator keys = map.keySet().iterator(); while (keys.hasNext()) { Object key = keys.next(); Object value = map.get(key); @@ -262,23 +235,24 @@ final class OSXHIDDevice { dumpObject(prefix + "\t", value); } } - + + @SuppressWarnings("unchecked") private final static void dumpObject(String prefix, Object obj) { if (obj instanceof Long) { Long l = (Long)obj; log.info(prefix + "0x" + Long.toHexString(l.longValue())); } else if (obj instanceof Map) - dumpMap(prefix, (Map)obj); + dumpMap(prefix, (Map)obj); else if (obj.getClass().isArray()) dumpArray(prefix, (Object[])obj); else log.info(prefix + obj); } - private final Map getDeviceProperties() throws IOException { + private final Map getDeviceProperties() throws IOException { return nGetDeviceProperties(device_address); } - private final static native Map nGetDeviceProperties(long device_address) throws IOException; + private final static native Map nGetDeviceProperties(long device_address) throws IOException; public final synchronized void release() throws IOException { try { diff --git a/plugins/OSX/src/main/java/net/java/games/input/OSXHIDQueue.java b/plugins/OSX/src/main/java/net/java/games/input/OSXHIDQueue.java index 884c76a..f97cf6a 100644 --- a/plugins/OSX/src/main/java/net/java/games/input/OSXHIDQueue.java +++ b/plugins/OSX/src/main/java/net/java/games/input/OSXHIDQueue.java @@ -1,41 +1,35 @@ /* - * %W% %E% + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistribution of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materails provided with the distribution. + * + * Neither the name Sun Microsystems, Inc. or the names of the contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. + * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING + * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR + * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND + * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS + * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS + * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST + * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, + * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY + * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, + * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for us in + * the design, construction, operation or maintenance of any nuclear facility * - * Copyright 2002 Sun Microsystems, Inc. All rights reserved. - * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ -/***************************************************************************** -* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* -* - Redistribution of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* - Redistribution in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation -* and/or other materails provided with the distribution. -* -* Neither the name Sun Microsystems, Inc. or the names of the contributors -* may be used to endorse or promote products derived from this software -* without specific prior written permission. -* -* This software is provided "AS IS," without a warranty of any kind. -* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING -* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR -* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND -* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS -* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS -* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST -* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, -* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY -* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, -* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. -* -* You acknowledge that this software is not designed or intended for us in -* the design, construction, operation or maintenance of any nuclear facility -* -*****************************************************************************/ package net.java.games.input; import java.io.IOException; @@ -47,7 +41,7 @@ import java.util.HashMap; * @version 1.0 */ final class OSXHIDQueue { - private final Map map = new HashMap(); + private final Map map = new HashMap<>(); private final long queue_address; private boolean released; @@ -80,7 +74,7 @@ final class OSXHIDQueue { } public final OSXComponent mapEvent(OSXEvent event) { - return (OSXComponent)map.get(new Long(event.getCookie())); + return map.get(event.getCookie()); } private final void open(int queue_depth) throws IOException { @@ -118,13 +112,13 @@ final class OSXHIDQueue { public final void addElement(OSXHIDElement element, OSXComponent component) throws IOException { nAddElement(queue_address, element.getCookie()); - map.put(new Long(element.getCookie()), component); + map.put(element.getCookie(), component); } private final static native void nAddElement(long queue_address, long cookie) throws IOException; public final void removeElement(OSXHIDElement element) throws IOException { nRemoveElement(queue_address, element.getCookie()); - map.remove(new Long(element.getCookie())); + map.remove(element.getCookie()); } private final static native void nRemoveElement(long queue_address, long cookie) throws IOException; diff --git a/plugins/OSX/src/main/java/net/java/games/input/Usage.java b/plugins/OSX/src/main/java/net/java/games/input/Usage.java index 8b79b3a..356ee94 100644 --- a/plugins/OSX/src/main/java/net/java/games/input/Usage.java +++ b/plugins/OSX/src/main/java/net/java/games/input/Usage.java @@ -1,41 +1,35 @@ /* - * %W% %E% + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistribution of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materails provided with the distribution. + * + * Neither the name Sun Microsystems, Inc. or the names of the contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. + * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING + * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR + * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND + * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS + * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS + * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST + * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, + * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY + * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, + * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for us in + * the design, construction, operation or maintenance of any nuclear facility * - * Copyright 2002 Sun Microsystems, Inc. All rights reserved. - * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ -/***************************************************************************** -* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* -* - Redistribution of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* - Redistribution in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation -* and/or other materails provided with the distribution. -* -* Neither the name Sun Microsystems, Inc. or the names of the contributors -* may be used to endorse or promote products derived from this software -* without specific prior written permission. -* -* This software is provided "AS IS," without a warranty of any kind. -* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING -* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR -* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND -* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS -* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS -* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST -* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, -* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY -* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, -* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. -* -* You acknowledge that this software is not designed or intended for us in -* the design, construction, operation or maintenance of any nuclear facility -* -*****************************************************************************/ package net.java.games.input; /** Generic Desktop Usages diff --git a/plugins/OSX/src/main/java/net/java/games/input/UsagePage.java b/plugins/OSX/src/main/java/net/java/games/input/UsagePage.java index bd50eab..59e0b9b 100644 --- a/plugins/OSX/src/main/java/net/java/games/input/UsagePage.java +++ b/plugins/OSX/src/main/java/net/java/games/input/UsagePage.java @@ -1,41 +1,35 @@ /* - * %W% %E% + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistribution of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materails provided with the distribution. + * + * Neither the name Sun Microsystems, Inc. or the names of the contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. + * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING + * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR + * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND + * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS + * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS + * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST + * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, + * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY + * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, + * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for us in + * the design, construction, operation or maintenance of any nuclear facility * - * Copyright 2002 Sun Microsystems, Inc. All rights reserved. - * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ -/***************************************************************************** -* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* -* - Redistribution of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* - Redistribution in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation -* and/or other materails provided with the distribution. -* -* Neither the name Sun Microsystems, Inc. or the names of the contributors -* may be used to endorse or promote products derived from this software -* without specific prior written permission. -* -* This software is provided "AS IS," without a warranty of any kind. -* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING -* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR -* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND -* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS -* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS -* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST -* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, -* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY -* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, -* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. -* -* You acknowledge that this software is not designed or intended for us in -* the design, construction, operation or maintenance of any nuclear facility -* -*****************************************************************************/ package net.java.games.input; import java.lang.reflect.Method; @@ -77,7 +71,7 @@ final class UsagePage { /* ReservedPointofSalepages 0x8E - 0X8F */ public final static UsagePage CAMERACONTROL= new UsagePage(0x90); /* USB Device Class Definition for Image Class Devices */ public final static UsagePage ARCADE = new UsagePage(0x91); /* OAAF Definitions for arcade and coinop related Devices */ - private final Class usage_class; + private final Class usage_class; private final int usage_page_id; public final static UsagePage map(int page_id) { @@ -86,7 +80,7 @@ final class UsagePage { return map[page_id]; } - private UsagePage(int page_id, Class usage_class) { + private UsagePage(int page_id, Class usage_class) { map[page_id] = this; this.usage_class = usage_class; this.usage_page_id = page_id; @@ -104,8 +98,8 @@ final class UsagePage { if (usage_class == null) return null; try { - Method map_method = usage_class.getMethod("map", new Class[]{int.class}); - Object result = map_method.invoke(null, new Object[]{new Integer(usage_id)}); + Method map_method = usage_class.getMethod("map", int.class); + Object result = map_method.invoke(null, usage_id); return (Usage)result; } catch (Exception e) { throw new Error(e); diff --git a/plugins/awt/src/main/java/net/java/games/input/AWTKeyboard.java b/plugins/awt/src/main/java/net/java/games/input/AWTKeyboard.java index dafd4df..b30a39d 100644 --- a/plugins/awt/src/main/java/net/java/games/input/AWTKeyboard.java +++ b/plugins/awt/src/main/java/net/java/games/input/AWTKeyboard.java @@ -1,4 +1,4 @@ -/** +/* * Copyright (C) 2004 Jeremy Booth (jeremy@newdawnsoftware.com) * * Redistribution and use in source and binary forms, with or without @@ -43,7 +43,7 @@ import java.lang.reflect.Modifier; * @author elias */ final class AWTKeyboard extends Keyboard implements AWTEventListener { - private final List awt_events = new ArrayList(); + private final List awt_events = new ArrayList<>(); private Event[] processed_events; private int processed_events_index; @@ -54,7 +54,7 @@ final class AWTKeyboard extends Keyboard implements AWTEventListener { } private final static Component[] createComponents() { - List components = new ArrayList(); + List components = new ArrayList<>(); Field[] vkey_fields = KeyEvent.class.getFields(); for (int i = 0; i < vkey_fields.length; i++) { Field vkey_field = vkey_fields[i]; @@ -80,7 +80,7 @@ final class AWTKeyboard extends Keyboard implements AWTEventListener { components.add(new Key(Component.Identifier.Key.RETURN)); components.add(new Key(Component.Identifier.Key.NUMPADCOMMA)); components.add(new Key(Component.Identifier.Key.COMMA)); - return (Component[])components.toArray(new Component[]{}); + return components.toArray(new Component[]{}); } private final void resizeEventQueue(int size) { @@ -96,13 +96,12 @@ final class AWTKeyboard extends Keyboard implements AWTEventListener { public final synchronized void eventDispatched(AWTEvent event) { if (event instanceof KeyEvent) - awt_events.add(event); + awt_events.add((KeyEvent)event); } public final synchronized void pollDevice() throws IOException { for (int i = 0; i < awt_events.size(); i++) { - KeyEvent event = (KeyEvent)awt_events.get(i); - processEvent(event); + processEvent(awt_events.get(i)); } awt_events.clear(); } diff --git a/plugins/awt/src/main/java/net/java/games/input/AWTMouse.java b/plugins/awt/src/main/java/net/java/games/input/AWTMouse.java index 37c8eee..8f8cb06 100644 --- a/plugins/awt/src/main/java/net/java/games/input/AWTMouse.java +++ b/plugins/awt/src/main/java/net/java/games/input/AWTMouse.java @@ -1,4 +1,4 @@ -/** +/* * Copyright (C) 2004 Jeremy Booth (jeremy@newdawnsoftware.com) * * Redistribution and use in source and binary forms, with or without @@ -27,7 +27,6 @@ package net.java.games.input; import java.awt.AWTEvent; -import java.awt.Point; import java.awt.Toolkit; import java.awt.event.AWTEventListener; import java.awt.event.MouseEvent; @@ -47,8 +46,8 @@ final class AWTMouse extends Mouse implements AWTEventListener { private final static int EVENT_Y = 2; private final static int EVENT_BUTTON = 4; - private final List awt_events = new ArrayList(); - private final List processed_awt_events = new ArrayList(); + private final List awt_events = new ArrayList<>(); + private final List processed_awt_events = new ArrayList<>(); private int event_state = EVENT_X; @@ -115,7 +114,7 @@ final class AWTMouse extends Mouse implements AWTEventListener { Axis wheel = (Axis)getWheel(); wheel.setValue(0); for (int i = 0; i < awt_events.size(); i++) { - AWTEvent event = (AWTEvent)awt_events.get(i); + AWTEvent event = awt_events.get(i); processEvent(event); processed_awt_events.add(event); } @@ -126,7 +125,7 @@ final class AWTMouse extends Mouse implements AWTEventListener { while (true) { if (processed_awt_events.isEmpty()) return false; - AWTEvent awt_event = (AWTEvent)processed_awt_events.get(0); + AWTEvent awt_event = processed_awt_events.get(0); if (awt_event instanceof MouseWheelEvent) { MouseWheelEvent awt_wheel_event = (MouseWheelEvent)awt_event; long nanos = awt_wheel_event.getWhen()*1000000L; diff --git a/plugins/linux/pom.xml b/plugins/linux/pom.xml index 6cd37f0..348b2be 100644 --- a/plugins/linux/pom.xml +++ b/plugins/linux/pom.xml @@ -29,12 +29,6 @@ maven-compiler-plugin - - - -h - ${project.build.directory}/generated-sources/natives - - maven-antrun-plugin diff --git a/plugins/linux/src/main/java/net/java/games/input/LinuxDeviceThread.java b/plugins/linux/src/main/java/net/java/games/input/LinuxDeviceThread.java index 62d1849..f550c24 100644 --- a/plugins/linux/src/main/java/net/java/games/input/LinuxDeviceThread.java +++ b/plugins/linux/src/main/java/net/java/games/input/LinuxDeviceThread.java @@ -40,7 +40,7 @@ import java.util.ArrayList; * is run on a single thread. */ final class LinuxDeviceThread extends Thread { - private final List tasks = new ArrayList(); + private final List tasks = new ArrayList<>(); public LinuxDeviceThread() { setDaemon(true); @@ -50,7 +50,7 @@ final class LinuxDeviceThread extends Thread { public synchronized final void run() { while (true) { if (!tasks.isEmpty()) { - LinuxDeviceTask task = (LinuxDeviceTask)tasks.remove(0); + LinuxDeviceTask task = tasks.remove(0); task.doExecute(); synchronized (task) { task.notify(); diff --git a/plugins/linux/src/main/java/net/java/games/input/LinuxEnvironmentPlugin.java b/plugins/linux/src/main/java/net/java/games/input/LinuxEnvironmentPlugin.java index 633f832..035b8f7 100644 --- a/plugins/linux/src/main/java/net/java/games/input/LinuxEnvironmentPlugin.java +++ b/plugins/linux/src/main/java/net/java/games/input/LinuxEnvironmentPlugin.java @@ -47,7 +47,7 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen private static boolean supported = false; private final Controller[] controllers; - private final List devices = new ArrayList(); + private final List devices = new ArrayList(); private final static LinuxDeviceThread device_thread = new LinuxDeviceThread(); /** @@ -58,9 +58,7 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen * */ static void loadLibrary(final String lib_name) { - AccessController.doPrivileged( - new PrivilegedAction() { - public final Object run() { + AccessController.doPrivileged((PrivilegedAction) () -> { String lib_path = System.getProperty("net.java.games.input.librarypath"); try { if(lib_path != null) @@ -73,25 +71,16 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen supported = false; } return null; - } }); } static String getPrivilegedProperty(final String property) { - return (String) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - return System.getProperty(property); - } - }); + return AccessController.doPrivileged((PrivilegedAction)() -> System.getProperty(property)); } static String getPrivilegedProperty(final String property, final String default_value) { - return (String) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - return System.getProperty(property, default_value); - } - }); + return AccessController.doPrivileged((PrivilegedAction)() -> System.getProperty(property, default_value)); } static { @@ -114,12 +103,9 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen if(isSupported()) { this.controllers = enumerateControllers(); log("Linux plugin claims to have found " + controllers.length + " controllers"); - AccessController.doPrivileged( - new PrivilegedAction() { - public final Object run() { + AccessController.doPrivileged((PrivilegedAction)() -> { Runtime.getRuntime().addShutdownHook(new ShutdownHook()); return null; - } }); } else { controllers = new Controller[0]; @@ -135,11 +121,11 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen return controllers; } - private final static Component[] createComponents(List event_components, LinuxEventDevice device) { + private final static Component[] createComponents(List event_components, LinuxEventDevice device) { LinuxEventComponent[][] povs = new LinuxEventComponent[4][2]; - List components = new ArrayList(); + List components = new ArrayList<>(); for(int i = 0; i < event_components.size(); i++) { - LinuxEventComponent event_component = (LinuxEventComponent) event_components.get(i); + LinuxEventComponent event_component = event_components.get(i); Component.Identifier identifier = event_component.getIdentifier(); if(identifier == Component.Identifier.Axis.POV) { @@ -213,7 +199,7 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen } private final static Controller createControllerFromDevice(LinuxEventDevice device) throws IOException { - List event_components = device.getComponents(); + List event_components = device.getComponents(); Component[] components = createComponents(event_components, device); Controller.Type type = device.getType(); @@ -228,16 +214,16 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen } private final Controller[] enumerateControllers() { - List controllers = new ArrayList(); - List eventControllers = new ArrayList(); - List jsControllers = new ArrayList(); + List controllers = new ArrayList<>(); + List eventControllers = new ArrayList<>(); + List jsControllers = new ArrayList<>(); enumerateEventControllers(eventControllers); enumerateJoystickControllers(jsControllers); for(int i = 0; i < eventControllers.size(); i++) { for(int j = 0; j < jsControllers.size(); j++) { - Controller evController = (Controller) eventControllers.get(i); - Controller jsController = (Controller) jsControllers.get(j); + Controller evController = eventControllers.get(i); + Controller jsController = jsControllers.get(j); // compare // Check if the nodes have the same name @@ -345,13 +331,13 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen } private final static Controller createJoystickFromJoystickDevice(LinuxJoystickDevice device) { - List components = new ArrayList(); + List components = new ArrayList<>(); byte[] axisMap = device.getAxisMap(); char[] buttonMap = device.getButtonMap(); LinuxJoystickAxis[] hatBits = new LinuxJoystickAxis[6]; for(int i = 0; i < device.getNumButtons(); i++) { - Component.Identifier button_id = (Component.Identifier) LinuxNativeTypesMap.getButtonID(buttonMap[i]); + Component.Identifier button_id = LinuxNativeTypesMap.getButtonID(buttonMap[i]); if(button_id != null) { LinuxJoystickButton button = new LinuxJoystickButton(button_id); device.registerButton(i, button); @@ -391,10 +377,10 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen } } - return new LinuxJoystickAbstractController(device, (Component[]) components.toArray(new Component[]{}), new Controller[]{}, new Rumbler[]{}); + return new LinuxJoystickAbstractController(device, components.toArray(new Component[]{}), new Controller[]{}, new Rumbler[]{}); } - private final void enumerateJoystickControllers(List controllers) { + private final void enumerateJoystickControllers(List controllers) { File[] joystick_device_files = enumerateJoystickDeviceFiles("/dev/input"); if(joystick_device_files == null || joystick_device_files.length == 0) { joystick_device_files = enumerateJoystickDeviceFiles("/dev"); @@ -428,39 +414,26 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen } private static String getAbsolutePathPrivileged(final File file) { - return (String) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - return file.getAbsolutePath(); - } - }); + return AccessController.doPrivileged((PrivilegedAction) () -> file.getAbsolutePath()); } private static File[] listFilesPrivileged(final File dir, final FilenameFilter filter) { - return (File[]) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { + return AccessController.doPrivileged((PrivilegedAction) () -> { File[] files = dir.listFiles(filter); if(files == null) { log("dir " + dir.getName() + " exists: " + dir.exists() + ", is writable: " + dir.isDirectory()); files = new File[]{}; } else { - Arrays.sort(files, new Comparator() { - public int compare(Object f1, Object f2) { - return ((File) f1).getName().compareTo(((File) f2).getName()); - } - }); + Arrays.sort(files, Comparator.comparing(File::getName)); } return files; - } }); } - private final void enumerateEventControllers(List controllers) { + private final void enumerateEventControllers(List controllers) { final File dev = new File("/dev/input"); - File[] event_device_files = listFilesPrivileged(dev, new FilenameFilter() { - public final boolean accept(File dir, String name) { - return name.startsWith("event"); - } - }); + File[] event_device_files = listFilesPrivileged(dev, (File dir, String name) -> name.startsWith("event")); + if(event_device_files == null) return; for(int i = 0; i < event_device_files.length; i++) { @@ -489,7 +462,7 @@ public final class LinuxEnvironmentPlugin extends ControllerEnvironment implemen public final void run() { for(int i = 0; i < devices.size(); i++) { try { - LinuxDevice device = (LinuxDevice) devices.get(i); + LinuxDevice device = devices.get(i); device.close(); } catch(IOException e) { log("Failed to close device: " + e.getMessage()); diff --git a/plugins/linux/src/main/java/net/java/games/input/LinuxEventDevice.java b/plugins/linux/src/main/java/net/java/games/input/LinuxEventDevice.java index 45c45c3..a69f9e8 100644 --- a/plugins/linux/src/main/java/net/java/games/input/LinuxEventDevice.java +++ b/plugins/linux/src/main/java/net/java/games/input/LinuxEventDevice.java @@ -1,4 +1,4 @@ -/** +/* * Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com) * * Redistribution and use in source and binary forms, with or without @@ -35,12 +35,12 @@ import java.util.ArrayList; * @author elias */ final class LinuxEventDevice implements LinuxDevice { - private final Map component_map = new HashMap(); + private final Map component_map = new HashMap<>(); private final Rumbler[] rumblers; private final long fd; private final String name; private final LinuxInputID input_id; - private final List components; + private final List components; private final Controller.Type type; /* Closed state variable that protects the validity of the file descriptor. @@ -83,10 +83,10 @@ final class LinuxEventDevice implements LinuxDevice { return type; } - private final static int countComponents(List components, Class id_type, boolean relative) { + private final static int countComponents(List components, Class id_type, boolean relative) { int count = 0; for (int i = 0; i < components.size(); i++) { - LinuxEventComponent component = (LinuxEventComponent)components.get(i); + LinuxEventComponent component = components.get(i); if (id_type.isInstance(component.getIdentifier()) && relative == component.isRelative()) count++; } @@ -94,7 +94,7 @@ final class LinuxEventDevice implements LinuxDevice { } private final Controller.Type guessType() throws IOException { - List components = getComponents(); + List components = getComponents(); if (components.size() == 0) return Controller.Type.UNKNOWN; int num_rel_axes = countComponents(components, Component.Identifier.Axis.class, true); @@ -118,7 +118,7 @@ final class LinuxEventDevice implements LinuxDevice { int num_gamepad_button_traits = 0; // count button traits for (int i = 0; i < components.size(); i++) { - LinuxEventComponent component = (LinuxEventComponent)components.get(i); + LinuxEventComponent component = components.get(i); if (component.getButtonTrait() == Controller.Type.MOUSE) num_mouse_button_traits++; else if (component.getButtonTrait() == Controller.Type.KEYBOARD) @@ -158,11 +158,11 @@ final class LinuxEventDevice implements LinuxDevice { } private final Rumbler[] enumerateRumblers() { - List rumblers = new ArrayList(); + List rumblers = new ArrayList<>(); try { int num_effects = getNumEffects(); if (num_effects <= 0) - return (Rumbler[])rumblers.toArray(new Rumbler[]{}); + return rumblers.toArray(new Rumbler[]{}); byte[] ff_bits = getForceFeedbackBits(); if (isBitSet(ff_bits, NativeDefinitions.FF_RUMBLE) && num_effects > rumblers.size()) { rumblers.add(new LinuxRumbleFF(this)); @@ -170,7 +170,7 @@ final class LinuxEventDevice implements LinuxDevice { } catch (IOException e) { LinuxEnvironmentPlugin.log("Failed to enumerate rumblers: " + e.getMessage()); } - return (Rumbler[])rumblers.toArray(new Rumbler[]{}); + return rumblers.toArray(new Rumbler[]{}); } public final Rumbler[] getRumblers() { @@ -205,7 +205,7 @@ final class LinuxEventDevice implements LinuxDevice { } public final LinuxComponent mapDescriptor(LinuxAxisDescriptor desc) { - return (LinuxComponent)component_map.get(desc); + return component_map.get(desc); } public final Controller.PortType getPortType() throws IOException { @@ -243,7 +243,7 @@ final class LinuxEventDevice implements LinuxDevice { } private final static native void nGetAbsInfo(long fd, int abs_axis, LinuxAbsInfo abs_info) throws IOException; - private final void addKeys(List components) throws IOException { + private final void addKeys(List components) throws IOException { byte[] bits = getKeysBits(); for (int i = 0; i < bits.length*8; i++) { if (isBitSet(bits, i)) { @@ -253,7 +253,7 @@ final class LinuxEventDevice implements LinuxDevice { } } - private final void addAbsoluteAxes(List components) throws IOException { + private final void addAbsoluteAxes(List components) throws IOException { byte[] bits = getAbsoluteAxesBits(); for (int i = 0; i < bits.length*8; i++) { if (isBitSet(bits, i)) { @@ -263,7 +263,7 @@ final class LinuxEventDevice implements LinuxDevice { } } - private final void addRelativeAxes(List components) throws IOException { + private final void addRelativeAxes(List components) throws IOException { byte[] bits = getRelativeAxesBits(); for (int i = 0; i < bits.length*8; i++) { if (isBitSet(bits, i)) { @@ -273,12 +273,12 @@ final class LinuxEventDevice implements LinuxDevice { } } - public final List getComponents() { + public final List getComponents() { return components; } - private final List getDeviceComponents() throws IOException { - List components = new ArrayList(); + private final List getDeviceComponents() throws IOException { + List components = new ArrayList<>(); byte[] evtype_bits = getEventTypeBits(); if (isBitSet(evtype_bits, NativeDefinitions.EV_KEY)) addKeys(components); @@ -360,6 +360,7 @@ final class LinuxEventDevice implements LinuxDevice { throw new IOException("Device is closed"); } + @SuppressWarnings("deprecation") protected void finalize() throws IOException { close(); } diff --git a/plugins/linux/src/main/java/net/java/games/input/LinuxJoystickDevice.java b/plugins/linux/src/main/java/net/java/games/input/LinuxJoystickDevice.java index 0dcd5da..c749684 100644 --- a/plugins/linux/src/main/java/net/java/games/input/LinuxJoystickDevice.java +++ b/plugins/linux/src/main/java/net/java/games/input/LinuxJoystickDevice.java @@ -1,4 +1,4 @@ -/** +/* * Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com) * * Redistribution and use in source and binary forms, with or without @@ -28,8 +28,6 @@ package net.java.games.input; import java.io.IOException; import java.util.Map; import java.util.HashMap; -import java.util.List; -import java.util.ArrayList; /** * @author elias @@ -48,8 +46,8 @@ final class LinuxJoystickDevice implements LinuxDevice { private final Event event = new Event(); private final LinuxJoystickButton[] buttons; private final LinuxJoystickAxis[] axes; - private final Map povXs = new HashMap(); - private final Map povYs = new HashMap(); + private final Map povXs = new HashMap<>(); + private final Map povYs = new HashMap<>(); private final byte[] axisMap; private final char[] buttonMap; @@ -102,12 +100,12 @@ final class LinuxJoystickDevice implements LinuxDevice { if (axis != null) { float value = (float)joystick_event.getValue()/AXIS_MAX_VALUE; axis.setValue(value); - if(povXs.containsKey(new Integer(index))) { - LinuxJoystickPOV pov = (LinuxJoystickPOV)(povXs.get(new Integer(index))); + if(povXs.containsKey(index)) { + LinuxJoystickPOV pov = povXs.get(index); pov.updateValue(); event.set(pov, pov.getPollData(), joystick_event.getNanos()); - } else if(povYs.containsKey(new Integer(index))) { - LinuxJoystickPOV pov = (LinuxJoystickPOV)(povYs.get(new Integer(index))); + } else if(povYs.containsKey(index)) { + LinuxJoystickPOV pov = povYs.get(index); pov.updateValue(); event.set(pov, pov.getPollData(), joystick_event.getNanos()); } else { @@ -150,8 +148,8 @@ final class LinuxJoystickDevice implements LinuxDevice { break; } } - povXs.put(new Integer(xIndex),pov); - povYs.put(new Integer(yIndex),pov); + povXs.put(xIndex,pov); + povYs.put(yIndex,pov); } public final synchronized boolean getNextEvent(Event event) throws IOException { @@ -233,6 +231,7 @@ final class LinuxJoystickDevice implements LinuxDevice { throw new IOException("Device is closed"); } + @SuppressWarnings("deprecation") protected void finalize() throws IOException { close(); } diff --git a/plugins/linux/src/main/java/net/java/games/input/LinuxRumbleFF.java b/plugins/linux/src/main/java/net/java/games/input/LinuxRumbleFF.java index 578793a..046eb14 100644 --- a/plugins/linux/src/main/java/net/java/games/input/LinuxRumbleFF.java +++ b/plugins/linux/src/main/java/net/java/games/input/LinuxRumbleFF.java @@ -1,4 +1,4 @@ -/** +/* * Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com) * * Redistribution and use in source and binary forms, with or without @@ -43,9 +43,9 @@ final class LinuxRumbleFF extends LinuxForceFeedbackEffect { weak_magnitude = (int)(0xc000*intensity); } else if (intensity > 0.3333333f) { strong_magnitude = (int)(0x8000*intensity); - weak_magnitude = (int)(0xc000*0); + weak_magnitude = 0; } else { - strong_magnitude = (int)(0x8000*0); + strong_magnitude = 0; weak_magnitude = (int)(0xc000*intensity); } diff --git a/plugins/windows/pom.xml b/plugins/windows/pom.xml index 185f7a0..11cdc17 100644 --- a/plugins/windows/pom.xml +++ b/plugins/windows/pom.xml @@ -29,12 +29,6 @@ maven-compiler-plugin - - - -h - ${project.build.directory}/generated-sources/natives - - maven-antrun-plugin diff --git a/plugins/windows/src/main/java/net/java/games/input/DataQueue.java b/plugins/windows/src/main/java/net/java/games/input/DataQueue.java index 8151d3f..a530bc6 100644 --- a/plugins/windows/src/main/java/net/java/games/input/DataQueue.java +++ b/plugins/windows/src/main/java/net/java/games/input/DataQueue.java @@ -1,10 +1,4 @@ /* - * %W% %E% - * - * Copyright 2002 Sun Microsystems, Inc. All rights reserved. - * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. - */ -/***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -38,23 +32,25 @@ *****************************************************************************/ package net.java.games.input; +import java.lang.reflect.Array; +import java.lang.reflect.InvocationTargetException; + /** * @author elias * @version 1.0 */ -final class DataQueue { - private final Object[] elements; +final class DataQueue { + private final T[] elements; private int position; private int limit; - public DataQueue(int size, Class element_type) { - this.elements= new Object[size]; + @SuppressWarnings("unchecked") + public DataQueue(int size, Class element_type) { + this.elements= (T[])Array.newInstance(element_type, size); for (int i = 0; i < elements.length; i++) { try { - elements[i] = element_type.newInstance(); - } catch (InstantiationException e) { - throw new RuntimeException(e); - } catch (IllegalAccessException e) { + elements[i] = element_type.getDeclaredConstructor().newInstance(); + } catch (InstantiationException|IllegalAccessException|NoSuchMethodException|InvocationTargetException e) { throw new RuntimeException(e); } } @@ -74,12 +70,12 @@ final class DataQueue { return limit; } - public final Object get(int index) { + public final T get(int index) { assert index < limit; return elements[index]; } - public final Object get() { + public final T get() { if (!hasRemaining()) return null; return get(position++); @@ -97,7 +93,7 @@ final class DataQueue { } private final void swap(int index1, int index2) { - Object temp = elements[index1]; + T temp = elements[index1]; elements[index1] = elements[index2]; elements[index2] = temp; } @@ -119,7 +115,7 @@ final class DataQueue { this.position = position; } - public final Object[] getElements() { + public final T[] getElements() { return elements; } } diff --git a/plugins/windows/src/main/java/net/java/games/input/DirectAndRawInputEnvironmentPlugin.java b/plugins/windows/src/main/java/net/java/games/input/DirectAndRawInputEnvironmentPlugin.java index c789986..29b6c07 100644 --- a/plugins/windows/src/main/java/net/java/games/input/DirectAndRawInputEnvironmentPlugin.java +++ b/plugins/windows/src/main/java/net/java/games/input/DirectAndRawInputEnvironmentPlugin.java @@ -53,7 +53,7 @@ public class DirectAndRawInputEnvironmentPlugin extends ControllerEnvironment { if(controllers == null) { boolean rawKeyboardFound = false; boolean rawMouseFound = false; - List tempControllers = new ArrayList(); + List tempControllers = new ArrayList<>(); Controller[] dinputControllers = dinputPlugin.getControllers(); Controller[] rawControllers = rawPlugin.getControllers(); for(int i=0;i) () -> { + try { String lib_path = System.getProperty("net.java.games.input.librarypath"); if (lib_path != null) System.load(lib_path + File.separator + System.mapLibraryName(lib_name)); @@ -78,25 +76,16 @@ public final class DirectInputEnvironmentPlugin extends ControllerEnvironment im supported = false; } return null; - } }); } static String getPrivilegedProperty(final String property) { - return (String)AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - return System.getProperty(property); - } - }); + return AccessController.doPrivileged((PrivilegedAction) () -> System.getProperty(property)); } static String getPrivilegedProperty(final String property, final String default_value) { - return (String)AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - return System.getProperty(property, default_value); - } - }); + return AccessController.doPrivileged((PrivilegedAction) () -> System.getProperty(property, default_value)); } static { @@ -112,7 +101,7 @@ public final class DirectInputEnvironmentPlugin extends ControllerEnvironment im } private final Controller[] controllers; - private final List active_devices = new ArrayList(); + private final List active_devices = new ArrayList<>(); private final DummyWindow window; /** Creates new DirectInputEnvironment */ @@ -133,12 +122,9 @@ public final class DirectInputEnvironmentPlugin extends ControllerEnvironment im } this.window = window; this.controllers = controllers; - AccessController.doPrivileged( - new PrivilegedAction() { - public final Object run() { + AccessController.doPrivileged((PrivilegedAction) () -> { Runtime.getRuntime().addShutdownHook(new ShutdownHook()); return null; - } }); } else { // These are final fields, so can't set them, then over ride @@ -153,10 +139,10 @@ public final class DirectInputEnvironmentPlugin extends ControllerEnvironment im } private final Component[] createComponents(IDirectInputDevice device, boolean map_mouse_buttons) { - List device_objects = device.getObjects(); - List controller_components = new ArrayList(); + List device_objects = device.getObjects(); + List controller_components = new ArrayList<>(); for (int i = 0; i < device_objects.size(); i++) { - DIDeviceObject device_object = (DIDeviceObject)device_objects.get(i); + DIDeviceObject device_object = device_objects.get(i); Component.Identifier identifier = device_object.getIdentifier(); if (identifier == null) continue; @@ -214,12 +200,12 @@ public final class DirectInputEnvironmentPlugin extends ControllerEnvironment im } private final Controller[] enumControllers(DummyWindow window) throws IOException { - List controllers = new ArrayList(); + List controllers = new ArrayList<>(); IDirectInput dinput = new IDirectInput(window); try { - List devices = dinput.getDevices(); + List devices = dinput.getDevices(); for (int i = 0; i < devices.size(); i++) { - IDirectInputDevice device = (IDirectInputDevice)devices.get(i); + IDirectInputDevice device = devices.get(i); Controller controller = createControllerFromDevice(device); if (controller != null) { controllers.add(controller); @@ -239,7 +225,7 @@ public final class DirectInputEnvironmentPlugin extends ControllerEnvironment im public final void run() { /* Release the devices to kill off active force feedback effects */ for (int i = 0; i < active_devices.size(); i++) { - IDirectInputDevice device = (IDirectInputDevice)active_devices.get(i); + IDirectInputDevice device = active_devices.get(i); device.release(); } /* We won't release the window since it is @@ -251,4 +237,4 @@ public final class DirectInputEnvironmentPlugin extends ControllerEnvironment im public boolean isSupported() { return supported; } -} // class DirectInputEnvironment +} \ No newline at end of file diff --git a/plugins/windows/src/main/java/net/java/games/input/IDirectInput.java b/plugins/windows/src/main/java/net/java/games/input/IDirectInput.java index c211261..e8c929b 100644 --- a/plugins/windows/src/main/java/net/java/games/input/IDirectInput.java +++ b/plugins/windows/src/main/java/net/java/games/input/IDirectInput.java @@ -48,7 +48,7 @@ import java.util.ArrayList; * @version 1.0 */ final class IDirectInput { - private final List devices = new ArrayList(); + private final List devices = new ArrayList<>(); private final long idirectinput_address; private final DummyWindow window; @@ -65,7 +65,7 @@ final class IDirectInput { } private final static native long createIDirectInput() throws IOException; - public final List getDevices() { + public final List getDevices() { return devices; } @@ -88,7 +88,7 @@ final class IDirectInput { public final void releaseDevices() { for (int i = 0; i < devices.size(); i++) { - IDirectInputDevice device = (IDirectInputDevice)devices.get(i); + IDirectInputDevice device = devices.get(i); device.release(); } } diff --git a/plugins/windows/src/main/java/net/java/games/input/IDirectInputDevice.java b/plugins/windows/src/main/java/net/java/games/input/IDirectInputDevice.java index 928f398..3fb29f7 100644 --- a/plugins/windows/src/main/java/net/java/games/input/IDirectInputDevice.java +++ b/plugins/windows/src/main/java/net/java/games/input/IDirectInputDevice.java @@ -1,10 +1,4 @@ /* - * %W% %E% - * - * Copyright 2002 Sun Microsystems, Inc. All rights reserved. - * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. - */ -/***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -201,16 +195,16 @@ final class IDirectInputDevice { private final int dev_subtype; private final String instance_name; private final String product_name; - private final List objects = new ArrayList(); - private final List effects = new ArrayList(); - private final List rumblers = new ArrayList(); + private final List objects = new ArrayList<>(); + private final List effects = new ArrayList<>(); + private final List rumblers = new ArrayList<>(); private final int[] device_state; - private final Map object_to_component = new HashMap(); + private final Map object_to_component = new HashMap<>(); private final boolean axes_in_relative_mode; private boolean released; - private DataQueue queue; + private DataQueue queue; private int button_counter; private int current_format_offset; @@ -242,7 +236,7 @@ final class IDirectInputDevice { boolean all_relative = true; boolean has_axis = false; for (int i = 0; i < objects.size(); i++) { - DIDeviceObject obj = (DIDeviceObject)objects.get(i); + DIDeviceObject obj = objects.get(i); if (obj.isAxis()) { has_axis = true; if (!obj.isRelative()) { @@ -272,10 +266,10 @@ final class IDirectInputDevice { } public final Rumbler[] getRumblers() { - return (Rumbler[])rumblers.toArray(new Rumbler[]{}); + return rumblers.toArray(new Rumbler[]{}); } - private final List createRumblers() throws IOException { + private final List createRumblers() throws IOException { DIDeviceObject x_axis = lookupObjectByGUID(GUID_XAxis); // DIDeviceObject y_axis = lookupObjectByGUID(GUID_YAxis); if(x_axis == null/* || y_axis == null*/) @@ -283,7 +277,7 @@ final class IDirectInputDevice { DIDeviceObject[] axes = {x_axis/*, y_axis*/}; long[] directions = {0/*, 0*/}; for (int i = 0; i < effects.size(); i++) { - DIEffectInfo info = (DIEffectInfo)effects.get(i); + DIEffectInfo info = effects.get(i); if ((info.getEffectType() & 0xff) == DIEFT_PERIODIC && (info.getDynamicParams() & DIEP_GAIN) != 0) { rumblers.add(createPeriodicRumbler(axes, directions, info)); @@ -304,7 +298,7 @@ final class IDirectInputDevice { private final DIDeviceObject lookupObjectByGUID(int guid_id) { for (int i = 0; i < objects.size(); i++) { - DIDeviceObject object = (DIDeviceObject)objects.get(i); + DIDeviceObject object = objects.get(i); if (guid_id == object.getGUIDType()) return object; } @@ -321,11 +315,11 @@ final class IDirectInputDevice { * for the int size (4 bytes) */ int format_offset = event.getFormatOffset()/4; - return (DIDeviceObject)objects.get(format_offset); + return objects.get(format_offset); } public final DIComponent mapObject(DIDeviceObject object) { - return (DIComponent)object_to_component.get(object); + return object_to_component.get(object); } public final void registerComponent(DIDeviceObject object, DIComponent component) { @@ -342,7 +336,7 @@ final class IDirectInputDevice { } public synchronized final boolean getNextEvent(DIDeviceObjectData data) { - DIDeviceObjectData next_event = (DIDeviceObjectData)queue.get(); + DIDeviceObjectData next_event = queue.get(); if (next_event == null) return false; data.set(next_event); @@ -375,7 +369,7 @@ final class IDirectInputDevice { } private final static native int nUnacquire(long address); - private final boolean getDeviceData(DataQueue queue) throws IOException { + private final boolean getDeviceData(DataQueue queue) throws IOException { int res = nGetDeviceData(address, 0, queue, queue.getElements(), queue.position(), queue.remaining()); if (res != DI_OK && res != DI_BUFFEROVERFLOW) { if (res == DIERR_NOTACQUIRED) { @@ -386,7 +380,7 @@ final class IDirectInputDevice { } return true; } - private final static native int nGetDeviceData(long address, int flags, DataQueue queue, Object[] queue_elements, int position, int remaining); + private final static native int nGetDeviceData(long address, int flags, DataQueue queue, Object[] queue_elements, int position, int remaining); private final void getDeviceState(int[] device_state) throws IOException { int res = nGetDeviceState(address, device_state); @@ -420,7 +414,7 @@ final class IDirectInputDevice { return dev_type; } - public final List getObjects() { + public final List getObjects() { return objects; } @@ -509,7 +503,7 @@ final class IDirectInputDevice { int res = nSetBufferSize(address, size); if (res != DI_OK && res != DI_PROPNOEFFECT && res != DI_POLLEDDEVICE) throw new IOException("Failed to set buffer size (" + Integer.toHexString(res) + ")"); - queue = new DataQueue(size, DIDeviceObjectData.class); + queue = new DataQueue<>(size, DIDeviceObjectData.class); queue.position(queue.limit()); acquire(); } @@ -540,6 +534,7 @@ final class IDirectInputDevice { throw new IOException("Device is released"); } + @SuppressWarnings("deprecation") protected void finalize() { release(); } diff --git a/plugins/windows/src/main/java/net/java/games/input/IDirectInputEffect.java b/plugins/windows/src/main/java/net/java/games/input/IDirectInputEffect.java index 4f098ff..77de468 100644 --- a/plugins/windows/src/main/java/net/java/games/input/IDirectInputEffect.java +++ b/plugins/windows/src/main/java/net/java/games/input/IDirectInputEffect.java @@ -58,7 +58,7 @@ final class IDirectInputEffect implements Rumbler { try { checkReleased(); if (intensity > 0) { - int int_gain = (int)Math.round(intensity*IDirectInputDevice.DI_FFNOMINALMAX); + int int_gain = Math.round(intensity*IDirectInputDevice.DI_FFNOMINALMAX); setGain(int_gain); start(1, 0); } else @@ -115,6 +115,7 @@ final class IDirectInputEffect implements Rumbler { } private final static native int nStop(long address); + @SuppressWarnings("deprecation") protected void finalize() { release(); } diff --git a/plugins/windows/src/main/java/net/java/games/input/RawDevice.java b/plugins/windows/src/main/java/net/java/games/input/RawDevice.java index 4841234..c7b0696 100644 --- a/plugins/windows/src/main/java/net/java/games/input/RawDevice.java +++ b/plugins/windows/src/main/java/net/java/games/input/RawDevice.java @@ -89,12 +89,12 @@ final class RawDevice { private final int type; /* Events from the event queue thread end here */ - private DataQueue keyboard_events; - private DataQueue mouse_events; + private DataQueue keyboard_events; + private DataQueue mouse_events; /* After processing in poll*(), the events are placed here */ - private DataQueue processed_keyboard_events; - private DataQueue processed_mouse_events; + private DataQueue processed_keyboard_events; + private DataQueue processed_mouse_events; /* mouse state */ private final boolean[] button_states = new boolean[5]; @@ -123,7 +123,7 @@ final class RawDevice { /* Careful, this is called from the event queue thread */ public final synchronized void addMouseEvent(long millis, int flags, int button_flags, int button_data, long raw_buttons, long last_x, long last_y, long extra_information) { if (mouse_events.hasRemaining()) { - RawMouseEvent event = (RawMouseEvent)mouse_events.get(); + RawMouseEvent event = mouse_events.get(); event.set(millis, flags, button_flags, button_data, raw_buttons, last_x, last_y, extra_information); } } @@ -131,7 +131,7 @@ final class RawDevice { /* Careful, this is called from the event queue thread */ public final synchronized void addKeyboardEvent(long millis, int make_code, int flags, int vkey, int message, long extra_information) { if (keyboard_events.hasRemaining()) { - RawKeyboardEvent event = (RawKeyboardEvent)keyboard_events.get(); + RawKeyboardEvent event = keyboard_events.get(); event.set(millis, make_code, flags, vkey, message, extra_information); } } @@ -140,10 +140,10 @@ final class RawDevice { relative_x = relative_y = wheel = 0; mouse_events.flip(); while (mouse_events.hasRemaining()) { - RawMouseEvent event = (RawMouseEvent)mouse_events.get(); + RawMouseEvent event = mouse_events.get(); boolean has_update = processMouseEvent(event); if (has_update && processed_mouse_events.hasRemaining()) { - RawMouseEvent processed_event = (RawMouseEvent)processed_mouse_events.get(); + RawMouseEvent processed_event = processed_mouse_events.get(); processed_event.set(event); } } @@ -153,10 +153,10 @@ final class RawDevice { public final synchronized void pollKeyboard() { keyboard_events.flip(); while (keyboard_events.hasRemaining()) { - RawKeyboardEvent event = (RawKeyboardEvent)keyboard_events.get(); + RawKeyboardEvent event = keyboard_events.get(); boolean has_update = processKeyboardEvent(event); if (has_update && processed_keyboard_events.hasRemaining()) { - RawKeyboardEvent processed_event = (RawKeyboardEvent)processed_keyboard_events.get(); + RawKeyboardEvent processed_event = processed_keyboard_events.get(); processed_event.set(event); } } @@ -250,7 +250,7 @@ final class RawDevice { processed_keyboard_events.compact(); return false; } - RawKeyboardEvent next_event = (RawKeyboardEvent)processed_keyboard_events.get(); + RawKeyboardEvent next_event = processed_keyboard_events.get(); event.set(next_event); processed_keyboard_events.compact(); return true; @@ -262,7 +262,7 @@ final class RawDevice { processed_mouse_events.compact(); return false; } - RawMouseEvent next_event = (RawMouseEvent)processed_mouse_events.get(); + RawMouseEvent next_event = processed_mouse_events.get(); if ((next_event.getFlags() & MOUSE_MOVE_ABSOLUTE) != 0) { event_relative_x = next_event.getLastX() - event_last_x; event_relative_y = next_event.getLastY() - event_last_y; @@ -284,10 +284,10 @@ final class RawDevice { } public final void setBufferSize(int size) { - keyboard_events = new DataQueue(size, RawKeyboardEvent.class); - mouse_events = new DataQueue(size, RawMouseEvent.class); - processed_keyboard_events = new DataQueue(size, RawKeyboardEvent.class); - processed_mouse_events = new DataQueue(size, RawMouseEvent.class); + keyboard_events = new DataQueue<>(size, RawKeyboardEvent.class); + mouse_events = new DataQueue<>(size, RawMouseEvent.class); + processed_keyboard_events = new DataQueue<>(size, RawKeyboardEvent.class); + processed_mouse_events = new DataQueue<>(size, RawMouseEvent.class); } public final int getType() { diff --git a/plugins/windows/src/main/java/net/java/games/input/RawInputEnvironmentPlugin.java b/plugins/windows/src/main/java/net/java/games/input/RawInputEnvironmentPlugin.java index c6335ce..9d409aa 100644 --- a/plugins/windows/src/main/java/net/java/games/input/RawInputEnvironmentPlugin.java +++ b/plugins/windows/src/main/java/net/java/games/input/RawInputEnvironmentPlugin.java @@ -64,9 +64,7 @@ public final class RawInputEnvironmentPlugin extends ControllerEnvironment imple * */ static void loadLibrary(final String lib_name) { - AccessController.doPrivileged( - new PrivilegedAction() { - public final Object run() { + AccessController.doPrivileged((PrivilegedAction) () -> { try { String lib_path = System.getProperty("net.java.games.input.librarypath"); if (lib_path != null) @@ -78,25 +76,16 @@ public final class RawInputEnvironmentPlugin extends ControllerEnvironment imple supported = false; } return null; - } }); } static String getPrivilegedProperty(final String property) { - return (String)AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - return System.getProperty(property); - } - }); + return AccessController.doPrivileged((PrivilegedAction) () -> System.getProperty(property)); } static String getPrivilegedProperty(final String property, final String default_value) { - return (String)AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - return System.getProperty(property, default_value); - } - }); + return AccessController.doPrivileged((PrivilegedAction) () -> System.getProperty(property, default_value)); } static { @@ -132,23 +121,23 @@ public final class RawInputEnvironmentPlugin extends ControllerEnvironment imple return controllers; } - private final static SetupAPIDevice lookupSetupAPIDevice(String device_name, List setupapi_devices) { + private final static SetupAPIDevice lookupSetupAPIDevice(String device_name, List setupapi_devices) { /* First, replace # with / in the device name, since that * seems to be the format in raw input device name */ device_name = device_name.replaceAll("#", "\\\\").toUpperCase(); for (int i = 0; i < setupapi_devices.size(); i++) { - SetupAPIDevice device = (SetupAPIDevice)setupapi_devices.get(i); - if (device_name.indexOf(device.getInstanceId().toUpperCase()) != -1) + SetupAPIDevice device = setupapi_devices.get(i); + if (device_name.contains(device.getInstanceId().toUpperCase())) return device; } return null; } - private final static void createControllersFromDevices(RawInputEventQueue queue, List controllers, List devices, List setupapi_devices) throws IOException { - List active_devices = new ArrayList(); + private final static void createControllersFromDevices(RawInputEventQueue queue, List controllers, List devices, List setupapi_devices) throws IOException { + List active_devices = new ArrayList<>(); for (int i = 0; i < devices.size(); i++) { - RawDevice device = (RawDevice)devices.get(i); + RawDevice device = devices.get(i); SetupAPIDevice setupapi_device = lookupSetupAPIDevice(device.getName(), setupapi_devices); if (setupapi_device == null) { /* Either the device is an RDP or we failed to locate the @@ -166,13 +155,13 @@ public final class RawInputEnvironmentPlugin extends ControllerEnvironment imple queue.start(active_devices); } - private final static native void enumerateDevices(RawInputEventQueue queue, List devices) throws IOException; + private final static native void enumerateDevices(RawInputEventQueue queue, List devices) throws IOException; private final Controller[] enumControllers(RawInputEventQueue queue) throws IOException { - List controllers = new ArrayList(); - List devices = new ArrayList(); + List controllers = new ArrayList<>(); + List devices = new ArrayList<>(); enumerateDevices(queue, devices); - List setupapi_devices = enumSetupAPIDevices(); + List setupapi_devices = enumSetupAPIDevices(); createControllersFromDevices(queue, controllers, devices, setupapi_devices); Controller[] controllers_array = new Controller[controllers.size()]; controllers.toArray(controllers_array); @@ -202,13 +191,13 @@ public final class RawInputEnvironmentPlugin extends ControllerEnvironment imple * descriptive names and at the same time filter out the unwanted * RDP devices. */ - private final static List enumSetupAPIDevices() throws IOException { - List devices = new ArrayList(); + private final static List enumSetupAPIDevices() throws IOException { + List devices = new ArrayList<>(); nEnumSetupAPIDevices(getKeyboardClassGUID(), devices); nEnumSetupAPIDevices(getMouseClassGUID(), devices); return devices; } - private final static native void nEnumSetupAPIDevices(byte[] guid, List devices) throws IOException; + private final static native void nEnumSetupAPIDevices(byte[] guid, List devices) throws IOException; private final static native byte[] getKeyboardClassGUID(); private final static native byte[] getMouseClassGUID(); diff --git a/plugins/windows/src/main/java/net/java/games/input/RawInputEventQueue.java b/plugins/windows/src/main/java/net/java/games/input/RawInputEventQueue.java index 99f486d..823f5f5 100644 --- a/plugins/windows/src/main/java/net/java/games/input/RawInputEventQueue.java +++ b/plugins/windows/src/main/java/net/java/games/input/RawInputEventQueue.java @@ -1,10 +1,4 @@ /* - * %W% %E% - * - * Copyright 2002 Sun Microsystems, Inc. All rights reserved. - * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. - */ -/***************************************************************************** * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -35,12 +29,11 @@ * You acknowledge that this software is not designed or intended for us in * the design, construction, operation or maintenance of any nuclear facility * - *****************************************************************************/ + */ package net.java.games.input; import java.io.IOException; import java.util.List; -import java.util.ArrayList; import java.util.Set; import java.util.HashSet; @@ -51,9 +44,9 @@ import java.util.HashSet; final class RawInputEventQueue { private final Object monitor = new Object(); - private List devices; + private List devices; - public final void start(List devices) throws IOException { + public final void start(List devices) throws IOException { this.devices = devices; QueueThread queue = new QueueThread(); synchronized (monitor) { @@ -71,7 +64,7 @@ final class RawInputEventQueue { private final RawDevice lookupDevice(long handle) { for (int i = 0; i < devices.size(); i++) { - RawDevice device = (RawDevice)devices.get(i); + RawDevice device = devices.get(i); if (device.getHandle() == handle) return device; } @@ -133,10 +126,10 @@ final class RawInputEventQueue { } if (exception != null) return; - Set active_infos = new HashSet(); + Set active_infos = new HashSet<>(); try { for (int i = 0; i < devices.size(); i++) { - RawDevice device = (RawDevice)devices.get(i); + RawDevice device = devices.get(i); active_infos.add(device.getInfo()); } RawDeviceInfo[] active_infos_array = new RawDeviceInfo[active_infos.size()]; diff --git a/plugins/windows/src/main/java/net/java/games/input/RawKeyboard.java b/plugins/windows/src/main/java/net/java/games/input/RawKeyboard.java index 728284f..61a05ed 100644 --- a/plugins/windows/src/main/java/net/java/games/input/RawKeyboard.java +++ b/plugins/windows/src/main/java/net/java/games/input/RawKeyboard.java @@ -1,41 +1,35 @@ /* - * %W% %E% + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistribution of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materails provided with the distribution. + * + * Neither the name Sun Microsystems, Inc. or the names of the contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. + * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING + * ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR + * NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND + * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS + * A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS + * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST + * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, + * INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY + * OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, + * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for us in + * the design, construction, operation or maintenance of any nuclear facility * - * Copyright 2002 Sun Microsystems, Inc. All rights reserved. - * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ -/***************************************************************************** -* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are met: -* -* - Redistribution of source code must retain the above copyright notice, -* this list of conditions and the following disclaimer. -* -* - Redistribution in binary form must reproduce the above copyright notice, -* this list of conditions and the following disclaimer in the documentation -* and/or other materails provided with the distribution. -* -* Neither the name Sun Microsystems, Inc. or the names of the contributors -* may be used to endorse or promote products derived from this software -* without specific prior written permission. -* -* This software is provided "AS IS," without a warranty of any kind. -* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING -* ANY IMPLIED WARRANT OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR -* NON-INFRINGEMEN, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN") AND -* ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS -* A RESULT OF USING, MODIFYING OR DESTRIBUTING THIS SOFTWARE OR ITS -* DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST -* REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, -* INCIDENTAL OR PUNITIVE DAMAGES. HOWEVER CAUSED AND REGARDLESS OF THE THEORY -* OF LIABILITY, ARISING OUT OF THE USE OF OUR INABILITY TO USE THIS SOFTWARE, -* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. -* -* You acknowledge that this software is not designed or intended for us in -* the design, construction, operation or maintenance of any nuclear facility -* -*****************************************************************************/ package net.java.games.input; import java.io.IOException; @@ -59,7 +53,7 @@ final class RawKeyboard extends Keyboard { } private final static Component[] createKeyboardComponents(RawDevice device) { - List components = new ArrayList(); + List components = new ArrayList<>(); Field[] vkey_fields = RawIdentifierMap.class.getFields(); for (int i = 0; i < vkey_fields.length; i++) { Field vkey_field = vkey_fields[i]; @@ -74,7 +68,7 @@ final class RawKeyboard extends Keyboard { throw new RuntimeException(e); } } - return (Component[])components.toArray(new Component[]{}); + return components.toArray(new Component[]{}); } protected final synchronized boolean getNextDeviceEvent(Event event) throws IOException { diff --git a/plugins/wintab/pom.xml b/plugins/wintab/pom.xml index d259150..57c1d6a 100644 --- a/plugins/wintab/pom.xml +++ b/plugins/wintab/pom.xml @@ -29,12 +29,6 @@ maven-compiler-plugin - - - -h - ${project.build.directory}/generated-sources/natives - - maven-antrun-plugin diff --git a/plugins/wintab/src/main/java/net/java/games/input/WinTabComponent.java b/plugins/wintab/src/main/java/net/java/games/input/WinTabComponent.java index 03bea98..a4c2ad9 100644 --- a/plugins/wintab/src/main/java/net/java/games/input/WinTabComponent.java +++ b/plugins/wintab/src/main/java/net/java/games/input/WinTabComponent.java @@ -1,4 +1,4 @@ -/** +/* * Copyright (C) 2006 Jeremy Booth (jeremy@newdawnsoftware.com) * * Redistribution and use in source and binary forms, with or without @@ -65,8 +65,8 @@ public class WinTabComponent extends AbstractComponent { return false; } - public static List createComponents(WinTabContext context, int parentDevice, int axisId, int[] axisRanges) { - List components = new ArrayList(); + public static List createComponents(WinTabContext context, int parentDevice, int axisId, int[] axisRanges) { + List components = new ArrayList<>(); Identifier id; switch(axisId) { case WinTabDevice.XAxis: @@ -110,26 +110,17 @@ public class WinTabComponent extends AbstractComponent { return components; } - public static Collection createButtons(WinTabContext context, int deviceIndex, int numberOfButtons) { - List buttons = new ArrayList(); + public static Collection createButtons(WinTabContext context, int deviceIndex, int numberOfButtons) { + List buttons = new ArrayList<>(); Identifier id; for(int i=0;i buttonIdClass = Identifier.Button.class; Field idField = buttonIdClass.getField("_" + i); id = (Identifier)idField.get(null); buttons.add(new WinTabButtonComponent(context, deviceIndex, id.getName(), id, i)); - } catch (SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (NoSuchFieldException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalArgumentException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IllegalAccessException e) { + } catch (SecurityException|NoSuchFieldException|IllegalArgumentException|IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } @@ -184,9 +175,9 @@ public class WinTabComponent extends AbstractComponent { return (value - min)/bottom; } - public static Collection createCursors(WinTabContext context, int deviceIndex, String[] cursorNames) { + public static Collection createCursors(WinTabContext context, int deviceIndex, String[] cursorNames) { Identifier id; - List cursors = new ArrayList(); + List cursors = new ArrayList<>(); for(int i=0;i devices = new ArrayList<>(); int numSupportedDevices = nGetNumberOfSupportedDevices(); for(int i=0;i eventList = new ArrayList<>(); private WinTabDevice(WinTabContext context, int index, String name, Component[] components) { super(name, components, new Controller[0], new Rumbler[0]); @@ -48,7 +48,7 @@ public class WinTabDevice extends AbstractController { protected boolean getNextDeviceEvent(Event event) throws IOException { if(eventList.size()>0) { - Event ourEvent = (Event)eventList.remove(0); + Event ourEvent = eventList.remove(0); event.set(ourEvent); return true; } else { @@ -80,7 +80,7 @@ public class WinTabDevice extends AbstractController { public static WinTabDevice createDevice(WinTabContext context, int deviceIndex) { String name = nGetName(deviceIndex); WinTabEnvironmentPlugin.log("Device " + deviceIndex + ", name: " + name); - List componentsList = new ArrayList(); + List componentsList = new ArrayList<>(); int[] axisDetails = nGetAxisDetails(deviceIndex, XAxis); if(axisDetails.length==0) { @@ -148,7 +148,7 @@ public class WinTabDevice extends AbstractController { WinTabEnvironmentPlugin.log("Device has " + numberOfButtons + " buttons"); componentsList.addAll(WinTabComponent.createButtons(context, deviceIndex, numberOfButtons)); - Component[] components = (Component[])componentsList.toArray(new Component[0]); + Component[] components = componentsList.toArray(new Component[0]); return new WinTabDevice(context, deviceIndex, name, components); } diff --git a/plugins/wintab/src/main/java/net/java/games/input/WinTabEnvironmentPlugin.java b/plugins/wintab/src/main/java/net/java/games/input/WinTabEnvironmentPlugin.java index 2a0d140..aa0c839 100644 --- a/plugins/wintab/src/main/java/net/java/games/input/WinTabEnvironmentPlugin.java +++ b/plugins/wintab/src/main/java/net/java/games/input/WinTabEnvironmentPlugin.java @@ -1,4 +1,4 @@ -/** +/* * Copyright (C) 2006 Jeremy Booth (jeremy@newdawnsoftware.com) * * Redistribution and use in source and binary forms, with or without @@ -44,9 +44,7 @@ public class WinTabEnvironmentPlugin extends ControllerEnvironment implements Pl * */ static void loadLibrary(final String lib_name) { - AccessController.doPrivileged( - new PrivilegedAction() { - public final Object run() { + AccessController.doPrivileged((PrivilegedAction) () -> { try { String lib_path = System.getProperty("net.java.games.input.librarypath"); if (lib_path != null) @@ -58,25 +56,16 @@ public class WinTabEnvironmentPlugin extends ControllerEnvironment implements Pl supported = false; } return null; - } }); } - + static String getPrivilegedProperty(final String property) { - return (String)AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - return System.getProperty(property); - } - }); - } - + return AccessController.doPrivileged((PrivilegedAction)() -> System.getProperty(property)); + } + static String getPrivilegedProperty(final String property, final String default_value) { - return (String)AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - return System.getProperty(property, default_value); - } - }); + return AccessController.doPrivileged((PrivilegedAction)() -> System.getProperty(property, default_value)); } static { @@ -88,13 +77,13 @@ public class WinTabEnvironmentPlugin extends ControllerEnvironment implements Pl } private final Controller[] controllers; - private final List active_devices = new ArrayList(); + private final List active_devices = new ArrayList<>(); private final WinTabContext winTabContext; /** Creates new DirectInputEnvironment */ public WinTabEnvironmentPlugin() { if(isSupported()) { - DummyWindow window = null; + DummyWindow window; WinTabContext winTabContext = null; Controller[] controllers = new Controller[]{}; try { @@ -113,12 +102,9 @@ public class WinTabEnvironmentPlugin extends ControllerEnvironment implements Pl } this.controllers = controllers; this.winTabContext = winTabContext; - AccessController.doPrivileged( - new PrivilegedAction() { - public final Object run() { + AccessController.doPrivileged((PrivilegedAction)() -> { Runtime.getRuntime().addShutdownHook(new ShutdownHook()); return null; - } }); } else { winTabContext = null; diff --git a/pom.xml b/pom.xml index 03912ef..b665c6d 100644 --- a/pom.xml +++ b/pom.xml @@ -39,8 +39,8 @@ UTF-8 - 1.6 - 1.6 + 8 + 8 @@ -70,6 +70,12 @@ true true + + -Werror + -Xlint:all,-options + -h + ${project.build.directory}/generated-sources/natives + diff --git a/tests/src/main/java/net/java/games/input/ControllerEventTest.java b/tests/src/main/java/net/java/games/input/ControllerEventTest.java index a6069e7..f44fa93 100644 --- a/tests/src/main/java/net/java/games/input/ControllerEventTest.java +++ b/tests/src/main/java/net/java/games/input/ControllerEventTest.java @@ -46,6 +46,7 @@ import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; +import javax.swing.WindowConstants; import net.java.games.input.Component; import net.java.games.input.Controller; @@ -55,7 +56,10 @@ import net.java.games.input.Event; import net.java.games.input.Version; public class ControllerEventTest extends JFrame{ + private static final long serialVersionUID = -8266185848160199092L; + private static abstract class AxisPanel extends JPanel{ + private static final long serialVersionUID = -6200599064870672000L; Component axis; float data; @@ -79,6 +83,7 @@ public class ControllerEventTest extends JFrame{ } private static class DigitalAxisPanel extends AxisPanel { + private static final long serialVersionUID = -4729666037860134626L; JLabel digitalState = new JLabel(""); public DigitalAxisPanel(Component ax) { @@ -102,6 +107,7 @@ public class ControllerEventTest extends JFrame{ } private static class DigitalHatPanel extends AxisPanel { + private static final long serialVersionUID = -6582605379682496832L; JLabel digitalState = new JLabel(""); public DigitalHatPanel(Component ax) { @@ -145,6 +151,7 @@ public class ControllerEventTest extends JFrame{ } } private static class AnalogAxisPanel extends AxisPanel { + private static final long serialVersionUID = 7536173405896285590L; JLabel analogState = new JLabel(""); public AnalogAxisPanel(Component ax) { @@ -164,8 +171,9 @@ public class ControllerEventTest extends JFrame{ private static class ControllerWindow extends JFrame { + private static final long serialVersionUID = 8623977198558568961L; Controller ca; - Map axes_to_panels = new HashMap(); + Map axes_to_panels = new HashMap<>(); boolean disabled = false; public ControllerWindow(JFrame frame,Controller ca){ @@ -207,7 +215,7 @@ public class ControllerEventTest extends JFrame{ } private void addAxis(JPanel p, Component ax){ - JPanel p2; + AxisPanel p2; if (ax.isAnalog()) { p2 = new AnalogAxisPanel(ax); } else { @@ -234,14 +242,14 @@ public class ControllerEventTest extends JFrame{ EventQueue event_queue = ca.getEventQueue(); Event event = new Event(); while (event_queue.getNextEvent(event)) { - AxisPanel panel = (AxisPanel)axes_to_panels.get(event.getComponent()); + AxisPanel panel = axes_to_panels.get(event.getComponent()); panel.setPollData(event.getValue()); } } } static final long HEARTBEATMS =100; // 10th of a second - List controllers = new ArrayList(); + List controllers = new ArrayList<>(); public ControllerEventTest() { super("Controller Event Test. Version: " + Version.getVersion()); @@ -251,14 +259,12 @@ public class ControllerEventTest extends JFrame{ makeController(ca[i]); } - new Thread(new Runnable() { - public void run(){ + new Thread(() -> { try { while(true){ - for(Iterator i=controllers.iterator();i.hasNext();){ + for(Iterator i=controllers.iterator();i.hasNext();){ try { - ControllerWindow cw = (ControllerWindow)i.next(); - cw.poll(); + i.next().poll(); } catch (Exception e) { e.printStackTrace(); } @@ -268,11 +274,10 @@ public class ControllerEventTest extends JFrame{ } catch (Exception e) { e.printStackTrace(); } - } }).start(); pack(); setSize(400,400); - setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setVisible(true); } diff --git a/tests/src/main/java/net/java/games/input/ControllerReadTest.java b/tests/src/main/java/net/java/games/input/ControllerReadTest.java index ee3b85d..2d3a62b 100644 --- a/tests/src/main/java/net/java/games/input/ControllerReadTest.java +++ b/tests/src/main/java/net/java/games/input/ControllerReadTest.java @@ -49,13 +49,17 @@ import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; +import javax.swing.WindowConstants; import net.java.games.input.Component; import net.java.games.input.Controller; import net.java.games.input.ControllerEnvironment; public class ControllerReadTest extends JFrame{ + private static final long serialVersionUID = -7129976919159465311L; + private abstract static class AxisPanel extends JPanel{ + private static final long serialVersionUID = -2117191506803328790L; Component axis; float data; @@ -79,6 +83,7 @@ public class ControllerReadTest extends JFrame{ } private static class DigitalAxisPanel extends AxisPanel { + private static final long serialVersionUID = -4006900519933869168L; JLabel digitalState = new JLabel(""); public DigitalAxisPanel(Component ax) { @@ -102,6 +107,7 @@ public class ControllerReadTest extends JFrame{ } private static class DigitalHatPanel extends AxisPanel { + private static final long serialVersionUID = -3293100130201231029L; JLabel digitalState = new JLabel(""); public DigitalHatPanel(Component ax) { @@ -145,6 +151,7 @@ public class ControllerReadTest extends JFrame{ } } private static class AnalogAxisPanel extends AxisPanel { + private static final long serialVersionUID = -3220244985697453835L; JLabel analogState = new JLabel(""); public AnalogAxisPanel(Component ax) { @@ -164,8 +171,9 @@ public class ControllerReadTest extends JFrame{ private static class ControllerWindow extends JFrame { + private static final long serialVersionUID = 5812903945250431578L; Controller ca; - List axisList = new ArrayList(); + List axisList = new ArrayList<>(); boolean disabled = false; public ControllerWindow(JFrame frame,Controller ca){ @@ -207,7 +215,7 @@ public class ControllerReadTest extends JFrame{ } private void addAxis(JPanel p, Component ax){ - JPanel p2; + AxisPanel p2; if (ax.isAnalog()) { p2 = new AnalogAxisPanel(ax); } else { @@ -233,9 +241,9 @@ public class ControllerReadTest extends JFrame{ setDisabled(false); } //System.out.println("Polled "+ca.getName()); - for(Iterator i =axisList.iterator();i.hasNext();){ + for(Iterator i =axisList.iterator();i.hasNext();){ try { - ((AxisPanel)i.next()).poll(); + i.next().poll(); }catch (Exception e) { e.printStackTrace(); } @@ -244,7 +252,7 @@ public class ControllerReadTest extends JFrame{ } static final long HEARTBEATMS =100; // 10th of a second - List controllers = new ArrayList(); + List controllers = new ArrayList<>(); public ControllerReadTest() { super("Controller Read Test. Version: " + Version.getVersion()); @@ -254,13 +262,12 @@ public class ControllerReadTest extends JFrame{ makeController(ca[i]); } - new Thread(new Runnable() { - public void run(){ + new Thread(() ->{ try { while(true){ - for(Iterator i=controllers.iterator();i.hasNext();){ + for(Iterator i=controllers.iterator();i.hasNext();){ try { - ControllerWindow cw = (ControllerWindow)i.next(); + ControllerWindow cw = i.next(); cw.poll(); } catch (Exception e) { e.printStackTrace(); @@ -271,11 +278,10 @@ public class ControllerReadTest extends JFrame{ } catch (Exception e) { e.printStackTrace(); } - } }).start(); pack(); setSize(400,400); - setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setVisible(true); } diff --git a/tests/src/main/java/net/java/games/input/ControllerTextTest.java b/tests/src/main/java/net/java/games/input/ControllerTextTest.java index 8e28c99..d3bfa09 100644 --- a/tests/src/main/java/net/java/games/input/ControllerTextTest.java +++ b/tests/src/main/java/net/java/games/input/ControllerTextTest.java @@ -37,12 +37,6 @@ *****************************************************************************/ package net.java.games.input; -/** - * - * @author administrator - */ -import net.java.games.input.*; - public class ControllerTextTest { ControllerEnvironment ce; /** Creates a new instance of ControllerScanner */ diff --git a/tests/src/main/java/net/java/games/input/RumbleTest.java b/tests/src/main/java/net/java/games/input/RumbleTest.java index 4dc0725..5e3c59e 100644 --- a/tests/src/main/java/net/java/games/input/RumbleTest.java +++ b/tests/src/main/java/net/java/games/input/RumbleTest.java @@ -1,19 +1,30 @@ /* - * RumbleTest.java + * Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com) * - * Created on 01 December 2003, 23:02 + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * The name of the author may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE */ package net.java.games.input; -import net.java.games.input.ControllerEnvironment; -import net.java.games.input.Controller; -import net.java.games.input.Rumbler; -import net.java.games.input.Version; - -/** - * - * @author Jeremy - */ public class RumbleTest { /** Creates a new instance of RumbleTest */ diff --git a/tests/src/main/java/net/java/games/input/VersionTest.java b/tests/src/main/java/net/java/games/input/VersionTest.java index caf2a44..f5831cf 100644 --- a/tests/src/main/java/net/java/games/input/VersionTest.java +++ b/tests/src/main/java/net/java/games/input/VersionTest.java @@ -1,12 +1,32 @@ +/* + * Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. + * The name of the author may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO + * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE + */ package net.java.games.input; -import net.java.games.input.Version; - public class VersionTest { - /** - * @param args - */ public static void main(String[] args) { System.out.println("JInput version: " + Version.getVersion()); } diff --git a/tests/src/main/java/net/java/games/input/applet/ControllerEventTestApplet.java b/tests/src/main/java/net/java/games/input/applet/ControllerEventTestApplet.java index 9127686..2b398b6 100644 --- a/tests/src/main/java/net/java/games/input/applet/ControllerEventTestApplet.java +++ b/tests/src/main/java/net/java/games/input/applet/ControllerEventTestApplet.java @@ -1,4 +1,4 @@ -/** +/* * Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com) * * Redistribution and use in source and binary forms, with or without @@ -25,15 +25,16 @@ */ package net.java.games.input.applet; -import java.applet.Applet; import java.io.IOException; import net.java.games.input.ControllerEventTest; -import net.java.games.input.applet.JInputAppletResourceLoader; -public class ControllerEventTestApplet extends Applet { +@SuppressWarnings("deprecation") +public class ControllerEventTestApplet extends java.applet.Applet { - public void init() { + private static final long serialVersionUID = 4250817143444220400L; + + public void init() { try { new JInputAppletResourceLoader().loadResources(getCodeBase()); } catch (IOException e) { diff --git a/tests/src/main/java/net/java/games/input/applet/ControllerReadTestApplet.java b/tests/src/main/java/net/java/games/input/applet/ControllerReadTestApplet.java index 1f9fff2..92b57e0 100644 --- a/tests/src/main/java/net/java/games/input/applet/ControllerReadTestApplet.java +++ b/tests/src/main/java/net/java/games/input/applet/ControllerReadTestApplet.java @@ -1,4 +1,4 @@ -/** +/* * Copyright (C) 2003 Jeremy Booth (jeremy@newdawnsoftware.com) * * Redistribution and use in source and binary forms, with or without @@ -25,13 +25,14 @@ */ package net.java.games.input.applet; -import java.applet.Applet; import java.io.IOException; import net.java.games.input.ControllerReadTest; -import net.java.games.input.applet.JInputAppletResourceLoader; -public class ControllerReadTestApplet extends Applet { +@SuppressWarnings("deprecation") +public class ControllerReadTestApplet extends java.applet.Applet { + + private static final long serialVersionUID = -2558493887683964119L; public void init() { try {