Skip to content

Commit 69cf49f

Browse files
Update Preferences.java
updated error solved
1 parent 3278173 commit 69cf49f

File tree

1 file changed

+65
-50
lines changed

1 file changed

+65
-50
lines changed

app/src/processing/app/Preferences.java

+65-50
Original file line numberDiff line numberDiff line change
@@ -23,116 +23,131 @@
2323

2424
import processing.app.helpers.PreferencesMap;
2525

26-
2726
/**
2827
* 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.
5331
*/
5432
public class Preferences {
5533

56-
5734
/**
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.
6036
*/
6137
static public int BUTTON_WIDTH = 80;
6238

6339
/**
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.
6941
*/
7042
static public int BUTTON_HEIGHT = 24;
7143

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
7645
static final int GUI_SMALL = 6;
7746

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+
*/
7952
public static String get(String attribute) {
8053
return PreferencesData.get(attribute);
8154
}
8255

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+
*/
8462
public static String get(String attribute, String defaultValue) {
8563
return PreferencesData.get(attribute, defaultValue);
8664
}
8765

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+
*/
8971
public static boolean has(String key) {
9072
return PreferencesData.has(key);
9173
}
9274

93-
@Deprecated
75+
/**
76+
* Removes a preference based on the key.
77+
* @param key The key of the preference to remove.
78+
*/
9479
public static void remove(String key) {
9580
PreferencesData.remove(key);
9681
}
9782

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+
*/
9988
public static void set(String attribute, String value) {
10089
PreferencesData.set(attribute, value);
10190
}
10291

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+
*/
10497
public static boolean getBoolean(String attribute) {
10598
return PreferencesData.getBoolean(attribute);
10699
}
107100

108-
@Deprecated
101+
/**
102+
* Sets a boolean preference.
103+
* @param attribute The key.
104+
* @param value The boolean value to set.
105+
*/
109106
public static void setBoolean(String attribute, boolean value) {
110107
PreferencesData.setBoolean(attribute, value);
111108
}
112109

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+
*/
114115
public static int getInteger(String attribute) {
115116
return PreferencesData.getInteger(attribute);
116117
}
117118

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+
*/
119125
public static int getInteger(String attribute, int defaultValue) {
120126
return PreferencesData.getInteger(attribute, defaultValue);
121127
}
122128

123-
@Deprecated
129+
/**
130+
* Sets an integer preference.
131+
* @param key The key.
132+
* @param value The integer value to store.
133+
*/
124134
public static void setInteger(String key, int value) {
125135
PreferencesData.setInteger(key, value);
126136
}
127137

128-
@Deprecated
138+
/**
139+
* Retrieves the preference map.
140+
* @return The preferences map.
141+
*/
129142
public static PreferencesMap getMap() {
130143
return PreferencesData.getMap();
131144
}
132145

133-
@Deprecated
146+
/**
147+
* Sets whether the preferences should be saved.
148+
* @param value True to enable saving, false otherwise.
149+
*/
134150
public static void setDoSave(boolean value) {
135151
PreferencesData.setDoSave(value);
136152
}
137-
138153
}

0 commit comments

Comments
 (0)