Merge branch 'master' of ssh://git.gag.com/scm/git/fw/altos
[fw/altos] / altosui / AltosEepromManage.java
index b64ee52597b9bf643f242fd31fb8dc66bc8b00a8..d10f79549b5bf242bac0fdfed6e13a461a12766e 100644 (file)
@@ -44,34 +44,56 @@ public class AltosEepromManage implements ActionListener {
 
        public void finish() {
                if (serial_line != null) {
-                       serial_line.flush_output();
+                       serial_line.flush_input();
                        serial_line.close();
                        serial_line = null;
                }
        }
 
+       private String showDeletedFlights() {
+               String  result = "";
+
+               for (AltosEepromLog flight : flights) {
+                       if (flight.delete) {
+                               if (result.equals(""))
+                                       result = String.format("%d", flight.flight);
+                               else
+                                       result = String.format("%s, %d", result, flight.flight);
+                       }
+               }
+               return result;
+       }
+
        public void actionPerformed(ActionEvent e) {
                String  cmd = e.getActionCommand();
                boolean success = e.getID() != 0;
+               boolean running = false;
 
                System.out.printf("Eeprom manager action %s %d\n", cmd, e.getID());
                if (cmd.equals("download")) {
                        if (success) {
-                               System.out.printf("Download succeeded\n");
-                               if (any_delete)
+                               if (any_delete) {
                                        delete.start();
-                               else
-                                       finish();
+                                       running = true;
+                               }
                        }
                } else if (cmd.equals("delete")) {
-                       if (success)
-                               System.out.printf("Delete succeeded\n");
-                       finish();
+                       if (success) {
+                               JOptionPane.showMessageDialog(frame,
+                                                             String.format("Flights erased: %s",
+                                                                           showDeletedFlights()),
+                                                             serial_line.device.toShortString(),
+                                                             JOptionPane.INFORMATION_MESSAGE);
+                       }
                }
+               if (!running)
+                       finish();
        }
 
        public AltosEepromManage(JFrame given_frame) {
 
+               boolean running = false;
+
                frame = given_frame;
                device = AltosDeviceDialog.show(frame, AltosDevice.product_any);
 
@@ -88,6 +110,11 @@ public class AltosEepromManage implements ActionListener {
                                flights = new AltosEepromList(serial_line, remote);
 
                                if (flights.size() == 0) {
+                                       JOptionPane.showMessageDialog(frame,
+                                                                     String.format("No flights available on %d",
+                                                                                   device.getSerial()),
+                                                                     serial_line.device.toShortString(),
+                                               JOptionPane.INFORMATION_MESSAGE);
                                } else {
                                        AltosEepromSelect       select = new AltosEepromSelect(frame, flights);
 
@@ -116,12 +143,14 @@ public class AltosEepromManage implements ActionListener {
                                                 * Start flight log download
                                                 */
 
-                                               if (any_download)
+                                               if (any_download) {
                                                        download.start();
-                                               else if (any_delete)
+                                                       running = true;
+                                               }
+                                               else if (any_delete) {
                                                        delete.start();
-                                               else
-                                                       finish();
+                                                       running = true;
+                                               }
                                        }
                                }
                        } catch (FileNotFoundException ee) {
@@ -141,17 +170,16 @@ public class AltosEepromManage implements ActionListener {
                                                              device.toShortString(),
                                                              ee.getLocalizedMessage(),
                                                              JOptionPane.ERROR_MESSAGE);
-                               finish();
                        } catch (TimeoutException te) {
                                JOptionPane.showMessageDialog(frame,
                                                              String.format("Communications failed with \"%s\"",
                                                                            device.toShortString()),
                                                              "Cannot open target device",
                                                              JOptionPane.ERROR_MESSAGE);
-                               finish();
                        } catch (InterruptedException ie) {
-                               finish();
                        }
+                       if (!running)
+                               finish();
                }
        }
 }