2 * Copyright © 2012 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.
18 package org.altusmetrum.micropeak;
21 import java.awt.event.*;
24 import java.util.concurrent.*;
26 import org.altusmetrum.AltosLib.*;
27 import org.altusmetrum.altosuilib.*;
29 public class MicroDownload extends AltosUIDialog implements Runnable, ActionListener {
37 private void done_internal() {
41 owner = owner.SetData(data);
42 MicroSave save = new MicroSave(owner, data);
44 owner.SetName(data.name);
46 JOptionPane.showMessageDialog(owner,
47 "Flight data corrupted",
49 JOptionPane.ERROR_MESSAGE);
56 Runnable r = new Runnable() {
60 } catch (Exception ex) {
64 SwingUtilities.invokeLater(r);
69 data = new MicroData(serial, device.toShortString());
71 } catch (FileNotFoundException fe) {
72 } catch (IOException ioe) {
73 } catch (InterruptedException ie) {
82 serial = new MicroSerial(device);
83 } catch (FileNotFoundException fe) {
86 serial_thread = new Thread(this);
87 serial_thread.start();
90 public void actionPerformed(ActionEvent ae) {
91 if (serial_thread != null) {
93 serial_thread.interrupt();
97 public MicroDownload(MicroPeak owner, AltosDevice device) {
98 super (owner, "Download MicroPeak Data", false);
100 GridBagConstraints c;
101 Insets il = new Insets(4,4,4,4);
102 Insets ir = new Insets(4,4,4,4);
105 this.device = device;
107 pane = getContentPane();
108 pane.setLayout(new GridBagLayout());
110 c = new GridBagConstraints();
111 c.gridx = 0; c.gridy = 0;
112 c.fill = GridBagConstraints.NONE;
113 c.anchor = GridBagConstraints.LINE_START;
115 JLabel device_label = new JLabel("Device:");
116 pane.add(device_label, c);
118 c = new GridBagConstraints();
119 c.gridx = 1; c.gridy = 0;
120 c.fill = GridBagConstraints.HORIZONTAL;
122 c.anchor = GridBagConstraints.LINE_START;
124 JLabel device_value = new JLabel(device.toString());
125 pane.add(device_value, c);
127 cancel = new JButton("Cancel");
128 c = new GridBagConstraints();
129 c.fill = GridBagConstraints.NONE;
130 c.anchor = GridBagConstraints.CENTER;
131 c.gridx = 0; c.gridy = 1;
132 c.gridwidth = GridBagConstraints.REMAINDER;
133 Insets ic = new Insets(4,4,4,4);
137 cancel.addActionListener(this);
140 setLocationRelativeTo(owner);