altosui: Change flight data saving UI to separate download/delete selections
authorKeith Packard <keithp@keithp.com>
Wed, 28 Mar 2012 01:24:51 +0000 (18:24 -0700)
committerKeith Packard <keithp@keithp.com>
Wed, 28 Mar 2012 01:24:51 +0000 (18:24 -0700)
First pop up a dialog to select flights for download. Download
them. Then, after that, pop up a *new* dialog to select flights for
delete. Offer to delete all of the downloaded flights by default. Then
delete the flights.

Signed-off-by: Keith Packard <keithp@keithp.com>
altosui/AltosEepromDelete.java
altosui/AltosEepromDownload.java
altosui/AltosEepromLog.java
altosui/AltosEepromManage.java
altosui/AltosEepromSelect.java

index a9d77788d06f84be4800ae0d8d4fb4255bb6ff99..fcce8155e634f976b259f339db3e2ee3dfff6307 100644 (file)
@@ -90,7 +90,7 @@ public class AltosEepromDelete implements Runnable {
                                serial_line.start_remote();
 
                        for (AltosEepromLog log : flights) {
-                               if (log.delete) {
+                               if (log.selected) {
                                        DeleteLog(log);
                                }
                        }
index e7e52466b71b24cd577036e18b51dde4bcf8a3e7..40c98bfd7d6b661083c5187fc2d3cea1fae46bca 100644 (file)
@@ -351,7 +351,7 @@ public class AltosEepromDownload implements Runnable {
 
                        for (AltosEepromLog log : flights) {
                                parse_exception = null;
-                               if (log.download) {
+                               if (log.selected) {
                                        monitor.reset();
                                        CaptureLog(log);
                                }
index ee77e5c84046fee5f1e4a4fa75e00b7cd8932948..475d7f122a6bb50e319591b390b9058ac429c56e 100644 (file)
@@ -43,8 +43,7 @@ public class AltosEepromLog {
 
        int             year, month, day;
 
-       boolean         download;
-       boolean         delete;
+       boolean         selected;
 
        public AltosEepromLog(AltosConfigData config_data,
                              AltosSerial serial_line,
@@ -63,10 +62,9 @@ public class AltosEepromLog {
                serial = config_data.serial;
 
                /*
-                * By default, request that every log be downloaded but not deleted
+                * Select all flights for download
                 */
-               download = true;
-               delete = false;
+               selected = true;
 
                /*
                 * Look in TeleMetrum log data for date
index 083c73725d44e4f2fa928ce8532b2fd8f7bb363d..1e06f4ca86d1aa17b3629630b6b98a9e8a24ad82 100644 (file)
@@ -39,8 +39,6 @@ public class AltosEepromManage implements ActionListener {
        AltosEepromList         flights;
        AltosEepromDownload     download;
        AltosEepromDelete       delete;
-       boolean                 any_download;
-       boolean                 any_delete;
 
        public void finish() {
                if (serial_line != null) {
@@ -57,7 +55,7 @@ public class AltosEepromManage implements ActionListener {
                String  result = "";
 
                for (AltosEepromLog flight : flights) {
-                       if (flight.delete) {
+                       if (flight.selected) {
                                if (result.equals(""))
                                        result = String.format("%d", flight.flight);
                                else
@@ -67,18 +65,38 @@ public class AltosEepromManage implements ActionListener {
                return result;
        }
 
+       public boolean download_done() {
+               AltosEepromSelect       select = new AltosEepromSelect(frame, flights, "Delete");
+
+               if (select.run()) {
+                       boolean any_selected = false;
+                       for (AltosEepromLog flight : flights)
+                               any_selected = any_selected || flight.selected;
+                       if (any_selected) {
+                               delete = new AltosEepromDelete(frame,
+                                                              serial_line,
+                                                              remote,
+                                                              flights);
+                               delete.addActionListener(this);
+                               /*
+                                * Start flight log delete
+                                */
+
+                               delete.start();
+                               return true;
+                       }
+               }
+               return false;
+       }
+
        public void actionPerformed(ActionEvent e) {
                String  cmd = e.getActionCommand();
                boolean success = e.getID() != 0;
                boolean running = false;
 
                if (cmd.equals("download")) {
-                       if (success) {
-                               if (any_delete) {
-                                       delete.start();
-                                       running = true;
-                               }
-                       }
+                       if (success)
+                               running = download_done();
                } else if (cmd.equals("delete")) {
                        if (success) {
                                JOptionPane.showMessageDialog(frame,
@@ -104,40 +122,26 @@ public class AltosEepromManage implements ActionListener {
                                                              serial_line.device.toShortString(),
                                                              JOptionPane.INFORMATION_MESSAGE);
                        } else {
-                               AltosEepromSelect       select = new AltosEepromSelect(frame, flights);
+                               AltosEepromSelect       select = new AltosEepromSelect(frame, flights, "Download");
 
                                if (select.run()) {
-                                       for (AltosEepromLog flight : flights) {
-                                               any_download = any_download || flight.download;
-                                               any_delete = any_delete || flight.delete;
-                                       }
-                                       if (any_download) {
+                                       boolean any_selected = false;
+                                       for (AltosEepromLog flight : flights)
+                                               any_selected = any_selected || flight.selected;
+                                       if (any_selected) {
                                                download = new AltosEepromDownload(frame,
                                                                                   serial_line,
                                                                                   remote,
                                                                                   flights);
                                                download.addActionListener(this);
-                                       }
-
-                                       if (any_delete) {
-                                               delete = new AltosEepromDelete(frame,
-                                                                              serial_line,
-                                                                              remote,
-                                                                              flights);
-                                               delete.addActionListener(this);
-                                       }
+                                               /*
+                                                * Start flight log download
+                                                */
 
-                                       /*
-                                        * Start flight log download
-                                        */
-
-                                       if (any_download) {
                                                download.start();
                                                running = true;
-                                       }
-                                       else if (any_delete) {
-                                               delete.start();
-                                               running = true;
+                                       } else {
+                                               running = download_done();
                                        }
                                }
                        }
@@ -203,8 +207,6 @@ public class AltosEepromManage implements ActionListener {
                device = AltosDeviceDialog.show(frame, Altos.product_any);
 
                remote = false;
-               any_download = false;
-               any_delete = false;
 
                if (device != null) {
                        try {
index ebafc4c87da3382f3f670035aea39a3bbc6f9f88..e0fbeeadefcdf67ade075d4ecad2e99b2ded324d 100644 (file)
@@ -31,15 +31,11 @@ import libaltosJNI.SWIGTYPE_p_altos_list;
 class AltosEepromItem implements ActionListener {
        AltosEepromLog  log;
        JLabel          label;
-       JCheckBox       download;
+       JCheckBox       action;
        JCheckBox       delete;
 
        public void actionPerformed(ActionEvent e) {
-               if (e.getSource() == download) {
-                       log.download = download.isSelected();
-               } else if (e.getSource() == delete) {
-                       log.delete = delete.isSelected();
-               }
+               log.selected = action.isSelected();
        }
 
        public AltosEepromItem(AltosEepromLog in_log) {
@@ -54,11 +50,8 @@ class AltosEepromItem implements ActionListener {
 
                label = new JLabel(text);
 
-               download = new JCheckBox("", log.download);
-               download.addActionListener(this);
-
-               delete = new JCheckBox("", log.delete);
-               delete.addActionListener(this);
+               action = new JCheckBox("", log.selected);
+               action.addActionListener(this);
        }
 }
 
@@ -86,7 +79,8 @@ public class AltosEepromSelect extends AltosDialog implements ActionListener {
        }
 
        public AltosEepromSelect (JFrame in_frame,
-                                 AltosEepromList flights) {
+                                 AltosEepromList flights,
+                                 String action) {
 
                super(in_frame, String.format("Flight list for serial %d", flights.config_data.serial), true);
                frame = in_frame;
@@ -95,7 +89,7 @@ public class AltosEepromSelect extends AltosDialog implements ActionListener {
                Container contentPane = getContentPane();
 
                /* First, we create a pane containing the dialog's header/title */
-               JLabel  selectLabel = new JLabel("Select flights to download and/or delete", SwingConstants.CENTER);
+               JLabel  selectLabel = new JLabel(String.format ("Select flights to %s", action), SwingConstants.CENTER);
 
                JPanel  labelPane = new JPanel();
                labelPane.setLayout(new BoxLayout(labelPane, BoxLayout.X_AXIS));
@@ -132,19 +126,9 @@ public class AltosEepromSelect extends AltosDialog implements ActionListener {
                c.weightx = 0.5;
                c.anchor = GridBagConstraints.CENTER;
                c.insets = i;
-               JLabel downloadHeaderLabel = new JLabel("Download");
+               JLabel downloadHeaderLabel = new JLabel(action);
                flightPane.add(downloadHeaderLabel, c);
 
-               /* Delete Header */
-               c = new GridBagConstraints();
-               c.gridx = 2; c.gridy = 0;
-               c.fill = GridBagConstraints.NONE;
-               c.weightx = 0.5;
-               c.anchor = GridBagConstraints.CENTER;
-               c.insets = i;
-               JLabel deleteHeaderLabel = new JLabel("Delete");
-               flightPane.add(deleteHeaderLabel, c);
-
                /* Add the flights to the GridBag */
                AltosEepromItem item;
                int itemNumber = 1;
@@ -163,23 +147,14 @@ public class AltosEepromSelect extends AltosDialog implements ActionListener {
                        c.insets = i;
                        flightPane.add(item.label, c);
 
-                       /* Add a download checkbox for the flight */
+                       /* Add action checkbox for the flight */
                        c = new GridBagConstraints();
                        c.gridx = 1; c.gridy = itemNumber;
                        c.fill = GridBagConstraints.NONE;
                        c.weightx = 0.5;
                        c.anchor = GridBagConstraints.CENTER;
                        c.insets = i;
-                       flightPane.add(item.download, c);
-
-                       /* Add a delete checkbox for the flight */
-                       c = new GridBagConstraints();
-                       c.gridx = 2; c.gridy = itemNumber;
-                       c.fill = GridBagConstraints.NONE;
-                       c.weightx = 0.5;
-                       c.anchor = GridBagConstraints.CENTER;
-                       c.insets = i;
-                       flightPane.add(item.delete, c);
+                       flightPane.add(item.action, c);
 
                        itemNumber++;
                }