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 void got_flights(AltosEepromList in_flights) {
93 boolean running = false;;
97 if (flights.size() == 0) {
98 JOptionPane.showMessageDialog(frame,
99 String.format("No flights available on %d",
101 serial_line.device.toShortString(),
102 JOptionPane.INFORMATION_MESSAGE);
104 AltosEepromSelect select = new AltosEepromSelect(frame, flights);
107 for (AltosEepromLog flight : flights) {
108 any_download = any_download || flight.download;
109 any_delete = any_delete || flight.delete;
112 download = new AltosEepromDownload(frame,
116 download.addActionListener(this);
120 delete = new AltosEepromDelete(frame,
124 delete.addActionListener(this);
128 * Start flight log download
135 else if (any_delete) {
143 } catch (Exception e) {
148 public void got_exception(Exception e) {
149 if (e instanceof IOException) {
150 IOException ee = (IOException) e;
151 JOptionPane.showMessageDialog(frame,
152 device.toShortString(),
153 ee.getLocalizedMessage(),
154 JOptionPane.ERROR_MESSAGE);
155 } else if (e instanceof TimeoutException) {
156 TimeoutException te = (TimeoutException) e;
157 JOptionPane.showMessageDialog(frame,
158 String.format("Communications failed with \"%s\"",
159 device.toShortString()),
160 "Cannot open target device",
161 JOptionPane.ERROR_MESSAGE);
166 class EepromGetList implements Runnable {
168 AltosEepromManage manage;
173 flights = new AltosEepromList(serial_line, remote);
176 got_flights(flights);
179 } catch (Exception e) {
180 final Exception f_e = e;
187 SwingUtilities.invokeLater(r);
190 public EepromGetList(AltosEepromManage in_manage) {
195 public AltosEepromManage(JFrame given_frame) {
197 boolean running = false;
200 device = AltosDeviceDialog.show(frame, Altos.product_any);
203 any_download = false;
206 if (device != null) {
208 serial_line = new AltosSerial(device);
209 if (device.matchProduct(Altos.product_basestation))
212 serial_line.set_frame(frame);
214 EepromGetList get_list = new EepromGetList(this);
215 Thread t = new Thread(get_list);
217 } catch (FileNotFoundException ee) {
218 JOptionPane.showMessageDialog(frame,
219 String.format("Cannot open device \"%s\"",
220 device.toShortString()),
221 "Cannot open target device",
222 JOptionPane.ERROR_MESSAGE);
223 } catch (AltosSerialInUseException si) {
224 JOptionPane.showMessageDialog(frame,
225 String.format("Device \"%s\" already in use",
226 device.toShortString()),
228 JOptionPane.ERROR_MESSAGE);