summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2014-01-21 22:01:39 -0800
committerKeith Packard <keithp@keithp.com>2014-01-21 22:01:39 -0800
commit42922b40fc695bdaa92e3fb0b41a248f7df918d0 (patch)
tree3c4f2520a46c5ac9b9458a2988272464935eea88
parentf118e33416e45ea9a2b5ede4157bd8b58ddb6ebb (diff)
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 <keithp@keithp.com>
-rw-r--r--altosui/AltosIgniteUI.java25
1 files 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<String>();
reply_queue = new LinkedBlockingQueue<String>();
+ 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;
}