2 * Copyright © 2011 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 import java.awt.event.*;
23 import javax.swing.filechooser.FileNameExtensionFilter;
24 import javax.swing.table.*;
28 import java.util.prefs.*;
29 import java.util.concurrent.*;
33 public class AltosEepromManage implements ActionListener {
38 AltosSerial serial_line;
39 AltosEepromList flights;
40 AltosEepromDownload download;
41 AltosEepromDelete delete;
45 public void finish() {
46 if (serial_line != null) {
47 serial_line.flush_input();
53 private String showDeletedFlights() {
56 for (AltosEepromLog flight : flights) {
58 if (result.equals(""))
59 result = String.format("%d", flight.flight);
61 result = String.format("%s, %d", result, flight.flight);
67 public void actionPerformed(ActionEvent e) {
68 String cmd = e.getActionCommand();
69 boolean success = e.getID() != 0;
70 boolean running = false;
72 if (cmd.equals("download")) {
79 } else if (cmd.equals("delete")) {
81 JOptionPane.showMessageDialog(frame,
82 String.format("Flights erased: %s",
83 showDeletedFlights()),
84 serial_line.device.toShortString(),
85 JOptionPane.INFORMATION_MESSAGE);
92 public AltosEepromManage(JFrame given_frame) {
94 boolean running = false;
97 device = AltosDeviceDialog.show(frame, AltosDevice.product_any);
100 any_download = false;
103 if (device != null) {
105 serial_line = new AltosSerial(device);
106 if (!device.matchProduct(AltosDevice.product_telemetrum))
109 flights = new AltosEepromList(serial_line, remote);
111 if (flights.size() == 0) {
112 JOptionPane.showMessageDialog(frame,
113 String.format("No flights available on %d",
115 serial_line.device.toShortString(),
116 JOptionPane.INFORMATION_MESSAGE);
118 AltosEepromSelect select = new AltosEepromSelect(frame, flights);
121 for (AltosEepromLog flight : flights) {
122 any_download = any_download || flight.download;
123 any_delete = any_delete || flight.delete;
126 download = new AltosEepromDownload(frame,
130 download.addActionListener(this);
134 delete = new AltosEepromDelete(frame,
138 delete.addActionListener(this);
142 * Start flight log download
149 else if (any_delete) {
155 } catch (FileNotFoundException ee) {
156 JOptionPane.showMessageDialog(frame,
157 String.format("Cannot open device \"%s\"",
158 device.toShortString()),
159 "Cannot open target device",
160 JOptionPane.ERROR_MESSAGE);
161 } catch (AltosSerialInUseException si) {
162 JOptionPane.showMessageDialog(frame,
163 String.format("Device \"%s\" already in use",
164 device.toShortString()),
166 JOptionPane.ERROR_MESSAGE);
167 } catch (IOException ee) {
168 JOptionPane.showMessageDialog(frame,
169 device.toShortString(),
170 ee.getLocalizedMessage(),
171 JOptionPane.ERROR_MESSAGE);
172 } catch (TimeoutException te) {
173 JOptionPane.showMessageDialog(frame,
174 String.format("Communications failed with \"%s\"",
175 device.toShortString()),
176 "Cannot open target device",
177 JOptionPane.ERROR_MESSAGE);
178 } catch (InterruptedException ie) {