altosui: Remember directory containing firmware files
authorKeith Packard <keithp@keithp.com>
Sat, 11 Sep 2010 04:07:14 +0000 (21:07 -0700)
committerKeith Packard <keithp@keithp.com>
Sat, 11 Sep 2010 04:07:14 +0000 (21:07 -0700)
Instead of forcing the user to navigate to the firmware directory each
time, this remembers the previous directory and starts there.

Signed-off-by: Keith Packard <keithp@keithp.com>
ao-tools/altosui/AltosFlashUI.java
ao-tools/altosui/AltosPreferences.java

index 5ed417da993a0d149146ff78d039ccb2a5f703c1..86f57a5fb3c862e755f1909c4310357e7b59bc09 100644 (file)
@@ -194,6 +194,10 @@ public class AltosFlashUI
 
                JFileChooser    hexfile_chooser = new JFileChooser();
 
 
                JFileChooser    hexfile_chooser = new JFileChooser();
 
+               File firmwaredir = AltosPreferences.firmwaredir();
+               if (firmwaredir != null)
+                       hexfile_chooser.setCurrentDirectory(firmwaredir);
+
                hexfile_chooser.setDialogTitle("Select Flash Image");
                hexfile_chooser.setFileFilter(new FileNameExtensionFilter("Flash Image", "ihx"));
                int returnVal = hexfile_chooser.showOpenDialog(frame);
                hexfile_chooser.setDialogTitle("Select Flash Image");
                hexfile_chooser.setFileFilter(new FileNameExtensionFilter("Flash Image", "ihx"));
                int returnVal = hexfile_chooser.showOpenDialog(frame);
@@ -203,6 +207,9 @@ public class AltosFlashUI
 
                file = hexfile_chooser.getSelectedFile();
 
 
                file = hexfile_chooser.getSelectedFile();
 
+               if (file != null)
+                       AltosPreferences.set_firmwaredir(file.getParentFile());
+
                thread = new Thread(this);
                thread.start();
        }
                thread = new Thread(this);
                thread.start();
        }
index 690f8f1ed5e60eff6e2f858147d7c66fc5ae4e8f..526275635ff07b90960aa3bd74aeaa8e402a5f13 100644 (file)
@@ -40,6 +40,9 @@ class AltosPreferences {
        /* callsign preference name */
        final static String callsignPreference = "CALLSIGN";
 
        /* callsign preference name */
        final static String callsignPreference = "CALLSIGN";
 
+       /* firmware directory preference name */
+       final static String firmwaredirPreference = "FIRMWARE";
+
        /* Default logdir is ~/TeleMetrum */
        final static String logdirName = "TeleMetrum";
 
        /* Default logdir is ~/TeleMetrum */
        final static String logdirName = "TeleMetrum";
 
@@ -55,8 +58,12 @@ class AltosPreferences {
        /* Voice preference */
        static boolean voice;
 
        /* Voice preference */
        static boolean voice;
 
+       /* Callsign preference */
        static String callsign;
 
        static String callsign;
 
+       /* Firmware directory */
+       static File firmwaredir;
+
        public static void init(Component ui) {
                preferences = Preferences.userRoot().node("/org/altusmetrum/altosui");
 
        public static void init(Component ui) {
                preferences = Preferences.userRoot().node("/org/altusmetrum/altosui");
 
@@ -78,6 +85,12 @@ class AltosPreferences {
                voice = preferences.getBoolean(voicePreference, true);
 
                callsign = preferences.get(callsignPreference,"N0CALL");
                voice = preferences.getBoolean(voicePreference, true);
 
                callsign = preferences.get(callsignPreference,"N0CALL");
+
+               String firmwaredir_string = preferences.get(firmwaredirPreference, null);
+               if (firmwaredir_string != null)
+                       firmwaredir = new File(firmwaredir_string);
+               else
+                       firmwaredir = null;
        }
 
        static void flush_preferences() {
        }
 
        static void flush_preferences() {
@@ -173,4 +186,16 @@ class AltosPreferences {
        public static String callsign() {
                return callsign;
        }
        public static String callsign() {
                return callsign;
        }
+
+       public static void set_firmwaredir(File new_firmwaredir) {
+               firmwaredir = new_firmwaredir;
+               synchronized (preferences) {
+                       preferences.put(firmwaredirPreference, firmwaredir.getPath());
+                       flush_preferences();
+               }
+       }
+
+       public static File firmwaredir() {
+               return firmwaredir;
+       }
 }
 }