diff --git a/src/main/java/net/rptools/lib/image/ImageUtil.java b/src/main/java/net/rptools/lib/image/ImageUtil.java
index fe4195ed5b..afce6c607d 100644
--- a/src/main/java/net/rptools/lib/image/ImageUtil.java
+++ b/src/main/java/net/rptools/lib/image/ImageUtil.java
@@ -155,7 +155,7 @@ public static BufferedImage createCompatibleImage(
Graphics2D g = null;
try {
g = compImg.createGraphics();
- AppPreferences.getRenderQuality().setRenderingHints(g);
+ AppPreferences.renderQuality.get().setRenderingHints(g);
g.drawImage(img, 0, 0, width, height, null);
} finally {
if (g != null) {
@@ -442,7 +442,7 @@ public static ImageIcon scaleImage(ImageIcon icon, int w, int h) {
*/
public static BufferedImage scaleBufferedImage(BufferedImage image, int width, int height) {
ResampleOp resampleOp =
- new ResampleOp(width, height, AppPreferences.getRenderQuality().getResampleOpFilter());
+ new ResampleOp(width, height, AppPreferences.renderQuality.get().getResampleOpFilter());
return resampleOp.filter(image, null);
}
}
diff --git a/src/main/java/net/rptools/lib/image/ThumbnailManager.java b/src/main/java/net/rptools/lib/image/ThumbnailManager.java
index e57db4cc4b..3067b916a6 100644
--- a/src/main/java/net/rptools/lib/image/ThumbnailManager.java
+++ b/src/main/java/net/rptools/lib/image/ThumbnailManager.java
@@ -79,7 +79,7 @@ private Image createThumbnail(File file) throws IOException {
new BufferedImage(imgSize.width, imgSize.height, ImageUtil.pickBestTransparency(image));
Graphics2D g = thumbnailImage.createGraphics();
- AppPreferences.getRenderQuality().setShrinkRenderingHints(g);
+ AppPreferences.renderQuality.get().setShrinkRenderingHints(g);
g.drawImage(image, 0, 0, imgSize.width, imgSize.height, null);
g.dispose();
diff --git a/src/main/java/net/rptools/maptool/client/AppActions.java b/src/main/java/net/rptools/maptool/client/AppActions.java
index c49300c1b7..afd87649f7 100644
--- a/src/main/java/net/rptools/maptool/client/AppActions.java
+++ b/src/main/java/net/rptools/maptool/client/AppActions.java
@@ -1195,7 +1195,7 @@ protected void executeAction() {
MapTool.showError("msg.error.mustSelectRootGroup");
return;
}
- AppPreferences.removeAssetRoot(dir.getPath());
+ AppStatePersisted.removeAssetRoot(dir.getPath());
assetPanel.removeAssetRoot(dir);
}
};
@@ -2600,7 +2600,7 @@ protected void done() {
ImageManager.flush(); // Clear out the old campaign's images
AppState.setCampaignFile(campaignFile);
- AppPreferences.setLoadDir(campaignFile.getParentFile());
+ AppPreferences.loadDirectory.set(campaignFile.getParentFile());
AppMenuBar.getMruManager().addMRUCampaign(campaignFile);
campaign.campaign.setName(AppState.getCampaignName()); // Update campaign name
@@ -2792,7 +2792,7 @@ private static void saveAndUpdateCampaignName(File selectedFile, Runnable onSucc
}
doSaveCampaign(campaignFile, onSuccess);
AppState.setCampaignFile(campaignFile);
- AppPreferences.setSaveDir(campaignFile.getParentFile());
+ AppPreferences.saveDirectory.set(campaignFile.getParentFile());
AppMenuBar.getMruManager().addMRUCampaign(AppState.getCampaignFile());
if (MapTool.isHostingServer() || MapTool.isPersonalServer()) {
MapTool.serverCommand().setCampaignName(AppState.getCampaignName());
@@ -2846,7 +2846,7 @@ protected void executeAction() {
}
}
PersistenceUtil.saveMap(zr.getZone(), mapFile);
- AppPreferences.setSaveMapDir(mapFile.getParentFile());
+ AppPreferences.mapSaveDirectory.set(mapFile.getParentFile());
MapTool.showInformation("msg.info.mapSaved");
} catch (IOException ioe) {
MapTool.showError("msg.error.failedSaveMap", ioe);
@@ -2973,7 +2973,7 @@ protected void done() {
try {
PersistedMap map = get();
- AppPreferences.setLoadDir(mapFile.getParentFile());
+ AppPreferences.loadDirectory.set(mapFile.getParentFile());
if ((map.zone.getExposedArea() != null && !map.zone.getExposedArea().isEmpty())
|| (map.zone.getExposedAreaMetaData() != null
&& !map.zone.getExposedAreaMetaData().isEmpty())) {
diff --git a/src/main/java/net/rptools/maptool/client/AppPreferences.java b/src/main/java/net/rptools/maptool/client/AppPreferences.java
index 298b30be10..ff458fbe5b 100644
--- a/src/main/java/net/rptools/maptool/client/AppPreferences.java
+++ b/src/main/java/net/rptools/maptool/client/AppPreferences.java
@@ -19,31 +19,23 @@
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.function.Consumer;
+import java.util.function.Predicate;
+import java.util.function.Supplier;
import java.util.prefs.Preferences;
-import net.rptools.maptool.client.ui.theme.RessourceManager;
+import javax.annotation.Nullable;
import net.rptools.maptool.client.walker.WalkerMetric;
import net.rptools.maptool.language.I18N;
import net.rptools.maptool.model.GridFactory;
import net.rptools.maptool.model.Label;
-import net.rptools.maptool.model.Token;
import net.rptools.maptool.model.Zone;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
-/** The AppPreferences class is used for managing the preferences of the application. */
+/** Manages and persists user preferences for the application. */
public class AppPreferences {
-
- /**
- * The log variable represents a logger object used for logging messages in the AppPreferences
- * class. It is a private static final variable of type Logger. The logger object is obtained
- * using the getLogger method from the LogManager class, specifying the AppPreferences class as
- * the logging context.
- */
private static final Logger log = LogManager.getLogger(AppPreferences.class);
/**
@@ -56,711 +48,379 @@ public class AppPreferences {
*
*
This variable is used to access and modify user preferences throughout the application.
*/
- private static Preferences prefs = Preferences.userRoot().node(AppConstants.APP_NAME + "/prefs");
-
- /** Holds the render quality preference setting for the application. */
- private static RenderQuality renderQuality;
-
- /**
- * Defines the key constant for retrieving asset roots.
- *
- *
This constant is used to define the key for accessing asset roots in a configuration file or
- * a data source. Asset roots represent the directories or paths where application assets are
- * stored.
- *
- *
The asset roots can be used to locate and load files, images, or other resources required by
- * the application at runtime. By convention, the asset root directories are organized in a
- * structured manner to facilitate easy retrieval of assets.
- */
- private static final String KEY_ASSET_ROOTS = "assetRoots";
-
- /**
- * The constant representing the key for the save directory.
- *
- *
This key is used to access and store the value of the save directory. The value associated
- * with this key should be a string representing the directory path.
- */
- private static final String KEY_SAVE_DIR = "saveDir";
-
- /**
- * The constant representing the key for saving token directory. This constant is used to retrieve
- * the directory path where token information will be exported.
- */
- private static final String KEY_SAVE_TOKEN_DIR = "saveTokenDir";
-
- /**
- * The variable to store the key for saving the map directory.
- *
- *
This variable is used to configure the directory where the map will be export.
- */
- private static final String KEY_SAVE_MAP_DIR = "saveMapDir";
-
- /**
- * The key for the load directory.
- *
- *
This constant represents the key used to specify the last directory used for loading files
- * so that subsequent dialogs will be opened with the same path.
- *
- *
The value should be a String representing the directory path.
- */
- private static final String KEY_LOAD_DIR = "loadDir";
-
- /**
- * The configuration key for specifying the directory path where the last add-on was loaded from,
- * so that subsequent dialogs will be opened with the same path.
- *
- *
The value should be a String representing the directory path.
- */
- private static final String KEY_ADD_ON_LOAD_DIR = "addOnLoadDir";
-
- /** Represents the key used to access the most recently used campaigns for the menu option. */
- private static final String KEY_MRU_CAMPAIGNS = "mruCampaigns";
-
- /** Represents the key used to load the most recent campaign on launch. Defaults to false */
- private static final String KEY_LOAD_MRU_CAMPAIGN_AT_START = "loadMRUCampaignAtStart";
-
- private static final boolean DEFAULT_LOAD_MRU_CAMPAIGN_AT_START = false;
-
- /** Represents the key used to save the paint textures to the preferences. */
- private static final String KEY_SAVED_PAINT_TEXTURES = "savedTextures";
-
- /**
- * Represents the key used to determine if the user should be prompted to save the campaign on
- * quit.
- */
- private static final String KEY_SAVE_REMINDER = "autoSaveReminder";
-
- /**
- * The default value for the {@code KEY_SAVE_REMINDER} key.
- *
- * @see #KEY_SAVE_REMINDER
- */
- private static final boolean DEFAULT_SAVE_REMINDER = true;
-
- /**
- * Represents the key for the method used to determine which name of the token (Player/GM) the
- * number is appended to.
- */
- private static final String KEY_TOKEN_NUMBER_DISPLAY = "tokenNumberDisplayg";
-
- /**
- * The default value for the {@code KEY_TOKEN_NUMBER_DISPLAY} preference option,.
- *
- * @see #KEY_TOKEN_NUMBER_DISPLAY
- */
- private static final String DEFAULT_TOKEN_NUMBER_DISPLAY = Token.NUM_ON_NAME;
-
- /** Represents the key used to retrieve the number of minutes between auto saves. */
- private static final String KEY_AUTO_SAVE_INCREMENT = "autoSaveIncrement";
-
- /**
- * The default value for the {@code KEY_AUTO_SAVE_INCREMENT} preference option.
- *
- * @see #KEY_AUTO_SAVE_INCREMENT
- */
- private static final int DEFAULT_AUTO_SAVE_INCREMENT = 5; // Minutes
-
- private static final String KEY_CHAT_AUTOSAVE_TIME = "chatAutosaveTime";
- private static final int DEFAULT_CHAT_AUTOSAVE_TIME = 0; // Minutes; zero=disabled
-
- private static final String KEY_CHAT_FILENAME_FORMAT = "chatFilenameFormat";
- private static final String DEFAULT_CHAT_FILENAME_FORMAT =
- "chatlog-%1$tF-%1$tR.html"; // http://download.oracle.com/javase/1.5.0/docs/api/java/util/Formatter.html
-
- private static final String KEY_DUPLICATE_TOKEN_NUMBER = "duplicateTokenNumber";
- private static final String DEFAULT_DUPLICATE_TOKEN_NUMBER = Token.NUM_INCREMENT;
-
- private static final String KEY_NEW_TOKEN_NAMING = "newTokenNaming";
- private static final String DEFAULT_NEW_TOKEN_NAMING = Token.NAME_USE_FILENAME;
-
- private static final String KEY_USE_HALO_COLOR_ON_VISION_OVERLAY = "useHaloColorForVisionOverlay";
- private static final boolean DEFAULT_USE_HALO_COLOR_ON_VISION_OVERLAY = false;
-
- private static final String KEY_HALO_OVERLAY_OPACITY = "haloOverlayOpacity";
- private static final int DEFAULT_HALO_OVERLAY_OPACITY = 60;
-
- private static final String KEY_AURA_OVERLAY_OPACITY = "auraOverlayOpacity";
- private static final int DEFAULT_AURA_OVERLAY_OPACITY = 60;
-
- private static final String KEY_LIGHT_OVERLAY_OPACITY = "lightOverlayOpacity";
- private static final int DEFAULT_LIGHT_OVERLAY_OPACITY = 60;
-
- private static final String KEY_LUMENS_OVERLAY_OPACITY = "lumensOverlayOpacity";
- private static final int DEFAULT_LUMENS_OVERLAY_OPACITY = 120;
-
- private static final String KEY_LUMENS_OVERLAY_BORDER_THICKNESS = "lumensOverlayBorderThickness";
- private static final int DEFAULT_LUMENS_OVERLAY_BORDER_THICKNESS = 5;
-
- private static final String KEY_LUMENS_OVERLAY_SHOW_BY_DEFAULT = "lumensOverlayShowByDefault";
- private static final boolean DEFAULT_LUMENS_OVERLAY_SHOW_BY_DEFAULT = false;
-
- private static final String KEY_LIGHTS_SHOW_BY_DEFAULT = "lightsShowByDefault";
- private static final boolean DEFAULT_LIGHTS_SHOW_BY_DEFAULT = true;
+ private static final Preferences prefs =
+ Preferences.userRoot().node(AppConstants.APP_NAME + "/prefs");
- private static final String KEY_FOG_OVERLAY_OPACITY = "fogOverlayOpacity";
- private static final int DEFAULT_FOG_OVERLAY_OPACITY = 100;
+ public static final Preference fillSelectionBox =
+ BooleanType.create("fillSelectionBox", true);
- private static final String KEY_HALO_LINE_WIDTH = "haloLineWidth";
- private static final int DEFAULT_HALO_LINE_WIDTH = 2;
+ public static final Preference chatColor =
+ ColorType.create("chatColor", Color.black, false);
- private static final String KEY_AUTO_REVEAL_VISION_ON_GM_MOVEMENT = "autoRevealVisionOnGMMove";
- private static final boolean DEFAULT_AUTO_REVEAL_VISION_ON_GM_MOVEMENT = false;
+ public static final Preference saveReminder =
+ BooleanType.create("autoSaveReminder", true);
- private static final String KEY_USE_SOFT_FOG_EDGES = "useSoftFog";
- private static final boolean DEFAULT_USE_SOFT_FOG_EDGES = true;
+ public static final Preference autoSaveIncrement =
+ IntegerType.create("autoSaveIncrement", 5);
- private static final String KEY_MAP_VISIBILITY_WARNING = "mapVisibilityWarning";
+ public static final Preference chatAutoSaveTimeInMinutes =
+ IntegerType.create("chatAutosaveTime", 0);
- private static final String KEY_NEW_MAPS_HAVE_FOW = "newMapsHaveFow";
- private static final boolean DEFAULT_NEW_MAPS_HAVE_FOW = false;
+ public static final Preference chatFilenameFormat =
+ StringType.create("chatFilenameFormat", "chatlog-%1$tF-%1$tR.html");
- private static final String KEY_NEW_TOKENS_VISIBLE = "newTokensVisible";
- private static final boolean DEFAULT_NEW_TOKENS_VISIBLE = true;
+ public static final Preference tokenNumberDisplay =
+ StringType.create("tokenNumberDisplayg", "Name");
- private static final String KEY_NEW_MAPS_VISIBLE = "newMapsVisible";
- private static final boolean DEFAULT_NEW_MAPS_VISIBLE = true;
+ public static final Preference duplicateTokenNumber =
+ StringType.create("duplicateTokenNumber", "Increment");
- private static final String KEY_NEW_OBJECTS_VISIBLE = "newObjectsVisible";
- private static final boolean DEFAULT_NEW_OBJECTS_VISIBLE = true;
+ public static final Preference newTokenNaming =
+ StringType.create("newTokenNaming", "Use Filename");
- private static final String KEY_NEW_BACKGROUNDS_VISIBLE = "newBackgroundsVisible";
- private static final boolean DEFAULT_NEW_BACKGROUNDS_VISIBLE = true;
+ public static final Preference useHaloColorOnVisionOverlay =
+ BooleanType.create("useHaloColorForVisionOverlay", false);
- private static final String KEY_TOKENS_START_FREESIZE = "newTokensStartFreesize";
- private static final boolean DEFAULT_TOKENS_START_FREESIZE = false;
+ public static final Preference mapVisibilityWarning =
+ BooleanType.create("mapVisibilityWarning", false);
- private static final String KEY_TOKENS_WARN_WHEN_DELETED = "tokensWarnWhenDeleted";
- private static final boolean DEFAULT_TOKENS_WARN_WHEN_DELETED = true;
+ public static final Preference autoRevealVisionOnGMMovement =
+ BooleanType.create("autoRevealVisionOnGMMove", false);
- private static final String KEY_DRAW_WARN_WHEN_DELETED = "drawWarnWhenDeleted";
- private static final boolean DEFAULT_DRAW_WARN_WHEN_DELETED = true;
+ public static final Preference haloOverlayOpacity =
+ ByteType.create("haloOverlayOpacity", 60);
- private static final String KEY_TOKENS_START_SNAP_TO_GRID = "newTokensStartSnapToGrid";
- private static final boolean DEFAULT_TOKENS_START_SNAP_TO_GRID = true;
+ public static final Preference auraOverlayOpacity =
+ ByteType.create("auraOverlayOpacity", 60);
- private static final String KEY_TOKENS_SNAP_WHILE_DRAGGING = "tokensSnapWhileDragging";
- private static final boolean DEFAULT_KEY_TOKENS_SNAP_WHILE_DRAGGING = true;
+ public static final Preference lightOverlayOpacity =
+ ByteType.create("lightOverlayOpacity", 60);
- private static final String KEY_HIDE_MOUSE_POINTER_WHILE_DRAGGING =
- "hideMousePointerWhileDragging";
- private static final boolean DEFAULT_KEY_HIDE_MOUSE_POINTER_WHILE_DRAGGING = true;
+ public static final Preference lumensOverlayOpacity =
+ ByteType.create("lumensOverlayOpacity", 120);
- private static final String KEY_HIDE_TOKEN_STACK_INDICATOR = "hideTokenStackIndicator";
- private static final boolean DEFAULT_KEY_HIDE_TOKEN_STACK_INDICATOR = false;
+ public static final Preference fogOverlayOpacity =
+ ByteType.create("fogOverlayOpacity", 100);
- private static final String KEY_OBJECTS_START_SNAP_TO_GRID = "newStampsStartSnapToGrid";
- private static final boolean DEFAULT_OBJECTS_START_SNAP_TO_GRID = false;
+ public static final Preference lumensOverlayBorderThickness =
+ IntegerType.create("lumensOverlayBorderThickness", 5);
- private static final String KEY_OBJECTS_START_FREESIZE = "newStampsStartFreesize";
- private static final boolean DEFAULT_OBJECTS_START_FREESIZE = true;
+ public static final Preference lumensOverlayShowByDefault =
+ BooleanType.create("lumensOverlayShowByDefault", false);
- private static final String KEY_BACKGROUNDS_START_SNAP_TO_GRID = "newBackgroundsStartSnapToGrid";
- private static final boolean DEFAULT_BACKGROUNDS_START_SNAP_TO_GRID = false;
+ public static final Preference lightsShowByDefault =
+ BooleanType.create("lightsShowByDefault", true);
- private static final String KEY_BACKGROUNDS_START_FREESIZE = "newBackgroundsStartFreesize";
- private static final boolean DEFAULT_BACKGROUNDS_START_FREESIZE = true;
+ public static final Preference haloLineWidth = IntegerType.create("haloLineWidth", 2);
- private static final String KEY_SOUNDS_ONLY_WHEN_NOT_FOCUSED =
- "playSystemSoundsOnlyWhenNotFocused";
- private static final boolean DEFAULT_SOUNDS_ONLY_WHEN_NOT_FOCUSED = false;
+ public static final Preference typingNotificationDurationInSeconds =
+ IntegerType.create("typingNotificationDuration", 5);
- private static final String KEY_SYRINSCAPE_ACTIVE = "syrinscapeActive";
- private static final boolean DEFAULT_SYRINSCAPE_ACTIVE = false;
+ public static final Preference chatNotificationBackground =
+ BooleanType.create("chatNotificationShowBackground", true);
- private static final String KEY_SHOW_AVATAR_IN_CHAT = "showAvatarInChat";
- private static final boolean DEFAULT_SHOW_AVATAR_IN_CHAT = true;
+ public static final Preference useToolTipForInlineRoll =
+ BooleanType.create("toolTipInlineRolls", false);
- private static final String KEY_SHOW_DIALOG_ON_NEW_TOKEN = "showDialogOnNewToken";
- private static final boolean DEFAULT_SHOW_DIALOG_ON_NEW_TOKEN = true;
+ public static final Preference suppressToolTipsForMacroLinks =
+ BooleanType.create("suppressToolTipsMacroLinks", false);
- private static final String KEY_INSERT_SMILIES = "insertSmilies";
- private static final boolean DEFAULT_SHOW_SMILIES = true;
+ public static final Preference chatNotificationColor =
+ ColorType.create("chatNotificationColor", Color.white, false);
- private static final String KEY_MOVEMENT_METRIC = "movementMetric";
- private static final WalkerMetric DEFAULT_MOVEMENT_METRIC = WalkerMetric.ONE_TWO_ONE;
+ public static final Preference trustedPrefixBackground =
+ ColorType.create("trustedPrefixBG", new Color(0xD8, 0xE9, 0xF6), false);
- private static final String KEY_SHOW_STAT_SHEET = "showStatSheet";
- private static final boolean DEFAULT_SHOW_STAT_SHEET = true;
+ public static final Preference trustedPrefixForeground =
+ ColorType.create("trustedPrefixFG", Color.BLACK, false);
- private static final String KEY_SHOW_PORTRAIT = "showPortrait";
- private static final boolean DEFAULT_SHOW_PORTRAIT = true;
+ public static final Preference toolTipInitialDelay =
+ IntegerType.create("toolTipInitialDelay", 250);
- private static final String KEY_SHOW_STAT_SHEET_MODIFIER = "showStatSheetModifier";
- private static final boolean DEFAULT_SHOW_STAT_SHEET_MODIFIER = false;
+ public static final Preference toolTipDismissDelay =
+ IntegerType.create("toolTipDismissDelay", 30000);
- private static final String KEY_FILL_SELECTION_BOX = "fillSelectionBox";
- private static final boolean DEFAULT_FILL_SELECTION_BOX = true;
+ public static final Preference allowPlayerMacroEditsDefault =
+ BooleanType.create("allowPlayerMacroEditsDefault", true);
- private static final String KEY_SHOW_INIT_GAIN_MESSAGE = "showInitGainMessage";
- private static final boolean DEFAULT_SHOW_INIT_GAIN_MESSAGE = true;
+ public static final Preference portraitSize = IntegerType.create("portraitSize", 175);
- private static final String KEY_FORCE_FACING_ARROW = "forceFacingArrow";
- private static final boolean DEFAULT_FORCE_FACING_ARROW = false;
+ public static final Preference thumbnailSize = IntegerType.create("thumbnailSize", 500);
- private static final String KEY_USE_ASTAR_PATHFINDING = "useAstarPathfinding";
- private static final boolean DEFAULT_USE_ASTAR_PATHFINDING = true;
+ public static final Preference showSmilies = BooleanType.create("insertSmilies", true);
- private static final String KEY_VBL_BLOCKS_MOVE = "vblBlocksMove";
- private static final boolean DEFAULT_VBL_BLOCKS_MOVE = true;
+ public static final Preference showDialogOnNewToken =
+ BooleanType.create("showDialogOnNewToken", true);
- private static final String MACRO_EDITOR_THEME = "macroEditorTheme";
- private static final String DEFAULT_MACRO_EDITOR_THEME = "Default";
+ public static final Preference showAvatarInChat =
+ BooleanType.create("showAvatarInChat", true);
- private static final String ICON_THEME = "iconTheme";
- private static final String DEFAULT_ICON_THEME = RessourceManager.ROD_TAKEHARA;
+ public static final Preference playSystemSounds =
+ BooleanType.create("playSystemSounds", true);
- // When hill VBL was introduced, older versions of MapTool were unable to read the new topology
- // modes. So we use a different preference key than in the past so older versions would not
- // unexpectedly break.
- private static final String KEY_TOPOLOGY_TYPES = "topologyTypes";
- private static final String KEY_OLD_TOPOLOGY_DRAWING_MODE = "topologyDrawingMode";
- private static final String DEFAULT_TOPOLOGY_TYPE = "VBL";
+ public static final Preference playSystemSoundsOnlyWhenNotFocused =
+ BooleanType.create("playSystemSoundsOnlyWhenNotFocused", false);
- private static final String KEY_WEB_END_POINT_PORT = "webEndPointPort";
- private static final int DEFAULT_WEB_END_POINT = 654555;
+ public static final Preference playStreams = BooleanType.create("playStreams", true);
- public static void setFillSelectionBox(boolean fill) {
- prefs.putBoolean(KEY_FILL_SELECTION_BOX, fill);
- }
-
- public static boolean getFillSelectionBox() {
- return prefs.getBoolean(KEY_FILL_SELECTION_BOX, DEFAULT_FILL_SELECTION_BOX);
- }
-
- public static Color getChatColor() {
- return new Color(prefs.getInt(KEY_CHAT_COLOR, DEFAULT_CHAT_COLOR.getRGB()));
- }
-
- public static void setSaveReminder(boolean reminder) {
- prefs.putBoolean(KEY_SAVE_REMINDER, reminder);
- }
-
- public static boolean getSaveReminder() {
- return prefs.getBoolean(KEY_SAVE_REMINDER, DEFAULT_SAVE_REMINDER);
- }
-
- // public static void setEnabledMapExportImport(boolean reminder) {
- // prefs.putBoolean(KEY_ENABLE_MAP_EXPORT_IMPORT, reminder);
- // AppActions.updateActions();
- // }
-
- // public static boolean isEnabledMapExportImport() {
- // return prefs.getBoolean(KEY_ENABLE_MAP_EXPORT_IMPORT, DEFAULT_ENABLE_MAP_EXPORT_IMPORT);
- // }
-
- public static void setAutoSaveIncrement(int increment) {
- prefs.putInt(KEY_AUTO_SAVE_INCREMENT, increment);
- }
-
- public static int getAutoSaveIncrement() {
- return prefs.getInt(KEY_AUTO_SAVE_INCREMENT, DEFAULT_AUTO_SAVE_INCREMENT);
- }
-
- public static void setChatAutosaveTime(int minutes) {
- if (minutes >= 0) {
- prefs.putInt(KEY_CHAT_AUTOSAVE_TIME, minutes);
- ChatAutoSave.changeTimeout(minutes);
- }
- }
-
- public static int getChatAutosaveTime() {
- return prefs.getInt(KEY_CHAT_AUTOSAVE_TIME, DEFAULT_CHAT_AUTOSAVE_TIME);
- }
+ public static final Preference syrinscapeActive =
+ BooleanType.create("syrinscapeActive", false);
- public static void setChatFilenameFormat(String pattern) {
- prefs.put(KEY_CHAT_FILENAME_FORMAT, pattern);
- }
+ public static final Preference fontSize = IntegerType.create("fontSize", 12);
- public static String getChatFilenameFormat() {
- return prefs.get(KEY_CHAT_FILENAME_FORMAT, DEFAULT_CHAT_FILENAME_FORMAT);
- }
+ public static final Preference defaultGridColor =
+ ColorType.create("defaultGridColor", Color.black, false);
- public static void clearChatFilenameFormat() {
- prefs.remove(KEY_CHAT_FILENAME_FORMAT);
- }
+ public static final Preference defaultGridSize =
+ IntegerType.create("defaultGridSize", 100);
- public static void setTokenNumberDisplay(String display) {
- prefs.put(KEY_TOKEN_NUMBER_DISPLAY, display);
- }
+ public static final Preference defaultUnitsPerCell =
+ DoubleType.create("unitsPerCell", 5.);
- public static String getTokenNumberDisplay() {
- return prefs.get(KEY_TOKEN_NUMBER_DISPLAY, DEFAULT_TOKEN_NUMBER_DISPLAY);
- }
+ public static final Preference faceVertex = BooleanType.create("faceVertex", false);
- public static void setDuplicateTokenNumber(String numbering) {
- prefs.put(KEY_DUPLICATE_TOKEN_NUMBER, numbering);
- }
+ public static final Preference faceEdge = BooleanType.create("faceEdge", true);
- public static String getDuplicateTokenNumber() {
- return prefs.get(KEY_DUPLICATE_TOKEN_NUMBER, DEFAULT_DUPLICATE_TOKEN_NUMBER);
- }
+ public static final Preference defaultVisionDistance =
+ IntegerType.create("defaultVisionDistance", 1000);
- public static void setNewTokenNaming(String naming) {
- prefs.put(KEY_NEW_TOKEN_NAMING, naming);
- }
+ public static final Preference defaultVisionType =
+ EnumType.create(Zone.VisionType.class, "defaultVisionType", Zone.VisionType.OFF);
- public static String getNewTokenNaming() {
- return prefs.get(KEY_NEW_TOKEN_NAMING, DEFAULT_NEW_TOKEN_NAMING);
- }
+ public static final Preference mapSortType =
+ EnumType.create(MapSortType.class, "sortByGMName", MapSortType.GMNAME);
- public static void setUseHaloColorOnVisionOverlay(boolean flag) {
- prefs.putBoolean(KEY_USE_HALO_COLOR_ON_VISION_OVERLAY, flag);
- }
+ public static final Preference useSoftFogEdges = BooleanType.create("useSoftFog", true);
- public static boolean getUseHaloColorOnVisionOverlay() {
- return prefs.getBoolean(
- KEY_USE_HALO_COLOR_ON_VISION_OVERLAY, DEFAULT_USE_HALO_COLOR_ON_VISION_OVERLAY);
- }
+ public static final Preference newMapsHaveFow =
+ BooleanType.create("newMapsHaveFow", false);
- public static void setMapVisibilityWarning(boolean flag) {
- prefs.putBoolean(KEY_MAP_VISIBILITY_WARNING, flag);
- }
+ public static final Preference newTokensVisible =
+ BooleanType.create("newTokensVisible", true);
- public static boolean getMapVisibilityWarning() {
- return prefs.getBoolean(KEY_MAP_VISIBILITY_WARNING, false);
- }
+ public static final Preference newMapsVisible =
+ BooleanType.create("newMapsVisible", true);
- public static void setAutoRevealVisionOnGMMovement(boolean flag) {
- prefs.putBoolean(KEY_AUTO_REVEAL_VISION_ON_GM_MOVEMENT, flag);
- }
+ public static final Preference newObjectsVisible =
+ BooleanType.create("newObjectsVisible", true);
- public static boolean getAutoRevealVisionOnGMMovement() {
- return prefs.getBoolean(
- KEY_AUTO_REVEAL_VISION_ON_GM_MOVEMENT, DEFAULT_AUTO_REVEAL_VISION_ON_GM_MOVEMENT);
- }
+ public static final Preference newBackgroundsVisible =
+ BooleanType.create("newBackgroundsVisible", true);
- private static int range0to255(int value) {
- return value < 1 ? 0 : Math.min(value, 255);
- }
+ public static final Preference saveDirectory =
+ FileType.create("saveDir", () -> new File(File.separator));
- public static void setHaloOverlayOpacity(int size) {
- prefs.putInt(KEY_HALO_OVERLAY_OPACITY, range0to255(size));
- }
+ public static final Preference tokenSaveDirectory =
+ FileType.create("saveTokenDir", saveDirectory::get);
- public static int getHaloOverlayOpacity() {
- int value = prefs.getInt(KEY_HALO_OVERLAY_OPACITY, DEFAULT_HALO_OVERLAY_OPACITY);
- return range0to255(value);
- }
+ public static final Preference mapSaveDirectory =
+ FileType.create("saveMapDir", saveDirectory::get);
- public static void setAuraOverlayOpacity(int size) {
- prefs.putInt(KEY_AURA_OVERLAY_OPACITY, range0to255(size));
- }
+ public static final Preference addOnLoadDirectory =
+ FileType.create("addOnLoadDir", saveDirectory::get);
- public static int getAuraOverlayOpacity() {
- int value = prefs.getInt(KEY_AURA_OVERLAY_OPACITY, DEFAULT_AURA_OVERLAY_OPACITY);
- return range0to255(value);
- }
+ public static final Preference loadDirectory =
+ FileType.create("loadDir", () -> new File(File.separator));
- public static void setLightOverlayOpacity(int size) {
- prefs.putInt(KEY_LIGHT_OVERLAY_OPACITY, range0to255(size));
- }
+ public static final Preference renderQuality =
+ EnumType.create(RenderQuality.class, "renderScaleQuality", RenderQuality.LOW_SCALING)
+ .cacheIt();
- public static int getLightOverlayOpacity() {
- int value = prefs.getInt(KEY_LIGHT_OVERLAY_OPACITY, DEFAULT_LIGHT_OVERLAY_OPACITY);
- return range0to255(value);
- }
+ /** The background color to use for NPC map labels. */
+ public static final Preference npcMapLabelBackground =
+ ColorType.create("npcMapLabelBG", Color.LIGHT_GRAY, true);
- public static void setLumensOverlayOpacity(int size) {
- prefs.putInt(KEY_LUMENS_OVERLAY_OPACITY, range0to255(size));
- }
+ /** The foreground color to use for NPC map labels. */
+ public static final Preference npcMapLabelForeground =
+ ColorType.create("npcMapLabelFG", Color.BLACK, true);
- public static int getLumensOverlayOpacity() {
- int value = prefs.getInt(KEY_LUMENS_OVERLAY_OPACITY, DEFAULT_LUMENS_OVERLAY_OPACITY);
- return range0to255(value);
- }
+ /** The border color to use for NPC map labels. */
+ public static final Preference npcMapLabelBorder =
+ ColorType.create("mapLabelBorderColor", npcMapLabelForeground.getDefault(), true);
- public static void setLumensOverlayBorderThickness(int thickness) {
- prefs.putInt(KEY_LUMENS_OVERLAY_BORDER_THICKNESS, thickness);
- }
+ /** The background color to use for PC map labels. */
+ public static final Preference pcMapLabelBackground =
+ ColorType.create("pcMapLabelBG", Color.WHITE, true);
- public static int getLumensOverlayBorderThickness() {
- return prefs.getInt(
- KEY_LUMENS_OVERLAY_BORDER_THICKNESS, DEFAULT_LUMENS_OVERLAY_BORDER_THICKNESS);
- }
+ /** The foreground color to use for PC map labels. */
+ public static final Preference pcMapLabelForeground =
+ ColorType.create("pcMapLabelFG", Color.BLUE, true);
- public static void setLumensOverlayShowByDefault(boolean show) {
- prefs.putBoolean(KEY_LUMENS_OVERLAY_SHOW_BY_DEFAULT, show);
- }
+ /** The border color to use for PC map labels. */
+ public static final Preference pcMapLabelBorder =
+ ColorType.create("pcMapLabelBorderColor", pcMapLabelForeground.getDefault(), true);
- public static boolean getLumensOverlayShowByDefault() {
- return prefs.getBoolean(
- KEY_LUMENS_OVERLAY_SHOW_BY_DEFAULT, DEFAULT_LUMENS_OVERLAY_SHOW_BY_DEFAULT);
- }
+ /** The background color to use for Non-Visible Token map labels. */
+ public static final Preference nonVisibleTokenMapLabelBackground =
+ ColorType.create("nonVisMapLabelBG", Color.BLACK, true);
- public static void setLightsShowByDefault(boolean show) {
- prefs.putBoolean(KEY_LIGHTS_SHOW_BY_DEFAULT, show);
- }
+ /** The foreground color to use for Non-Visible Token map labels. */
+ public static final Preference nonVisibleTokenMapLabelForeground =
+ ColorType.create("nonVisMapLabelFG", Color.WHITE, true);
- public static boolean getLightsShowByDefault() {
- return prefs.getBoolean(KEY_LIGHTS_SHOW_BY_DEFAULT, DEFAULT_LIGHTS_SHOW_BY_DEFAULT);
- }
+ /** The border color to use for Non-Visible Token map labels. */
+ public static final Preference nonVisibleTokenMapLabelBorder =
+ ColorType.create(
+ "nonVisMapLabelBorderColor", nonVisibleTokenMapLabelForeground.getDefault(), true);
- public static void setFogOverlayOpacity(int size) {
- prefs.putInt(KEY_FOG_OVERLAY_OPACITY, range0to255(size));
+ /** The font size to use for token map labels. */
+ public static final Preference mapLabelFontSize =
+ IntegerType.create("mapLabelFontSize", AppStyle.labelFont.getSize());
- // FIXME Force ModelChange event to flush fog from zone :(
- Zone zone = MapTool.getFrame().getCurrentZoneRenderer().getZone();
- zone.setHasFog(zone.hasFog());
- }
+ /** The width of the border for token map labels, in pixels. */
+ public static final Preference mapLabelBorderWidth =
+ IntegerType.create("mapLabelBorderWidth", Label.DEFAULT_LABEL_BORDER_WIDTH);
- public static int getFogOverlayOpacity() {
- int value = prefs.getInt(KEY_FOG_OVERLAY_OPACITY, DEFAULT_FOG_OVERLAY_OPACITY);
- return range0to255(value);
- }
+ /** The size of the border arc for token map labels. */
+ public static final Preference mapLabelBorderArc =
+ IntegerType.create("mapLabelBorderArc", Label.DEFAULT_LABEL_BORDER_ARC);
- private static final String KEY_DEFAULT_GRID_TYPE = "defaultGridType";
- private static final String DEFAULT_DEFAULT_GRID_TYPE = GridFactory.SQUARE;
+ /** {@code true} if borders should be shown around map labels, {@code false} otherwise. */
+ public static final Preference mapLabelShowBorder =
+ BooleanType.create("mapLabelShowBorder", true);
- private static final String KEY_FACE_VERTEX = "faceVertex";
- private static final boolean DEFAULT_FACE_VERTEX = false;
+ // TODO Why is the default not a valid port?
+ public static final Preference webEndpointPort =
+ IntegerType.create("webEndPointPort", 654555);
- private static final String KEY_FACE_EDGE = "faceEdge";
- private static final boolean DEFAULT_FACE_EDGE = true;
+ public static final Preference tokensWarnWhenDeleted =
+ BooleanType.create("tokensWarnWhenDeleted", true);
- private static final String KEY_DEFAULT_GRID_SIZE = "defaultGridSize";
- private static final int DEFAULT_DEFAULT_GRID_SIZE = 100;
+ public static final Preference drawingsWarnWhenDeleted =
+ BooleanType.create("drawWarnWhenDeleted", true);
- private static final String KEY_DEFAULT_GRID_COLOR = "defaultGridColor";
- private static final int DEFAULT_DEFAULT_GRID_COLOR = Color.black.getRGB();
+ public static final Preference tokensSnapWhileDragging =
+ BooleanType.create("tokensSnapWhileDragging", true);
- private static final String KEY_DEFAULT_UNITS_PER_CELL = "unitsPerCell";
- private static final int DEFAULT_DEFAULT_UNITS_PER_CELL = 5;
+ public static final Preference hideMousePointerWhileDragging =
+ BooleanType.create("hideMousePointerWhileDragging", true);
- private static final String KEY_DEFAULT_VISION_DISTANCE = "defaultVisionDistance";
- private static final int DEFAULT_DEFAULT_VISION_DISTANCE = 1000;
+ public static final Preference hideTokenStackIndicator =
+ BooleanType.create("hideTokenStackIndicator", false);
- private static final String KEY_DEFAULT_VISION_TYPE = "defaultVisionType";
- private static final Zone.VisionType DEFAULT_VISION_TYPE = Zone.VisionType.OFF;
+ public static final Preference tokensStartSnapToGrid =
+ BooleanType.create("newTokensStartSnapToGrid", true);
- private static final String KEY_MAP_SORT_TYPE = "sortByGMName";
- private static final MapSortType DEFAULT_MAP_SORT_TYPE = MapSortType.GMNAME;
+ public static final Preference objectsStartSnapToGrid =
+ BooleanType.create("newStampsStartSnapToGrid", false);
- private static final String KEY_FONT_SIZE = "fontSize";
- private static final int DEFAULT_FONT_SIZE = 12;
+ public static final Preference backgroundsStartSnapToGrid =
+ BooleanType.create("newBackgroundsStartSnapToGrid", false);
- private static final String KEY_CHAT_COLOR = "chatColor";
- private static final Color DEFAULT_CHAT_COLOR = Color.black;
+ public static final Preference tokensStartFreesize =
+ BooleanType.create("newTokensStartFreesize", false);
- private static final String KEY_PLAY_SYSTEM_SOUNDS = "playSystemSounds";
- private static final boolean DEFAULT_PLAY_SYSTEM_SOUNDS = true;
+ public static final Preference objectsStartFreesize =
+ BooleanType.create("newStampsStartFreesize", true);
- private static final String KEY_PLAY_STREAMS = "playStreams";
- private static final boolean DEFAULT_PLAY_STREAMS = true;
+ public static final Preference backgroundsStartFreesize =
+ BooleanType.create("newBackgroundsStartFreesize", true);
- /**
- * The key for retrieving the background color of NPC map labels. The value of this key is used to
- * store and retrieve background color information for NPC map The background color is used to
- * style the text of the map labels for Non-Player Characters (NPCs). labels. The value associated
- * with this key should be a valid color value.
- */
- private static final String KEY_NPC_MAP_LABEL_BG_COLOR = "npcMapLabelBG";
+ public static final Preference defaultGridType =
+ StringType.create("defaultGridType", GridFactory.SQUARE);
- /**
- * Constant variable for the foreground color of NPC map labels. The value represents the key used
- * to retrieve the color from a map or configuration file. The foreground color is used to style
- * the text of the map labels for Non-Player Characters (NPCs). This constant is intended to be
- * used within the context of a software application or system.
- */
- private static final String KEY_NPC_MAP_LABEL_FG_COLOR = "npcMapLabelFG";
+ public static final Preference showStatSheet = BooleanType.create("showStatSheet", true);
- /**
- * Constant variable for the border color of NPC map labels. The value represents the key used to
- * retrieve the color from a map or configuration file. The foreground color is used to style the
- * text of the map labels for Non-Player Characters (NPCs). This constant is intended to be used
- * within the context of a software application or system.
- */
- private static final String KEY_NPC_MAP_LABEL_BORDER_COLOR = "mapLabelBorderColor";
+ public static final Preference showStatSheetRequiresModifierKey =
+ BooleanType.create("showStatSheetModifier", false);
- /**
- * The key for retrieving the background color of PC map labels. The value of this key is used to
- * store and retrieve background color information for NPC map The background color is used to
- * style the text of the map labels for Player Characters (PCs) labels. The value associated with
- * this key should be a valid color value.
- */
- private static final String KEY_PC_MAP_LABEL_BG_COLOR = "pcMapLabelBG";
+ public static final Preference showPortrait = BooleanType.create("showPortrait", true);
- /**
- * Constant variable for the foreground color of NPC map labels. The value represents the key used
- * to retrieve the color from a map or configuration file. The border color is used to style the
- * text of the map labels for Non Player Characters (NPCs).
- */
- private static final String KEY_PC_MAP_LABEL_FG_COLOR = "pcMapLabelFG";
+ public static final Preference forceFacingArrow =
+ BooleanType.create("forceFacingArrow", false);
- /**
- * Constant variable for the foreground color of PC map labels. The value represents the key used
- * to retrieve the color from a map or configuration file. The border color is used to style the
- * text of the map labels for Player Characters (PCs).
- */
- private static final String KEY_PC_MAP_LABEL_BORDER_COLOR = "pcMapLabelBorderColor";
+ public static final Preference fitGmView = BooleanType.create("fitGMView", true);
- /**
- * This variable represents the key used to store the background color of non-visible token map
- * labels. The background color is used to style the text of the map labels for tokens that are
- * not visible to the player. The value associated with this key should be a valid color value.
- */
- private static final String KEY_NONVIS_MAP_LABEL_BG_COLOR = "nonVisMapLabelBG";
+ public static final Preference defaultUserName =
+ StringType.create(
+ "defaultUsername", I18N.getString("Preferences.client.default.username.value"));
- /**
- * This variable represents the key used to store the foreground color of non-visible token map
- * labels. The foreground color is used to style the text of the map labels for tokens that are
- * not visible to the player. The value associated with this key should be a valid color value.
- */
- private static final String KEY_NONVIS_MAP_LABEL_FG_COLOR = "nonVisMapLabelFG";
+ public static final Preference movementMetric =
+ EnumType.create(WalkerMetric.class, "movementMetric", WalkerMetric.ONE_TWO_ONE);
- /**
- * This variable represents the key used to store the border color of non-visible token map
- * labels. The foreground color is used to style the text of the map labels for tokens that are
- * not visible to the player. The value associated with this key should be a valid color value.
- */
- private static final String KEY_NONVIS_MAP_LABEL_BORDER_COLOR = "nonVisMapLabelBorderColor";
+ public static final Preference frameRateCap =
+ IntegerType.create("frameRateCap", 60).validateIt(cap -> cap > 0);
- /**
- * The KEY_MAP_LABEL_FONT_SIZE constant is used to define the name of the key that represents the
- * font size of map labels.
- */
- private static final String KEY_MAP_LABEL_FONT_SIZE = "mapLabelFontSize";
+ public static final Preference upnpDiscoveryTimeout =
+ IntegerType.create("upnpDiscoveryTimeout", 5000);
- /** The configuration key for specifying the width of the border around map labels for tokens. */
- private static final String KEY_MAP_LABEL_BORDER_WIDTH = "mapLabelBorderWidth";
+ public static final Preference fileSyncPath = StringType.create("fileSyncPath", "");
- /** The configuration key for specifying the arc of the border around map labels for tokens. */
- private static final String KEY_MAP_LABEL_BORDER_ARC = "mapLabelBorderArc";
+ public static final Preference skipAutoUpdate =
+ BooleanType.create("skipAutoUpdate", false);
- /** The configuration key for specifying the width of the border around map labels for tokens. */
- private static final String KEY_MAP_LABEL_SHOW_BORDER = "mapLabelShowBorder";
+ public static final Preference skipAutoUpdateRelease =
+ StringType.create("skipAutoUpdateRelease", "");
- /** The default background color for the NPC map label. */
- private static final Color DEFAULT_NPC_MAP_LABEL_BG_COLOR = Color.LIGHT_GRAY;
+ public static final Preference allowExternalMacroAccess =
+ BooleanType.create("allowExternalMacroAccess", false);
- /** The default foreground color for NPC map labels. */
- private static final Color DEFAULT_NPC_MAP_LABEL_FG_COLOR = Color.BLACK;
+ public static final Preference loadMruCampaignAtStart =
+ BooleanType.create("loadMRUCampaignAtStart", false);
- /** The default border color for NPC map labels. */
- private static final Color DEFAULT_NPC_MAP_LABEL_BORDER_COLOR = DEFAULT_NPC_MAP_LABEL_FG_COLOR;
+ public static final Preference initiativePanelShowsTokenImage =
+ BooleanType.create("initShowTokens", true);
- /** The default background color for the PC map label. */
- private static final Color DEFAULT_PC_MAP_LABEL_BG_COLOR = Color.WHITE;
+ public static final Preference initiativePanelShowsTokenState =
+ BooleanType.create("initShowTokenStates", true);
- /** The default foreground color for the map labels in the PC map. */
- private static final Color DEFAULT_PC_MAP_LABEL_FG_COLOR = Color.BLUE;
+ public static final Preference initiativePanelShowsInitiative =
+ BooleanType.create("initShowInitiative", true);
- /** The default border color for the PC map labels. */
- private static final Color DEFAULT_PC_MAP_LABEL_BORDER_COLOR = DEFAULT_PC_MAP_LABEL_FG_COLOR;
+ public static final Preference initiativePanelShowsInitiativeOnLine2 =
+ BooleanType.create("initShow2ndLine", false);
- /** The default background color for non-visible map labels. */
- private static final Color DEFAULT_NONVIS_MAP_LABEL_BG_COLOR = Color.BLACK;
+ public static final Preference initiativePanelHidesNpcs =
+ BooleanType.create("initHideNpcs", false);
- /** The default foreground color for non-visible map labels. */
- private static final Color DEFAULT_NONVIS_MAP_LABEL_FG_COLOR = Color.WHITE;
+ public static final Preference initiativePanelAllowsOwnerPermissions =
+ BooleanType.create("initOwnerPermissions", false);
- /** The default border color for non-visible map labels. */
- private static final Color DEFAULT_NONVIS_MAP_LABEL_BORDER_COLOR =
- DEFAULT_NONVIS_MAP_LABEL_FG_COLOR;
+ public static final Preference initiativeMovementLocked =
+ BooleanType.create("initLockMovement", false);
- /** The default font size for map labels. */
- private static final int DEFAULT_MAP_LABEL_FONT_SIZE = AppStyle.labelFont.getSize();
+ public static final Preference showInitiativeGainedMessage =
+ BooleanType.create("showInitGainMessage", true);
- /** The default border width for token map labels. */
- private static final int DEFAULT_MAP_LABEL_BORDER_WIDTH = Label.DEFAULT_LABEL_BORDER_WIDTH;
+ public static final Preference pathfindingEnabled =
+ BooleanType.create("useAstarPathfinding", true);
- /** The default border arc for token map labels. */
- private static final int DEFAULT_MAP_LABEL_BORDER_ARC = Label.DEFAULT_LABEL_BORDER_ARC;
+ public static final Preference pathfindingBlockedByVbl =
+ BooleanType.create("vblBlocksMove", true);
- /** The default border arc for token map labels. */
- private static final boolean DEFAULT_MAP_LABEL_SHOW_BORDER = true;
+ public static final Preference defaultMacroEditorTheme =
+ StringType.create("macroEditorTheme", "Default");
- public static void setHaloLineWidth(int size) {
- prefs.putInt(KEY_HALO_LINE_WIDTH, size);
- }
+ public static final Preference iconTheme = StringType.create("iconTheme", "Rod Takehara");
- public static int getHaloLineWidth() {
- return prefs.getInt(KEY_HALO_LINE_WIDTH, DEFAULT_HALO_LINE_WIDTH);
+ static {
+ // Used to be stored as separate components but now is one color. Add if not already there.
+ if (prefs.get("trustedPrefixFG", null) == null) {
+ var defaultValue = trustedPrefixForeground.getDefault();
+ trustedPrefixForeground.set(
+ new Color(
+ prefs.getInt("trustedPrefixFGRed", defaultValue.getRed()),
+ prefs.getInt("trustedPrefixFGGreen", defaultValue.getGreen()),
+ prefs.getInt("trustedPrefixFBlue", defaultValue.getBlue())));
+ }
+ if (prefs.get("trustedPrefixBG", null) == null) {
+ var defaultValue = trustedPrefixBackground.getDefault();
+ trustedPrefixBackground.set(
+ new Color(
+ prefs.getInt("trustedPrefixBGRed", defaultValue.getRed()),
+ prefs.getInt("trustedPrefixBGGreen", defaultValue.getGreen()),
+ prefs.getInt("trustedPrefixBBlue", defaultValue.getBlue())));
+ }
+ if (prefs.get("chatNotificationColor", null) == null) {
+ var defaultValue = chatNotificationColor.getDefault();
+ chatNotificationColor.set(
+ new Color(
+ prefs.getInt("chatNotificationColorRed", defaultValue.getRed()),
+ prefs.getInt("chatNotificationColorGreen", defaultValue.getGreen()),
+ prefs.getInt("chatNotificationColorBlue", defaultValue.getBlue())));
+ }
}
- private static final String KEY_PORTRAIT_SIZE = "portraitSize";
- private static final int DEFAULT_PORTRAIT_SIZE = 175;
-
- private static final String KEY_THUMBNAIL_SIZE = "thumbnailSize";
- private static final int DEFAULT_THUMBNAIL_SIZE = 500;
-
- private static final String KEY_ALLOW_PLAYER_MACRO_EDITS_DEFAULT = "allowPlayerMacroEditsDefault";
- private static final boolean DEFAULT_ALLOW_PLAYER_MACRO_EDITS_DEFAULT = true;
-
- private static final String KEY_TOOLTIP_INITIAL_DELAY = "toolTipInitialDelay";
- private static final int DEFAULT_TOOLTIP_INITIAL_DELAY = 250;
-
- private static final String KEY_TOOLTIP_DISMISS_DELAY = "toolTipDismissDelay";
- private static final int DEFAULT_TOOLTIP_DISMISS_DELAY = 30000;
-
- private static final String KEY_TOOLTIP_FOR_INLINE_ROLLS = "toolTipInlineRolls";
- private static final boolean DEFAULT_TOOLTIP_FOR_INLINE_ROLLS = false;
-
- private static final String KEY_SUPPRESS_TOOLTIPS_FOR_MACROLINKS = "suppressToolTipsMacroLinks";
- private static final boolean DEFAULT_SUPPRESS_TOOLTIPS_FOR_MACROLINKS = false;
-
- // chat notification colors
- private static final String KEY_CHAT_NOTIFICATION_COLOR_RED = "chatNotificationColorRed";
- private static final int DEFAULT_CHAT_NOTIFICATION_COLOR_RED = 0xFF;
-
- private static final String KEY_CHAT_NOTIFICATION_COLOR_GREEN = "chatNotificationColorGreen";
- private static final int DEFAULT_CHAT_NOTIFICATION_COLOR_GREEN = 0xFF;
-
- private static final String KEY_CHAT_NOTIFICATION_COLOR_BLUE = "chatNotificationColorBlue";
- private static final int DEFAULT_CHAT_NOTIFICATION_COLOR_BLUE = 0xFF;
-
- // end chat notification colors
-
- private static final String KEY_CHAT_NOTIFICATION_SHOW_BACKGROUND =
- "chatNotificationShowBackground";
- private static final boolean DEFAULT_CHAT_NOTIFICATION_SHOW_BACKGROUND = true;
-
- private static final String KEY_TRUSTED_PREFIX_BG_RED = "trustedPrefixBGRed";
- private static final int DEFAULT_TRUSTED_PREFIX_BG_RED = 0xD8;
-
- private static final String KEY_TRUSTED_PREFIX_BG_GREEN = "trustedPrefixBGGreen";
- private static final int DEFAULT_TRUSTED_PREFIX_BG_GREEN = 0xE9;
-
- private static final String KEY_TRUSTED_PREFIX_BG_BLUE = "trustedPrefixBBlue";
- private static final int DEFAULT_TRUSTED_PREFIX_BG_BLUE = 0xF6;
-
- private static final String KEY_TRUSTED_PREFIX_FG_RED = "trustedPrefixFGRed";
- private static final int DEFAULT_TRUSTED_PREFIX_FG_RED = 0x00;
-
- private static final String KEY_TRUSTED_PREFIX_FG_GREEN = "trustedPrefixFGGreen";
- private static final int DEFAULT_TRUSTED_PREFIX_FG_GREEN = 0x00;
-
- private static final String KEY_TRUSTED_PREFIX_FG_BLUE = "trustedPrefixFBlue";
- private static final int DEFAULT_TRUSTED_PREFIX_FG_BLUE = 0x00;
-
- private static final String KEY_FIT_GM_VIEW = "fitGMView";
- private static final boolean DEFAULT_FIT_GM_VIEW = true;
-
- private static final String KEY_DEFAULT_USERNAME = "defaultUsername";
- private static final String DEFAULT_USERNAME =
- I18N.getString("Preferences.client.default.username.value");
-
- private static final String KEY_TYPING_NOTIFICATION_DURATION = "typingNotificationDuration";
- private static final int DEFAULT_TYPING_NOTIFICATION_DURATION = 5000;
-
- private static final String KEY_FRAME_RATE_CAP = "frameRateCap";
- private static final int DEFAULT_FRAME_RATE_CAP = 60;
-
- private static final String KEY_UPNP_DISCOVERY_TIMEOUT = "upnpDiscoveryTimeout";
- private static final int DEFAULT_UPNP_DISCOVERY_TIMEOUT = 5000;
-
- private static final String KEY_FILE_SYNC_PATH = "fileSyncPath";
- private static final String DEFAULT_FILE_SYNC_PATH = "";
-
- private static final String KEY_SKIP_AUTO_UPDATE = "skipAutoUpdate";
- private static final boolean DEFAULT_SKIP_AUTO_UPDATE = false;
- private static final String KEY_SKIP_AUTO_UPDATE_RELEASE = "skipAutoUpdateRelease";
- private static final String DEFAULT_SKIP_AUTO_UPDATE_RELEASE = "";
-
- private static final String KEY_ALLOW_EXTERNAL_MACRO_ACCESS = "allowExternalMacroAccess";
- private static final boolean DEFAULT_ALLOW_EXTERNAL_MACRO_ACCESS = false;
-
- private static final String KEY_RENDER_QUALITY = "renderScaleQuality";
-
public enum RenderQuality {
LOW_SCALING,
PIXEL_ART_SCALING,
@@ -818,1150 +478,285 @@ public int getResampleOpFilter() {
}
}
- public static void setRenderQuality(RenderQuality quality) {
- prefs.put(KEY_RENDER_QUALITY, quality.name());
- renderQuality = quality;
- }
+ // Based off vision type enum in Zone.java, this could easily get tossed somewhere else if
+ // preferred.
+ public enum MapSortType {
+ DISPLAYNAME(),
+ GMNAME();
- public static RenderQuality getRenderQuality() {
- if (renderQuality == null) {
- try {
- renderQuality =
- RenderQuality.valueOf(prefs.get(KEY_RENDER_QUALITY, RenderQuality.LOW_SCALING.name()));
- } catch (Exception e) {
- renderQuality = RenderQuality.LOW_SCALING;
- }
+ private final String displayName;
+
+ MapSortType() {
+ displayName = I18N.getString("mapSortType." + name());
}
- return renderQuality;
- }
- public static void setTypingNotificationDuration(int ms) {
- prefs.putInt(KEY_TYPING_NOTIFICATION_DURATION, ms);
- MapTool.getFrame().setChatNotifyDuration(ms);
+ @Override
+ public String toString() {
+ return displayName;
+ }
}
- public static Integer getTypingNotificationDuration() {
- Integer value =
- prefs.getInt(KEY_TYPING_NOTIFICATION_DURATION, DEFAULT_TYPING_NOTIFICATION_DURATION);
- return value;
- }
+ private interface Type {
+ void set(Preferences node, String key, T value);
- public static void setUseToolTipForInlineRoll(boolean tooltip) {
- prefs.putBoolean(KEY_TOOLTIP_FOR_INLINE_ROLLS, tooltip);
+ T get(Preferences node, String key, Supplier defaultValue);
}
- public static boolean getUseToolTipForInlineRoll() {
- return prefs.getBoolean(KEY_TOOLTIP_FOR_INLINE_ROLLS, DEFAULT_TOOLTIP_FOR_INLINE_ROLLS);
- }
+ public static final class Preference {
+ private final String key;
+ private final Supplier defaultValue;
+ private final Type type;
- public static void setSuppressToolTipsForMacroLinks(boolean tooltip) {
- prefs.putBoolean(KEY_SUPPRESS_TOOLTIPS_FOR_MACROLINKS, tooltip);
- }
+ private Predicate validator = value -> true;
+ private boolean cachingEnabled = false;
+ private @Nullable T cachedValue;
- public static boolean getSuppressToolTipsForMacroLinks() {
- return prefs.getBoolean(
- KEY_SUPPRESS_TOOLTIPS_FOR_MACROLINKS, DEFAULT_SUPPRESS_TOOLTIPS_FOR_MACROLINKS);
- }
+ private final List> onChangeHandlers = new CopyOnWriteArrayList<>();
- public static void setChatNotificationColor(Color color) {
- prefs.putInt(KEY_CHAT_NOTIFICATION_COLOR_RED, color.getRed());
- prefs.putInt(KEY_CHAT_NOTIFICATION_COLOR_GREEN, color.getGreen());
- prefs.putInt(KEY_CHAT_NOTIFICATION_COLOR_BLUE, color.getBlue());
- }
+ private Preference(String key, T defaultValue, Type type) {
+ this.key = key;
+ this.defaultValue = () -> defaultValue;
+ this.type = type;
+ }
- public static Color getChatNotificationColor() {
- return new Color(
- prefs.getInt(KEY_CHAT_NOTIFICATION_COLOR_RED, DEFAULT_CHAT_NOTIFICATION_COLOR_RED),
- prefs.getInt(KEY_CHAT_NOTIFICATION_COLOR_GREEN, DEFAULT_CHAT_NOTIFICATION_COLOR_GREEN),
- prefs.getInt(KEY_CHAT_NOTIFICATION_COLOR_BLUE, DEFAULT_CHAT_NOTIFICATION_COLOR_BLUE));
- }
+ private Preference(String key, Supplier defaultValue, Type type) {
+ this.key = key;
+ this.defaultValue = defaultValue;
+ this.type = type;
+ }
- public static void setTrustedPrefixBG(Color color) {
- prefs.putInt(KEY_TRUSTED_PREFIX_BG_RED, color.getRed());
- prefs.putInt(KEY_TRUSTED_PREFIX_BG_GREEN, color.getGreen());
- prefs.putInt(KEY_TRUSTED_PREFIX_BG_BLUE, color.getBlue());
- }
+ public String name() {
+ return key;
+ }
- public static Color getTrustedPrefixBG() {
- return new Color(
- prefs.getInt(KEY_TRUSTED_PREFIX_BG_RED, DEFAULT_TRUSTED_PREFIX_BG_RED),
- prefs.getInt(KEY_TRUSTED_PREFIX_BG_GREEN, DEFAULT_TRUSTED_PREFIX_BG_GREEN),
- prefs.getInt(KEY_TRUSTED_PREFIX_BG_BLUE, DEFAULT_TRUSTED_PREFIX_BG_BLUE));
- }
+ /**
+ * Loads and validates the value of the preference.
+ *
+ *
If validation is unsuccessful, clears the preference and returns it the default value.
+ *
+ * @return The value of the preference.
+ */
+ public T get() {
+ if (cachingEnabled && cachedValue != null) {
+ return cachedValue;
+ }
- public static void setTrustedPrefixFG(Color color) {
- prefs.putInt(KEY_TRUSTED_PREFIX_FG_RED, color.getRed());
- prefs.putInt(KEY_TRUSTED_PREFIX_FG_GREEN, color.getGreen());
- prefs.putInt(KEY_TRUSTED_PREFIX_FG_BLUE, color.getBlue());
- }
+ var value = type.get(prefs, key, defaultValue);
+ if (!validator.test(value)) {
+ log.warn("Value read from preference {} did not pass validation: {}", name(), value);
+ value = getDefault();
+ remove();
+ }
- public static Color getTrustedPrefixFG() {
- return new Color(
- prefs.getInt(KEY_TRUSTED_PREFIX_FG_RED, DEFAULT_TRUSTED_PREFIX_FG_RED),
- prefs.getInt(KEY_TRUSTED_PREFIX_FG_GREEN, DEFAULT_TRUSTED_PREFIX_FG_GREEN),
- prefs.getInt(KEY_TRUSTED_PREFIX_FG_BLUE, DEFAULT_TRUSTED_PREFIX_FG_BLUE));
- }
+ cachedValue = value;
+ return value;
+ }
- public static void setToolTipInitialDelay(int ms) {
- prefs.putInt(KEY_TOOLTIP_INITIAL_DELAY, ms);
- }
+ /**
+ * Validates and stores the value of the preference.
+ *
+ *
If validation is unsuccessful, stores the default value instead.
+ *
+ * @param value The value to set.
+ */
+ public void set(T value) {
+ if (!validator.test(value)) {
+ log.warn("Value written to preference {} did not pass validation: {}", name(), value);
+ value = getDefault();
+ }
- public static int getToolTipInitialDelay() {
- return prefs.getInt(KEY_TOOLTIP_INITIAL_DELAY, DEFAULT_TOOLTIP_INITIAL_DELAY);
- }
+ type.set(prefs, key, value);
+ cachedValue = value;
- public static void setToolTipDismissDelay(int ms) {
- prefs.putInt(KEY_TOOLTIP_DISMISS_DELAY, ms);
- }
+ for (var handler : onChangeHandlers) {
+ handler.accept(value);
+ }
+ }
- public static int getToolTipDismissDelay() {
- return prefs.getInt(KEY_TOOLTIP_DISMISS_DELAY, DEFAULT_TOOLTIP_DISMISS_DELAY);
- }
+ public void remove() {
+ prefs.remove(key);
+ cachedValue = getDefault();
- public static void setAllowPlayerMacroEditsDefault(boolean show) {
- prefs.putBoolean(KEY_ALLOW_PLAYER_MACRO_EDITS_DEFAULT, show);
- }
+ for (var handler : onChangeHandlers) {
+ handler.accept(cachedValue);
+ }
+ }
- public static boolean getAllowPlayerMacroEditsDefault() {
- return prefs.getBoolean(
- KEY_ALLOW_PLAYER_MACRO_EDITS_DEFAULT, DEFAULT_ALLOW_PLAYER_MACRO_EDITS_DEFAULT);
- }
+ public T getDefault() {
+ return defaultValue.get();
+ }
- public static void setPortraitSize(int size) {
- prefs.putInt(KEY_PORTRAIT_SIZE, size);
- }
+ public Preference cacheIt() {
+ this.cachingEnabled = true;
+ return this;
+ }
- public static int getPortraitSize() {
- return prefs.getInt(KEY_PORTRAIT_SIZE, DEFAULT_PORTRAIT_SIZE);
- }
+ public Preference validateIt(Predicate predicate) {
+ validator = predicate;
+ return this;
+ }
- public static void setThumbnailSize(int size) {
- prefs.putInt(KEY_THUMBNAIL_SIZE, size);
+ public void onChange(Consumer handler) {
+ onChangeHandlers.add(handler);
+ }
}
- public static int getThumbnailSize() {
- return prefs.getInt(KEY_THUMBNAIL_SIZE, DEFAULT_THUMBNAIL_SIZE);
- }
+ private static final class BooleanType implements Type {
+ public static Preference create(String key, boolean defaultValue) {
+ return new Preference<>(key, defaultValue, new BooleanType());
+ }
- public static void setShowSmilies(boolean show) {
- prefs.putBoolean(KEY_INSERT_SMILIES, show);
- }
+ @Override
+ public void set(Preferences prefs, String key, Boolean value) {
+ prefs.putBoolean(key, value);
+ }
- public static boolean getShowSmilies() {
- return prefs.getBoolean(KEY_INSERT_SMILIES, DEFAULT_SHOW_SMILIES);
+ @Override
+ public Boolean get(Preferences prefs, String key, Supplier defaultValue) {
+ return prefs.getBoolean(key, defaultValue.get());
+ }
}
- public static void setShowDialogOnNewToken(boolean show) {
- prefs.putBoolean(KEY_SHOW_DIALOG_ON_NEW_TOKEN, show);
- }
+ private static final class IntegerType implements Type {
+ public static Preference create(String key, int defaultValue) {
+ return new Preference<>(key, defaultValue, new IntegerType());
+ }
- public static boolean getShowDialogOnNewToken() {
- return prefs.getBoolean(KEY_SHOW_DIALOG_ON_NEW_TOKEN, DEFAULT_SHOW_DIALOG_ON_NEW_TOKEN);
- }
+ @Override
+ public void set(Preferences prefs, String key, Integer value) {
+ prefs.putInt(key, value);
+ }
- public static void setShowAvatarInChat(boolean show) {
- prefs.putBoolean(KEY_SHOW_AVATAR_IN_CHAT, show);
+ @Override
+ public Integer get(Preferences prefs, String key, Supplier defaultValue) {
+ return prefs.getInt(key, defaultValue.get());
+ }
}
- public static boolean getShowAvatarInChat() {
- return prefs.getBoolean(KEY_SHOW_AVATAR_IN_CHAT, DEFAULT_SHOW_AVATAR_IN_CHAT);
- }
+ private static final class ByteType implements Type {
+ public static Preference create(String key, int defaultValue) {
+ return new Preference<>(key, defaultValue, new ByteType());
+ }
- public static void setPlaySystemSounds(boolean play) {
- prefs.putBoolean(KEY_PLAY_SYSTEM_SOUNDS, play);
- }
+ @Override
+ public void set(Preferences prefs, String key, Integer value) {
+ prefs.putInt(key, range0to255(value));
+ }
- public static void setPlayStreams(boolean play) {
- prefs.putBoolean(KEY_PLAY_STREAMS, play);
- }
+ @Override
+ public Integer get(Preferences prefs, String key, Supplier defaultValue) {
+ return range0to255(prefs.getInt(key, defaultValue.get()));
+ }
- public static boolean getPlaySystemSounds() {
- return prefs.getBoolean(KEY_PLAY_SYSTEM_SOUNDS, DEFAULT_PLAY_SYSTEM_SOUNDS);
+ private static int range0to255(int value) {
+ return Math.clamp(value, 0, 255);
+ }
}
- public static boolean getPlayStreams() {
- return prefs.getBoolean(KEY_PLAY_STREAMS, DEFAULT_PLAY_STREAMS);
- }
+ private static final class DoubleType implements Type {
+ public static Preference create(String key, double defaultValue) {
+ return new Preference<>(key, defaultValue, new DoubleType());
+ }
- public static void setPlaySystemSoundsOnlyWhenNotFocused(boolean play) {
- prefs.putBoolean(KEY_SOUNDS_ONLY_WHEN_NOT_FOCUSED, play);
- }
+ @Override
+ public void set(Preferences prefs, String key, Double value) {
+ prefs.putDouble(key, value);
+ }
- public static boolean getPlaySystemSoundsOnlyWhenNotFocused() {
- return prefs.getBoolean(KEY_SOUNDS_ONLY_WHEN_NOT_FOCUSED, DEFAULT_SOUNDS_ONLY_WHEN_NOT_FOCUSED);
+ @Override
+ public Double get(Preferences prefs, String key, Supplier defaultValue) {
+ return prefs.getDouble(key, defaultValue.get());
+ }
}
- public static void setSyrinscapeActive(boolean active) {
- prefs.putBoolean(KEY_SYRINSCAPE_ACTIVE, active);
- }
+ private static final class StringType implements Type {
+ public static Preference create(String key, String defaultValue) {
+ return new Preference<>(key, defaultValue, new StringType());
+ }
- public static boolean getSyrinscapeActive() {
- return prefs.getBoolean(KEY_SYRINSCAPE_ACTIVE, DEFAULT_SYRINSCAPE_ACTIVE);
- }
+ @Override
+ public void set(Preferences prefs, String key, String value) {
+ prefs.put(key, value);
+ }
- public static void setChatColor(Color color) {
- prefs.putInt(KEY_CHAT_COLOR, color.getRGB());
+ @Override
+ public String get(Preferences prefs, String key, Supplier defaultValue) {
+ return prefs.get(key, defaultValue.get());
+ }
}
- public static void setFontSize(int size) {
- prefs.putInt(KEY_FONT_SIZE, size);
- }
-
- public static int getFontSize() {
- return prefs.getInt(KEY_FONT_SIZE, DEFAULT_FONT_SIZE);
- }
-
- public static void setDefaultGridColor(Color color) {
- prefs.putInt(KEY_DEFAULT_GRID_COLOR, color.getRGB());
- }
-
- public static Color getDefaultGridColor() {
- return new Color(prefs.getInt(KEY_DEFAULT_GRID_COLOR, DEFAULT_DEFAULT_GRID_COLOR));
- }
-
- public static boolean getFaceVertex() {
- return prefs.getBoolean(KEY_FACE_VERTEX, DEFAULT_FACE_VERTEX);
- }
-
- public static void setFaceVertex(boolean yesNo) {
- prefs.putBoolean(KEY_FACE_VERTEX, yesNo);
- }
-
- public static boolean getFaceEdge() {
- return prefs.getBoolean(KEY_FACE_EDGE, DEFAULT_FACE_EDGE);
- }
-
- public static void setFaceEdge(boolean yesNo) {
- prefs.putBoolean(KEY_FACE_EDGE, yesNo);
- }
-
- public static void clearAssetRoots() {
- prefs.put(KEY_ASSET_ROOTS, "");
- }
-
- public static void setSaveDir(File file) {
- prefs.put(KEY_SAVE_DIR, file.toString());
- }
-
- public static void setDefaultGridSize(int size) {
- prefs.putInt(KEY_DEFAULT_GRID_SIZE, size);
- }
-
- public static int getDefaultGridSize() {
- return prefs.getInt(KEY_DEFAULT_GRID_SIZE, DEFAULT_DEFAULT_GRID_SIZE);
- }
-
- public static void setDefaultUnitsPerCell(double size) {
- prefs.putDouble(KEY_DEFAULT_UNITS_PER_CELL, size);
- }
-
- public static double getDefaultUnitsPerCell() {
- return prefs.getDouble(KEY_DEFAULT_UNITS_PER_CELL, DEFAULT_DEFAULT_UNITS_PER_CELL);
- }
-
- public static void setDefaultVisionDistance(int dist) {
- prefs.putInt(KEY_DEFAULT_VISION_DISTANCE, dist);
- }
-
- public static int getDefaultVisionDistance() {
- return prefs.getInt(KEY_DEFAULT_VISION_DISTANCE, DEFAULT_DEFAULT_VISION_DISTANCE);
- }
-
- public static void setDefaultVisionType(Zone.VisionType visionType) {
- prefs.put(KEY_DEFAULT_VISION_TYPE, visionType.name());
- }
-
- public static void setMapSortType(MapSortType mapSortType) {
- prefs.put(KEY_MAP_SORT_TYPE, mapSortType.name());
- }
-
- public static Zone.VisionType getDefaultVisionType() {
- try {
- return Zone.VisionType.valueOf(
- prefs.get(KEY_DEFAULT_VISION_TYPE, DEFAULT_VISION_TYPE.name()));
- } catch (Exception e) {
- return DEFAULT_VISION_TYPE;
+ private static final class FileType implements Type {
+ public static Preference create(String key, Supplier defaultValue) {
+ return new Preference<>(key, defaultValue, new FileType());
}
- }
- public static MapSortType getMapSortType() {
- try {
- return MapSortType.valueOf(prefs.get(KEY_MAP_SORT_TYPE, DEFAULT_MAP_SORT_TYPE.name()));
- } catch (Exception e) {
- return DEFAULT_MAP_SORT_TYPE;
+ @Override
+ public void set(Preferences prefs, String key, File value) {
+ prefs.put(key, value.toString());
}
- }
-
- public static void setUseSoftFogEdges(boolean flag) {
- prefs.putBoolean(KEY_USE_SOFT_FOG_EDGES, flag);
- }
- public static boolean getUseSoftFogEdges() {
- return prefs.getBoolean(KEY_USE_SOFT_FOG_EDGES, DEFAULT_USE_SOFT_FOG_EDGES);
- }
-
- public static void setNewMapsHaveFOW(boolean flag) {
- prefs.putBoolean(KEY_NEW_MAPS_HAVE_FOW, flag);
- }
-
- public static boolean getNewMapsHaveFOW() {
- return prefs.getBoolean(KEY_NEW_MAPS_HAVE_FOW, DEFAULT_NEW_MAPS_HAVE_FOW);
- }
-
- public static void setNewTokensVisible(boolean flag) {
- prefs.putBoolean(KEY_NEW_TOKENS_VISIBLE, flag);
- }
-
- public static boolean getNewTokensVisible() {
- return prefs.getBoolean(KEY_NEW_TOKENS_VISIBLE, DEFAULT_NEW_TOKENS_VISIBLE);
- }
-
- public static void setNewMapsVisible(boolean flag) {
- prefs.putBoolean(KEY_NEW_MAPS_VISIBLE, flag);
- }
-
- public static boolean getNewMapsVisible() {
- return prefs.getBoolean(KEY_NEW_MAPS_VISIBLE, DEFAULT_NEW_MAPS_VISIBLE);
- }
-
- public static void setNewObjectsVisible(boolean flag) {
- prefs.putBoolean(KEY_NEW_OBJECTS_VISIBLE, flag);
- }
-
- public static boolean getNewObjectsVisible() {
- return prefs.getBoolean(KEY_NEW_OBJECTS_VISIBLE, DEFAULT_NEW_OBJECTS_VISIBLE);
- }
-
- public static void setNewBackgroundsVisible(boolean flag) {
- prefs.putBoolean(KEY_NEW_BACKGROUNDS_VISIBLE, flag);
- }
-
- public static boolean getNewBackgroundsVisible() {
- return prefs.getBoolean(KEY_NEW_BACKGROUNDS_VISIBLE, DEFAULT_NEW_BACKGROUNDS_VISIBLE);
- }
-
- public static void setTokensWarnWhenDeleted(boolean flag) {
- prefs.putBoolean(KEY_TOKENS_WARN_WHEN_DELETED, flag);
- }
-
- public static boolean getTokensWarnWhenDeleted() {
- return prefs.getBoolean(KEY_TOKENS_WARN_WHEN_DELETED, DEFAULT_TOKENS_WARN_WHEN_DELETED);
- }
-
- public static void setDrawWarnWhenDeleted(boolean flag) {
- prefs.putBoolean(KEY_DRAW_WARN_WHEN_DELETED, flag);
- }
-
- public static boolean getDrawWarnWhenDeleted() {
- return prefs.getBoolean(KEY_DRAW_WARN_WHEN_DELETED, DEFAULT_DRAW_WARN_WHEN_DELETED);
- }
-
- public static void setTokensStartSnapToGrid(boolean flag) {
- prefs.putBoolean(KEY_TOKENS_START_SNAP_TO_GRID, flag);
- }
-
- public static boolean getTokensStartSnapToGrid() {
- return prefs.getBoolean(KEY_TOKENS_START_SNAP_TO_GRID, DEFAULT_TOKENS_START_SNAP_TO_GRID);
- }
-
- public static void setTokensSnapWhileDragging(boolean flag) {
- prefs.putBoolean(KEY_TOKENS_SNAP_WHILE_DRAGGING, flag);
- }
-
- public static boolean getTokensSnapWhileDragging() {
- return prefs.getBoolean(KEY_TOKENS_SNAP_WHILE_DRAGGING, DEFAULT_KEY_TOKENS_SNAP_WHILE_DRAGGING);
- }
-
- public static void setHideMousePointerWhileDragging(boolean flag) {
- prefs.putBoolean(KEY_HIDE_MOUSE_POINTER_WHILE_DRAGGING, flag);
- }
-
- public static boolean getHideMousePointerWhileDragging() {
- return prefs.getBoolean(
- KEY_HIDE_MOUSE_POINTER_WHILE_DRAGGING, DEFAULT_KEY_HIDE_MOUSE_POINTER_WHILE_DRAGGING);
- }
-
- public static void setHideTokenStackIndicator(boolean flag) {
- prefs.putBoolean(KEY_HIDE_TOKEN_STACK_INDICATOR, flag);
- }
-
- public static boolean getHideTokenStackIndicator() {
- return prefs.getBoolean(KEY_HIDE_TOKEN_STACK_INDICATOR, DEFAULT_KEY_HIDE_TOKEN_STACK_INDICATOR);
- }
-
- public static void setObjectsStartSnapToGrid(boolean flag) {
- prefs.putBoolean(KEY_OBJECTS_START_SNAP_TO_GRID, flag);
- }
-
- public static boolean getObjectsStartSnapToGrid() {
- return prefs.getBoolean(KEY_OBJECTS_START_SNAP_TO_GRID, DEFAULT_OBJECTS_START_SNAP_TO_GRID);
- }
-
- public static void setTokensStartFreesize(boolean flag) {
- prefs.putBoolean(KEY_TOKENS_START_FREESIZE, flag);
- }
-
- public static boolean getTokensStartFreesize() {
- return prefs.getBoolean(KEY_TOKENS_START_FREESIZE, DEFAULT_TOKENS_START_FREESIZE);
- }
-
- public static void setObjectsStartFreesize(boolean flag) {
- prefs.putBoolean(KEY_OBJECTS_START_FREESIZE, flag);
- }
-
- public static boolean getObjectsStartFreesize() {
- return prefs.getBoolean(KEY_OBJECTS_START_FREESIZE, DEFAULT_OBJECTS_START_FREESIZE);
- }
-
- public static void setBackgroundsStartSnapToGrid(boolean flag) {
- prefs.putBoolean(KEY_BACKGROUNDS_START_SNAP_TO_GRID, flag);
- }
-
- public static boolean getBackgroundsStartSnapToGrid() {
- return prefs.getBoolean(
- KEY_BACKGROUNDS_START_SNAP_TO_GRID, DEFAULT_BACKGROUNDS_START_SNAP_TO_GRID);
- }
-
- public static void setBackgroundsStartFreesize(boolean flag) {
- prefs.putBoolean(KEY_BACKGROUNDS_START_FREESIZE, flag);
- }
-
- public static boolean getBackgroundsStartFreesize() {
- return prefs.getBoolean(KEY_BACKGROUNDS_START_FREESIZE, DEFAULT_BACKGROUNDS_START_FREESIZE);
- }
-
- public static String getDefaultGridType() {
- return prefs.get(KEY_DEFAULT_GRID_TYPE, DEFAULT_DEFAULT_GRID_TYPE);
- }
-
- public static void setDefaultGridType(String type) {
- prefs.put(KEY_DEFAULT_GRID_TYPE, type);
- }
-
- public static boolean getShowStatSheet() {
- return prefs.getBoolean(KEY_SHOW_STAT_SHEET, DEFAULT_SHOW_STAT_SHEET);
- }
-
- public static void setShowStatSheet(boolean show) {
- prefs.putBoolean(KEY_SHOW_STAT_SHEET, show);
- }
-
- public static boolean getShowPortrait() {
- return prefs.getBoolean(KEY_SHOW_PORTRAIT, DEFAULT_SHOW_PORTRAIT);
- }
-
- public static void setShowPortrait(boolean show) {
- prefs.putBoolean(KEY_SHOW_PORTRAIT, show);
- }
-
- public static boolean getShowStatSheetModifier() {
- return prefs.getBoolean(KEY_SHOW_STAT_SHEET_MODIFIER, DEFAULT_SHOW_STAT_SHEET_MODIFIER);
- }
-
- public static void setShowStatSheetModifier(boolean show) {
- prefs.putBoolean(KEY_SHOW_STAT_SHEET_MODIFIER, show);
- }
-
- public static boolean getForceFacingArrow() {
- return prefs.getBoolean(KEY_FORCE_FACING_ARROW, DEFAULT_FORCE_FACING_ARROW);
- }
-
- public static void setForceFacingArrow(boolean show) {
- prefs.putBoolean(KEY_FORCE_FACING_ARROW, show);
- }
-
- public static boolean getFitGMView() {
- return prefs.getBoolean(KEY_FIT_GM_VIEW, DEFAULT_FIT_GM_VIEW);
- }
-
- public static void setFitGMView(boolean fit) {
- prefs.putBoolean(KEY_FIT_GM_VIEW, fit);
- }
-
- public static String getDefaultUserName() {
- return prefs.get(KEY_DEFAULT_USERNAME, DEFAULT_USERNAME);
- }
-
- public static void setDefaultUserName(String uname) {
- prefs.put(KEY_DEFAULT_USERNAME, uname);
- }
-
- public static void setMovementMetric(WalkerMetric metric) {
- prefs.put(KEY_MOVEMENT_METRIC, metric.name());
- }
-
- public static void setFrameRateCap(int cap) {
- if (cap <= 0) {
- // The provided value is invalid. Change to default instead.
- cap = DEFAULT_FRAME_RATE_CAP;
- }
- prefs.putInt(KEY_FRAME_RATE_CAP, cap);
- }
+ @Override
+ public File get(Preferences prefs, String key, Supplier defaultValue) {
+ String filePath = prefs.get(key, null);
+ if (filePath != null) {
+ return new File(filePath);
+ }
- public static int getFrameRateCap() {
- int result = prefs.getInt(KEY_FRAME_RATE_CAP, DEFAULT_FRAME_RATE_CAP);
- if (result <= 0) {
- // An invalid value is stored. Fix that.
- result = DEFAULT_FRAME_RATE_CAP;
- setFrameRateCap(result);
+ return defaultValue.get();
}
- return result;
- }
-
- public static void setUpnpDiscoveryTimeout(int timeout) {
- prefs.putInt(KEY_UPNP_DISCOVERY_TIMEOUT, timeout);
- }
-
- public static int getUpnpDiscoveryTimeout() {
- return prefs.getInt(KEY_UPNP_DISCOVERY_TIMEOUT, DEFAULT_UPNP_DISCOVERY_TIMEOUT);
- }
-
- public static String getFileSyncPath() {
- return prefs.get(KEY_FILE_SYNC_PATH, DEFAULT_FILE_SYNC_PATH);
- }
-
- public static void setFileSyncPath(String path) {
- prefs.put(KEY_FILE_SYNC_PATH, path);
- }
-
- public static boolean getSkipAutoUpdate() {
- return prefs.getBoolean(KEY_SKIP_AUTO_UPDATE, DEFAULT_SKIP_AUTO_UPDATE);
- }
-
- public static void setSkipAutoUpdate(boolean value) {
- prefs.putBoolean(KEY_SKIP_AUTO_UPDATE, value);
- }
-
- public static String getSkipAutoUpdateRelease() {
- return prefs.get(KEY_SKIP_AUTO_UPDATE_RELEASE, DEFAULT_SKIP_AUTO_UPDATE_RELEASE);
- }
-
- public static void setSkipAutoUpdateRelease(String releaseId) {
- prefs.put(KEY_SKIP_AUTO_UPDATE_RELEASE, releaseId);
- }
-
- public static boolean getAllowExternalMacroAccess() {
- return prefs.getBoolean(KEY_ALLOW_EXTERNAL_MACRO_ACCESS, DEFAULT_ALLOW_EXTERNAL_MACRO_ACCESS);
- }
-
- public static void setAllowExternalMacroAccess(boolean value) {
- prefs.putBoolean(KEY_ALLOW_EXTERNAL_MACRO_ACCESS, value);
- }
-
- public static boolean getLoadMRUCampaignAtStart() {
- return prefs.getBoolean(KEY_LOAD_MRU_CAMPAIGN_AT_START, DEFAULT_LOAD_MRU_CAMPAIGN_AT_START);
- }
-
- public static void setLoadMRUCampaignAtStart(boolean value) {
- prefs.putBoolean(KEY_LOAD_MRU_CAMPAIGN_AT_START, value);
}
- public static WalkerMetric getMovementMetric() {
- WalkerMetric metric;
- try {
- metric = WalkerMetric.valueOf(prefs.get(KEY_MOVEMENT_METRIC, DEFAULT_MOVEMENT_METRIC.name()));
- } catch (Exception exc) {
- metric = DEFAULT_MOVEMENT_METRIC;
+ private static final class EnumType> implements Type {
+ public static > Preference create(
+ Class class_, String key, T defaultValue) {
+ return new Preference<>(key, defaultValue, new EnumType<>(class_));
}
- return metric;
- }
-
- public static File getSaveDir() {
- String filePath = prefs.get(KEY_SAVE_DIR, null);
- return filePath != null ? new File(filePath) : new File(File.separator);
- }
-
- public static File getSaveTokenDir() {
- String filePath = prefs.get(KEY_SAVE_TOKEN_DIR, null);
- return filePath != null ? new File(filePath) : getSaveDir();
- }
-
- public static void setTokenSaveDir(File file) {
- prefs.put(KEY_SAVE_TOKEN_DIR, file.toString());
- }
-
- public static File getSaveMapDir() {
- String filePath = prefs.get(KEY_SAVE_MAP_DIR, null);
- return filePath != null ? new File(filePath) : getSaveDir();
- }
- public static void setSaveMapDir(File file) {
- prefs.put(KEY_SAVE_MAP_DIR, file.toString());
- }
+ private final Class class_;
- public static void setLoadDir(File file) {
- prefs.put(KEY_LOAD_DIR, file.toString());
- }
-
- public static File getLoadDir() {
- String filePath = prefs.get(KEY_LOAD_DIR, null);
- return filePath != null ? new File(filePath) : new File(File.separator);
- }
-
- public static File getAddOnLoadDir() {
- String filePath = prefs.get(KEY_ADD_ON_LOAD_DIR, null);
- return filePath != null ? new File(filePath) : getSaveDir();
- }
-
- public static void setAddOnLoadDir(File file) {
- prefs.put(KEY_ADD_ON_LOAD_DIR, file.toString());
- }
-
- public static void addAssetRoot(File root) {
- String list = prefs.get(KEY_ASSET_ROOTS, "");
- if (!list.isEmpty()) {
- // Add the new one and then remove all duplicates.
- list += ";" + root.getPath();
- String[] roots = list.split(";");
- StringBuilder result = new StringBuilder(list.length() + root.getPath().length() + 10);
- Set rootList = new HashSet(roots.length);
-
- // This loop ensures that each path only appears once. If there are currently
- // duplicates in the list, only the first one is kept.
- for (String r : roots) {
- if (!rootList.contains(r)) {
- result.append(';').append(r);
- rootList.add(r);
- }
- }
- list = result.substring(1);
- } else {
- list += root.getPath();
+ public EnumType(Class class_) {
+ this.class_ = class_;
}
- prefs.put(KEY_ASSET_ROOTS, list);
- }
-
- public static Set getAssetRoots() {
- String list = prefs.get(KEY_ASSET_ROOTS, "");
- String[] roots = list.split(";"); // FJE Probably should be File.path_separator ...
-
- Set rootList = new HashSet();
- for (String root : roots) {
- File file = new File(root);
- // LATER: Should this actually remove it from the pref list ?
- if (!file.exists()) {
- continue;
- }
- rootList.add(file);
+ @Override
+ public void set(Preferences prefs, String key, T value) {
+ prefs.put(key, value.name());
}
- return rootList;
- }
- public static void removeAssetRoot(File root) {
- String list = prefs.get(KEY_ASSET_ROOTS, "");
- if (!list.isEmpty()) {
- // Add the new one and then remove all duplicates.
- String[] roots = list.split(";");
- StringBuilder result = new StringBuilder(list.length());
- Set rootList = new HashSet(roots.length);
- String rootPath = root.getPath();
-
- // This loop ensures that each path only appears once. If there are
- // duplicates in the list, only the first one is kept.
- for (String r : roots) {
- if (!r.equals(rootPath) && !rootList.contains(r)) {
- result.append(';').append(r);
- rootList.add(r);
- }
+ @Override
+ public T get(Preferences prefs, String key, Supplier defaultValue) {
+ var stored = prefs.get(key, null);
+ if (stored == null) {
+ return defaultValue.get();
}
- list = result.substring(result.length() > 0 ? 1 : 0);
- prefs.put(KEY_ASSET_ROOTS, list);
- }
- }
- public static void setMruCampaigns(List mruCampaigns) {
- StringBuilder combined = new StringBuilder();
- for (File file : mruCampaigns) {
- String path = null;
try {
- path = file.getCanonicalPath();
- } catch (IOException e) {
- // Probably pretty rare, but we want to know about it
- log.info("unexpected during file.getCanonicalPath()", e); // $NON-NLS-1$
- path = file.getPath();
+ return Enum.valueOf(class_, stored);
+ } catch (Exception e) {
+ return defaultValue.get();
}
- // It's important that '%3A' is done last. Note that the pathSeparator may not be a colon on
- // the current platform, but it doesn't matter since it will be reconverted when read back in
- // again.
- // THink of the '%3A' as a symbol of the separator, not an encoding of the character.
- combined.append(path.replaceAll("%", "%25").replaceAll(File.pathSeparator, "%3A"));
- combined.append(File.pathSeparator);
}
- prefs.put(KEY_MRU_CAMPAIGNS, combined.toString());
}
- public static List getMruCampaigns() {
- List mruCampaigns = new ArrayList();
- String combined = prefs.get(KEY_MRU_CAMPAIGNS, null);
- if (combined != null) {
- // It's important that '%3A' is done first
- combined = combined.replaceAll("%3A", File.pathSeparator).replaceAll("%25", "%");
- String[] all = combined.split(File.pathSeparator);
- for (String s : all) {
- mruCampaigns.add(new File(s));
- }
+ private static final class ColorType implements Type {
+ public static Preference create(String key, Color defaultValue, boolean hasAlpha) {
+ return new Preference<>(key, defaultValue, new ColorType(hasAlpha));
}
- return mruCampaigns;
- }
- public static void setSavedPaintTextures(List savedTextures) {
- StringBuilder combined = new StringBuilder();
- for (File savedTexture : savedTextures) {
- combined.append(savedTexture.getPath());
- combined.append(File.pathSeparator);
- }
- prefs.put(KEY_SAVED_PAINT_TEXTURES, combined.toString());
- }
+ private final boolean hasAlpha;
- public static List getSavedPaintTextures() {
- List savedTextures = new ArrayList();
- String combined = prefs.get(KEY_SAVED_PAINT_TEXTURES, null);
- if (combined != null) {
- String[] all = combined.split(File.pathSeparator);
- for (String s : all) {
- savedTextures.add(new File(s));
- }
- }
- return savedTextures;
- }
-
- private static final String INIT_SHOW_TOKENS = "initShowTokens";
- private static final boolean DEFAULT_INIT_SHOW_TOKENS = true;
-
- private static final String INIT_SHOW_TOKEN_STATES = "initShowTokenStates";
- private static final boolean DEFAULT_INIT_SHOW_TOKEN_STATES = true;
-
- private static final String INIT_SHOW_INITIATIVE = "initShowInitiative";
- private static final boolean DEFAULT_INIT_SHOW_INITIATIVE = true;
-
- private static final String INIT_SHOW_2ND_LINE = "initShow2ndLine";
- private static final boolean DEFAULT_INIT_SHOW_2ND_LINE = false;
-
- private static final String INIT_HIDE_NPCS = "initHideNpcs";
- private static final boolean DEFAULT_INIT_HIDE_NPCS = false;
-
- private static final String INIT_OWNER_PERMISSIONS = "initOwnerPermissions";
- private static final boolean DEFAULT_INIT_OWNER_PERMISSIONS = false;
-
- private static final String INIT_LOCK_MOVEMENT = "initLockMovement";
- private static final boolean DEFAULT_INIT_LOCK_MOVEMENT = false;
-
- public static boolean getInitShowTokens() {
- return prefs.getBoolean(INIT_SHOW_TOKENS, DEFAULT_INIT_SHOW_TOKENS);
- }
-
- public static void setInitShowTokens(boolean showTokens) {
- prefs.putBoolean(INIT_SHOW_TOKENS, showTokens);
- }
-
- public static boolean getInitShowTokenStates() {
- return prefs.getBoolean(INIT_SHOW_TOKEN_STATES, DEFAULT_INIT_SHOW_TOKEN_STATES);
- }
-
- public static void setInitShowTokenStates(boolean showTokenStates) {
- prefs.putBoolean(INIT_SHOW_TOKEN_STATES, showTokenStates);
- }
-
- public static boolean getInitShowInitiative() {
- return prefs.getBoolean(INIT_SHOW_INITIATIVE, DEFAULT_INIT_SHOW_INITIATIVE);
- }
-
- public static void setInitShowInitiative(boolean showInitiative) {
- prefs.putBoolean(INIT_SHOW_INITIATIVE, showInitiative);
- }
-
- public static boolean getInitShow2ndLine() {
- return prefs.getBoolean(INIT_SHOW_2ND_LINE, DEFAULT_INIT_SHOW_2ND_LINE);
- }
-
- public static void setInitShow2ndLine(boolean secondLine) {
- prefs.putBoolean(INIT_SHOW_2ND_LINE, secondLine);
- }
-
- public static boolean getInitHideNpcs() {
- return prefs.getBoolean(INIT_HIDE_NPCS, DEFAULT_INIT_HIDE_NPCS);
- }
-
- public static void setInitHideNpcs(boolean hideNpcs) {
- prefs.putBoolean(INIT_HIDE_NPCS, hideNpcs);
- }
-
- public static boolean getInitOwnerPermissions() {
- return prefs.getBoolean(INIT_OWNER_PERMISSIONS, DEFAULT_INIT_OWNER_PERMISSIONS);
- }
-
- public static void setInitOwnerPermissions(boolean ownerPermissions) {
- prefs.putBoolean(INIT_OWNER_PERMISSIONS, ownerPermissions);
- }
-
- public static boolean getInitLockMovement() {
- return prefs.getBoolean(INIT_LOCK_MOVEMENT, DEFAULT_INIT_LOCK_MOVEMENT);
- }
-
- public static void setInitLockMovement(boolean lockMovement) {
- prefs.putBoolean(INIT_LOCK_MOVEMENT, lockMovement);
- }
-
- public static boolean getChatNotificationShowBackground() {
- // System.out.println("Getting Value:" + prefs.getBoolean(KEY_CHAT_NOTIFICATION_SHOW_BACKGROUND,
- // DEFAULT_CHAT_NOTIFICATION_SHOW_BACKGROUND));
- return prefs.getBoolean(
- KEY_CHAT_NOTIFICATION_SHOW_BACKGROUND, DEFAULT_CHAT_NOTIFICATION_SHOW_BACKGROUND);
- }
-
- public static void setChatNotificationShowBackground(boolean flag) {
- prefs.putBoolean(KEY_CHAT_NOTIFICATION_SHOW_BACKGROUND, flag);
- }
-
- public static boolean isShowInitGainMessage() {
- // KEY_SHOW_INIT_GAIN_MESSAGE
- return prefs.getBoolean(KEY_SHOW_INIT_GAIN_MESSAGE, DEFAULT_SHOW_INIT_GAIN_MESSAGE);
- }
-
- public static void setShowInitGainMessage(boolean flag) {
- prefs.putBoolean(KEY_SHOW_INIT_GAIN_MESSAGE, flag);
- }
-
- public static boolean isUsingAstarPathfinding() {
- return prefs.getBoolean(KEY_USE_ASTAR_PATHFINDING, DEFAULT_USE_ASTAR_PATHFINDING);
- }
-
- public static void setUseAstarPathfinding(boolean show) {
- prefs.putBoolean(KEY_USE_ASTAR_PATHFINDING, show);
- }
-
- public static boolean getVblBlocksMove() {
- return prefs.getBoolean(KEY_VBL_BLOCKS_MOVE, DEFAULT_VBL_BLOCKS_MOVE);
- }
-
- public static void setVblBlocksMove(boolean use) {
- prefs.putBoolean(KEY_VBL_BLOCKS_MOVE, use);
- }
-
- public static String getDefaultMacroEditorTheme() {
- return prefs.get(MACRO_EDITOR_THEME, DEFAULT_MACRO_EDITOR_THEME);
- }
-
- public static void setDefaultMacroEditorTheme(String type) {
- prefs.put(MACRO_EDITOR_THEME, type);
- }
-
- public static String getIconTheme() {
- return prefs.get(ICON_THEME, DEFAULT_ICON_THEME);
- }
-
- public static void setIconTheme(String theme) {
- prefs.put(ICON_THEME, theme);
- }
-
- public static Zone.TopologyTypeSet getTopologyTypes() {
- try {
- String typeNames = prefs.get(KEY_TOPOLOGY_TYPES, "");
- if ("".equals(typeNames)) {
- // Fallback to the key used prior to the introduction of various VBL types.
- String oldDrawingMode = prefs.get(KEY_OLD_TOPOLOGY_DRAWING_MODE, DEFAULT_TOPOLOGY_TYPE);
- return switch (oldDrawingMode) {
- default -> new Zone.TopologyTypeSet(Zone.TopologyType.WALL_VBL);
- case "VBL" -> new Zone.TopologyTypeSet(Zone.TopologyType.WALL_VBL);
- case "MBL" -> new Zone.TopologyTypeSet(Zone.TopologyType.MBL);
- case "COMBINED" -> new Zone.TopologyTypeSet(
- Zone.TopologyType.WALL_VBL, Zone.TopologyType.MBL);
- };
- } else {
- return Zone.TopologyTypeSet.valueOf(typeNames);
- }
- } catch (Exception exc) {
- return new Zone.TopologyTypeSet(Zone.TopologyType.WALL_VBL);
- }
- }
-
- public static void setWebEndPointPort(int value) {
- prefs.putInt(KEY_WEB_END_POINT_PORT, value);
- }
-
- public static int getWebEndPointPort() {
- return prefs.getInt(KEY_WEB_END_POINT_PORT, DEFAULT_WEB_END_POINT);
- }
-
- // Based off vision type enum in Zone.java, this could easily get tossed somewhere else if
- // preferred.
- public enum MapSortType {
- DISPLAYNAME(),
- GMNAME();
-
- private final String displayName;
-
- MapSortType() {
- displayName = I18N.getString("mapSortType." + name());
+ public ColorType(boolean hasAlpha) {
+ this.hasAlpha = hasAlpha;
}
@Override
- public String toString() {
- return displayName;
+ public void set(Preferences prefs, String key, Color value) {
+ prefs.putInt(key, value.getRGB());
}
- }
- /**
- * Sets the topology mode preference.
- *
- * @param types the topology types. A value of null resets to default.
- */
- public static void setTopologyTypes(Zone.TopologyTypeSet types) {
- if (types == null) {
- prefs.remove(KEY_TOPOLOGY_TYPES);
- } else {
- prefs.put(KEY_TOPOLOGY_TYPES, types.toString());
+ @Override
+ public Color get(Preferences prefs, String key, Supplier defaultValue) {
+ return new Color(prefs.getInt(key, defaultValue.get().getRGB()), hasAlpha);
}
}
-
- /**
- * Returns the background color to use for NPC Map Labels.
- *
- * @return the background color to use for NPC Map Labels.
- */
- public static Color getNPCMapLabelBG() {
- return new Color(
- prefs.getInt(KEY_NPC_MAP_LABEL_BG_COLOR, DEFAULT_NPC_MAP_LABEL_BG_COLOR.getRGB()), true);
- }
-
- /**
- * Sets the background color to use for NPC Map Labels.
- *
- * @param color the background color to use for NPC Map Labels.
- */
- public static void setNPCMapLabelBG(Color color) {
- prefs.putInt(KEY_NPC_MAP_LABEL_BG_COLOR, color.getRGB());
- }
-
- /**
- * Returns the border color to use for PC Map Labels.
- *
- * @return the border color to use for PC Map Labels.
- */
- public static Color getPCMapLabelBorder() {
- return new Color(
- prefs.getInt(KEY_PC_MAP_LABEL_BORDER_COLOR, DEFAULT_PC_MAP_LABEL_BORDER_COLOR.getRGB()),
- true);
- }
-
- /**
- * Sets the border color to use for PC Map Labels.
- *
- * @param color the border color to use for PC Map Labels.
- */
- public static void setPCMapLabelBorder(Color color) {
- prefs.putInt(KEY_PC_MAP_LABEL_BORDER_COLOR, color.getRGB());
- }
-
- /**
- * Returns the foreground color to use for NPC Map Labels.
- *
- * @return the foreground color to use for NPC Map Labels.
- */
- public static Color getNPCMapLabelFG() {
- return new Color(
- prefs.getInt(KEY_NPC_MAP_LABEL_FG_COLOR, DEFAULT_NPC_MAP_LABEL_FG_COLOR.getRGB()), true);
- }
-
- /**
- * Sets the foreground color to use for NPC Map Labels.
- *
- * @param color the foreground color to use for NPC Map Labels.
- */
- public static void setNPCMapLabelFG(Color color) {
- prefs.putInt(KEY_NPC_MAP_LABEL_FG_COLOR, color.getRGB());
- }
-
- /**
- * Returns the border color to use for NPC Map Labels.
- *
- * @return the border color to use for NPC Map Labels.
- */
- public static Color getNPCMapLabelBorder() {
- return new Color(
- prefs.getInt(KEY_NPC_MAP_LABEL_BORDER_COLOR, DEFAULT_NPC_MAP_LABEL_BORDER_COLOR.getRGB()),
- true);
- }
-
- /**
- * Sets the border color to use for NPC Map Labels.
- *
- * @param color the border color to use for NPC Map Labels.
- */
- public static void setNPCMapLabelBorder(Color color) {
- prefs.putInt(KEY_NPC_MAP_LABEL_BORDER_COLOR, color.getRGB());
- }
-
- /**
- * Returns the background color to use for PC Map Labels.
- *
- * @return the background color to use for PC Map Labels.
- */
- public static Color getPCMapLabelBG() {
- return new Color(
- prefs.getInt(KEY_PC_MAP_LABEL_BG_COLOR, DEFAULT_PC_MAP_LABEL_BG_COLOR.getRGB()), true);
- }
-
- /**
- * Sets the background color to use for PC Map Labels.
- *
- * @param color the background color to use for PC Map Labels.
- */
- public static void setPCMapLabelBG(Color color) {
- prefs.putInt(KEY_PC_MAP_LABEL_BG_COLOR, color.getRGB());
- }
-
- /**
- * Returns the foreground color to use for PC Map Labels.
- *
- * @return the foreground color to use for PC Map Labels.
- */
- public static Color getPCMapLabelFG() {
- return new Color(
- prefs.getInt(KEY_PC_MAP_LABEL_FG_COLOR, DEFAULT_PC_MAP_LABEL_FG_COLOR.getRGB()), true);
- }
-
- /**
- * Sets the foreground color to use for PC Map Labels.
- *
- * @param color the foreground color to use for PC Map Labels.
- */
- public static void setPCMapLabelFG(Color color) {
- prefs.putInt(KEY_PC_MAP_LABEL_FG_COLOR, color.getRGB());
- }
-
- /**
- * Returns the background color to use for Non-Visible Token Map Labels.
- *
- * @return the background color to use for Non-Visible Token Map Labels.
- */
- public static Color getNonVisMapLabelBG() {
- return new Color(
- prefs.getInt(KEY_NONVIS_MAP_LABEL_BG_COLOR, DEFAULT_NONVIS_MAP_LABEL_BG_COLOR.getRGB()),
- true);
- }
-
- /**
- * Sets the background color to use for Non-Visible Token Map Labels.
- *
- * @param color the background color to use for Non-Visible Token Map Labels.
- */
- public static void setNonVisMapLabelBG(Color color) {
- prefs.putInt(KEY_NONVIS_MAP_LABEL_BG_COLOR, color.getRGB());
- }
-
- /**
- * Returns the foreground color to use for Non-Visible Token Map Labels.
- *
- * @return the foreground color to use for Non-Visible Token Map Labels.
- */
- public static Color getNonVisMapLabelFG() {
- return new Color(
- prefs.getInt(KEY_NONVIS_MAP_LABEL_FG_COLOR, DEFAULT_NONVIS_MAP_LABEL_FG_COLOR.getRGB()),
- true);
- }
-
- /**
- * Sets the foreground color to use for Non-Visible Token Map Labels.
- *
- * @param color the foreground color to use for Non-Visible Token Map Labels.
- */
- public static void setNonVisMapLabelFG(Color color) {
- prefs.putInt(KEY_NONVIS_MAP_LABEL_FG_COLOR, color.getRGB());
- }
-
- /**
- * Returns the border color to use for Non-Visible Token Map Labels.
- *
- * @return the border color to use for Non-Visible Token Map Labels.
- */
- public static Color getNonVisMapLabelBorder() {
- return new Color(
- prefs.getInt(
- KEY_NONVIS_MAP_LABEL_BORDER_COLOR, DEFAULT_NONVIS_MAP_LABEL_BORDER_COLOR.getRGB()),
- true);
- }
-
- /**
- * Sets the border color to use for Non-Visible Token Map Labels.
- *
- * @param color the border color to use for Non-Visible Token Map Labels.
- */
- public static void setNonVisMapLabelBorder(Color color) {
- prefs.putInt(KEY_NONVIS_MAP_LABEL_BORDER_COLOR, color.getRGB());
- }
-
- /**
- * Returns the font size to use for Map Token Labels.
- *
- * @return the font size to use for Map Token Labels.
- */
- public static int getMapLabelFontSize() {
- return prefs.getInt(KEY_MAP_LABEL_FONT_SIZE, DEFAULT_MAP_LABEL_FONT_SIZE);
- }
-
- /**
- * Sets the font size to use for Map Token Labels.
- *
- * @param size the font size to use for Map Token Labels.
- */
- public static void setMapLabelFontSize(int size) {
- prefs.putInt(KEY_MAP_LABEL_FONT_SIZE, size);
- }
-
- /**
- * Gets the width of the border for token map labels.
- *
- * @return The width of the border for map labels.
- */
- public static int getMapLabelBorderWidth() {
- return prefs.getInt(KEY_MAP_LABEL_BORDER_WIDTH, DEFAULT_MAP_LABEL_BORDER_WIDTH);
- }
-
- /**
- * Sets the width of the border for token map labels.
- *
- * @param width the width of the border in pixels
- */
- public static void setMapLabelBorderWidth(int width) {
- prefs.putInt(KEY_MAP_LABEL_BORDER_WIDTH, width);
- }
-
- /**
- * Returns the value of the preference for the map label border arc.
- *
- * @return the value of the preference for the map label border arc
- */
- public static int getMapLabelBorderArc() {
- return prefs.getInt(KEY_MAP_LABEL_BORDER_ARC, DEFAULT_MAP_LABEL_BORDER_ARC);
- }
-
- /**
- * Sets the value of the preference for the map label border arc.
- *
- * @param arc the value of the preference for the map label border arc
- */
- public static void setMapLabelBorderArc(int arc) {
- prefs.putInt(KEY_MAP_LABEL_BORDER_ARC, arc);
- }
-
- /**
- * Returns the value of the preference "show map label border". The preference determines whether
- * the border should be shown around the map label or not.
- *
- * @return {@code true} if the map label border should be shown, {@code false} otherwise.
- */
- public static boolean getShowMapLabelBorder() {
- return prefs.getBoolean(KEY_MAP_LABEL_SHOW_BORDER, DEFAULT_MAP_LABEL_SHOW_BORDER);
- }
-
- /**
- * Sets the preference for showing or hiding the border of map labels.
- *
- * @param show {@code true} to show the border, {@code false} to hide the border
- */
- public static void setShowMapLabelBorder(boolean show) {
- prefs.putBoolean(KEY_MAP_LABEL_SHOW_BORDER, show);
- }
}
diff --git a/src/main/java/net/rptools/maptool/client/AppSetup.java b/src/main/java/net/rptools/maptool/client/AppSetup.java
index 3bbf22149e..289391663d 100644
--- a/src/main/java/net/rptools/maptool/client/AppSetup.java
+++ b/src/main/java/net/rptools/maptool/client/AppSetup.java
@@ -157,7 +157,7 @@ public static void installLibrary(String libraryName, URL resourceFile) throws I
public static void installLibrary(final String libraryName, final File root) {
// Add as a resource root
- AppPreferences.addAssetRoot(root);
+ AppStatePersisted.addAssetRoot(root);
if (MapTool.getFrame() != null) {
MapTool.getFrame().addAssetRoot(root);
diff --git a/src/main/java/net/rptools/maptool/client/AppState.java b/src/main/java/net/rptools/maptool/client/AppState.java
index 81b9cc4531..e06e395879 100644
--- a/src/main/java/net/rptools/maptool/client/AppState.java
+++ b/src/main/java/net/rptools/maptool/client/AppState.java
@@ -50,8 +50,8 @@ public class AppState {
private static PropertyChangeSupport changeSupport = new PropertyChangeSupport(AppState.class);
static {
- showLumensOverlay = AppPreferences.getLumensOverlayShowByDefault();
- showLights = AppPreferences.getLightsShowByDefault();
+ showLumensOverlay = AppPreferences.lumensOverlayShowByDefault.get();
+ showLights = AppPreferences.lightsShowByDefault.get();
}
public static void addPropertyChangeListener(PropertyChangeListener listener) {
diff --git a/src/main/java/net/rptools/maptool/client/AppStatePersisted.java b/src/main/java/net/rptools/maptool/client/AppStatePersisted.java
new file mode 100644
index 0000000000..90efabd4f5
--- /dev/null
+++ b/src/main/java/net/rptools/maptool/client/AppStatePersisted.java
@@ -0,0 +1,224 @@
+/*
+ * This software Copyright by the RPTools.net development team, and
+ * licensed under the Affero GPL Version 3 or, at your option, any later
+ * version.
+ *
+ * MapTool Source Code is distributed in the hope that it will be
+ * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License * along with this source Code. If not, please visit
+ * and specifically the Affero license
+ * text at .
+ */
+package net.rptools.maptool.client;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.prefs.Preferences;
+import net.rptools.maptool.model.Zone;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+/**
+ * Keeps track of application state between runs.
+ *
+ *
This started as an offshoot of {@link net.rptools.maptool.client.AppPreferences}, hence why
+ * the same node is used. But these keys do not represent preferences of the user, rather they are
+ * application state such as MRU lists the need to be remembered between runs. This also makes it
+ * different from {@link net.rptools.maptool.client.AppState} which is application state that is not
+ * preserved between runs.
+ */
+public class AppStatePersisted {
+ private static final Logger log = LogManager.getLogger(AppStatePersisted.class);
+ private static final Preferences prefs =
+ Preferences.userRoot().node(AppConstants.APP_NAME + "/prefs");
+
+ /**
+ * Defines the key constant for retrieving asset roots.
+ *
+ *
This constant is used to define the key for accessing asset roots in a configuration file or
+ * a data source. Asset roots represent the directories or paths where application assets are
+ * stored.
+ *
+ *
The asset roots can be used to locate and load files, images, or other resources required by
+ * the application at runtime. By convention, the asset root directories are organized in a
+ * structured manner to facilitate easy retrieval of assets.
+ */
+ private static final String KEY_ASSET_ROOTS = "assetRoots";
+
+ /** Represents the key used to access the most recently used campaigns for the menu option. */
+ private static final String KEY_MRU_CAMPAIGNS = "mruCampaigns";
+
+ // When hill VBL was introduced, older versions of MapTool were unable to read the new topology
+ // modes. So we use a different preference key than in the past so older versions would not
+ // unexpectedly break.
+ private static final String KEY_TOPOLOGY_TYPES = "topologyTypes";
+ private static final String KEY_OLD_TOPOLOGY_DRAWING_MODE = "topologyDrawingMode";
+ private static final String DEFAULT_TOPOLOGY_TYPE = "VBL";
+
+ /** Represents the key used to save the paint textures to the preferences. */
+ private static final String KEY_SAVED_PAINT_TEXTURES = "savedTextures";
+
+ public static void clearAssetRoots() {
+ prefs.put(KEY_ASSET_ROOTS, "");
+ }
+
+ public static void addAssetRoot(File root) {
+ String list = prefs.get(KEY_ASSET_ROOTS, "");
+ if (!list.isEmpty()) {
+ // Add the new one and then remove all duplicates.
+ list += ";" + root.getPath();
+ String[] roots = list.split(";");
+ var result = new StringBuilder(list.length() + root.getPath().length() + 10);
+ var rootList = new HashSet(roots.length);
+
+ // This loop ensures that each path only appears once. If there are currently
+ // duplicates in the list, only the first one is kept.
+ for (String r : roots) {
+ if (!rootList.contains(r)) {
+ result.append(';').append(r);
+ rootList.add(r);
+ }
+ }
+ list = result.substring(1);
+ } else {
+ list += root.getPath();
+ }
+ prefs.put(KEY_ASSET_ROOTS, list);
+ }
+
+ public static Set getAssetRoots() {
+ String list = prefs.get(KEY_ASSET_ROOTS, "");
+ String[] roots = list.split(";"); // FJE Probably should be File.path_separator ...
+
+ var rootList = new HashSet();
+ for (String root : roots) {
+ File file = new File(root);
+
+ // LATER: Should this actually remove it from the pref list ?
+ if (!file.exists()) {
+ continue;
+ }
+ rootList.add(file);
+ }
+ return rootList;
+ }
+
+ public static void removeAssetRoot(File root) {
+ String list = prefs.get(KEY_ASSET_ROOTS, "");
+ if (!list.isEmpty()) {
+ // Add the new one and then remove all duplicates.
+ String[] roots = list.split(";");
+ var result = new StringBuilder(list.length());
+ var rootList = new HashSet(roots.length);
+ String rootPath = root.getPath();
+
+ // This loop ensures that each path only appears once. If there are
+ // duplicates in the list, only the first one is kept.
+ for (String r : roots) {
+ if (!r.equals(rootPath) && !rootList.contains(r)) {
+ result.append(';').append(r);
+ rootList.add(r);
+ }
+ }
+ list = result.substring(result.isEmpty() ? 0 : 1);
+ prefs.put(KEY_ASSET_ROOTS, list);
+ }
+ }
+
+ public static void setMruCampaigns(List mruCampaigns) {
+ StringBuilder combined = new StringBuilder();
+ for (File file : mruCampaigns) {
+ String path;
+ try {
+ path = file.getCanonicalPath();
+ } catch (IOException e) {
+ // Probably pretty rare, but we want to know about it
+ log.info("unexpected during file.getCanonicalPath()", e); // $NON-NLS-1$
+ path = file.getPath();
+ }
+ // It's important that '%3A' is done last. Note that the pathSeparator may not be a colon on
+ // the current platform, but it doesn't matter since it will be reconverted when read back in
+ // again.
+ // THink of the '%3A' as a symbol of the separator, not an encoding of the character.
+ combined.append(path.replaceAll("%", "%25").replaceAll(File.pathSeparator, "%3A"));
+ combined.append(File.pathSeparator);
+ }
+ prefs.put(KEY_MRU_CAMPAIGNS, combined.toString());
+ }
+
+ public static List getMruCampaigns() {
+ var mruCampaigns = new ArrayList();
+ String combined = prefs.get(KEY_MRU_CAMPAIGNS, null);
+ if (combined != null) {
+ // It's important that '%3A' is done first
+ combined = combined.replaceAll("%3A", File.pathSeparator).replaceAll("%25", "%");
+ String[] all = combined.split(File.pathSeparator);
+ for (String s : all) {
+ mruCampaigns.add(new File(s));
+ }
+ }
+ return mruCampaigns;
+ }
+
+ public static Zone.TopologyTypeSet getTopologyTypes() {
+ try {
+ String typeNames = prefs.get(KEY_TOPOLOGY_TYPES, "");
+ if ("".equals(typeNames)) {
+ // Fallback to the key used prior to the introduction of various VBL types.
+ String oldDrawingMode = prefs.get(KEY_OLD_TOPOLOGY_DRAWING_MODE, DEFAULT_TOPOLOGY_TYPE);
+ return switch (oldDrawingMode) {
+ case "VBL" -> new Zone.TopologyTypeSet(Zone.TopologyType.WALL_VBL);
+ case "MBL" -> new Zone.TopologyTypeSet(Zone.TopologyType.MBL);
+ case "COMBINED" -> new Zone.TopologyTypeSet(
+ Zone.TopologyType.WALL_VBL, Zone.TopologyType.MBL);
+ default -> new Zone.TopologyTypeSet(Zone.TopologyType.WALL_VBL);
+ };
+ } else {
+ return Zone.TopologyTypeSet.valueOf(typeNames);
+ }
+ } catch (Exception exc) {
+ return new Zone.TopologyTypeSet(Zone.TopologyType.WALL_VBL);
+ }
+ }
+
+ /**
+ * Sets the selected topology modes.
+ *
+ * @param types the topology types. A value of null resets to default.
+ */
+ public static void setTopologyTypes(Zone.TopologyTypeSet types) {
+ if (types == null) {
+ prefs.remove(KEY_TOPOLOGY_TYPES);
+ } else {
+ prefs.put(KEY_TOPOLOGY_TYPES, types.toString());
+ }
+ }
+
+ public static void setSavedPaintTextures(List savedTextures) {
+ StringBuilder combined = new StringBuilder();
+ for (File savedTexture : savedTextures) {
+ combined.append(savedTexture.getPath());
+ combined.append(File.pathSeparator);
+ }
+ prefs.put(KEY_SAVED_PAINT_TEXTURES, combined.toString());
+ }
+
+ public static List getSavedPaintTextures() {
+ var savedTextures = new ArrayList();
+ String combined = prefs.get(KEY_SAVED_PAINT_TEXTURES, null);
+ if (combined != null) {
+ String[] all = combined.split(File.pathSeparator);
+ for (String s : all) {
+ savedTextures.add(new File(s));
+ }
+ }
+ return savedTextures;
+ }
+}
diff --git a/src/main/java/net/rptools/maptool/client/AppUpdate.java b/src/main/java/net/rptools/maptool/client/AppUpdate.java
index 8b1973cf63..27f515ce90 100644
--- a/src/main/java/net/rptools/maptool/client/AppUpdate.java
+++ b/src/main/java/net/rptools/maptool/client/AppUpdate.java
@@ -47,7 +47,9 @@ public class AppUpdate {
*/
public static boolean gitHubReleases() {
// AppPreferences.setSkipAutoUpdate(false); // For testing only
- if (AppPreferences.getSkipAutoUpdate()) return false;
+ if (AppPreferences.skipAutoUpdate.get()) {
+ return false;
+ }
// Default for Linux?
String DOWNLOAD_EXTENSION = ".deb";
@@ -75,7 +77,7 @@ public static boolean gitHubReleases() {
return false;
}
- if (!AppPreferences.getSkipAutoUpdateRelease().equals(latestReleaseId)
+ if (!AppPreferences.skipAutoUpdateRelease.get().equals(latestReleaseId)
&& ModelVersionManager.isBefore(runningVersion, latestReleaseVersion)) {
JsonArray releaseAssets = latestRelease.get("assets").getAsJsonArray();
@@ -240,9 +242,11 @@ private static boolean showMessage(String releaseId, String tagName) {
options[1]);
boolean dontAsk = dontAskCheckbox.isSelected();
- if (dontAsk) AppPreferences.setSkipAutoUpdate(true);
+ if (dontAsk) {
+ AppPreferences.skipAutoUpdate.set(true);
+ }
- if (result == JOptionPane.CANCEL_OPTION) AppPreferences.setSkipAutoUpdateRelease(releaseId);
+ if (result == JOptionPane.CANCEL_OPTION) AppPreferences.skipAutoUpdateRelease.set(releaseId);
return (result == JOptionPane.YES_OPTION);
}
diff --git a/src/main/java/net/rptools/maptool/client/AutoSaveManager.java b/src/main/java/net/rptools/maptool/client/AutoSaveManager.java
index 5e7d5b33cb..650982b19f 100644
--- a/src/main/java/net/rptools/maptool/client/AutoSaveManager.java
+++ b/src/main/java/net/rptools/maptool/client/AutoSaveManager.java
@@ -65,7 +65,7 @@ private void execute() {
private boolean executeAndContinue() {
int interval =
- AppPreferences.getAutoSaveIncrement()
+ AppPreferences.autoSaveIncrement.get()
* 1000
* (DeveloperOptions.Toggle.AutoSaveMeasuredInSeconds.isEnabled() ? 1 : 60);
diff --git a/src/main/java/net/rptools/maptool/client/ChatAutoSave.java b/src/main/java/net/rptools/maptool/client/ChatAutoSave.java
index fe40fe5d9b..b6ca2610ef 100644
--- a/src/main/java/net/rptools/maptool/client/ChatAutoSave.java
+++ b/src/main/java/net/rptools/maptool/client/ChatAutoSave.java
@@ -20,6 +20,7 @@
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
+import java.util.concurrent.TimeUnit;
import net.rptools.maptool.client.ui.commandpanel.CommandPanel;
import net.rptools.maptool.language.I18N;
import org.apache.logging.log4j.LogManager;
@@ -29,34 +30,35 @@
* @author frank
*/
public class ChatAutoSave {
- private static Logger log = LogManager.getLogger(ChatAutoSave.class);
- private static final ChatAutoSave self = new ChatAutoSave();
+ private static final Logger log = LogManager.getLogger(ChatAutoSave.class);
private final Timer countdown;
private TimerTask task;
private long delay;
- private static String chatlog = null;
+ private String chatlog = null;
- private ChatAutoSave() {
+ public ChatAutoSave() {
log.debug("Creating chat log autosave timer"); // $NON-NLS-1$
// Only way to set the delay is to call changeTimeout()
- delay = 0;
+ this.delay = 0;
countdown = new Timer();
}
- private static TimerTask createTimer(final long timeout) {
+ private TimerTask createTimer(final long timeout) {
TimerTask t =
new TimerTask() {
@Override
public void run() {
+ log.info("Running the task");
+
log.debug("Chat log autosave countdown complete from {}", timeout); // $NON-NLS-1$
if (chatlog == null) {
- String filename = AppPreferences.getChatFilenameFormat();
+ String filename = AppPreferences.chatFilenameFormat.get();
// FJE Ugly kludge to replace older default entry with newer default
// TODO This is going into 1.3.b77 so remove it in 3-4 builds
if ("chatlog.html".equals(filename)) { // $NON-NLS-1$
- AppPreferences.clearChatFilenameFormat();
- filename = AppPreferences.getChatFilenameFormat();
+ AppPreferences.chatFilenameFormat.remove();
+ filename = AppPreferences.chatFilenameFormat.get();
}
chatlog = String.format(filename, new Date()).replace(':', '-');
}
@@ -89,13 +91,9 @@ public void run() {
return t;
}
- private static ChatAutoSave getInstance() {
- return self;
- }
-
- public static void changeTimeout(int timeout) {
- getInstance().delay = timeout * 1000 * 60;
- getInstance().start();
+ public void setTimeout(int timeout) {
+ delay = TimeUnit.MINUTES.toMillis(timeout);
+ start();
}
private void stop() {
@@ -106,6 +104,8 @@ private void stop() {
}
private void start() {
+ log.info("Starting the countdown again");
+
if (delay > 0) {
stop();
task = createTimer(delay);
diff --git a/src/main/java/net/rptools/maptool/client/ClientMessageHandler.java b/src/main/java/net/rptools/maptool/client/ClientMessageHandler.java
index 9b66a3a4e0..34d8031a18 100644
--- a/src/main/java/net/rptools/maptool/client/ClientMessageHandler.java
+++ b/src/main/java/net/rptools/maptool/client/ClientMessageHandler.java
@@ -917,7 +917,7 @@ private void handle(EnforceZoneViewMsg msg) {
if (renderer == null) {
return;
}
- if (AppPreferences.getFitGMView()) {
+ if (AppPreferences.fitGmView.get()) {
renderer.enforceView(x, y, scale, gmWidth, gmHeight);
} else {
renderer.setScale(scale);
diff --git a/src/main/java/net/rptools/maptool/client/MRUCampaignManager.java b/src/main/java/net/rptools/maptool/client/MRUCampaignManager.java
index 68428192b5..f7fc5661bd 100644
--- a/src/main/java/net/rptools/maptool/client/MRUCampaignManager.java
+++ b/src/main/java/net/rptools/maptool/client/MRUCampaignManager.java
@@ -105,11 +105,11 @@ private void addMRUsToMenu() {
}
private void saveMruCampaignList() {
- AppPreferences.setMruCampaigns(mruCampaigns);
+ AppStatePersisted.setMruCampaigns(mruCampaigns);
}
private void loadMruCampaignList() {
- mruCampaigns = AppPreferences.getMruCampaigns();
+ mruCampaigns = AppStatePersisted.getMruCampaigns();
addMRUsToMenu();
}
}
diff --git a/src/main/java/net/rptools/maptool/client/MapTool.java b/src/main/java/net/rptools/maptool/client/MapTool.java
index d01e8fe067..441d8470c6 100644
--- a/src/main/java/net/rptools/maptool/client/MapTool.java
+++ b/src/main/java/net/rptools/maptool/client/MapTool.java
@@ -145,7 +145,7 @@ public class MapTool {
// Set it to 500 (from 100) for now to support larger asset window previews
// TODO: Add preferences option as well as add auto-purge after x days preferences
private static final Dimension THUMBNAIL_SIZE =
- new Dimension(AppPreferences.getThumbnailSize(), AppPreferences.getThumbnailSize());
+ new Dimension(AppPreferences.thumbnailSize.get(), AppPreferences.thumbnailSize.get());
private static ThumbnailManager thumbnailManager;
private static String version = "DEVELOPMENT";
@@ -168,6 +168,7 @@ public class MapTool {
private static TaskBarFlasher taskbarFlasher;
private static MapToolLineParser parser = new MapToolLineParser();
private static String lastWhisperer;
+ private static ChatAutoSave chatAutoSave;
// Jamz: To support new command line parameters for multi-monitor support & enhanced PrintStream
private static boolean debug = false;
@@ -394,7 +395,7 @@ public static int confirmImpl(String title, int buttons, String message, Object.
* @return true if the token should be deleted.
*/
public static boolean confirmTokenDelete() {
- if (!AppPreferences.getTokensWarnWhenDeleted()) {
+ if (!AppPreferences.tokensWarnWhenDeleted.get()) {
return true;
}
@@ -404,7 +405,7 @@ public static boolean confirmTokenDelete() {
// "Yes, don't show again" Button
if (val == 2) {
showInformation("msg.confirm.deleteToken.removed");
- AppPreferences.setTokensWarnWhenDeleted(false);
+ AppPreferences.tokensWarnWhenDeleted.set(false);
}
// Any version of 'Yes' returns true, false otherwise
return val == JOptionPane.YES_OPTION || val == 2;
@@ -418,7 +419,7 @@ public static boolean confirmTokenDelete() {
* @return true if the user clicks either Yes button, falsee otherwise.
*/
public static boolean confirmDrawDelete() {
- if (!AppPreferences.getDrawWarnWhenDeleted()) {
+ if (!AppPreferences.drawingsWarnWhenDeleted.get()) {
return true;
}
@@ -428,7 +429,7 @@ public static boolean confirmDrawDelete() {
// "Yes, don't show again" Button
if (val == JOptionPane.CANCEL_OPTION) {
showInformation("msg.confirm.deleteDraw.removed");
- AppPreferences.setDrawWarnWhenDeleted(false);
+ AppPreferences.drawingsWarnWhenDeleted.set(false);
}
// Any version of 'Yes' returns true, otherwise false
return val == JOptionPane.YES_OPTION || val == JOptionPane.CANCEL_OPTION;
@@ -530,8 +531,8 @@ public static void showDocument(String url) {
* @param eventId the eventId of the sound.
*/
public static void playSound(String eventId) {
- if (AppPreferences.getPlaySystemSounds()) {
- if (AppPreferences.getPlaySystemSoundsOnlyWhenNotFocused() && isInFocus()) {
+ if (AppPreferences.playSystemSounds.get()) {
+ if (AppPreferences.playSystemSoundsOnlyWhenNotFocused.get() && isInFocus()) {
return;
}
SoundManager.playSoundEvent(eventId);
@@ -674,7 +675,7 @@ private static void initialize() {
Campaign cmpgn = CampaignFactory.createBasicCampaign();
// Set the Topology drawing mode to the last mode used for convenience
// Should only be one zone, but let's cover our bases.
- cmpgn.getZones().forEach(zone -> zone.setTopologyTypes(AppPreferences.getTopologyTypes()));
+ cmpgn.getZones().forEach(zone -> zone.setTopologyTypes(AppStatePersisted.getTopologyTypes()));
// Stop the pre-init client/server.
disconnect();
@@ -686,9 +687,12 @@ private static void initialize() {
}
AppActions.updateActions();
- ToolTipManager.sharedInstance().setInitialDelay(AppPreferences.getToolTipInitialDelay());
- ToolTipManager.sharedInstance().setDismissDelay(AppPreferences.getToolTipDismissDelay());
- ChatAutoSave.changeTimeout(AppPreferences.getChatAutosaveTime());
+ ToolTipManager.sharedInstance().setInitialDelay(AppPreferences.toolTipInitialDelay.get());
+ ToolTipManager.sharedInstance().setDismissDelay(AppPreferences.toolTipDismissDelay.get());
+
+ chatAutoSave = new ChatAutoSave();
+ chatAutoSave.setTimeout(AppPreferences.chatAutoSaveTimeInMinutes.get());
+ AppPreferences.chatAutoSaveTimeInMinutes.onChange(chatAutoSave::setTimeout);
// TODO: make this more formal when we switch to mina
new ServerHeartBeatThread().start();
@@ -1276,9 +1280,9 @@ private static void postInitialize() {
}
}
// alternately load MRU campaign if preference set
- else if (AppPreferences.getLoadMRUCampaignAtStart()) {
+ else if (AppPreferences.loadMruCampaignAtStart.get()) {
try {
- campaignFile = AppPreferences.getMruCampaigns().getFirst();
+ campaignFile = AppStatePersisted.getMruCampaigns().getFirst();
if (campaignFile.exists()) {
AppActions.loadCampaign(campaignFile);
}
@@ -1354,7 +1358,7 @@ public static String getLastWhisperer() {
public static boolean useToolTipsForUnformatedRolls() {
if (isPersonalServer() || getServerPolicy() == null) {
- return AppPreferences.getUseToolTipForInlineRoll();
+ return AppPreferences.useToolTipForInlineRoll.get();
} else {
return getServerPolicy().getUseToolTipsForDefaultRollFormat();
}
@@ -1653,7 +1657,7 @@ public static void main(String[] args) {
factory.registerProtocol("lib", new LibraryURLStreamHandler());
// Syrinscape Protocols
- if (AppPreferences.getSyrinscapeActive()) {
+ if (AppPreferences.syrinscapeActive.get()) {
factory.registerProtocol("syrinscape-fantasy", new SyrinscapeURLStreamHandler());
factory.registerProtocol("syrinscape-sci-fi", new SyrinscapeURLStreamHandler());
factory.registerProtocol("syrinscape-boardgame", new SyrinscapeURLStreamHandler());
diff --git a/src/main/java/net/rptools/maptool/client/MapToolUtil.java b/src/main/java/net/rptools/maptool/client/MapToolUtil.java
index 2c915970e1..fb8cec1852 100644
--- a/src/main/java/net/rptools/maptool/client/MapToolUtil.java
+++ b/src/main/java/net/rptools/maptool/client/MapToolUtil.java
@@ -137,7 +137,7 @@ public static String nextTokenId(Zone zone, Token token, boolean force) {
String newName;
Integer newNum = null;
- if (isToken && AppPreferences.getNewTokenNaming().equals(Token.NAME_USE_CREATURE)) {
+ if (isToken && AppPreferences.newTokenNaming.get().equals(Token.NAME_USE_CREATURE)) {
newName = I18N.getString("Token.name.creature");
} else if (!force) {
return baseName;
@@ -162,9 +162,12 @@ public static String nextTokenId(Zone zone, Token token, boolean force) {
newName = baseName;
}
}
- boolean random = (isToken && AppPreferences.getDuplicateTokenNumber().equals(Token.NUM_RANDOM));
- boolean addNumToGM = !AppPreferences.getTokenNumberDisplay().equals(Token.NUM_ON_NAME);
- boolean addNumToName = !AppPreferences.getTokenNumberDisplay().equals(Token.NUM_ON_GM);
+ boolean random =
+ (isToken && AppPreferences.duplicateTokenNumber.get().equals(Token.NUM_RANDOM));
+
+ var tokenNumberDisplay = AppPreferences.tokenNumberDisplay.get();
+ boolean addNumToGM = !tokenNumberDisplay.equals(Token.NUM_ON_NAME);
+ boolean addNumToName = !tokenNumberDisplay.equals(Token.NUM_ON_GM);
/*
* If the token already has a number suffix, if the preferences indicate that token numbering should be random and this token is on the Token layer, or if the token already exists somewhere on
diff --git a/src/main/java/net/rptools/maptool/client/functions/ExportDataFunctions.java b/src/main/java/net/rptools/maptool/client/functions/ExportDataFunctions.java
index 7ebc0e4c40..e96b3cbc6d 100644
--- a/src/main/java/net/rptools/maptool/client/functions/ExportDataFunctions.java
+++ b/src/main/java/net/rptools/maptool/client/functions/ExportDataFunctions.java
@@ -57,7 +57,7 @@ public Object childEvaluate(
if (!MapTool.getParser().isMacroTrusted())
throw new ParserException(I18N.getText("macro.function.general.noPerm", functionName));
- if (!AppPreferences.getAllowExternalMacroAccess())
+ if (!AppPreferences.allowExternalMacroAccess.get())
throw new ParserException(I18N.getText("macro.function.general.accessDenied", functionName));
// New function to save data to an external file.
diff --git a/src/main/java/net/rptools/maptool/client/functions/IsTrustedFunction.java b/src/main/java/net/rptools/maptool/client/functions/IsTrustedFunction.java
index 176ed41ac1..b601d0db12 100644
--- a/src/main/java/net/rptools/maptool/client/functions/IsTrustedFunction.java
+++ b/src/main/java/net/rptools/maptool/client/functions/IsTrustedFunction.java
@@ -44,7 +44,7 @@ public Object childEvaluate(
if (functionName.equalsIgnoreCase("isTrusted")) {
return MapTool.getParser().isMacroTrusted() ? BigDecimal.ONE : BigDecimal.ZERO;
} else if (functionName.equalsIgnoreCase("isExternalMacroAccessAllowed")) {
- return AppPreferences.getAllowExternalMacroAccess() ? BigDecimal.ONE : BigDecimal.ZERO;
+ return AppPreferences.allowExternalMacroAccess.get() ? BigDecimal.ONE : BigDecimal.ZERO;
} else if ("isGM".equalsIgnoreCase(functionName)) {
if (parameters.isEmpty())
return MapTool.getPlayer().isGM() ? BigDecimal.ONE : BigDecimal.ZERO;
diff --git a/src/main/java/net/rptools/maptool/client/functions/MapFunctions.java b/src/main/java/net/rptools/maptool/client/functions/MapFunctions.java
index a448e822f0..eb10bd3645 100644
--- a/src/main/java/net/rptools/maptool/client/functions/MapFunctions.java
+++ b/src/main/java/net/rptools/maptool/client/functions/MapFunctions.java
@@ -229,25 +229,25 @@ public Object childEvaluate(
final var gridType =
gridConfig.has("type")
? gridConfig.getAsJsonPrimitive("type").getAsString()
- : AppPreferences.getDefaultGridType();
+ : AppPreferences.defaultGridType.get();
final var grid = GridFactory.createGrid(gridType);
final var gridColor =
gridConfig.has("color")
? MapToolUtil.getColor(gridConfig.getAsJsonPrimitive("color").getAsString())
- : AppPreferences.getDefaultGridColor();
+ : AppPreferences.defaultGridColor.get();
newMap.setGridColor(gridColor.getRGB());
final var gridUnitsPerCell =
gridConfig.has("units per cell")
? gridConfig.getAsJsonPrimitive("units per cell").getAsDouble()
- : AppPreferences.getDefaultUnitsPerCell();
+ : AppPreferences.defaultUnitsPerCell.get();
newMap.setUnitsPerCell(gridUnitsPerCell);
final var gridSize =
gridConfig.has("size")
? gridConfig.getAsJsonPrimitive("size").getAsInt()
- : AppPreferences.getDefaultGridSize();
+ : AppPreferences.defaultGridSize.get();
grid.setSize(gridSize);
final var gridOffsetX =
diff --git a/src/main/java/net/rptools/maptool/client/functions/RESTfulFunctions.java b/src/main/java/net/rptools/maptool/client/functions/RESTfulFunctions.java
index 57abffd710..36ba87b3b1 100644
--- a/src/main/java/net/rptools/maptool/client/functions/RESTfulFunctions.java
+++ b/src/main/java/net/rptools/maptool/client/functions/RESTfulFunctions.java
@@ -79,7 +79,7 @@ public Object childEvaluate(
throw new ParserException(I18N.getText("macro.function.general.noPerm", functionName));
}
- if (!AppPreferences.getAllowExternalMacroAccess()) {
+ if (!AppPreferences.allowExternalMacroAccess.get()) {
throw new ParserException(I18N.getText("macro.function.general.accessDenied", functionName));
}
@@ -282,7 +282,7 @@ private Map> getHeaderMap(List