public Joystick[] loadJoysticks(InputManager inputManager){ ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment(); Controller[] cs = ce.getControllers(); List<Joystick> list = new ArrayList<Joystick>(); for( Controller c : ce.getControllers() ) { if (c.getType() == Controller.Type.KEYBOARD || c.getType() == Controller.Type.MOUSE) continue; logger.log(Level.FINE, "Attempting to create joystick for: \"{0}\"", c); // Try to create it like a joystick JInputJoystick stick = new JInputJoystick(inputManager, this, c, list.size(), c.getName()); for( Component comp : c.getComponents() ) { stick.addComponent(comp); } // If it has no axes then we'll assume it's not // a joystick if( stick.getAxisCount() == 0 ) { logger.log(Level.FINE, "Not a joystick: {0}", c); continue; } joystickIndex.put(c, stick); list.add(stick); } joysticks = list.toArray( new JInputJoystick[list.size()] ); return joysticks; }
public JInputControllerDevice(ControllerConfig config) { this.config = config; ControllerEnvironment env = ControllerEnvironment.getDefaultEnvironment(); // Unfortunately, no existing implementation env.addControllerListener(new ControllerListener() { @Override public void controllerRemoved(ControllerEvent ev) { Controller controller = ev.getController(); logger.info("Controller disconnected: " + controller.getName()); removeController(controller); } @Override public void controllerAdded(ControllerEvent ev) { Controller controller = ev.getController(); logger.info("Controller connected: " + controller.getName()); addController(controller); } }); for (Controller c : env.getControllers()) { addController(c); } }
private void scanControllersAt(String path) { File file = new File(path); if (!file.exists()) { return; } try { Plugins plugins = new Plugins(file); @SuppressWarnings("unchecked") Class<ControllerEnvironment>[] envClasses = plugins.getExtends(ControllerEnvironment.class); for(int i=0;i<envClasses.length;i++){ try { ControllerEnvironment.log("ControllerEnvironment "+ envClasses[i].getName() +" loaded by "+envClasses[i].getClassLoader()); ControllerEnvironment ce = envClasses[i].getDeclaredConstructor().newInstance(); if(ce.isSupported()) { addControllers(ce.getControllers()); loadedPluginNames.add(ce.getClass().getName()); } else { log(envClasses[i].getName() + " is not supported"); } } catch (Throwable e) { e.printStackTrace(); } } } catch (Exception e) { e.printStackTrace(); } }
Class<?> ceClass = Class.forName(className); ControllerEnvironment ce = (ControllerEnvironment) ceClass.getDeclaredConstructor().newInstance(); if(ce.isSupported()) { addControllers(ce.getControllers()); loadedPluginNames.add(ce.getClass().getName()); } else {
public GamepadInputDeviceService(){ try{final JVM jvm = new JVM(); if(operatingSystem.contains("win")){ jvm.loadFromJarToFile("/jinput-dx8_64.dll"); //jvm.loadFromJarToFile("/jinput-dx8.dll"); jvm.loadFromJarToFile("/jinput-raw_64.dll"); //jvm.loadFromJarToFile("/jinput-raw.dll"); jvm.loadFromJarToFile("/jinput-wintab.dll"); } else if(operatingSystem.contains("linux")){ jvm.loadFromJarToFile("/libjinput-linux64.so"); //jvm.loadFromJarToFile("/libjinput-linux.so"); } else if(operatingSystem.contains("mac")){ jvm.loadFromJarToFile("/libjinput-osx.jnilib"); } else System.err.println("Warning: Couldn't determine OS; jInput will likely fail to load."); System.setProperty("net.java.games.input.librarypath", new File("DeleteMe").getAbsolutePath()); }catch(Exception e){e.printStackTrace();} this.controllerEnvironment = ControllerEnvironment.getDefaultEnvironment(); if(controllerEnvironment.isSupported()){ //Filter out the keyboards in favor of AWT's event-based tracking for(Controller controller:controllerEnvironment.getControllers()){ final Type type = controller.getType(); if( type != Controller.Type.KEYBOARD && type != Controller.Type.MOUSE && type != Controller.Type.TRACKBALL) inputDevices.add(new GamepadInputDevice(controller)); }//end for(controller types) }//end if(controllerEnvironment.isSupported()) else System.err.println("GamepadInputDeviceServiceFactory() WARNING: jInput indicates environment not supported. There will be no Gamepad controller support by this Feature."); }//end constructor
private void scanControllersAt(String path) { File file = new File(path); if (!file.exists()) { return; } try { Plugins plugins = new Plugins(file); Class[] envClasses = plugins.getExtends(ControllerEnvironment.class); for(int i=0;i<envClasses.length;i++){ try { ControllerEnvironment.logln("ControllerEnvironment "+ envClasses[i].getName() +" loaded by "+envClasses[i].getClassLoader()); ControllerEnvironment ce = (ControllerEnvironment) envClasses[i].newInstance(); if(ce.isSupported()) { addControllers(ce.getControllers()); loadedPlugins.add(ce.getClass().getName()); } else { logln(envClasses[i].getName() + " is not supported"); } } catch (Throwable e) { e.printStackTrace(); } } } catch (Exception e) { e.printStackTrace(); } }
static void logln(String msg) { log(msg + "\n"); }
private void scanControllersAt(String path) { File file = new File(path); if (!file.exists()) { return; } try { Plugins plugins = new Plugins(file); @SuppressWarnings("unchecked") Class<ControllerEnvironment>[] envClasses = plugins.getExtends(ControllerEnvironment.class); for(int i=0;i<envClasses.length;i++){ try { ControllerEnvironment.log("ControllerEnvironment "+ envClasses[i].getName() +" loaded by "+envClasses[i].getClassLoader()); ControllerEnvironment ce = envClasses[i].getDeclaredConstructor().newInstance(); if(ce.isSupported()) { addControllers(ce.getControllers()); loadedPluginNames.add(ce.getClass().getName()); } else { log(envClasses[i].getName() + " is not supported"); } } catch (Throwable e) { e.printStackTrace(); } } } catch (Exception e) { e.printStackTrace(); } }
Class<?> ceClass = Class.forName(className); ControllerEnvironment ce = (ControllerEnvironment) ceClass.getDeclaredConstructor().newInstance(); if(ce.isSupported()) { addControllers(ce.getControllers()); loadedPluginNames.add(ce.getClass().getName()); } else {
public final void run() { for(int i = 0; i < devices.size(); i++) { try { LinuxDevice device = devices.get(i); device.close(); } catch(IOException e) { log("Failed to close device: " + e.getMessage()); } } } }
public void update() { ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment(); Controller[] cs = ce.getControllers(); Event e = new Event(); for (int i = 0; i < cs.length; i++){
private void scanControllersAt(String path) { File file = new File(path); if (!file.exists()) { return; } try { Plugins plugins = new Plugins(file); @SuppressWarnings("unchecked") Class<ControllerEnvironment>[] envClasses = plugins.getExtends(ControllerEnvironment.class); for(int i=0;i<envClasses.length;i++){ try { ControllerEnvironment.log("ControllerEnvironment "+ envClasses[i].getName() +" loaded by "+envClasses[i].getClassLoader()); ControllerEnvironment ce = envClasses[i].getDeclaredConstructor().newInstance(); if(ce.isSupported()) { addControllers(ce.getControllers()); loadedPluginNames.add(ce.getClass().getName()); } else { log(envClasses[i].getName() + " is not supported"); } } catch (Throwable e) { e.printStackTrace(); } } } catch (Exception e) { e.printStackTrace(); } }
Class<?> ceClass = Class.forName(className); ControllerEnvironment ce = (ControllerEnvironment) ceClass.getDeclaredConstructor().newInstance(); if(ce.isSupported()) { addControllers(ce.getControllers()); loadedPluginNames.add(ce.getClass().getName()); } else {
/** * Creates a new EventQueue. Events in old queue are lost. */ public final void setEventQueueSize(int size) { try { setDeviceEventQueueSize(size); event_queue = new EventQueue(size); } catch (IOException e) { ControllerEnvironment.log("Failed to create new event queue of size " + size + ": " + e); } }
private Controller getSelectedController() { if (controllerBox != null) { int controllerIndex = controllerBox.getSelectedIndex(); ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment(); Controller[] controllers = ce.getControllers(); if (controllers != null && controllerIndex >= 0 && controllerIndex < controllers.length) { return controllers[controllerIndex]; } } return null; }
Class ceClass = Class.forName(className); ControllerEnvironment ce = (ControllerEnvironment) ceClass.newInstance(); if(ce.isSupported()) { addControllers(ce.getControllers()); loadedPlugins.add(ce.getClass().getName()); } else {
/** * Creates a new EventQueue. Events in old queue are lost. */ public final void setEventQueueSize(int size) { try { setDeviceEventQueueSize(size); event_queue = new EventQueue(size); } catch (IOException e) { ControllerEnvironment.log("Failed to create new event queue of size " + size + ": " + e); } }
public void setInputControllerIndex(int index) { ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment(); net.java.games.input.Controller[] controllers = ce.getControllers(); if (controllers != null && index >= 0 && index < controllers.length) { setInputController(controllers[index]); } }
/** * Creates a new EventQueue. Events in old queue are lost. */ public final void setEventQueueSize(int size) { try { setDeviceEventQueueSize(size); event_queue = new EventQueue(size); } catch (IOException e) { ControllerEnvironment.log("Failed to create new event queue of size " + size + ": " + e); } }
public ComboBoxModel makeControllerComboBoxModel() { MutableComboBoxModel comboBox = new DefaultComboBoxModel(); ControllerEnvironment ce = ControllerEnvironment.getDefaultEnvironment(); Controller[] controllers = ce.getControllers(); for (Controller c : controllers) { comboBox.addElement(c); } return comboBox; }