import java.text.*;
import java.util.prefs.*;
import java.util.concurrent.*;
+import org.altusmetrum.AltosLib.*;
import libaltosJNI.*;
AltosEepromList flights;
AltosEepromDownload download;
AltosEepromDelete delete;
- boolean any_download;
- boolean any_delete;
public void finish() {
if (serial_line != null) {
- serial_line.flush_input();
+ try {
+ serial_line.flush_input();
+ } catch (InterruptedException ie) {
+ }
serial_line.close();
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();
}
}
}
AltosEepromManage manage;
public void run () {
+ Runnable r;
try {
flights = new AltosEepromList(serial_line, remote);
- Runnable r = new Runnable() {
+ r = new Runnable() {
public void run() {
- manage.got_flights(flights);
+ got_flights(flights);
}
};
- SwingUtilities.invokeLater(r);
} catch (Exception e) {
- manage.got_exception(e);
+ final Exception f_e = e;
+ r = new Runnable() {
+ public void run() {
+ got_exception(f_e);
+ }
+ };
}
+ SwingUtilities.invokeLater(r);
}
public EepromGetList(AltosEepromManage in_manage) {
boolean running = false;
frame = given_frame;
- device = AltosDeviceDialog.show(frame, AltosDevice.product_any);
+ device = AltosDeviceDialog.show(frame, Altos.product_any);
remote = false;
- any_download = false;
- any_delete = false;
if (device != null) {
try {
serial_line = new AltosSerial(device);
- if (!device.matchProduct(AltosDevice.product_telemetrum))
+ if (device.matchProduct(Altos.product_basestation))
remote = true;
serial_line.set_frame(frame);
t.start();
} catch (FileNotFoundException ee) {
JOptionPane.showMessageDialog(frame,
- String.format("Cannot open device \"%s\"",
- device.toShortString()),
+ ee.getMessage(),
"Cannot open target device",
JOptionPane.ERROR_MESSAGE);
} catch (AltosSerialInUseException si) {