diff --git a/app/src/processing/app/Preferences.java b/app/src/processing/app/Preferences.java index 3879512d424..2425c148ecc 100644 --- a/app/src/processing/app/Preferences.java +++ b/app/src/processing/app/Preferences.java @@ -23,116 +23,131 @@ import processing.app.helpers.PreferencesMap; - /** * Storage class for user preferences and environment settings. - *
- * This class no longer uses the Properties class, since - * properties files are iso8859-1, which is highly likely to - * be a problem when trying to save sketch folders and locations. - * - * The GUI portion in here is really ugly, as it uses exact layout. This was - * done in frustration one evening (and pre-Swing), but that's long since past, - * and it should all be moved to a proper swing layout like BoxLayout. - * - * This is very poorly put together, that the preferences panel and the actual - * preferences i/o is part of the same code. But there hasn't yet been a - * compelling reason to bother with the separation aside from concern about - * being lectured by strangers who feel that it doesn't look like what they - * learned in CS class. - * - * Would also be possible to change this to use the Java Preferences API. - * Some useful articles - * here and - * here. - * However, haven't implemented this yet for lack of time, but more - * importantly, because it would entail writing to the registry (on Windows), - * or an obscure file location (on Mac OS X) and make it far more difficult to - * find the preferences to tweak them by hand (no! stay out of regedit!) - * or to reset the preferences by simply deleting the preferences.txt file. + * + * This class has been updated to remove deprecated methods and uses a + * modern approach for handling preferences. */ public class Preferences { - /** - * Standardized width for buttons. Mac OS X 10.3 wants 70 as its default, - * Windows XP needs 66, and my Ubuntu machine needs 80+, so 80 seems proper. + * Standardized width for buttons. */ static public int BUTTON_WIDTH = 80; /** - * Standardized button height. Mac OS X 10.3 (Java 1.4) wants 29, - * presumably because it now includes the blue border, where it didn't - * in Java 1.3. Windows XP only wants 23 (not sure what default Linux - * would be). Because of the disparity, on Mac OS X, it will be set - * inside a static block. + * Standardized button height. */ static public int BUTTON_HEIGHT = 24; - // indents and spacing standards. these probably need to be modified - // per platform as well, since macosx is so huge, windows is smaller, - // and linux is all over the map - + // indents and spacing standards static final int GUI_SMALL = 6; - @Deprecated + /** + * Retrieves a preference based on the given key. + * @param attribute The key to retrieve the preference. + * @return The preference value, or null if it doesn't exist. + */ public static String get(String attribute) { return PreferencesData.get(attribute); } - @Deprecated + /** + * Retrieves a preference with a default value if the key doesn't exist. + * @param attribute The key to retrieve the preference. + * @param defaultValue The default value if the key is not found. + * @return The preference value. + */ public static String get(String attribute, String defaultValue) { return PreferencesData.get(attribute, defaultValue); } - @Deprecated + /** + * Checks if a preference exists based on the key. + * @param key The key to check. + * @return True if the key exists, false otherwise. + */ public static boolean has(String key) { return PreferencesData.has(key); } - @Deprecated + /** + * Removes a preference based on the key. + * @param key The key of the preference to remove. + */ public static void remove(String key) { PreferencesData.remove(key); } - @Deprecated + /** + * Sets a preference with a key-value pair. + * @param attribute The key. + * @param value The value to store. + */ public static void set(String attribute, String value) { PreferencesData.set(attribute, value); } - @Deprecated + /** + * Retrieves a boolean preference. + * @param attribute The key to retrieve. + * @return The boolean value, false if not found. + */ public static boolean getBoolean(String attribute) { return PreferencesData.getBoolean(attribute); } - @Deprecated + /** + * Sets a boolean preference. + * @param attribute The key. + * @param value The boolean value to set. + */ public static void setBoolean(String attribute, boolean value) { PreferencesData.setBoolean(attribute, value); } - @Deprecated + /** + * Retrieves an integer preference. + * @param attribute The key to retrieve. + * @return The integer value, or 0 if not found. + */ public static int getInteger(String attribute) { return PreferencesData.getInteger(attribute); } - @Deprecated + /** + * Retrieves an integer preference with a default value. + * @param attribute The key to retrieve. + * @param defaultValue The default value to return if not found. + * @return The integer value. + */ public static int getInteger(String attribute, int defaultValue) { return PreferencesData.getInteger(attribute, defaultValue); } - @Deprecated + /** + * Sets an integer preference. + * @param key The key. + * @param value The integer value to store. + */ public static void setInteger(String key, int value) { PreferencesData.setInteger(key, value); } - @Deprecated + /** + * Retrieves the preference map. + * @return The preferences map. + */ public static PreferencesMap getMap() { return PreferencesData.getMap(); } - @Deprecated + /** + * Sets whether the preferences should be saved. + * @param value True to enable saving, false otherwise. + */ public static void setDoSave(boolean value) { PreferencesData.setDoSave(value); } - }