diff options
| author | Keith Packard <keithp@keithp.com> | 2015-02-14 01:11:30 -0800 | 
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2015-02-14 01:11:30 -0800 | 
| commit | 0e929ee2d0a3d1b1bacd36c2c3723ab860eb40b6 (patch) | |
| tree | 85072f46906c1aed41856be228b1ae291311df29 | |
| parent | f4c812bef76a2cd95f675cb27ea89059561ceec7 (diff) | |
altosui: Run all igniter status requests from non-GUI thread
Anything run from the UI thread blocks the UI entirely; the Fire
Igniters startup code to collect the number of pyro channels when
building the UI was doing that from the UI thread. Switch that around
so that the UI doesn't get built until that reply comes back, allowing
the user to see the 'connecting' dialog, and cancel it if required.
Signed-off-by: Keith Packard <keithp@keithp.com>
| -rw-r--r-- | altosui/AltosIgniteUI.java | 60 | 
1 files changed, 18 insertions, 42 deletions
diff --git a/altosui/AltosIgniteUI.java b/altosui/AltosIgniteUI.java index 944c659b..1a2dc4f1 100644 --- a/altosui/AltosIgniteUI.java +++ b/altosui/AltosIgniteUI.java @@ -50,8 +50,6 @@ public class AltosIgniteUI  	LinkedBlockingQueue<String>	command_queue; -	LinkedBlockingQueue<String>	reply_queue; -  	class Igniter {  		JRadioButton	button;  		JLabel		status_label; @@ -150,8 +148,7 @@ public class AltosIgniteUI  						}  						reply = "status";  					} else if (command.equals("get_npyro")) { -						put_reply(String.format("%d", ignite.npyro())); -						continue; +						reply = String.format("npyro %d", ignite.npyro());  					} else if (command.equals("quit")) {  						ignite.close();  						break; @@ -211,6 +208,9 @@ public class AltosIgniteUI  			set_ignite_status();  		} else if (reply.equals("fired")) {  			fired(); +		} else if (reply.startsWith("npyro")) { +			npyro = Integer.parseInt(reply.substring(6)); +			make_ui();  		}  	} @@ -250,24 +250,6 @@ public class AltosIgniteUI  		}  	} -	void put_reply(String reply) { -		try { -			reply_queue.put(reply); -		} catch (Exception ex) { -			ignite_exception(ex); -		} -	} - -	String get_reply() { -		String reply = ""; -		try { -			reply = reply_queue.take(); -		} catch (Exception ex) { -			ignite_exception(ex); -		} -		return reply; -	} -  	boolean	getting_status = false;  	boolean	visible = false; @@ -287,12 +269,6 @@ public class AltosIgniteUI  		}  	} -	int get_npyro() { -		send_command("get_npyro"); -		String reply = get_reply(); -		return Integer.parseInt(reply); -	} -  	boolean	firing = false;  	void start_fire(String which) { @@ -310,8 +286,9 @@ public class AltosIgniteUI  	void close() {  		if (opened) {  			send_command("quit"); -			timer.stop();  		} +		if (timer != null) +			timer.stop();  		setVisible(false);  		dispose();  	} @@ -383,7 +360,6 @@ public class AltosIgniteUI  	private boolean open() {  		command_queue = new LinkedBlockingQueue<String>(); -		reply_queue = new LinkedBlockingQueue<String>();  		opened = false;  		device = AltosDeviceUIDialog.show(owner, Altos.product_any); @@ -403,13 +379,7 @@ public class AltosIgniteUI  		return false;  	} -	public AltosIgniteUI(JFrame in_owner) { - -		owner = in_owner; - -		if (!open()) -			return; - +	private void make_ui() {  		group = new ButtonGroup();  		Container		pane = getContentPane(); @@ -422,8 +392,6 @@ public class AltosIgniteUI  		timer_running = false;  		timer.restart(); -		owner = in_owner; -  		pane.setLayout(new GridBagLayout());  		c.fill = GridBagConstraints.NONE; @@ -443,8 +411,6 @@ public class AltosIgniteUI  		y++; -		int npyro = get_npyro(); -  		igniters = new Igniter[2 + npyro];  		igniters[0] = new Igniter(this, "Apogee", AltosIgnite.Apogee, y++); @@ -492,4 +458,14 @@ public class AltosIgniteUI  		addWindowListener(new ConfigListener(this));  	} -}
\ No newline at end of file + +	public AltosIgniteUI(JFrame in_owner) { + +		owner = in_owner; + +		if (!open()) +			return; + +		send_command("get_npyro"); +	} +}  | 
