示例#1
0
  void processMacro(JSONObject data) {
    // FIXME: need to check parameters.
    // FIXME: need to check permissions.
    if ("callMacro".equalsIgnoreCase(data.getString("command"))) {
      Token token = findTokenFromId(data.getString("tokenId"));

      MacroButtonProperties macro = token.getMacro(data.getInt("macroIndex"), false);
      macro.executeMacro(token.getId());
    }
  }
示例#2
0
 public static void delete(MacroButtonProperties properties) {
   int index = properties.getIndex();
   String paddedIndex = String.format(FORMAT_STRING, index);
   Preferences prefs =
       Preferences.userRoot().node(AppConstants.APP_NAME + "/macros/" + paddedIndex);
   try {
     prefs.removeNode();
   } catch (BackingStoreException e) {
     MapTool.showError("Problem when removing a Global macro?!", e);
   }
   MapTool.getFrame().getGlobalPanel().reset();
 }
示例#3
0
  void sendTokenRegisterdProperties(MTWebSocket mtws, String inResponseTo, JSONObject data) {
    String tokenId = data.getString("tokenId");
    Token token = findTokenFromId(tokenId);

    if (token == null) {
      System.out.println("DEBUG: sendTokenInfo(): Unable to find token " + tokenId);
      return;
      // FIXME: log this error
    }

    JSONObject jobj = new JSONObject();
    jobj.put("tokenId", tokenId);
    jobj.put("name", token.getName());
    jobj.put("label", token.getLabel());
    jobj.put("notes", token.getNotes());

    JSONObject jprop = new JSONObject();

    for (TokenProperty tp : MapTool.getCampaign().getTokenPropertyList(token.getPropertyType())) {
      JSONObject jp = new JSONObject();
      jp.put("name", tp.getName());
      if (tp.getShortName() != null) {
        jp.put("shortName", tp.getShortName());
      }
      if (tp.getDefaultValue() != null) {
        jp.put("defaultValue", tp.getDefaultValue());
      }
      jp.put("value", token.getProperty(tp.getName()));
      jp.put("showOnStatSheet", tp.isShowOnStatSheet());

      jprop.put(tp.getName(), jp);
    }

    jobj.put("properties", jprop);

    JSONArray jmacros = new JSONArray();

    for (MacroButtonProperties macro : token.getMacroList(false)) {
      JSONObject jmb = new JSONObject();
      jmb.put("label", macro.getLabel());
      jmb.put("tooltip", macro.getEvaluatedToolTip());
      jmb.put("index", macro.getIndex());
      jmb.put("fontColor", macro.getFontColorAsHtml());
      jmb.put("displayGroup", macro.getGroupForDisplay());
      jmb.put("group", macro.getGroup());
      jmb.put("index", macro.getIndex());
      jmb.put("autoExecute", macro.getAutoExecute());
      jmb.put("maxWidth", macro.getMaxWidth());
      jmb.put("minWidth", macro.getMinWidth());
      jmb.put("applyToTokens", macro.getApplyToTokens());

      jmacros.add(jmb);
    }

    jobj.put("macros", jmacros);

    mtws.sendMessage("tokenInfo", inResponseTo, jobj);
  }
示例#4
0
  public static void savePreferences(MacroButtonProperties properties) {
    int index = properties.getIndex();

    // use zero padding to ensure proper ordering in the registry (otherwise 10 will come before 2
    // etc.)
    String paddedIndex = String.format(FORMAT_STRING, index);

    //		prefs = Preferences.userRoot().node(AppConstants.APP_NAME + "/macros/" + paddedIndex);
    Preferences prefs = Preferences.userRoot().node(AppConstants.APP_NAME + "/macros");

    try {
      if (!prefs.nodeExists(paddedIndex)) {
        prefs = prefs.node(paddedIndex);
      } else {
        prefs = prefs.node(paddedIndex);
      }
      // Start with the macro text itself.  Apparently Windows has a length limit for registry
      // values and the JRE doesn't
      // re-read the registry to determine if all information was actually written...  So we'll do
      // it ourselves.  We start with
      // the macro text because if it fails, we don't want to bother saving the rest of the fields.
      String text = properties.getCommand();
      prefs.put(PREF_COMMAND_KEY, text);
      String readback = prefs.get(PREF_COMMAND_KEY, null);
      if (readback == null || !readback.equals(text)) {
        MapTool.showError(
            "Macro body not written properly?!  Operating system may have truncated to "
                + Preferences.MAX_VALUE_LENGTH
                + " characters.");
        return;
      }
      prefs.put(PREF_COLOR_KEY, properties.getColorKey());
      prefs.put(PREF_LABEL_KEY, properties.getLabel());
      prefs.put(PREF_GROUP_KEY, properties.getGroup());
      prefs.put(PREF_SORTBY_KEY, properties.getSortby());
      prefs.putBoolean(PREF_AUTO_EXECUTE, properties.getAutoExecute());
      prefs.putBoolean(PREF_INCLUDE_LABEL, properties.getIncludeLabel());
      prefs.putBoolean(PREF_APPLYTOTOKENS, properties.getApplyToTokens());
      prefs.put(PREF_HOTKEY_KEY, properties.getHotKey());
      prefs.put(PREF_FONT_COLOR_KEY, properties.getFontColorKey());
      prefs.put(PREF_FONT_SIZE, properties.getFontSize());
      prefs.put(PREF_MIN_WIDTH, properties.getMinWidth());
      prefs.put(PREF_MAX_WIDTH, properties.getMaxWidth());
      prefs.put(PREF_TOOLTIP, properties.getToolTip());
      prefs.flush();
      MapTool.getFrame().getGlobalPanel().reset();
    } catch (BackingStoreException e) {
      MapTool.showError("Problem saving Global macros?!", e);
    }
  }