/** * Adds a preconfigured set of mappings in Properties object * form where the names are dot notation "joystick"."axis/button" * and the values are the remapped component name. This calls * addMapping(stickName, sourceComponent, remap) for every property * that it is able to parse. */ public static void addMappings( Properties p ) { for( Map.Entry<Object,Object> e : p.entrySet() ) { String key = String.valueOf(e.getKey()).trim(); int split = key.lastIndexOf( '.' ); if( split < 0 ) { logger.log(Level.WARNING, "Skipping mapping:{0}", e); continue; } String stick = key.substring(0, split).trim(); String component = key.substring(split+1).trim(); String value = String.valueOf(e.getValue()).trim(); addMapping(stick, component, value); } }
/** * Loads a set of compatibility mappings from the property file * specified by the given URL. */ public static void loadMappingProperties( URL u ) throws IOException { logger.log(Level.FINE, "Loading mapping properties:{0}", u); InputStream in = u.openStream(); try { Properties p = new Properties(); p.load(in); addMappings(p); } finally { in.close(); } }
/** * Adds a single Joystick axis or button remapping based on the * joystick's name and axis/button name. The "remap" value will be * used instead. */ public static void addMapping( String stickName, String sourceComponentId, String remapId ) { logger.log(Level.FINE, "addMapping(" + stickName + ", " + sourceComponentId + ", " + remapId + ")" ); getMappings(stickName, true).put( sourceComponentId, remapId ); }
protected void addButton( Component comp ) { logger.log(Level.FINE, "Adding button: \"{0}\" id:" + comp.getIdentifier(), comp); Identifier id = comp.getIdentifier(); if( !(id instanceof Button) ) { throw new IllegalArgumentException( "Component is not an button:" + comp ); } String name = comp.getName(); String original = id.getName(); try { Integer.parseInt(original); } catch (NumberFormatException e){ original = String.valueOf(buttonIndex.size()); } String logicalId = JoystickCompatibilityMappings.remapComponent( controller.getName(), original ); if( logicalId != original ) { logger.log(Level.FINE, "Remapped:" + original + " to:" + logicalId); } JoystickButton button = new DefaultJoystickButton( getInputManager(), this, getButtonCount(), name, logicalId ); addButton(button); buttonIndex.put( comp, button ); }
protected static void loadMappings( ClassLoader cl, String path ) throws IOException { logger.log(Level.FINE, "Searching for mappings for path:{0}", path); for( Enumeration<URL> en = cl.getResources(path); en.hasMoreElements(); ) { URL u = en.nextElement(); try { loadMappingProperties(u); } catch( IOException e ) { logger.log(Level.SEVERE, "Error loading:" + u, e); } } }
/** * Loads the default compatibility mappings by looking for * joystick-mapping.properties files on the classpath. */ protected static void loadDefaultMappings() { for( String s : searchPaths ) { try { loadMappings(JoystickCompatibilityMappings.class.getClassLoader(), s); } catch( IOException e ) { logger.log(Level.SEVERE, "Error searching resource path:{0}", s); } } } }
@Override public Joystick[] loadJoysticks(final InputManager inputManager) { for (int i = 0; i < GLFW_JOYSTICK_LAST; i++) { if (glfwJoystickPresent(i)) { final String name = glfwGetJoystickName(i); final GlfwJoystick joystick = new GlfwJoystick(inputManager, this, i, name); joysticks.put(i, joystick); final FloatBuffer floatBuffer = glfwGetJoystickAxes(i); int axisIndex = 0; while (floatBuffer.hasRemaining()) { floatBuffer.get(); final String logicalId = JoystickCompatibilityMappings.remapComponent(joystick.getName(), convertAxisIndex(axisIndex)); final JoystickAxis joystickAxis = new DefaultJoystickAxis(inputManager, joystick, axisIndex, convertAxisIndex(axisIndex), logicalId, true, false, 0.0f); joystick.addAxis(axisIndex, joystickAxis); axisIndex++; } final ByteBuffer byteBuffer = glfwGetJoystickButtons(i); int buttonIndex = 0; while (byteBuffer.hasRemaining()) { byteBuffer.get(); final String logicalId = JoystickCompatibilityMappings.remapComponent(joystick.getName(), String.valueOf(buttonIndex)); final JoystickButton button = new DefaultJoystickButton(inputManager, joystick, buttonIndex, String.valueOf(buttonIndex), logicalId); joystick.addButton(button); joyButtonPressed.put(button, false); buttonIndex++; } } } return joysticks.values().toArray(new GlfwJoystick[joysticks.size()]); }
protected static void loadMappings( ClassLoader cl, String path ) throws IOException { logger.log(Level.FINE, "Searching for mappings for path:{0}", path); for( Enumeration<URL> en = cl.getResources(path); en.hasMoreElements(); ) { URL u = en.nextElement(); try { loadMappingProperties(u); } catch( IOException e ) { logger.log(Level.SEVERE, "Error loading:" + u, e); } } }
/** * Loads the default compatibility mappings by looking for * joystick-mapping.properties files on the classpath. */ protected static void loadDefaultMappings() { for( String s : searchPaths ) { try { loadMappings(JoystickCompatibilityMappings.class.getClassLoader(), s); } catch( IOException e ) { logger.log(Level.SEVERE, "Error searching resource path:{0}", s); } } } }
String logicalId = JoystickCompatibilityMappings.remapComponent( getName(), original ); if( logicalId == null ? original != null : !logicalId.equals(original) ) { logger.log(Level.FINE, "Remapped: {0} to: {1}",
/** * Returns the remapped version of the axis/button name if there * is a mapping for it otherwise it returns the original name. */ public static String remapComponent( String joystickName, String componentId ) { Map<String,String> map = getMappings(joystickName.trim(), false); if( map == null ) return componentId; if( !map.containsKey(componentId) ) return componentId; return map.get(componentId); }
/** * Loads a set of compatibility mappings from the property file * specified by the given URL. */ public static void loadMappingProperties( URL u ) throws IOException { logger.log(Level.FINE, "Loading mapping properties:{0}", u); InputStream in = u.openStream(); try { Properties p = new Properties(); p.load(in); addMappings(p); } finally { in.close(); } }
/** * Adds a preconfigured set of mappings in Properties object * form where the names are dot notation "joystick"."axis/button" * and the values are the remapped component name. This calls * addMapping(stickName, sourceComponent, remap) for every property * that it is able to parse. */ public static void addMappings( Properties p ) { for( Map.Entry<Object,Object> e : p.entrySet() ) { String key = String.valueOf(e.getKey()).trim(); int split = key.lastIndexOf( '.' ); if( split < 0 ) { logger.log(Level.WARNING, "Skipping mapping:{0}", e); continue; } String stick = key.substring(0, split).trim(); String component = key.substring(split+1).trim(); String value = String.valueOf(e.getValue()).trim(); addMapping(stick, component, value); } }
String logicalId = JoystickCompatibilityMappings.remapComponent( controller.getName(), original ); if( logicalId != original ) { logger.log(Level.FINE, "Remapped:" + original + " to:" + logicalId);
/** * Returns a set of Joystick axis/button name remappings if they exist otherwise * it returns an empty map. */ public static Map<String,String> getJoystickMappings( String joystickName ) { Map<String,String> result = getMappings(joystickName.trim(), false); if( result == null ) return Collections.emptyMap(); return Collections.unmodifiableMap(result); }
original = JoystickAxis.POV_Y; String logicalId = JoystickCompatibilityMappings.remapComponent( getName(), original ); if( logicalId == null ? original != null : !logicalId.equals(original) ) { logger.log(Level.FINE, "Remapped: {0} to: {1}",
/** * Adds a single Joystick axis or button remapping based on the * joystick's name and axis/button name. The "remap" value will be * used instead. */ public static void addMapping( String stickName, String sourceComponentId, String remapId ) { logger.log(Level.FINE, "addMapping(" + stickName + ", " + sourceComponentId + ", " + remapId + ")" ); getMappings(stickName, true).put( sourceComponentId, remapId ); }
@Override public Joystick[] loadJoysticks(final InputManager inputManager) { for (int i = 0; i < GLFW_JOYSTICK_LAST; i++) { if (glfwJoystickPresent(i)) { final String name = glfwGetJoystickName(i); final GlfwJoystick joystick = new GlfwJoystick(inputManager, this, i, name); joysticks.put(i, joystick); final FloatBuffer floatBuffer = glfwGetJoystickAxes(i); int axisIndex = 0; while (floatBuffer.hasRemaining()) { floatBuffer.get(); final String logicalId = JoystickCompatibilityMappings.remapComponent(joystick.getName(), convertAxisIndex(axisIndex)); final JoystickAxis joystickAxis = new DefaultJoystickAxis(inputManager, joystick, axisIndex, convertAxisIndex(axisIndex), logicalId, true, false, 0.0f); joystick.addAxis(axisIndex, joystickAxis); axisIndex++; } final ByteBuffer byteBuffer = glfwGetJoystickButtons(i); int buttonIndex = 0; while (byteBuffer.hasRemaining()) { byteBuffer.get(); final String logicalId = JoystickCompatibilityMappings.remapComponent(joystick.getName(), String.valueOf(buttonIndex)); joystick.addButton(new DefaultJoystickButton(inputManager, joystick, buttonIndex, String.valueOf(buttonIndex), logicalId)); buttonIndex++; } } } return joysticks.values().toArray(new GlfwJoystick[joysticks.size()]); }
/** * Returns the remapped version of the axis/button name if there * is a mapping for it otherwise it returns the original name. */ public static String remapComponent( String joystickName, String componentId ) { Map<String,String> map = getMappings(joystickName.trim(), false); if( map == null ) return componentId; if( !map.containsKey(componentId) ) return componentId; return map.get(componentId); }
protected void addButton( Component comp ) { logger.log(Level.FINE, "Adding button: \"{0}\" id:" + comp.getIdentifier(), comp); Identifier id = comp.getIdentifier(); if( !(id instanceof Button) ) { throw new IllegalArgumentException( "Component is not an axis:" + comp ); } String name = comp.getName(); String original = id.getName(); String logicalId = JoystickCompatibilityMappings.remapComponent( controller.getName(), original ); if( name != original ) { logger.log(Level.FINE, "Remapped:" + original + " to:" + logicalId); } JoystickButton button = new DefaultJoystickButton( getInputManager(), this, getButtonCount(), name, logicalId ); addButton(button); buttonIndex.put( comp, button ); }