summaryrefslogtreecommitdiff
path: root/altosui
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2015-02-07 14:43:11 -0800
committerKeith Packard <keithp@keithp.com>2015-02-07 14:43:11 -0800
commite70f3dca01b15b75b0b8795eb71bd12817af4800 (patch)
tree7958f178d7456fc4d66f196ac1f31f7c0f4d106e /altosui
parent08f07d0af123e1c307bc4c0c973da07fae8246b1 (diff)
altoslib: Mark listener as 'not running' on EOF.
This adds a 'running' member to the AltosListenerState class, and when the replay reader reaches EOF, marks the listener as no longer running. AltosUI and TeleGPS now display 'done' in the 'Age' field when this occurs, to let the user know that the replay is over. Also make sure that the display timers are stopped when this happens, or when the window is closed. Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'altosui')
-rw-r--r--altosui/AltosFlightStatus.java30
-rw-r--r--altosui/AltosFlightUI.java10
2 files changed, 32 insertions, 8 deletions
diff --git a/altosui/AltosFlightStatus.java b/altosui/AltosFlightStatus.java
index 7e7efa64..a847d884 100644
--- a/altosui/AltosFlightStatus.java
+++ b/altosui/AltosFlightStatus.java
@@ -229,10 +229,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 +280,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 +291,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();
diff --git a/altosui/AltosFlightUI.java b/altosui/AltosFlightUI.java
index 6af345ea..d7c8223e 100644
--- a/altosui/AltosFlightUI.java
+++ b/altosui/AltosFlightUI.java
@@ -97,6 +97,7 @@ public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay {
public void show(AltosState state, AltosListenerState listener_state) {
status_update.saved_state = state;
+ status_update.saved_listener_state = listener_state;
if (state == null)
state = new AltosState();
@@ -335,9 +336,14 @@ public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay {
AltosUIPreferences.register_font_listener(this);
AltosPreferences.register_units_listener(this);
+ status_update = new AltosFlightStatusUpdate(flightStatus);
+
+ flightStatus.start(status_update);
+
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
+ flightStatus.stop();
disconnect();
setVisible(false);
dispose();
@@ -353,10 +359,6 @@ public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay {
thread = new AltosDisplayThread(this, voice, this, reader);
- status_update = new AltosFlightStatusUpdate(flightStatus);
-
- new javax.swing.Timer(100, status_update).start();
-
thread.start();
}