altosui: Use persistent list of bluetooth devices for device dialogs
[fw/altos] / altosui / AltosPreferences.java
index 5f82765569dae85f0a69211c41bc0d1ed04b119f..b1192be110e1f3573e2626939f73e238c68a3fda 100644 (file)
@@ -79,11 +79,9 @@ class AltosPreferences {
        /* Serial debug */
        static boolean serial_debug;
 
-       public static void init(Component ui) {
+       public static void init() {
                preferences = Preferences.userRoot().node("/org/altusmetrum/altosui");
 
-               component = ui;
-
                /* Initialize logdir from preferences */
                String logdir_string = preferences.get(logdirPreference, null);
                if (logdir_string != null)
@@ -116,14 +114,23 @@ class AltosPreferences {
                AltosSerial.set_debug(serial_debug);
        }
 
+       static { init(); }
+
+       static void set_component(Component in_component) {
+               component = in_component;
+       }
+
        static void flush_preferences() {
                try {
                        preferences.flush();
                } catch (BackingStoreException ee) {
-                       JOptionPane.showMessageDialog(component,
-                                                     preferences.absolutePath(),
-                                                     "Cannot save prefernces",
-                                                     JOptionPane.ERROR_MESSAGE);
+                       if (component != null)
+                               JOptionPane.showMessageDialog(component,
+                                                             preferences.absolutePath(),
+                                                             "Cannot save prefernces",
+                                                             JOptionPane.ERROR_MESSAGE);
+                       else
+                               System.err.printf("Cannot save preferences\n");
                }
        }
 
@@ -262,4 +269,8 @@ class AltosPreferences {
        public static boolean serial_debug() {
                return serial_debug;
        }
+
+       public static Preferences bt_devices() {
+               return preferences.node("bt_devices");
+       }
 }