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 /* Default logdir is ~/TeleMetrum */
35 final static String logdirName = "TeleMetrum";
37 /* UI Component to pop dialogs up */
38 static Component component;
43 public static void init(Component ui) {
44 preferences = Preferences.userRoot().node("/org/altusmetrum/altosui");
48 /* Initialize logdir from preferences */
49 String logdir_string = preferences.get(logdirPreference, null);
50 if (logdir_string != null)
51 logdir = new File(logdir_string);
53 /* Use the file system view default directory */
54 logdir = new File(FileSystemView.getFileSystemView().getDefaultDirectory(), logdirName);
60 static void flush_preferences() {
63 } catch (BackingStoreException ee) {
64 JOptionPane.showMessageDialog(component,
65 preferences.absolutePath(),
66 "Cannot save prefernces",
67 JOptionPane.ERROR_MESSAGE);
71 public static void set_logdir(File new_logdir) {
73 synchronized (preferences) {
74 preferences.put(logdirPreference, logdir.getPath());
79 private static boolean check_dir(File dir) {
82 JOptionPane.showMessageDialog(component,
84 "Cannot create directory",
85 JOptionPane.ERROR_MESSAGE);
88 } else if (!dir.isDirectory()) {
89 JOptionPane.showMessageDialog(component,
92 JOptionPane.ERROR_MESSAGE);
98 /* Configure the log directory. This is where all telemetry and eeprom files
99 * will be written to, and where replay will look for telemetry files
101 public static void ConfigureLog() {
102 JFileChooser logdir_chooser = new JFileChooser(logdir.getParentFile());
104 logdir_chooser.setDialogTitle("Configure Data Logging Directory");
105 logdir_chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
107 if (logdir_chooser.showDialog(component, "Select Directory") == JFileChooser.APPROVE_OPTION) {
108 File dir = logdir_chooser.getSelectedFile();
114 public static File logdir() {