java: Bump java library versions for next release
[fw/altos] / altoslib / AltosPreferences.java
index ef30f8e92fd81549ddb016ef1783c6610725435b..159951e46f83ffd501f94ee46989acdd275536ef 100644 (file)
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.AltosLib;
+package org.altusmetrum.altoslib_5;
 
 import java.io.*;
 import java.util.*;
-import javax.swing.filechooser.FileSystemView;
 
 public class AltosPreferences {
        public static AltosPreferencesBackend backend = null;
@@ -56,13 +55,16 @@ public class AltosPreferences {
 
        /* Launcher channel preference name */
        public final static String launcherChannelPreference = "LAUNCHER-CHANNEL";
-       
+
        /* Default logdir is ~/TeleMetrum */
        public final static String logdirName = "TeleMetrum";
 
        /* Log directory */
        public static File logdir;
 
+       /* Last log directory - use this next time we open or save something */
+       public static File last_logdir;
+
        /* Map directory -- hangs of logdir */
        public static File mapdir;
 
@@ -137,16 +139,15 @@ public class AltosPreferences {
 
        public static int launcher_channel;
 
-       public static void init() {
-               //preferences = Preferences.userRoot().node("/org/altusmetrum/altosui");
+       public static void init(AltosPreferencesBackend in_backend) {
+               backend = in_backend;
 
                /* Initialize logdir from preferences */
                String logdir_string = backend.getString(logdirPreference, null);
                if (logdir_string != null)
                        logdir = new File(logdir_string);
                else {
-                       /* Use the file system view default directory */
-                       logdir = new File(FileSystemView.getFileSystemView().getDefaultDirectory(), logdirName);
+                       logdir = new File(backend.homeDirectory(), logdirName);
                        if (!logdir.exists())
                                logdir.mkdirs();
                }
@@ -179,8 +180,6 @@ public class AltosPreferences {
                AltosConvert.imperial_units = backend.getBoolean(unitsPreference, false);
        }
 
-       static { init(); }
-
        public static void flush_preferences() {
                backend.flush();
        }
@@ -202,6 +201,24 @@ public class AltosPreferences {
                }
        }
 
+       public static File last_logdir() {
+               synchronized (backend) {
+                       if (last_logdir == null)
+                               last_logdir = logdir;
+                       return last_logdir;
+               }
+       }
+
+       public static void set_last_logdir(File file) {
+               synchronized(backend) {
+                       if (file != null && !file.isDirectory())
+                               file = file.getParentFile();
+                       if (file == null)
+                               file = new File(".");
+                       last_logdir = file;
+               }
+       }
+
        public static File mapdir() {
                synchronized (backend) {
                        return mapdir;
@@ -332,7 +349,7 @@ public class AltosPreferences {
                        return launcher_channel;
                }
        }
-       
+
        public static AltosPreferencesBackend bt_devices() {
                synchronized (backend) {
                        return backend.node("bt_devices");
@@ -371,6 +388,8 @@ public class AltosPreferences {
                set_common_frequencies(new_frequencies);
        }
 
+       static LinkedList<AltosUnitsListener> units_listeners;
+
        public static boolean imperial_units() {
                synchronized(backend) {
                        return AltosConvert.imperial_units;
@@ -383,5 +402,24 @@ public class AltosPreferences {
                        backend.putBoolean(unitsPreference, imperial_units);
                        flush_preferences();
                }
+               if (units_listeners != null) {
+                       for (AltosUnitsListener l : units_listeners) {
+                               l.units_changed(imperial_units);
+                       }
+               }
+       }
+
+       public static void register_units_listener(AltosUnitsListener l) {
+               synchronized(backend) {
+                       if (units_listeners == null)
+                               units_listeners = new LinkedList<AltosUnitsListener>();
+                       units_listeners.add(l);
+               }
+       }
+
+       public static void unregister_units_listener(AltosUnitsListener l) {
+               synchronized(backend) {
+                       units_listeners.remove(l);
+               }
        }
 }