/[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 787 - (show annotations) (download)
Mon Oct 10 16:03:12 2005 UTC (18 years, 5 months ago) by iliev
File size: 4532 byte(s)
* The first alpha-release of JSampler

1 /*
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 *
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 public final static String INTERFACE_LANGUAGE = "iface.language";
39 public final static String DEF_INTERFACE_LANGUAGE = "en";
40
41 public final static String INTERFACE_COUNTRY = "iface.country";
42 public final static String DEF_INTERFACE_COUNTRY = "US";
43
44 public final static String INTERFACE_FONT = "iface.font";
45 public final static String DEF_INTERFACE_FONT = null;
46
47 public final static String LS_ADDRESS = "LinuxSampler.address";
48 public final static String DEF_LS_ADDRESS = "127.0.0.1";
49
50 public final static String LS_PORT = "LinuxSampler.port";
51 public final static int DEF_LS_PORT = 8888;
52
53
54
55 private static Preferences sysPrefs = Preferences.systemRoot().node(prefNode);
56 private static Preferences userPrefs = Preferences.userRoot().node(prefNode);
57
58 public static Preferences
59 sys() { return sysPrefs; }
60
61 public static Preferences
62 user() { return userPrefs; }
63
64 // VIEW
65 public static String
66 getView() { return user().get(VIEW, DEF_VIEW); }
67
68 public static void
69 setView(String view) {
70 if(view == null) user().remove(VIEW);
71 else if(!view.equals(getView())) user().put(VIEW, view);
72 }
73
74 public static String
75 getInterfaceLanguage() { return user().get(INTERFACE_LANGUAGE, DEF_INTERFACE_LANGUAGE); }
76
77 /**
78 * Sets the interface language.
79 * @return <code>true</code> if the interface language has changed and <code>false</code>
80 * otherwise.
81 */
82 public static boolean
83 setInterfaceLanguage(String language) {
84 if(language == null) {
85 user().remove(INTERFACE_LANGUAGE);
86 return true;
87 } else if(!language.equals(getInterfaceLanguage())) {
88 user().put(INTERFACE_LANGUAGE, language);
89 return true;
90 }
91 return false;
92 }
93
94 public static String
95 getInterfaceCountry() { return user().get(INTERFACE_COUNTRY, DEF_INTERFACE_COUNTRY); }
96
97 /**
98 * Sets the interface country.
99 * @return <code>true</code> if the interface country has changed and <code>false</code>
100 * otherwise.
101 */
102 public static boolean
103 setInterfaceCountry(String country) {
104 if(country == null) {
105 user().remove(INTERFACE_COUNTRY);
106 return true;
107 } else if(!country.equals(getInterfaceCountry())) {
108 user().put(INTERFACE_COUNTRY, country);
109 return true;
110 }
111 return false;
112 }
113
114 public static String
115 getInterfaceFont() { return user().get(INTERFACE_FONT, DEF_INTERFACE_FONT); }
116
117 /**
118 * Sets the interface font.
119 * @return <code>true</code> if the interface font has changed and <code>false</code>
120 * otherwise.
121 */
122 public static boolean
123 setInterfaceFont(String font) {
124 if(font == null) {
125 if(getInterfaceFont() == null) return false;
126 user().remove(INTERFACE_FONT);
127 return true;
128 } else if(!font.equals(getInterfaceFont())) {
129 user().put(INTERFACE_FONT, font);
130 return true;
131 }
132 return false;
133 }
134
135 // PREFERENCES
136 public static String
137 getLSAddress() { return user().get(LS_ADDRESS, DEF_LS_ADDRESS); }
138
139 public static void
140 setLSAddress(String address) {
141 if(address.length() == 0) user().remove(LS_ADDRESS);
142 else if(!address.equals(getLSAddress()))
143 user().put(LS_ADDRESS, address);
144 }
145
146 public static int
147 getLSPort() { return user().getInt(LS_PORT, DEF_LS_PORT); }
148
149 /**
150 * Sets the LinuxSampler port number.
151 * This method das not check the validity of the port number.
152 * @param port the port number. Use -1 to reset to default value.
153 */
154 public static void
155 setAuthSrvPort(int port) {
156 if(port == -1) user().remove(LS_PORT);
157 else if(port != getLSPort()) user().putInt(LS_PORT, port);
158 }
159 }

  ViewVC Help
Powered by ViewVC