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() {
40 owner = owner.SetData(data);
41 MicroSave save = new MicroSave(owner, data);
43 owner.SetName(data.name);
49 Runnable r = new Runnable() {
53 } catch (Exception ex) {
57 SwingUtilities.invokeLater(r);
62 data = new MicroData(serial, device.toShortString());
64 } catch (FileNotFoundException fe) {
65 } catch (IOException ioe) {
66 } catch (InterruptedException ie) {
75 serial = new MicroSerial(device);
76 } catch (FileNotFoundException fe) {
79 serial_thread = new Thread(this);
80 serial_thread.start();
83 public void actionPerformed(ActionEvent ae) {
84 System.out.printf ("command %s\n", ae.getActionCommand());
85 if (serial_thread != null) {
86 System.out.printf ("Interrupting serial_thread\n");
88 serial_thread.interrupt();
92 public MicroDownload(MicroPeak owner, AltosDevice device) {
93 super (owner, "Download MicroPeak Data", false);
96 Insets il = new Insets(4,4,4,4);
97 Insets ir = new Insets(4,4,4,4);
100 this.device = device;
102 pane = getContentPane();
103 pane.setLayout(new GridBagLayout());
105 c = new GridBagConstraints();
106 c.gridx = 0; c.gridy = 0;
107 c.fill = GridBagConstraints.NONE;
108 c.anchor = GridBagConstraints.LINE_START;
110 JLabel device_label = new JLabel("Device:");
111 pane.add(device_label, c);
113 c = new GridBagConstraints();
114 c.gridx = 1; c.gridy = 0;
115 c.fill = GridBagConstraints.HORIZONTAL;
117 c.anchor = GridBagConstraints.LINE_START;
119 JLabel device_value = new JLabel(device.toString());
120 pane.add(device_value, c);
122 cancel = new JButton("Cancel");
123 c = new GridBagConstraints();
124 c.fill = GridBagConstraints.NONE;
125 c.anchor = GridBagConstraints.CENTER;
126 c.gridx = 0; c.gridy = 1;
127 c.gridwidth = GridBagConstraints.REMAINDER;
128 Insets ic = new Insets(4,4,4,4);
132 cancel.addActionListener(this);
135 setLocationRelativeTo(owner);