X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altosui%2FAltosEepromManage.java;h=b12d95fa0c48b5b0064205cbbced922f78a80ef0;hp=b64ee52597b9bf643f242fd31fb8dc66bc8b00a8;hb=dea80af81b388cc3d7073444919f4e98b12fa730;hpb=8801b8c1947bd39f7c985b91a2ba8dbc81bcc91a diff --git a/altosui/AltosEepromManage.java b/altosui/AltosEepromManage.java index b64ee525..b12d95fa 100644 --- a/altosui/AltosEepromManage.java +++ b/altosui/AltosEepromManage.java @@ -44,34 +44,55 @@ 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 +109,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 +142,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 +169,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(); } } }