altoslib: Make sure AltosFlightSeries is filled in before use
[fw/altos] / altosui / AltosConfig.java
index c4dba735184b23d204c8e4ebe8bc26ccdc0d58b9..07802247c9e0d824d020f5b1e83b8eaa8ee0eb66 100644 (file)
@@ -3,7 +3,8 @@
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -22,8 +23,8 @@ import javax.swing.*;
 import java.io.*;
 import java.util.concurrent.*;
 import java.text.*;
-import org.altusmetrum.altoslib.*;
-import org.altusmetrum.altosuilib.*;
+import org.altusmetrum.altoslib_11.*;
+import org.altusmetrum.altosuilib_11.*;
 
 public class AltosConfig implements ActionListener {
 
@@ -161,9 +162,9 @@ public class AltosConfig implements ActionListener {
                        } finally {
                                try {
                                        stop_serial();
+                                       serial_line.close();
                                } catch (InterruptedException ie) {
                                }
-                               serial_line.close();
                        }
                }
 
@@ -229,22 +230,28 @@ public class AltosConfig implements ActionListener {
 
        void save_data() {
 
-               /* bounds check stuff */
-               if (config_ui.flight_log_max() > data.log_limit()) {
+               try {
+                       /* bounds check stuff */
+                       if (config_ui.flight_log_max() > data.log_space() / 1024) {
+                               JOptionPane.showMessageDialog(owner,
+                                                             String.format("Requested flight log, %dk, is larger than the available space, %dk.\n",
+                                                                           config_ui.flight_log_max(),
+                                                                           data.log_space() / 1024),
+                                                             "Maximum Flight Log Too Large",
+                                                             JOptionPane.ERROR_MESSAGE);
+                               return;
+                       }
+
+                       /* Pull data out of the UI and stuff back into our local data record */
+
+                       data.get_values(config_ui);
+                       run_serial_thread(serial_mode_save);
+               } catch (AltosConfigDataException ae) {
                        JOptionPane.showMessageDialog(owner,
-                                                     String.format("Requested flight log, %dk, is larger than the available space, %dk.\n",
-                                                                   config_ui.flight_log_max(),
-                                                                   data.log_limit()),
-                                                     "Maximum Flight Log Too Large",
+                                                     ae.getMessage(),
+                                                     "Configuration Data Error",
                                                      JOptionPane.ERROR_MESSAGE);
-                       return;
                }
-
-               /* Pull data out of the UI and stuff back into our local data record */
-
-               data.get_values(config_ui);
-
-               run_serial_thread(serial_mode_save);
        }
 
        public void actionPerformed(ActionEvent e) {
@@ -298,4 +305,4 @@ public class AltosConfig implements ActionListener {
                        }
                }
        }
-}
\ No newline at end of file
+}