--- jsampler/trunk/src/org/jsampler/Prefs.java 2006/03/04 16:23:53 841
+++ jsampler/trunk/src/org/jsampler/Prefs.java 2006/03/16 18:08:34 842
@@ -26,51 +26,139 @@
/**
- *
+ * This class represents the preferences of the JSampler package.
* @author Grigor Iliev
*/
public class Prefs {
private final static String prefNode = "org.jsampler";
+ private final static String WINDOW_SIZE_AND_LOCATION = "Mainframe.sizeAndLocation";
+ private final static String DEF_WINDOW_SIZE_AND_LOCATION = null;
+
+ private final static String WINDOW_MAXIMIZED = "Mainframe.maximized";
+ private final static boolean DEF_WINDOW_MAXIMIZED = false;
+
+ private final static String SAVE_WINDOW_PROPERTIES = "Mainframe.saveProperties";
+ private final static boolean DEF_SAVE_WINDOW_PROPERTIES = true;
+
private final static String VIEW = "VIEW";
private final static String DEF_VIEW = "classic";
- public final static String INTERFACE_LANGUAGE = "iface.language";
- public final static String DEF_INTERFACE_LANGUAGE = "en";
+ private final static String INTERFACE_LANGUAGE = "iface.language";
+ private final static String DEF_INTERFACE_LANGUAGE = "en";
- public final static String INTERFACE_COUNTRY = "iface.country";
- public final static String DEF_INTERFACE_COUNTRY = "US";
+ private final static String INTERFACE_COUNTRY = "iface.country";
+ private final static String DEF_INTERFACE_COUNTRY = "US";
- public final static String INTERFACE_FONT = "iface.font";
- public final static String DEF_INTERFACE_FONT = null;
+ private final static String INTERFACE_FONT = "iface.font";
+ private final static String DEF_INTERFACE_FONT = null;
- public final static String LS_ADDRESS = "LinuxSampler.address";
- public final static String DEF_LS_ADDRESS = "127.0.0.1";
+ private final static String LS_ADDRESS = "LinuxSampler.address";
+ private final static String DEF_LS_ADDRESS = "127.0.0.1";
- public final static String LS_PORT = "LinuxSampler.port";
- public final static int DEF_LS_PORT = 8888;
+ private final static String LS_PORT = "LinuxSampler.port";
+ private final static int DEF_LS_PORT = 8888;
- private static Preferences sysPrefs = Preferences.systemRoot().node(prefNode);
private static Preferences userPrefs = Preferences.userRoot().node(prefNode);
- public static Preferences
- sys() { return sysPrefs; }
-
- public static Preferences
+ /**
+ * Gets the user preferences node of the JSampler package.
+ * @return The user preferences node of the JSampler package.
+ */
+ private static Preferences
user() { return userPrefs; }
+ /**
+ * Gets a string representation of the main window's size and location.
+ * The string representation is a comma-separated list
+ * of x and y coordinates, and width and height of the window.
+ * @return A string representation of the main window's size and location,
+ * or null
if the value is not set.
+ */
+ public static String
+ getWindowSizeAndLocation() {
+ return user().get(WINDOW_SIZE_AND_LOCATION, DEF_WINDOW_SIZE_AND_LOCATION);
+ }
+
+ /**
+ * Sets the main window's size and location.
+ * Use null
to remove the current value.
+ * @param s A string representation of the main window's size and location.
+ */
+ public static void
+ setWindowSizeAndLocation(String s) {
+ if(s == null) {
+ user().remove(WINDOW_SIZE_AND_LOCATION);
+ return;
+ }
+
+ user().put(WINDOW_SIZE_AND_LOCATION, s);
+ }
+
+ /**
+ * Determines whether the main window should be maximized.
+ * @return true
if the main window should be maximized,
+ * false
otherwise.
+ */
+ public static boolean
+ getWindowMaximized() {
+ return user().getBoolean(WINDOW_MAXIMIZED, DEF_WINDOW_MAXIMIZED);
+ }
+
+ /**
+ * Sets whether the main window should be maximized.
+ * @param b If true
the main window should be maximized.
+ */
+ public static void
+ setWindowMaximized(boolean b) {
+ if(b == getWindowMaximized()) return;
+ user().putBoolean(WINDOW_MAXIMIZED, b);
+ }
+
+ /**
+ * Determines whether the window properties (like size and location) should be saved.
+ * @return true
if the window properties should be saved,
+ * false
otherwise.
+ */
+ public static boolean
+ getSaveWindowProperties() {
+ return user().getBoolean(SAVE_WINDOW_PROPERTIES, DEF_SAVE_WINDOW_PROPERTIES);
+ }
+
+ /**
+ * Sets whether the window properties (like size and location) should be saved.
+ * @param b If true
the window properties will be saved.
+ */
+ public static void
+ setSaveWindowProperties(boolean b) {
+ if(b == getSaveWindowProperties()) return;
+ user().putBoolean(SAVE_WINDOW_PROPERTIES, b);
+ }
+
// VIEW
+ /**
+ * Gets the name of the current View.
+ * @return the name of the current View.
+ */
public static String
getView() { return user().get(VIEW, DEF_VIEW); }
+ /**
+ * Sets the current View of JSampler.
+ * @param view the name of the new View.
+ */
public static void
setView(String view) {
if(view == null) user().remove(VIEW);
else if(!view.equals(getView())) user().put(VIEW, view);
}
+ /**
+ * Gets the interface language.
+ * @return The interface language.
+ */
public static String
getInterfaceLanguage() { return user().get(INTERFACE_LANGUAGE, DEF_INTERFACE_LANGUAGE); }
@@ -91,6 +179,10 @@
return false;
}
+ /**
+ * Gets the interface country.
+ * @return The interface country.
+ */
public static String
getInterfaceCountry() { return user().get(INTERFACE_COUNTRY, DEF_INTERFACE_COUNTRY); }
@@ -111,6 +203,10 @@
return false;
}
+ /**
+ * Gets the interface font.
+ * @return The interface font.
+ */
public static String
getInterfaceFont() { return user().get(INTERFACE_FONT, DEF_INTERFACE_FONT); }
@@ -133,9 +229,17 @@
}
// PREFERENCES
+ /**
+ * Gets the LinuxSampler address.
+ * @return The LinuxSampler address.
+ */
public static String
getLSAddress() { return user().get(LS_ADDRESS, DEF_LS_ADDRESS); }
+ /**
+ * Sets the LinuxSampler address.
+ * @param address The LinuxSampler address.
+ */
public static void
setLSAddress(String address) {
if(address.length() == 0) user().remove(LS_ADDRESS);
@@ -143,6 +247,10 @@
user().put(LS_ADDRESS, address);
}
+ /**
+ * Gets the LinuxSampler port.
+ * @return The LinuxSampler port number.
+ */
public static int
getLSPort() { return user().getInt(LS_PORT, DEF_LS_PORT); }
@@ -152,7 +260,7 @@
* @param port the port number. Use -1 to reset to default value.
*/
public static void
- setAuthSrvPort(int port) {
+ setLSPort(int port) {
if(port == -1) user().remove(LS_PORT);
else if(port != getLSPort()) user().putInt(LS_PORT, port);
}