/[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 911 - (hide annotations) (download)
Mon Aug 7 18:25:58 2006 UTC (17 years, 9 months ago) by iliev
File size: 5880 byte(s)
updating to JSampler 0.3a

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     private final static String VIEW = "VIEW";
36     private final static String DEF_VIEW = "classic";
37    
38 iliev 842 private final static String INTERFACE_LANGUAGE = "iface.language";
39     private final static String DEF_INTERFACE_LANGUAGE = "en";
40 iliev 787
41 iliev 842 private final static String INTERFACE_COUNTRY = "iface.country";
42     private final static String DEF_INTERFACE_COUNTRY = "US";
43 iliev 787
44 iliev 842 private final static String INTERFACE_FONT = "iface.font";
45     private final static String DEF_INTERFACE_FONT = null;
46 iliev 787
47 iliev 842 private final static String LS_ADDRESS = "LinuxSampler.address";
48     private final static String DEF_LS_ADDRESS = "127.0.0.1";
49 iliev 787
50 iliev 842 private final static String LS_PORT = "LinuxSampler.port";
51     private final static int DEF_LS_PORT = 8888;
52 iliev 787
53 iliev 911 private final static String ORCHESTRAS = "Orchestras";
54     private final static String DEF_ORCHESTRAS = null;
55 iliev 787
56 iliev 911
57 iliev 787 private static Preferences userPrefs = Preferences.userRoot().node(prefNode);
58    
59 iliev 842 /**
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 iliev 787 user() { return userPrefs; }
65    
66 iliev 842
67 iliev 787 // VIEW
68 iliev 842 /**
69     * Gets the name of the current View.
70     * @return the name of the current View.
71     */
72 iliev 787 public static String
73     getView() { return user().get(VIEW, DEF_VIEW); }
74    
75 iliev 842 /**
76     * Sets the current View of JSampler.
77     * @param view the name of the new View.
78     */
79 iliev 787 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 iliev 842 /**
86     * Gets the interface language.
87     * @return The interface language.
88     */
89 iliev 787 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 iliev 842 /**
110     * Gets the interface country.
111     * @return The interface country.
112     */
113 iliev 787 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 iliev 842 /**
134     * Gets the interface font.
135     * @return The interface font.
136     */
137 iliev 787 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 iliev 842 /**
160     * Gets the LinuxSampler address.
161     * @return The LinuxSampler address.
162     */
163 iliev 787 public static String
164     getLSAddress() { return user().get(LS_ADDRESS, DEF_LS_ADDRESS); }
165    
166 iliev 842 /**
167     * Sets the LinuxSampler address.
168     * @param address The LinuxSampler address.
169     */
170 iliev 787 public static void
171     setLSAddress(String address) {
172     if(address.length() == 0) user().remove(LS_ADDRESS);
173     else if(!address.equals(getLSAddress()))
174     user().put(LS_ADDRESS, address);
175     }
176    
177 iliev 842 /**
178     * Gets the LinuxSampler port.
179     * @return The LinuxSampler port number.
180     */
181 iliev 787 public static int
182     getLSPort() { return user().getInt(LS_PORT, DEF_LS_PORT); }
183    
184     /**
185     * Sets the LinuxSampler port number.
186     * This method das not check the validity of the port number.
187     * @param port the port number. Use -1 to reset to default value.
188     */
189     public static void
190 iliev 842 setLSPort(int port) {
191 iliev 787 if(port == -1) user().remove(LS_PORT);
192     else if(port != getLSPort()) user().putInt(LS_PORT, port);
193     }
194 iliev 911
195     /**
196     * Gets the orchestras' content (in XML format).
197     * @return The orchestras' content (in XML format).
198     */
199     public static String
200     getOrchestras() { return user().get(ORCHESTRAS, DEF_ORCHESTRAS); }
201    
202     /**
203     * Sets the orchestras' content (in XML format).
204     * @param s The orchestras' content (in XML format).
205     */
206     public static void
207     setOrchestras(String s) {
208     if(s == null) {
209     user().remove(ORCHESTRAS);
210     return;
211     }
212     if(s.equals(getOrchestras())) return;
213    
214     user().put(ORCHESTRAS, s);
215     }
216 iliev 787 }

  ViewVC Help
Powered by ViewVC