Skip to content

Commit

Permalink
Update Preferences.java
Browse files Browse the repository at this point in the history
updated error solved
  • Loading branch information
vikashmurugesh authored Oct 18, 2024
1 parent 3278173 commit 69cf49f
Showing 1 changed file with 65 additions and 50 deletions.
115 changes: 65 additions & 50 deletions app/src/processing/app/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,116 +23,131 @@

import processing.app.helpers.PreferencesMap;


/**
* Storage class for user preferences and environment settings.
* <p/>
* 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.
* <p/>
* 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.
* <p/>
* 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.
* <p/>
* Would also be possible to change this to use the Java Preferences API.
* Some useful articles
* <a href="http://www.onjava.com/pub/a/onjava/synd/2001/10/17/j2se.html">here</a> and
* <a href="http://www.particle.kth.se/~lindsey/JavaCourse/Book/Part1/Java/Chapter10/Preferences.html">here</a>.
* 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);
}

}

0 comments on commit 69cf49f

Please sign in to comment.