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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 842 - (hide annotations) (download)
Thu Mar 16 18:08:34 2006 UTC (18 years, 2 months ago) by iliev
File size: 7762 byte(s)
Updating to version 0.2a

1 iliev 787 /*
2     * JSampler - a java front-end for LinuxSampler
3     *
4     * Copyright (C) 2005 Grigor Kirilov Iliev
5     *
6     * This file is part of JSampler.
7     *
8     * JSampler is free software; you can redistribute it and/or modify
9     * it under the terms of the GNU General Public License version 2
10     * as published by the Free Software Foundation.
11     *
12     * JSampler is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with JSampler; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20     * MA 02111-1307 USA
21     */
22    
23     package org.jsampler;
24    
25     import java.util.prefs.Preferences;
26    
27    
28     /**
29 iliev 842 * This class represents the preferences of the JSampler package.
30 iliev 787 * @author Grigor Iliev
31     */
32     public class Prefs {
33     private final static String prefNode = "org.jsampler";
34    
35 iliev 842 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 iliev 787 private final static String VIEW = "VIEW";
45     private final static String DEF_VIEW = "classic";
46    
47 iliev 842 private final static String INTERFACE_LANGUAGE = "iface.language";
48     private final static String DEF_INTERFACE_LANGUAGE = "en";
49 iliev 787
50 iliev 842 private final static String INTERFACE_COUNTRY = "iface.country";
51     private final static String DEF_INTERFACE_COUNTRY = "US";
52 iliev 787
53 iliev 842 private final static String INTERFACE_FONT = "iface.font";
54     private final static String DEF_INTERFACE_FONT = null;
55 iliev 787
56 iliev 842 private final static String LS_ADDRESS = "LinuxSampler.address";
57     private final static String DEF_LS_ADDRESS = "127.0.0.1";
58 iliev 787
59 iliev 842 private final static String LS_PORT = "LinuxSampler.port";
60     private final static int DEF_LS_PORT = 8888;
61 iliev 787
62    
63    
64     private static Preferences userPrefs = Preferences.userRoot().node(prefNode);
65    
66 iliev 842 /**
67     * Gets the user preferences node of the JSampler package.
68     * @return The user preferences node of the JSampler package.
69     */
70     private static Preferences
71 iliev 787 user() { return userPrefs; }
72    
73 iliev 842 /**
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 iliev 787 // VIEW
141 iliev 842 /**
142     * Gets the name of the current View.
143     * @return the name of the current View.
144     */
145 iliev 787 public static String
146     getView() { return user().get(VIEW, DEF_VIEW); }
147    
148 iliev 842 /**
149     * Sets the current View of JSampler.
150     * @param view the name of the new View.
151     */
152 iliev 787 public static void
153     setView(String view) {
154     if(view == null) user().remove(VIEW);
155     else if(!view.equals(getView())) user().put(VIEW, view);
156     }
157    
158 iliev 842 /**
159     * Gets the interface language.
160     * @return The interface language.
161     */
162 iliev 787 public static String
163     getInterfaceLanguage() { return user().get(INTERFACE_LANGUAGE, DEF_INTERFACE_LANGUAGE); }
164    
165     /**
166     * Sets the interface language.
167     * @return <code>true</code> if the interface language has changed and <code>false</code>
168     * otherwise.
169     */
170     public static boolean
171     setInterfaceLanguage(String language) {
172     if(language == null) {
173     user().remove(INTERFACE_LANGUAGE);
174     return true;
175     } else if(!language.equals(getInterfaceLanguage())) {
176     user().put(INTERFACE_LANGUAGE, language);
177     return true;
178     }
179     return false;
180     }
181    
182 iliev 842 /**
183     * Gets the interface country.
184     * @return The interface country.
185     */
186 iliev 787 public static String
187     getInterfaceCountry() { return user().get(INTERFACE_COUNTRY, DEF_INTERFACE_COUNTRY); }
188    
189     /**
190     * Sets the interface country.
191     * @return <code>true</code> if the interface country has changed and <code>false</code>
192     * otherwise.
193     */
194     public static boolean
195     setInterfaceCountry(String country) {
196     if(country == null) {
197     user().remove(INTERFACE_COUNTRY);
198     return true;
199     } else if(!country.equals(getInterfaceCountry())) {
200     user().put(INTERFACE_COUNTRY, country);
201     return true;
202     }
203     return false;
204     }
205    
206 iliev 842 /**
207     * Gets the interface font.
208     * @return The interface font.
209     */
210 iliev 787 public static String
211     getInterfaceFont() { return user().get(INTERFACE_FONT, DEF_INTERFACE_FONT); }
212    
213     /**
214     * Sets the interface font.
215     * @return <code>true</code> if the interface font has changed and <code>false</code>
216     * otherwise.
217     */
218     public static boolean
219     setInterfaceFont(String font) {
220     if(font == null) {
221     if(getInterfaceFont() == null) return false;
222     user().remove(INTERFACE_FONT);
223     return true;
224     } else if(!font.equals(getInterfaceFont())) {
225     user().put(INTERFACE_FONT, font);
226     return true;
227     }
228     return false;
229     }
230    
231     // PREFERENCES
232 iliev 842 /**
233     * Gets the LinuxSampler address.
234     * @return The LinuxSampler address.
235     */
236 iliev 787 public static String
237     getLSAddress() { return user().get(LS_ADDRESS, DEF_LS_ADDRESS); }
238    
239 iliev 842 /**
240     * Sets the LinuxSampler address.
241     * @param address The LinuxSampler address.
242     */
243 iliev 787 public static void
244     setLSAddress(String address) {
245     if(address.length() == 0) user().remove(LS_ADDRESS);
246     else if(!address.equals(getLSAddress()))
247     user().put(LS_ADDRESS, address);
248     }
249    
250 iliev 842 /**
251     * Gets the LinuxSampler port.
252     * @return The LinuxSampler port number.
253     */
254 iliev 787 public static int
255     getLSPort() { return user().getInt(LS_PORT, DEF_LS_PORT); }
256    
257     /**
258     * Sets the LinuxSampler port number.
259     * This method das not check the validity of the port number.
260     * @param port the port number. Use -1 to reset to default value.
261     */
262     public static void
263 iliev 842 setLSPort(int port) {
264 iliev 787 if(port == -1) user().remove(LS_PORT);
265     else if(port != getLSPort()) user().putInt(LS_PORT, port);
266     }
267     }

  ViewVC Help
Powered by ViewVC