diff options
| author | Keith Packard <keithp@keithp.com> | 2010-11-25 16:23:18 -0800 |
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2010-11-25 16:30:19 -0800 |
| commit | 7f88520089660845009148b69bfcea6c9dff9672 (patch) | |
| tree | c7e7e885a77379f9dd4d8a1a59d2c0cfe7c52965 /altosui/AltosEepromDownload.java | |
| parent | 6d3612e267cd4c1e7fdd74fc33952b3f26f870f5 (diff) | |
altosui: Flight data download GUI operations called only from main thread
Swing doesn't like UI functions being called from non-dispatch thread,
so fix up the eeprom download code to use SwingUtilities.invokeLater
to make sure this works right.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'altosui/AltosEepromDownload.java')
| -rw-r--r-- | altosui/AltosEepromDownload.java | 49 |
1 files changed, 34 insertions, 15 deletions
diff --git a/altosui/AltosEepromDownload.java b/altosui/AltosEepromDownload.java index 02fc36f2..e5ff766c 100644 --- a/altosui/AltosEepromDownload.java +++ b/altosui/AltosEepromDownload.java @@ -214,6 +214,27 @@ public class AltosEepromDownload implements Runnable { } } + private void show_error_internal(String message, String title) { + JOptionPane.showMessageDialog(frame, + message, + title, + JOptionPane.ERROR_MESSAGE); + } + + private void show_error(String in_message, String in_title) { + final String message = in_message; + final String title = in_title; + Runnable r = new Runnable() { + public void run() { + try { + show_error_internal(message, title); + } catch (Exception ex) { + } + } + }; + SwingUtilities.invokeLater(r); + } + public void run () { if (remote) { serial_line.set_radio(); @@ -221,26 +242,16 @@ public class AltosEepromDownload implements Runnable { serial_line.flush_input(); } - monitor = new AltosEepromMonitor(frame, Altos.ao_flight_boost, Altos.ao_flight_landed); - monitor.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - eeprom_thread.interrupt(); - } - }); try { CaptureLog(); } catch (IOException ee) { - JOptionPane.showMessageDialog(frame, - device.toShortString(), - ee.getLocalizedMessage(), - JOptionPane.ERROR_MESSAGE); + show_error (device.toShortString(), + ee.getLocalizedMessage()); } catch (InterruptedException ie) { } catch (TimeoutException te) { - JOptionPane.showMessageDialog(frame, - String.format("Connection to \"%s\" failed", - device.toShortString()), - "Connection Failed", - JOptionPane.ERROR_MESSAGE); + show_error (String.format("Connection to \"%s\" failed", + device.toShortString()), + "Connection Failed"); } if (remote) serial_line.printf("~"); @@ -260,6 +271,14 @@ public class AltosEepromDownload implements Runnable { serial_line = new AltosSerial(device); if (!device.matchProduct(AltosDevice.product_telemetrum)) remote = true; + monitor = new AltosEepromMonitor(frame, Altos.ao_flight_boost, Altos.ao_flight_landed); + monitor.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + if (eeprom_thread != null) + eeprom_thread.interrupt(); + } + }); + eeprom_thread = new Thread(this); eeprom_thread.start(); } catch (FileNotFoundException ee) { |
