AltosEepromList flights;
AltosEepromDownload download;
AltosEepromDelete delete;
- boolean any_download;
- boolean any_delete;
public void finish() {
if (serial_line != null) {
String result = "";
for (AltosEepromLog flight : flights) {
- if (flight.delete) {
+ if (flight.selected) {
if (result.equals(""))
result = String.format("%d", flight.flight);
else
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,
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();
}
}
}
device = AltosDeviceDialog.show(frame, Altos.product_any);
remote = false;
- any_download = false;
- any_delete = false;
if (device != null) {
try {
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) {
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);
}
}
}
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;
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));
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;
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++;
}