/[svn]/jsampler/trunk/src/org/jsampler/Prefs.java
ViewVC logotype

Diff of /jsampler/trunk/src/org/jsampler/Prefs.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 841 by iliev, Mon Oct 10 16:03:12 2005 UTC revision 842 by iliev, Thu Mar 16 18:08:34 2006 UTC
# Line 26  import java.util.prefs.Preferences; Line 26  import java.util.prefs.Preferences;
26    
27    
28  /**  /**
29   *   * This class represents the preferences of the JSampler package.
30   * @author Grigor Iliev   * @author Grigor Iliev
31   */   */
32  public class Prefs {  public class Prefs {
33          private final static String prefNode = "org.jsampler";          private final static String prefNode = "org.jsampler";
34                    
35            private final static String WINDOW_SIZE_AND_LOCATION = "Mainframe.sizeAndLocation";
36            private final static String DEF_WINDOW_SIZE_AND_LOCATION = null;
37            
38            private final static String WINDOW_MAXIMIZED = "Mainframe.maximized";
39            private final static boolean DEF_WINDOW_MAXIMIZED = false;
40            
41            private final static String SAVE_WINDOW_PROPERTIES = "Mainframe.saveProperties";
42            private final static boolean DEF_SAVE_WINDOW_PROPERTIES = true;
43            
44          private final static String VIEW = "VIEW";          private final static String VIEW = "VIEW";
45          private final static String DEF_VIEW = "classic";          private final static String DEF_VIEW = "classic";
46                    
47          public final static String INTERFACE_LANGUAGE = "iface.language";          private final static String INTERFACE_LANGUAGE = "iface.language";
48          public final static String DEF_INTERFACE_LANGUAGE = "en";          private final static String DEF_INTERFACE_LANGUAGE = "en";
49                    
50          public final static String INTERFACE_COUNTRY = "iface.country";          private final static String INTERFACE_COUNTRY = "iface.country";
51          public final static String DEF_INTERFACE_COUNTRY = "US";          private final static String DEF_INTERFACE_COUNTRY = "US";
52                    
53          public final static String INTERFACE_FONT = "iface.font";          private final static String INTERFACE_FONT = "iface.font";
54          public final static String DEF_INTERFACE_FONT = null;          private final static String DEF_INTERFACE_FONT = null;
55                    
56          public final static String LS_ADDRESS = "LinuxSampler.address";          private final static String LS_ADDRESS = "LinuxSampler.address";
57          public final static String DEF_LS_ADDRESS = "127.0.0.1";          private final static String DEF_LS_ADDRESS = "127.0.0.1";
58                    
59          public final static String LS_PORT = "LinuxSampler.port";          private final static String LS_PORT = "LinuxSampler.port";
60          public final static int DEF_LS_PORT = 8888;          private final static int DEF_LS_PORT = 8888;
61                    
62                    
63                    
         private static Preferences sysPrefs = Preferences.systemRoot().node(prefNode);  
64          private static Preferences userPrefs = Preferences.userRoot().node(prefNode);          private static Preferences userPrefs = Preferences.userRoot().node(prefNode);
65                    
66          public static Preferences          /**
67          sys() { return sysPrefs; }           * Gets the user preferences node of the JSampler package.
68                     * @return The user preferences node of the JSampler package.
69          public static Preferences           */
70            private static Preferences
71          user() { return userPrefs; }          user() { return userPrefs; }
72                    
73            /**
74             * Gets a string representation of the main window's size and location.
75             * The string representation is a comma-separated list
76             * of x and y coordinates, and width and height of the window.
77             * @return A string representation of the main window's size and location,
78             * or <code>null</code> if the value is not set.
79             */
80            public static String
81            getWindowSizeAndLocation() {
82                    return user().get(WINDOW_SIZE_AND_LOCATION, DEF_WINDOW_SIZE_AND_LOCATION);
83            }
84            
85            /**
86             * Sets the main window's size and location.
87             * Use <code>null</code> to remove the current value.
88             * @param s A string representation of the main window's size and location.
89             */
90            public static void
91            setWindowSizeAndLocation(String s) {
92                    if(s == null) {
93                            user().remove(WINDOW_SIZE_AND_LOCATION);
94                            return;
95                    }
96                    
97                    user().put(WINDOW_SIZE_AND_LOCATION, s);
98            }
99            
100            /**
101             * Determines whether the main window should be maximized.
102             * @return <code>true</code> if the main window should be maximized,
103             * <code>false</code> otherwise.
104             */
105            public static boolean
106            getWindowMaximized() {
107                    return user().getBoolean(WINDOW_MAXIMIZED, DEF_WINDOW_MAXIMIZED);
108            }
109            
110            /**
111             * Sets whether the main window should be maximized.
112             * @param b If <code>true</code> the main window should be maximized.
113             */
114            public static void
115            setWindowMaximized(boolean b) {
116                    if(b == getWindowMaximized()) return;
117                    user().putBoolean(WINDOW_MAXIMIZED, b);
118            }
119            
120            /**
121             * Determines whether the window properties (like size and location) should be saved.
122             * @return <code>true</code> if the window properties should be saved,
123             * <code>false</code> otherwise.
124             */
125            public static boolean
126            getSaveWindowProperties() {
127                    return user().getBoolean(SAVE_WINDOW_PROPERTIES, DEF_SAVE_WINDOW_PROPERTIES);
128            }
129            
130            /**
131             * Sets whether the window properties (like size and location) should be saved.
132             * @param b If <code>true</code> the window properties will be saved.
133             */
134            public static void
135            setSaveWindowProperties(boolean b) {
136                    if(b == getSaveWindowProperties()) return;
137                    user().putBoolean(SAVE_WINDOW_PROPERTIES, b);
138            }
139            
140  // VIEW  // VIEW
141            /**
142             * Gets the name of the current View.
143             * @return the name of the current View.
144             */
145          public static String          public static String
146          getView() { return user().get(VIEW, DEF_VIEW); }          getView() { return user().get(VIEW, DEF_VIEW); }
147                    
148            /**
149             * Sets the current View of JSampler.
150             * @param view the name of the new View.
151             */
152          public static void          public static void
153          setView(String view) {          setView(String view) {
154                  if(view == null) user().remove(VIEW);                  if(view == null) user().remove(VIEW);
155                  else if(!view.equals(getView())) user().put(VIEW, view);                  else if(!view.equals(getView())) user().put(VIEW, view);
156          }          }
157                    
158            /**
159             * Gets the interface language.
160             * @return The interface language.
161             */
162          public static String          public static String
163          getInterfaceLanguage() { return user().get(INTERFACE_LANGUAGE, DEF_INTERFACE_LANGUAGE); }          getInterfaceLanguage() { return user().get(INTERFACE_LANGUAGE, DEF_INTERFACE_LANGUAGE); }
164                    
# Line 91  public class Prefs { Line 179  public class Prefs {
179                  return false;                  return false;
180          }          }
181                    
182            /**
183             * Gets the interface country.
184             * @return The interface country.
185             */
186          public static String          public static String
187          getInterfaceCountry() { return user().get(INTERFACE_COUNTRY, DEF_INTERFACE_COUNTRY); }          getInterfaceCountry() { return user().get(INTERFACE_COUNTRY, DEF_INTERFACE_COUNTRY); }
188                    
# Line 111  public class Prefs { Line 203  public class Prefs {
203                  return false;                  return false;
204          }          }
205                    
206            /**
207             * Gets the interface font.
208             * @return The interface font.
209             */
210          public static String          public static String
211          getInterfaceFont() { return user().get(INTERFACE_FONT, DEF_INTERFACE_FONT); }          getInterfaceFont() { return user().get(INTERFACE_FONT, DEF_INTERFACE_FONT); }
212                    
# Line 133  public class Prefs { Line 229  public class Prefs {
229          }          }
230    
231  // PREFERENCES  // PREFERENCES
232            /**
233             * Gets the LinuxSampler address.
234             * @return The LinuxSampler address.
235             */
236          public static String          public static String
237          getLSAddress() { return user().get(LS_ADDRESS, DEF_LS_ADDRESS); }          getLSAddress() { return user().get(LS_ADDRESS, DEF_LS_ADDRESS); }
238                    
239            /**
240             * Sets the LinuxSampler address.
241             * @param address The LinuxSampler address.
242             */
243          public static void          public static void
244          setLSAddress(String address) {          setLSAddress(String address) {
245                  if(address.length() == 0) user().remove(LS_ADDRESS);                  if(address.length() == 0) user().remove(LS_ADDRESS);
# Line 143  public class Prefs { Line 247  public class Prefs {
247                          user().put(LS_ADDRESS, address);                          user().put(LS_ADDRESS, address);
248          }          }
249    
250            /**
251             * Gets the LinuxSampler port.
252             * @return The LinuxSampler port number.
253             */
254          public static int          public static int
255          getLSPort() { return user().getInt(LS_PORT, DEF_LS_PORT); }          getLSPort() { return user().getInt(LS_PORT, DEF_LS_PORT); }
256                    
# Line 152  public class Prefs { Line 260  public class Prefs {
260           * @param port the port number. Use -1 to reset to default value.           * @param port the port number. Use -1 to reset to default value.
261           */           */
262          public static void          public static void
263          setAuthSrvPort(int port) {          setLSPort(int port) {
264                  if(port == -1) user().remove(LS_PORT);                  if(port == -1) user().remove(LS_PORT);
265                  else if(port != getLSPort()) user().putInt(LS_PORT, port);                  else if(port != getLSPort()) user().putInt(LS_PORT, port);
266          }          }

Legend:
Removed from v.841  
changed lines
  Added in v.842

  ViewVC Help
Powered by ViewVC