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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1143 - (show annotations) (download)
Mon Apr 2 21:18:31 2007 UTC (17 years ago) by iliev
File size: 6833 byte(s)
* upgrading to version 0.4a

1 /*
2 * JSampler - a java front-end for LinuxSampler
3 *
4 * Copyright (C) 2005-2006 Grigor Iliev <grigor@grigoriliev.com>
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 * This class represents the preferences of the JSampler package.
30 * @author Grigor Iliev
31 */
32 public class Prefs {
33 private final static String prefNode = "org.jsampler";
34
35 private final static String VIEW = "VIEW";
36 private final static String DEF_VIEW = "classic";
37
38 private final static String JSAMPLER_HOME = "JSampler.home";
39 private final static String DEF_JSAMPLER_HOME = null;
40
41 private final static String INTERFACE_LANGUAGE = "iface.language";
42 private final static String DEF_INTERFACE_LANGUAGE = "en";
43
44 private final static String INTERFACE_COUNTRY = "iface.country";
45 private final static String DEF_INTERFACE_COUNTRY = "US";
46
47 private final static String INTERFACE_FONT = "iface.font";
48 private final static String DEF_INTERFACE_FONT = null;
49
50 private final static String LS_ADDRESS = "LinuxSampler.address";
51 private final static String DEF_LS_ADDRESS = "127.0.0.1";
52
53 private final static String LS_PORT = "LinuxSampler.port";
54 private final static int DEF_LS_PORT = 8888;
55
56 private final static String ORCHESTRAS = "Orchestras";
57 private final static String DEF_ORCHESTRAS = null;
58
59
60 private static Preferences userPrefs = Preferences.userRoot().node(prefNode);
61
62 /**
63 * Gets the user preferences node of the JSampler package.
64 * @return The user preferences node of the JSampler package.
65 */
66 private static Preferences
67 user() { return userPrefs; }
68
69
70 // VIEW
71 /**
72 * Gets the name of the current View.
73 * @return the name of the current View.
74 */
75 public static String
76 getView() { return user().get(VIEW, DEF_VIEW); }
77
78 /**
79 * Sets the current View of JSampler.
80 * @param view the name of the new View.
81 */
82 public static void
83 setView(String view) {
84 if(view == null) user().remove(VIEW);
85 else if(!view.equals(getView())) user().put(VIEW, view);
86 }
87
88 /**
89 * Gets the interface language.
90 * @return The interface language.
91 */
92 public static String
93 getInterfaceLanguage() { return user().get(INTERFACE_LANGUAGE, DEF_INTERFACE_LANGUAGE); }
94
95 /**
96 * Sets the interface language.
97 * @return <code>true</code> if the interface language has changed and <code>false</code>
98 * otherwise.
99 */
100 public static boolean
101 setInterfaceLanguage(String language) {
102 if(language == null) {
103 user().remove(INTERFACE_LANGUAGE);
104 return true;
105 } else if(!language.equals(getInterfaceLanguage())) {
106 user().put(INTERFACE_LANGUAGE, language);
107 return true;
108 }
109 return false;
110 }
111
112 /**
113 * Gets the interface country.
114 * @return The interface country.
115 */
116 public static String
117 getInterfaceCountry() { return user().get(INTERFACE_COUNTRY, DEF_INTERFACE_COUNTRY); }
118
119 /**
120 * Sets the interface country.
121 * @return <code>true</code> if the interface country has changed and <code>false</code>
122 * otherwise.
123 */
124 public static boolean
125 setInterfaceCountry(String country) {
126 if(country == null) {
127 user().remove(INTERFACE_COUNTRY);
128 return true;
129 } else if(!country.equals(getInterfaceCountry())) {
130 user().put(INTERFACE_COUNTRY, country);
131 return true;
132 }
133 return false;
134 }
135
136 /**
137 * Gets the interface font.
138 * @return The interface font.
139 */
140 public static String
141 getInterfaceFont() { return user().get(INTERFACE_FONT, DEF_INTERFACE_FONT); }
142
143 /**
144 * Sets the interface font.
145 * @return <code>true</code> if the interface font has changed and <code>false</code>
146 * otherwise.
147 */
148 public static boolean
149 setInterfaceFont(String font) {
150 if(font == null) {
151 if(getInterfaceFont() == null) return false;
152 user().remove(INTERFACE_FONT);
153 return true;
154 } else if(!font.equals(getInterfaceFont())) {
155 user().put(INTERFACE_FONT, font);
156 return true;
157 }
158 return false;
159 }
160
161 // PREFERENCES
162 /**
163 * Gets the absolute path of JSampler home directory.
164 * @return The absolute path of JSampler home directory or
165 * <code>null</code> if the JSampler home directory is not set.
166 */
167 public static String
168 getJSamplerHome() { return user().get(JSAMPLER_HOME, DEF_JSAMPLER_HOME); }
169
170 /**
171 * Sets the JSampler home directory.
172 * @param home The absolute path of JSampler home directory.
173 * @return <code>true</code> if the JSampler home directory has
174 * been changed and <code>false</code> otherwise.
175 */
176 public static boolean
177 setJSamplerHome(String home) {
178 if(home == null) {
179 if(getJSamplerHome() == null) return false;
180 user().remove(JSAMPLER_HOME);
181 return true;
182 } else if(!home.equals(getJSamplerHome())) {
183 user().put(JSAMPLER_HOME, home);
184 return true;
185 }
186 return false;
187 }
188
189 /**
190 * Gets the LinuxSampler address.
191 * @return The LinuxSampler address.
192 */
193 public static String
194 getLSAddress() { return user().get(LS_ADDRESS, DEF_LS_ADDRESS); }
195
196 /**
197 * Sets the LinuxSampler address.
198 * @param address The LinuxSampler address.
199 */
200 public static void
201 setLSAddress(String address) {
202 if(address.length() == 0) user().remove(LS_ADDRESS);
203 else if(!address.equals(getLSAddress()))
204 user().put(LS_ADDRESS, address);
205 }
206
207 /**
208 * Gets the LinuxSampler port.
209 * @return The LinuxSampler port number.
210 */
211 public static int
212 getLSPort() { return user().getInt(LS_PORT, DEF_LS_PORT); }
213
214 /**
215 * Sets the LinuxSampler port number.
216 * This method das not check the validity of the port number.
217 * @param port the port number. Use -1 to reset to default value.
218 */
219 public static void
220 setLSPort(int port) {
221 if(port == -1) user().remove(LS_PORT);
222 else if(port != getLSPort()) user().putInt(LS_PORT, port);
223 }
224
225 /**
226 * Gets the orchestras' content (in XML format).
227 * @return The orchestras' content (in XML format).
228 */
229 public static String
230 getOrchestras() { return user().get(ORCHESTRAS, DEF_ORCHESTRAS); }
231
232 /**
233 * Sets the orchestras' content (in XML format).
234 * @param s The orchestras' content (in XML format).
235 */
236 public static void
237 setOrchestras(String s) {
238 if(s == null) {
239 user().remove(ORCHESTRAS);
240 return;
241 }
242 if(s.equals(getOrchestras())) return;
243
244 user().put(ORCHESTRAS, s);
245 }
246 }

  ViewVC Help
Powered by ViewVC