2 * Copyright © 2010 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
22 import java.util.prefs.*;
23 import java.util.concurrent.LinkedBlockingQueue;
24 import java.awt.Component;
26 import javax.swing.filechooser.FileSystemView;
28 class AltosPreferences {
29 static Preferences preferences;
31 /* logdir preference name */
32 final static String logdirPreference = "LOGDIR";
34 /* channel preference name */
35 final static String channelPreference = "CHANNEL";
37 /* voice preference name */
38 final static String voicePreference = "VOICE";
40 /* callsign preference name */
41 final static String callsignPreference = "CALLSIGN";
43 /* Default logdir is ~/TeleMetrum */
44 final static String logdirName = "TeleMetrum";
46 /* UI Component to pop dialogs up */
47 static Component component;
52 /* Telemetry channel */
55 /* Voice preference */
58 static String callsign;
60 public static void init(Component ui) {
61 preferences = Preferences.userRoot().node("/org/altusmetrum/altosui");
65 /* Initialize logdir from preferences */
66 String logdir_string = preferences.get(logdirPreference, null);
67 if (logdir_string != null)
68 logdir = new File(logdir_string);
70 /* Use the file system view default directory */
71 logdir = new File(FileSystemView.getFileSystemView().getDefaultDirectory(), logdirName);
76 channel = preferences.getInt(channelPreference, 0);
78 voice = preferences.getBoolean(voicePreference, true);
80 callsign = preferences.get(callsignPreference,"N0CALL");
83 static void flush_preferences() {
86 } catch (BackingStoreException ee) {
87 JOptionPane.showMessageDialog(component,
88 preferences.absolutePath(),
89 "Cannot save prefernces",
90 JOptionPane.ERROR_MESSAGE);
94 public static void set_logdir(File new_logdir) {
96 synchronized (preferences) {
97 preferences.put(logdirPreference, logdir.getPath());
102 private static boolean check_dir(File dir) {
105 JOptionPane.showMessageDialog(component,
107 "Cannot create directory",
108 JOptionPane.ERROR_MESSAGE);
111 } else if (!dir.isDirectory()) {
112 JOptionPane.showMessageDialog(component,
114 "Is not a directory",
115 JOptionPane.ERROR_MESSAGE);
121 /* Configure the log directory. This is where all telemetry and eeprom files
122 * will be written to, and where replay will look for telemetry files
124 public static void ConfigureLog() {
125 JFileChooser logdir_chooser = new JFileChooser(logdir.getParentFile());
127 logdir_chooser.setDialogTitle("Configure Data Logging Directory");
128 logdir_chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
130 if (logdir_chooser.showDialog(component, "Select Directory") == JFileChooser.APPROVE_OPTION) {
131 File dir = logdir_chooser.getSelectedFile();
137 public static File logdir() {
141 public static void set_channel(int new_channel) {
142 channel = new_channel;
143 synchronized (preferences) {
144 preferences.putInt(channelPreference, channel);
149 public static int channel() {
153 public static void set_voice(boolean new_voice) {
155 synchronized (preferences) {
156 preferences.putBoolean(voicePreference, voice);
161 public static boolean voice() {
165 public static void set_callsign(String new_callsign) {
166 callsign = new_callsign;
167 synchronized(preferences) {
168 preferences.put(callsignPreference, callsign);
173 public static String callsign() {