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); } }