summaryrefslogtreecommitdiff
path: root/altosui/AltosLanded.java
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2014-06-12 14:12:08 -0700
committerKeith Packard <keithp@keithp.com>2014-06-12 14:12:08 -0700
commit8044eb8e23366e91c741060939baff5137f841c7 (patch)
tree82d8676369d840051b91a462859a3883bb678a80 /altosui/AltosLanded.java
parente00ffe6ab6197ab48ba8ce3cf71a197f7215649f (diff)
altosui/telegps: Reduce CPU time needed for flight displays
Don't update displays which aren't shown; track hierarchy changes to trigger display from most recent state data. Don't update values which haven't changed; remember previous values and compare with new before updating widget contents. Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'altosui/AltosLanded.java')
-rw-r--r--altosui/AltosLanded.java30
1 files changed, 28 insertions, 2 deletions
diff --git a/altosui/AltosLanded.java b/altosui/AltosLanded.java
index d2628fb0..760b2d64 100644
--- a/altosui/AltosLanded.java
+++ b/altosui/AltosLanded.java
@@ -24,14 +24,18 @@ import java.io.*;
import org.altusmetrum.altoslib_4.*;
import org.altusmetrum.altosuilib_2.*;
-public class AltosLanded extends JComponent implements AltosFlightDisplay, ActionListener {
+public class AltosLanded extends JComponent implements AltosFlightDisplay, ActionListener, HierarchyListener {
GridBagLayout layout;
+ private AltosState last_state;
+ private AltosListenerState last_listener_state;
+
public abstract class LandedValue implements AltosFontListener, AltosUnitsListener {
JLabel label;
JTextField value;
AltosUnits units;
double v;
+ String last_value = "";
abstract void show(AltosState state, AltosListenerState listener_state);
@@ -46,7 +50,10 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio
void show(String s) {
show();
- value.setText(s);
+ if (!last_value.equals(s)) {
+ value.setText(s);
+ last_value = s;
+ }
}
void show(double v) {
@@ -94,6 +101,7 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio
add(label);
value = new JTextField(Altos.text_width);
+ value.setEditable(false);
value.setFont(Altos.value_font);
value.setHorizontalAlignment(SwingConstants.RIGHT);
c.gridx = 1; c.gridy = y;
@@ -244,6 +252,12 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio
}
public void show(AltosState state, AltosListenerState listener_state) {
+ if (!isShowing()) {
+ last_state = state;
+ last_listener_state = listener_state;
+ return;
+ }
+
if (state.gps != null && state.gps.connected) {
bearing.show(state, listener_state);
distance.show(state, listener_state);
@@ -302,6 +316,17 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio
return "Landed";
}
+ public void hierarchyChanged(HierarchyEvent e) {
+ if (last_state != null && isShowing()) {
+ AltosState state = last_state;
+ AltosListenerState listener_state = last_listener_state;
+
+ last_state = null;
+ last_listener_state = null;
+ show(state, listener_state);
+ }
+ }
+
public AltosLanded(AltosFlightReader in_reader) {
layout = new GridBagLayout();
@@ -332,5 +357,6 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio
c.weighty = 0;
c.fill = GridBagConstraints.VERTICAL;
add(graph, c);
+ addHierarchyListener(this);
}
}