X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altosui%2FAltosIgniteUI.java;h=84dc54dbe52e6d42c13843caf093e3208ed5cd75;hp=2e69249f42771db2c9d5854e5d64da8583002def;hb=40abb0d1e2f43a60ffa34b055ebb913ee3e20faf;hpb=42922b40fc695bdaa92e3fb0b41a248f7df918d0 diff --git a/altosui/AltosIgniteUI.java b/altosui/AltosIgniteUI.java index 2e69249f..84dc54db 100644 --- a/altosui/AltosIgniteUI.java +++ b/altosui/AltosIgniteUI.java @@ -24,8 +24,8 @@ import java.io.*; import java.text.*; import java.util.*; import java.util.concurrent.*; -import org.altusmetrum.altoslib_3.*; -import org.altusmetrum.altosuilib_1.*; +import org.altusmetrum.altoslib_11.*; +import org.altusmetrum.altosuilib_11.*; public class AltosIgniteUI extends AltosUIDialog @@ -48,9 +48,9 @@ public class AltosIgniteUI int time_remaining; boolean timer_running; - LinkedBlockingQueue command_queue; + int poll_remaining; - LinkedBlockingQueue reply_queue; + LinkedBlockingQueue command_queue; class Igniter { JRadioButton button; @@ -150,8 +150,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 +210,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,30 +252,13 @@ 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; void set_ignite_status() { getting_status = false; + poll_remaining = 2; if (!visible) { visible = true; setVisible(true); @@ -281,18 +266,16 @@ public class AltosIgniteUI } void poll_ignite_status() { + if (poll_remaining > 0) { + --poll_remaining; + return; + } if (!getting_status) { getting_status = true; send_command("get_status"); } } - 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 +293,9 @@ public class AltosIgniteUI void close() { if (opened) { send_command("quit"); - timer.stop(); } + if (timer != null) + timer.stop(); setVisible(false); dispose(); } @@ -383,7 +367,6 @@ public class AltosIgniteUI private boolean open() { command_queue = new LinkedBlockingQueue(); - reply_queue = new LinkedBlockingQueue(); opened = false; device = AltosDeviceUIDialog.show(owner, Altos.product_any); @@ -403,13 +386,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 +399,6 @@ public class AltosIgniteUI timer_running = false; timer.restart(); - owner = in_owner; - pane.setLayout(new GridBagLayout()); c.fill = GridBagConstraints.NONE; @@ -443,8 +418,6 @@ public class AltosIgniteUI y++; - int npyro = get_npyro(); - igniters = new Igniter[2 + npyro]; igniters[0] = new Igniter(this, "Apogee", AltosIgnite.Apogee, y++); @@ -486,10 +459,20 @@ public class AltosIgniteUI pane.add(close, c); close.addActionListener(this); close.setActionCommand("close"); - + pack(); setLocationRelativeTo(owner); 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"); + } +}