X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=altosui%2FAltosDisplayThread.java;h=03ce4efda1d918e88c693e9378bfd0795c08ac45;hb=675ccd41e3b668cd4e1d2dd282dd317a00d00151;hp=3e719130a6a7c67475f41d98a8740b9904e66e01;hpb=51c7741040d95c5deece939dae5e4136cc04afc4;p=fw%2Faltos diff --git a/altosui/AltosDisplayThread.java b/altosui/AltosDisplayThread.java index 3e719130..03ce4efd 100644 --- a/altosui/AltosDisplayThread.java +++ b/altosui/AltosDisplayThread.java @@ -27,22 +27,55 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.LinkedBlockingQueue; +import org.altusmetrum.AltosLib.*; public class AltosDisplayThread extends Thread { Frame parent; IdleThread idle_thread; AltosVoice voice; - String name; AltosFlightReader reader; int crc_errors; AltosFlightDisplay display; - synchronized void show(AltosState state, int crc_errors) { + void show_internal(AltosState state, int crc_errors) { if (state != null) display.show(state, crc_errors); } + void show_safely(AltosState in_state, int in_crc_errors) { + final AltosState state = in_state; + final int crc_errors = in_crc_errors; + Runnable r = new Runnable() { + public void run() { + try { + show_internal(state, crc_errors); + } catch (Exception ex) { + } + } + }; + SwingUtilities.invokeLater(r); + } + + void reading_error_internal() { + JOptionPane.showMessageDialog(parent, + String.format("Error reading from \"%s\"", reader.name), + "Telemetry Read Error", + JOptionPane.ERROR_MESSAGE); + } + + void reading_error_safely() { + Runnable r = new Runnable() { + public void run() { + try { + reading_error_internal(); + } catch (Exception ex) { + } + } + }; + SwingUtilities.invokeLater(r); + } + class IdleThread extends Thread { boolean started; @@ -102,7 +135,7 @@ public class AltosDisplayThread extends Thread { ++reported_landing; if (state.state != Altos.ao_flight_landed) { state.state = Altos.ao_flight_landed; - show(state, 0); + show_safely(state, 0); } } } @@ -202,7 +235,6 @@ public class AltosDisplayThread extends Thread { idle_thread = new IdleThread(); - display.reset(); try { for (;;) { try { @@ -212,23 +244,20 @@ public class AltosDisplayThread extends Thread { old_state = state; state = new AltosState(record, state); reader.update(state); - show(state, crc_errors); + show_safely(state, crc_errors); told = tell(state, old_state); idle_thread.notice(state, told); } catch (ParseException pp) { System.out.printf("Parse error: %d \"%s\"\n", pp.getErrorOffset(), pp.getMessage()); } catch (AltosCRCException ce) { ++crc_errors; - show(state, crc_errors); + show_safely(state, crc_errors); } } } catch (InterruptedException ee) { interrupted = true; } catch (IOException ie) { - JOptionPane.showMessageDialog(parent, - String.format("Error reading from \"%s\"", name), - "Telemetry Read Error", - JOptionPane.ERROR_MESSAGE); + reading_error_safely(); } finally { if (!interrupted) idle_thread.report(true); @@ -245,5 +274,6 @@ public class AltosDisplayThread extends Thread { voice = in_voice; display = in_display; reader = in_reader; + display.reset(); } }