X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altosui%2FAltosFlightStatus.java;h=207c44b48da275e086944f5b1dbef1521fb254e1;hp=7e7efa64d91a96621b7256c6905e6c676eb00085;hb=24db798925e26a4c411afe88f7e4844d6554fe0c;hpb=c8078d352a7f54a4a97d25af080155d3f875536a diff --git a/altosui/AltosFlightStatus.java b/altosui/AltosFlightStatus.java index 7e7efa64..207c44b4 100644 --- a/altosui/AltosFlightStatus.java +++ b/altosui/AltosFlightStatus.java @@ -3,7 +3,8 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of @@ -19,8 +20,8 @@ package altosui; import java.awt.*; import javax.swing.*; -import org.altusmetrum.altoslib_5.*; -import org.altusmetrum.altosuilib_3.*; +import org.altusmetrum.altoslib_13.*; +import org.altusmetrum.altosuilib_13.*; public class AltosFlightStatus extends JComponent implements AltosFlightDisplay { GridBagLayout layout; @@ -92,14 +93,14 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay } void show(AltosState state, AltosListenerState listener_state) { - if (!same_call(state.callsign)) { + if (!same_call(state.cal_data().callsign)) { show(); - value.setText(state.callsign); - if (state.callsign == null) + value.setText(state.cal_data().callsign); + if (state.cal_data().callsign == null) setVisible(false); else setVisible(true); - last_call = state.callsign; + last_call = state.cal_data().callsign; } } @@ -119,13 +120,14 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay int last_serial = -1; void show(AltosState state, AltosListenerState listener_state) { - if (state.serial != last_serial) { + AltosCalData cal_data = state.cal_data(); + if (cal_data.serial != last_serial) { show(); - if (state.serial == AltosLib.MISSING) + if (cal_data.serial == AltosLib.MISSING) value.setText("none"); else - value.setText(String.format("%d", state.serial)); - last_serial = state.serial; + value.setText(String.format("%d", cal_data.serial)); + last_serial = cal_data.serial; } } @@ -146,13 +148,14 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay int last_flight = -1; void show(AltosState state, AltosListenerState listener_state) { - if (state.flight != last_flight) { + AltosCalData cal_data = state.cal_data(); + if (cal_data.flight != last_flight) { show(); - if (state.flight == AltosLib.MISSING) + if (cal_data.flight == AltosLib.MISSING) value.setText("none"); else - value.setText(String.format("%d", state.flight)); - last_flight = state.flight; + value.setText(String.format("%d", cal_data.flight)); + last_flight = cal_data.flight; } } @@ -173,14 +176,14 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay int last_state = -1; void show(AltosState state, AltosListenerState listener_state) { - if (state.state != last_state) { - if (state.state == AltosLib.ao_flight_stateless) + if (state.state() != last_state) { + if (state.state() == AltosLib.ao_flight_stateless) hide(); else { show(); value.setText(state.state_name()); } - last_state = state.state; + last_state = state.state(); } } @@ -229,10 +232,14 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay long last_secs = -1; void show(AltosState state, AltosListenerState listener_state) { - long secs = (System.currentTimeMillis() - state.received_time + 500) / 1000; - if (secs != last_secs) { - value.setText(String.format("%d", secs)); - last_secs = secs; + if (listener_state.running) { + long secs = (System.currentTimeMillis() - state.received_time + 500) / 1000; + if (secs != last_secs) { + value.setText(String.format("%d", secs)); + last_secs = secs; + } + } else { + value.setText("done"); } } @@ -276,6 +283,8 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay flight_state.show(state, listener_state); rssi.show(state, listener_state); last_packet.show(state, listener_state); + if (!listener_state.running) + stop(); } public int height() { @@ -285,6 +294,22 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay public String getName() { return "Flight Status"; } + AltosFlightStatusUpdate status_update; + javax.swing.Timer timer; + + public void start(AltosFlightStatusUpdate status_update) { + this.status_update = status_update; + timer = new javax.swing.Timer(100, status_update); + timer.start(); + } + + public void stop() { + if (timer != null) { + timer.stop(); + timer = null; + } + } + public AltosFlightStatus() { layout = new GridBagLayout();