Example #1
0
  /** Make a keybinding out of an XML element */
  public static KeyBinding readXML(Element e) {
    try {
      String plugin = e.getAttributeValue("plugin");
      String desc = e.getAttributeValue("desc");
      KeyBinding b = new KeyBinding(plugin, desc, null);

      for (Object neo : e.getChildren()) {
        Element ne = (Element) neo;
        if (ne.getName().equals("char"))
          b.types.add(new TypeChar(ne.getAttributeValue("char").charAt(0)));
        else if (ne.getName().equals("keycode"))
          b.types.add(
              new TypeKeycode(
                  ne.getAttribute("keyCode").getIntValue(),
                  ne.getAttribute("modifier").getIntValue()));
        else if (ne.getName().equals("jinput"))
          b.types.add(
              new TypeJInput(
                  ne.getAttributeValue("ident"), ne.getAttribute("value").getFloatValue()));
      }

      // backwards compatibility
      if (e.getAttribute("key") != null) {
        TypeChar kb = new TypeChar(e.getAttributeValue("key").charAt(0));
        b.types.add(kb);
      } else if (e.getAttribute("keyCode") != null) {
        TypeKeycode kb =
            new TypeKeycode(
                e.getAttribute("keyCode").getIntValue(), e.getAttribute("modifier").getIntValue());
        b.types.add(kb);
      }
      return b;
    } catch (DataConversionException e1) {
      e1.printStackTrace();
      return null;
    }
  }