Пример #1
0
  static {
    root = new Key();
    root.name = "<root>";
    root.subKeys = new java.util.HashMap();
    java.io.File aliceHasNotExitedFile =
        new java.io.File(
            edu.cmu.cs.stage3.alice.authoringtool.JAlice.getAliceUserDirectory(),
            "aliceHasNotExited.txt");
    if (aliceHasNotExitedFile.canRead()) {
      try {
        storeConfig();
      } catch (java.io.IOException e2) {
        edu.cmu.cs.stage3.alice.authoringtool.AuthoringTool.showErrorDialog(
            java.util.ResourceBundle.getBundle(
                    "edu/cmu/cs/stage3/alice/authoringtool/util/Configuration")
                .getString("UNABLE_TO_CREATE_NEW_PREFERENCES_FILE."),
            e2);
      }
    } else {
      try {
        loadConfig(configLocation);
      } catch (Exception e) {

      }
    }
  }
Пример #2
0
 public static Key fromString(String string) {
   for (Key key : Key.values()) {
     if (key.name().equals(string.toUpperCase())) {
       return key;
     }
   }
   return null;
 }
Пример #3
0
    public Key createSubKey(String name) {
      if (subKeys == null) {
        subKeys = new java.util.HashMap();
      }

      int i = name.indexOf('.');
      if (i == -1) {
        Key subKey = (Key) subKeys.get(name);
        if (subKey == null) {
          subKey = new Key();
          subKey.name = name;
          subKeys.put(name, subKey);
        }
        return subKey;
      } else {
        Key subKey = (Key) subKeys.get(name.substring(0, i));
        if (subKey == null) {
          subKey = new Key();
          subKey.name = name.substring(0, i);
          subKeys.put(subKey.name, subKey);
        }
        return subKey.createSubKey(name.substring(i + 1));
      }
    }
Пример #4
0
 /** @param position */
 public void setKey(Key position) {
   if (position == null) set("key", null);
   else set("key", position.name().replace('_', ' ').toLowerCase());
 }
Пример #5
0
  private static Key loadKey(org.w3c.dom.Element keyElement) {
    Key key = new Key();

    String visibility = keyElement.getAttribute("visibility").trim();
    if (visibility.equals("open")) {
      key.visibility = VIS_OPEN;
    } else if (visibility.equals("advanced")) {
      key.visibility = VIS_ADVANCED;
    } else if (visibility.equals("hidden")) {
      key.visibility = VIS_HIDDEN;
    }

    java.util.HashMap map = parseSingleNode(keyElement);

    org.w3c.dom.Element nameElement = (org.w3c.dom.Element) map.get("name");
    if (nameElement != null) {
      org.w3c.dom.Text textNode = (org.w3c.dom.Text) parseSingleNode(nameElement).get("text");
      if (textNode != null) {
        key.name = textNode.getData().trim();
      }
    }

    org.w3c.dom.Element valueElement = (org.w3c.dom.Element) map.get("value");
    if (valueElement != null) {
      org.w3c.dom.Element listElement =
          (org.w3c.dom.Element) parseSingleNode(valueElement).get("list");
      if (listElement != null) {
        key.valueList = new java.util.ArrayList();
        java.util.ArrayList items = (java.util.ArrayList) parseSingleNode(listElement).get("items");
        if (items != null) {
          for (java.util.Iterator iter = items.iterator(); iter.hasNext(); ) {
            org.w3c.dom.Element itemElement = (org.w3c.dom.Element) iter.next();
            if (itemElement != null) {
              org.w3c.dom.Text textNode =
                  (org.w3c.dom.Text) parseSingleNode(itemElement).get("text");
              if (textNode != null) {
                key.valueList.add(textNode.getData().trim());
              }
            }
          }
        }
      } else {
        org.w3c.dom.Text textNode = (org.w3c.dom.Text) parseSingleNode(valueElement).get("text");
        if (textNode != null) {
          key.value = textNode.getData().trim();
        }
      }
    }

    java.util.ArrayList keys = (java.util.ArrayList) map.get("keys");
    if (keys != null) {
      for (java.util.Iterator iter = keys.iterator(); iter.hasNext(); ) {
        org.w3c.dom.Element subKeyElement = (org.w3c.dom.Element) iter.next();
        if (subKeyElement != null) {
          if (key.subKeys == null) {
            key.subKeys = new java.util.HashMap();
          }
          Key subKey = loadKey(subKeyElement);
          if ((subKey != null) && (subKey.name != null)) {
            key.subKeys.put(subKey.name, subKey);
          }
        }
      }
    }

    return key;
  }