コード例 #1
0
ファイル: InputManager.java プロジェクト: brianhgt/jme4webgl
  /**
   * Deletes a specific trigger registered to a mapping.
   *
   * <p>The given mapping will no longer receive events raised by the trigger.
   *
   * @param mappingName The mapping name to cease receiving events from the trigger.
   * @param trigger The trigger to no longer invoke events on the mapping.
   */
  public void deleteTrigger(String mappingName, Trigger trigger) {
    Mapping mapping = mappings.get(mappingName);
    if (mapping == null) {
      throw new IllegalArgumentException("Cannot find mapping: " + mappingName);
    }

    ArrayList<Mapping> maps = bindings.get(trigger.triggerHashCode());
    maps.remove(mapping);
  }
コード例 #2
0
ファイル: InputManager.java プロジェクト: brianhgt/jme4webgl
  /**
   * Create a new mapping to the given triggers.
   *
   * <p>The given mapping will be assigned to the given triggers, when any of the triggers given
   * raise an event, the listeners registered to the mappings will receive appropriate events.
   *
   * @param mappingName The mapping name to assign.
   * @param triggers The triggers to which the mapping is to be registered.
   * @see InputManager#deleteMapping(java.lang.String)
   */
  public void addMapping(String mappingName, Trigger... triggers) {
    Mapping mapping = mappings.get(mappingName);
    if (mapping == null) {
      mapping = new Mapping(mappingName);
      mappings.put(mappingName, mapping);
    }

    for (Trigger trigger : triggers) {
      int hash = trigger.triggerHashCode();
      ArrayList<Mapping> names = bindings.get(hash);
      if (names == null) {
        names = new ArrayList<Mapping>();
        bindings.put(hash, names);
      }
      if (!names.contains(mapping)) {
        names.add(mapping);
        mapping.triggers.add(hash);
      } else {
        logger.log(
            Level.WARNING, "Attempted to add mapping \"{0}\" twice to trigger.", mappingName);
      }
    }
  }