altosui: When replay thread is interrupted, don't make final report
authorKeith Packard <keithp@keithp.com>
Sun, 5 Sep 2010 08:08:50 +0000 (01:08 -0700)
committerKeith Packard <keithp@keithp.com>
Sun, 5 Sep 2010 08:08:50 +0000 (01:08 -0700)
Normally, the replay process makes one final report after the file has
been parsed. However, if the reading process is interrupted to display
something else, this report is just annoying, so don't make it.

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

index 6a1814ff87034fad92f922779f925b2f10aa81e1..4915376645d71ca5543d4d87a5e3af8b331cfaf3 100644 (file)
@@ -384,11 +384,12 @@ public class AltosUI extends JFrame {
 
                AltosRecord read() throws InterruptedException, ParseException, AltosCRCException, IOException { return null; }
 
-               void close() { }
+               void close(boolean interrupted) { }
 
                void update(AltosState state) throws InterruptedException { }
 
                public void run() {
+                       boolean         interrupted = false;
                        String          line;
                        AltosState      state = null;
                        AltosState      old_state = null;
@@ -418,14 +419,18 @@ public class AltosUI extends JFrame {
                                        }
                                }
                        } catch (InterruptedException ee) {
+                               interrupted = true;
                        } catch (IOException ie) {
                                JOptionPane.showMessageDialog(AltosUI.this,
                                                              String.format("Error reading from \"%s\"", name),
                                                              "Telemetry Read Error",
                                                              JOptionPane.ERROR_MESSAGE);
                        } finally {
-                               close();
+                               close(interrupted);
                                idle_thread.interrupt();
+                               try {
+                                       idle_thread.join();
+                               } catch (InterruptedException ie) {}
                        }
                }
 
@@ -446,7 +451,7 @@ public class AltosUI extends JFrame {
                        return new AltosTelemetry(l.line);
                }
 
-               void close() {
+               void close(boolean interrupted) {
                        serial.close();
                        serial.remove_monitor(telem);
                }
@@ -530,8 +535,9 @@ public class AltosUI extends JFrame {
                        return null;
                }
 
-               public void close () {
-                       report();
+               public void close (boolean interrupted) {
+                       if (!interrupted)
+                               report();
                }
 
                public ReplayThread(AltosReader in_reader, String in_name) {