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 /* Default logdir is ~/TeleMetrum */
41 final static String logdirName = "TeleMetrum";
43 /* UI Component to pop dialogs up */
44 static Component component;
49 /* Telemetry channel */
52 /* Voice preference */
55 public static void init(Component ui) {
56 preferences = Preferences.userRoot().node("/org/altusmetrum/altosui");
60 /* Initialize logdir from preferences */
61 String logdir_string = preferences.get(logdirPreference, null);
62 if (logdir_string != null)
63 logdir = new File(logdir_string);
65 /* Use the file system view default directory */
66 logdir = new File(FileSystemView.getFileSystemView().getDefaultDirectory(), logdirName);
71 channel = preferences.getInt(channelPreference, 0);
73 voice = preferences.getBoolean(voicePreference, true);
76 static void flush_preferences() {
79 } catch (BackingStoreException ee) {
80 JOptionPane.showMessageDialog(component,
81 preferences.absolutePath(),
82 "Cannot save prefernces",
83 JOptionPane.ERROR_MESSAGE);
87 public static void set_logdir(File new_logdir) {
89 synchronized (preferences) {
90 preferences.put(logdirPreference, logdir.getPath());
95 private static boolean check_dir(File dir) {
98 JOptionPane.showMessageDialog(component,
100 "Cannot create directory",
101 JOptionPane.ERROR_MESSAGE);
104 } else if (!dir.isDirectory()) {
105 JOptionPane.showMessageDialog(component,
107 "Is not a directory",
108 JOptionPane.ERROR_MESSAGE);
114 /* Configure the log directory. This is where all telemetry and eeprom files
115 * will be written to, and where replay will look for telemetry files
117 public static void ConfigureLog() {
118 JFileChooser logdir_chooser = new JFileChooser(logdir.getParentFile());
120 logdir_chooser.setDialogTitle("Configure Data Logging Directory");
121 logdir_chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
123 if (logdir_chooser.showDialog(component, "Select Directory") == JFileChooser.APPROVE_OPTION) {
124 File dir = logdir_chooser.getSelectedFile();
130 public static File logdir() {
134 public static void set_channel(int new_channel) {
135 channel = new_channel;
136 synchronized (preferences) {
137 preferences.putInt(channelPreference, channel);
142 public static int channel() {
146 public static void set_voice(boolean new_voice) {
148 synchronized (preferences) {
149 preferences.putBoolean(voicePreference, voice);
154 public static boolean voice() {