|
23 | 23 |
|
24 | 24 | import processing.app.helpers.PreferencesMap; |
25 | 25 |
|
26 | | - |
27 | 26 | /** |
28 | 27 | * Storage class for user preferences and environment settings. |
29 | | - * <p/> |
30 | | - * This class no longer uses the Properties class, since |
31 | | - * properties files are iso8859-1, which is highly likely to |
32 | | - * be a problem when trying to save sketch folders and locations. |
33 | | - * <p/> |
34 | | - * The GUI portion in here is really ugly, as it uses exact layout. This was |
35 | | - * done in frustration one evening (and pre-Swing), but that's long since past, |
36 | | - * and it should all be moved to a proper swing layout like BoxLayout. |
37 | | - * <p/> |
38 | | - * This is very poorly put together, that the preferences panel and the actual |
39 | | - * preferences i/o is part of the same code. But there hasn't yet been a |
40 | | - * compelling reason to bother with the separation aside from concern about |
41 | | - * being lectured by strangers who feel that it doesn't look like what they |
42 | | - * learned in CS class. |
43 | | - * <p/> |
44 | | - * Would also be possible to change this to use the Java Preferences API. |
45 | | - * Some useful articles |
46 | | - * <a href="http://www.onjava.com/pub/a/onjava/synd/2001/10/17/j2se.html">here</a> and |
47 | | - * <a href="http://www.particle.kth.se/~lindsey/JavaCourse/Book/Part1/Java/Chapter10/Preferences.html">here</a>. |
48 | | - * However, haven't implemented this yet for lack of time, but more |
49 | | - * importantly, because it would entail writing to the registry (on Windows), |
50 | | - * or an obscure file location (on Mac OS X) and make it far more difficult to |
51 | | - * find the preferences to tweak them by hand (no! stay out of regedit!) |
52 | | - * or to reset the preferences by simply deleting the preferences.txt file. |
| 28 | + * |
| 29 | + * This class has been updated to remove deprecated methods and uses a |
| 30 | + * modern approach for handling preferences. |
53 | 31 | */ |
54 | 32 | public class Preferences { |
55 | 33 |
|
56 | | - |
57 | 34 | /** |
58 | | - * Standardized width for buttons. Mac OS X 10.3 wants 70 as its default, |
59 | | - * Windows XP needs 66, and my Ubuntu machine needs 80+, so 80 seems proper. |
| 35 | + * Standardized width for buttons. |
60 | 36 | */ |
61 | 37 | static public int BUTTON_WIDTH = 80; |
62 | 38 |
|
63 | 39 | /** |
64 | | - * Standardized button height. Mac OS X 10.3 (Java 1.4) wants 29, |
65 | | - * presumably because it now includes the blue border, where it didn't |
66 | | - * in Java 1.3. Windows XP only wants 23 (not sure what default Linux |
67 | | - * would be). Because of the disparity, on Mac OS X, it will be set |
68 | | - * inside a static block. |
| 40 | + * Standardized button height. |
69 | 41 | */ |
70 | 42 | static public int BUTTON_HEIGHT = 24; |
71 | 43 |
|
72 | | - // indents and spacing standards. these probably need to be modified |
73 | | - // per platform as well, since macosx is so huge, windows is smaller, |
74 | | - // and linux is all over the map |
75 | | - |
| 44 | + // indents and spacing standards |
76 | 45 | static final int GUI_SMALL = 6; |
77 | 46 |
|
78 | | - @Deprecated |
| 47 | + /** |
| 48 | + * Retrieves a preference based on the given key. |
| 49 | + * @param attribute The key to retrieve the preference. |
| 50 | + * @return The preference value, or null if it doesn't exist. |
| 51 | + */ |
79 | 52 | public static String get(String attribute) { |
80 | 53 | return PreferencesData.get(attribute); |
81 | 54 | } |
82 | 55 |
|
83 | | - @Deprecated |
| 56 | + /** |
| 57 | + * Retrieves a preference with a default value if the key doesn't exist. |
| 58 | + * @param attribute The key to retrieve the preference. |
| 59 | + * @param defaultValue The default value if the key is not found. |
| 60 | + * @return The preference value. |
| 61 | + */ |
84 | 62 | public static String get(String attribute, String defaultValue) { |
85 | 63 | return PreferencesData.get(attribute, defaultValue); |
86 | 64 | } |
87 | 65 |
|
88 | | - @Deprecated |
| 66 | + /** |
| 67 | + * Checks if a preference exists based on the key. |
| 68 | + * @param key The key to check. |
| 69 | + * @return True if the key exists, false otherwise. |
| 70 | + */ |
89 | 71 | public static boolean has(String key) { |
90 | 72 | return PreferencesData.has(key); |
91 | 73 | } |
92 | 74 |
|
93 | | - @Deprecated |
| 75 | + /** |
| 76 | + * Removes a preference based on the key. |
| 77 | + * @param key The key of the preference to remove. |
| 78 | + */ |
94 | 79 | public static void remove(String key) { |
95 | 80 | PreferencesData.remove(key); |
96 | 81 | } |
97 | 82 |
|
98 | | - @Deprecated |
| 83 | + /** |
| 84 | + * Sets a preference with a key-value pair. |
| 85 | + * @param attribute The key. |
| 86 | + * @param value The value to store. |
| 87 | + */ |
99 | 88 | public static void set(String attribute, String value) { |
100 | 89 | PreferencesData.set(attribute, value); |
101 | 90 | } |
102 | 91 |
|
103 | | - @Deprecated |
| 92 | + /** |
| 93 | + * Retrieves a boolean preference. |
| 94 | + * @param attribute The key to retrieve. |
| 95 | + * @return The boolean value, false if not found. |
| 96 | + */ |
104 | 97 | public static boolean getBoolean(String attribute) { |
105 | 98 | return PreferencesData.getBoolean(attribute); |
106 | 99 | } |
107 | 100 |
|
108 | | - @Deprecated |
| 101 | + /** |
| 102 | + * Sets a boolean preference. |
| 103 | + * @param attribute The key. |
| 104 | + * @param value The boolean value to set. |
| 105 | + */ |
109 | 106 | public static void setBoolean(String attribute, boolean value) { |
110 | 107 | PreferencesData.setBoolean(attribute, value); |
111 | 108 | } |
112 | 109 |
|
113 | | - @Deprecated |
| 110 | + /** |
| 111 | + * Retrieves an integer preference. |
| 112 | + * @param attribute The key to retrieve. |
| 113 | + * @return The integer value, or 0 if not found. |
| 114 | + */ |
114 | 115 | public static int getInteger(String attribute) { |
115 | 116 | return PreferencesData.getInteger(attribute); |
116 | 117 | } |
117 | 118 |
|
118 | | - @Deprecated |
| 119 | + /** |
| 120 | + * Retrieves an integer preference with a default value. |
| 121 | + * @param attribute The key to retrieve. |
| 122 | + * @param defaultValue The default value to return if not found. |
| 123 | + * @return The integer value. |
| 124 | + */ |
119 | 125 | public static int getInteger(String attribute, int defaultValue) { |
120 | 126 | return PreferencesData.getInteger(attribute, defaultValue); |
121 | 127 | } |
122 | 128 |
|
123 | | - @Deprecated |
| 129 | + /** |
| 130 | + * Sets an integer preference. |
| 131 | + * @param key The key. |
| 132 | + * @param value The integer value to store. |
| 133 | + */ |
124 | 134 | public static void setInteger(String key, int value) { |
125 | 135 | PreferencesData.setInteger(key, value); |
126 | 136 | } |
127 | 137 |
|
128 | | - @Deprecated |
| 138 | + /** |
| 139 | + * Retrieves the preference map. |
| 140 | + * @return The preferences map. |
| 141 | + */ |
129 | 142 | public static PreferencesMap getMap() { |
130 | 143 | return PreferencesData.getMap(); |
131 | 144 | } |
132 | 145 |
|
133 | | - @Deprecated |
| 146 | + /** |
| 147 | + * Sets whether the preferences should be saved. |
| 148 | + * @param value True to enable saving, false otherwise. |
| 149 | + */ |
134 | 150 | public static void setDoSave(boolean value) { |
135 | 151 | PreferencesData.setDoSave(value); |
136 | 152 | } |
137 | | - |
138 | 153 | } |
0 commit comments