/[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 1329 - (show annotations) (download)
Sat Sep 8 18:33:05 2007 UTC (16 years, 7 months ago) by iliev
File size: 6217 byte(s)
* Implemented some UI enhancements for speeding up
  the MIDI instrument mapping process
* some minor bugfixes

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
57 private static Preferences userPrefs = Preferences.userRoot().node(prefNode);
58
59 /**
60 * Gets the user preferences node of the JSampler package.
61 * @return The user preferences node of the JSampler package.
62 */
63 private static Preferences
64 user() { return userPrefs; }
65
66
67 // VIEW
68 /**
69 * Gets the name of the current View.
70 * @return the name of the current View.
71 */
72 public static String
73 getView() { return user().get(VIEW, DEF_VIEW); }
74
75 /**
76 * Sets the current View of JSampler.
77 * @param view the name of the new View.
78 */
79 public static void
80 setView(String view) {
81 if(view == null) user().remove(VIEW);
82 else if(!view.equals(getView())) user().put(VIEW, view);
83 }
84
85 /**
86 * Gets the interface language.
87 * @return The interface language.
88 */
89 public static String
90 getInterfaceLanguage() { return user().get(INTERFACE_LANGUAGE, DEF_INTERFACE_LANGUAGE); }
91
92 /**
93 * Sets the interface language.
94 * @return <code>true</code> if the interface language has changed and <code>false</code>
95 * otherwise.
96 */
97 public static boolean
98 setInterfaceLanguage(String language) {
99 if(language == null) {
100 user().remove(INTERFACE_LANGUAGE);
101 return true;
102 } else if(!language.equals(getInterfaceLanguage())) {
103 user().put(INTERFACE_LANGUAGE, language);
104 return true;
105 }
106 return false;
107 }
108
109 /**
110 * Gets the interface country.
111 * @return The interface country.
112 */
113 public static String
114 getInterfaceCountry() { return user().get(INTERFACE_COUNTRY, DEF_INTERFACE_COUNTRY); }
115
116 /**
117 * Sets the interface country.
118 * @return <code>true</code> if the interface country has changed and <code>false</code>
119 * otherwise.
120 */
121 public static boolean
122 setInterfaceCountry(String country) {
123 if(country == null) {
124 user().remove(INTERFACE_COUNTRY);
125 return true;
126 } else if(!country.equals(getInterfaceCountry())) {
127 user().put(INTERFACE_COUNTRY, country);
128 return true;
129 }
130 return false;
131 }
132
133 /**
134 * Gets the interface font.
135 * @return The interface font.
136 */
137 public static String
138 getInterfaceFont() { return user().get(INTERFACE_FONT, DEF_INTERFACE_FONT); }
139
140 /**
141 * Sets the interface font.
142 * @return <code>true</code> if the interface font has changed and <code>false</code>
143 * otherwise.
144 */
145 public static boolean
146 setInterfaceFont(String font) {
147 if(font == null) {
148 if(getInterfaceFont() == null) return false;
149 user().remove(INTERFACE_FONT);
150 return true;
151 } else if(!font.equals(getInterfaceFont())) {
152 user().put(INTERFACE_FONT, font);
153 return true;
154 }
155 return false;
156 }
157
158 // PREFERENCES
159 /**
160 * Gets the absolute path of JSampler home directory.
161 * @return The absolute path of JSampler home directory or
162 * <code>null</code> if the JSampler home directory is not set.
163 */
164 public static String
165 getJSamplerHome() { return user().get(JSAMPLER_HOME, DEF_JSAMPLER_HOME); }
166
167 /**
168 * Sets the JSampler home directory.
169 * @param home The absolute path of JSampler home directory.
170 * @return <code>true</code> if the JSampler home directory has
171 * been changed and <code>false</code> otherwise.
172 */
173 public static boolean
174 setJSamplerHome(String home) {
175 if(home == null) {
176 if(getJSamplerHome() == null) return false;
177 user().remove(JSAMPLER_HOME);
178 return true;
179 } else if(!home.equals(getJSamplerHome())) {
180 user().put(JSAMPLER_HOME, home);
181 return true;
182 }
183 return false;
184 }
185
186 /**
187 * Gets the LinuxSampler address.
188 * @return The LinuxSampler address.
189 */
190 public static String
191 getLSAddress() { return user().get(LS_ADDRESS, DEF_LS_ADDRESS); }
192
193 /**
194 * Sets the LinuxSampler address.
195 * @param address The LinuxSampler address.
196 */
197 public static void
198 setLSAddress(String address) {
199 if(address.length() == 0) user().remove(LS_ADDRESS);
200 else if(!address.equals(getLSAddress()))
201 user().put(LS_ADDRESS, address);
202 }
203
204 /**
205 * Gets the LinuxSampler port.
206 * @return The LinuxSampler port number.
207 */
208 public static int
209 getLSPort() { return user().getInt(LS_PORT, DEF_LS_PORT); }
210
211 /**
212 * Sets the LinuxSampler port number.
213 * This method das not check the validity of the port number.
214 * @param port the port number. Use -1 to reset to default value.
215 */
216 public static void
217 setLSPort(int port) {
218 if(port == -1) user().remove(LS_PORT);
219 else if(port != getLSPort()) user().putInt(LS_PORT, port);
220 }
221 }

  ViewVC Help
Powered by ViewVC