From 42922b40fc695bdaa92e3fb0b41a248f7df918d0 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 21 Jan 2014 22:01:39 -0800 Subject: [PATCH 1/1] altosui: Handle already-opened link in IgniteUI Must run the link open from the UI thread so that we can put up the in-use dialog immdiately; otherwise the UI thread is blocked which means the dialog never appears and the app appears to hang. Signed-off-by: Keith Packard --- altosui/AltosIgniteUI.java | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/altosui/AltosIgniteUI.java b/altosui/AltosIgniteUI.java index 9d063702..2e69249f 100644 --- a/altosui/AltosIgniteUI.java +++ b/altosui/AltosIgniteUI.java @@ -39,6 +39,7 @@ public class AltosIgniteUI javax.swing.Timer timer; JButton close; ButtonGroup group; + Boolean opened; int npyro; @@ -110,6 +111,7 @@ public class AltosIgniteUI class IgniteHandler implements Runnable { AltosIgnite ignite; JFrame owner; + AltosLink link; void send_exception(Exception e) { final Exception f_e = e; @@ -123,9 +125,7 @@ public class AltosIgniteUI public void run () { try { - AltosSerial serial = new AltosSerial(device); - serial.set_frame(owner); - ignite = new AltosIgnite(serial, + ignite = new AltosIgnite(link, !device.matchProduct(Altos.product_altimeter)); } catch (Exception e) { @@ -172,8 +172,9 @@ public class AltosIgniteUI } } - public IgniteHandler(JFrame in_owner) { + public IgniteHandler(JFrame in_owner, AltosLink in_link) { owner = in_owner; + link = in_link; } } @@ -307,8 +308,10 @@ public class AltosIgniteUI } void close() { - send_command("quit"); - timer.stop(); + if (opened) { + send_command("quit"); + timer.stop(); + } setVisible(false); dispose(); } @@ -382,12 +385,20 @@ public class AltosIgniteUI command_queue = new LinkedBlockingQueue(); reply_queue = new LinkedBlockingQueue(); + opened = false; device = AltosDeviceUIDialog.show(owner, Altos.product_any); if (device != null) { - IgniteHandler handler = new IgniteHandler(owner); + try { + AltosSerial serial = new AltosSerial(device); + serial.set_frame(owner); + IgniteHandler handler = new IgniteHandler(owner, serial); Thread t = new Thread(handler); t.start(); + opened = true; return true; + } catch (Exception ex) { + ignite_exception(ex); + } } return false; } -- 2.30.2