altosui: With --replay option, exit when replay window is closed
authorKeith Packard <keithp@keithp.com>
Sun, 14 Nov 2010 11:26:57 +0000 (03:26 -0800)
committerKeith Packard <keithp@keithp.com>
Sun, 14 Nov 2010 11:26:57 +0000 (03:26 -0800)
Otherwise, the application hangs around forever.

Signed-off-by: Keith Packard <keithp@keithp.com>
ao-tools/altosui/AltosFlightUI.java
ao-tools/altosui/AltosUI.java

index ae31048d2648754573d879cb863a65714f214204..5134a24ebd731ed09533e2c1f1e05bcf3f9866a8 100644 (file)
@@ -56,6 +56,8 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay {
 
        int cur_tab = 0;
 
 
        int cur_tab = 0;
 
+       boolean exit_on_close = false;
+
        int which_tab(AltosState state) {
                if (state.state < Altos.ao_flight_boost)
                        return tab_pad;
        int which_tab(AltosState state) {
                if (state.state < Altos.ao_flight_boost)
                        return tab_pad;
@@ -122,8 +124,12 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay {
                flightInfo.show(state, crc_errors);
        }
 
                flightInfo.show(state, crc_errors);
        }
 
+       public void set_exit_on_close() {
+               exit_on_close = true;
+       }
+
        public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) {
        public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) {
-        AltosPreferences.init(this);
+               AltosPreferences.init(this);
 
                voice = in_voice;
                reader = in_reader;
 
                voice = in_voice;
                reader = in_reader;
@@ -191,6 +197,8 @@ public class AltosFlightUI extends JFrame implements AltosFlightDisplay {
                                disconnect();
                                setVisible(false);
                                dispose();
                                disconnect();
                                setVisible(false);
                                dispose();
+                               if (exit_on_close)
+                                       System.exit(0);
                        }
                });
 
                        }
                });
 
index 0d8f0e8d30d48bb6ca89c09e47a555495bd37929..a2e416bad59308548b9099baa927e7e3817dff81 100644 (file)
@@ -443,26 +443,27 @@ public class AltosUI extends JFrame {
        public static void main(final String[] args) {
                int     process = 0;
                /* Handle batch-mode */
        public static void main(final String[] args) {
                int     process = 0;
                /* Handle batch-mode */
-        if (args.length == 2 && args[0].equals("--replay")) {
-            String filename = args[1];
-            FileInputStream in;
-            try {
-                in = new FileInputStream(filename);
-            } catch (Exception e) {
-                System.out.printf("Failed to open file '%s'\n", filename);
-                return;
-            }
-            AltosRecordIterable recs;
-            AltosReplayReader reader;
-            if (filename.endsWith("eeprom")) {
-              recs = new AltosEepromIterable(in);
-            } else {
-              recs = new AltosTelemetryIterable(in); 
-            }
-            reader = new AltosReplayReader(recs.iterator(), filename);
-            new AltosFlightUI(new AltosVoice(), reader);
-            return;
-        } else if (args.length > 0) {
+               if (args.length == 2 && args[0].equals("--replay")) {
+                       String filename = args[1];
+                       FileInputStream in;
+                       try {
+                               in = new FileInputStream(filename);
+                       } catch (Exception e) {
+                               System.out.printf("Failed to open file '%s'\n", filename);
+                               return;
+                       }
+                       AltosRecordIterable recs;
+                       AltosReplayReader reader;
+                       if (filename.endsWith("eeprom")) {
+                               recs = new AltosEepromIterable(in);
+                       } else {
+                               recs = new AltosTelemetryIterable(in);
+                       }
+                       reader = new AltosReplayReader(recs.iterator(), filename);
+                       AltosFlightUI flight_ui = new AltosFlightUI(new AltosVoice(), reader);
+                       flight_ui.set_exit_on_close();
+                       return;
+               } else if (args.length > 0) {
                        for (int i = 0; i < args.length; i++) {
                                if (args[i].equals("--kml"))
                                        process |= process_kml;
                        for (int i = 0; i < args.length; i++) {
                                if (args[i].equals("--kml"))
                                        process |= process_kml;