telegps: Add status tab
authorKeith Packard <keithp@keithp.com>
Fri, 13 Jun 2014 22:23:30 +0000 (15:23 -0700)
committerKeith Packard <keithp@keithp.com>
Fri, 13 Jun 2014 22:23:30 +0000 (15:23 -0700)
This includes pad-relative information, battery voltage and version information

Signed-off-by: Keith Packard <keithp@keithp.com>
telegps/Makefile.am
telegps/TeleGPS.java
telegps/TeleGPSInfo.java
telegps/TeleGPSState.java [new file with mode: 0644]

index e0d596e798e42fdbfc00775e31abc12ddaaa5b13..31bcbd7962d8694e70e7348bc4441cbe66b21dab 100644 (file)
@@ -16,6 +16,7 @@ telegps_JAVA= \
        TeleGPSStatus.java \
        TeleGPSStatusUpdate.java \
        TeleGPSInfo.java \
        TeleGPSStatus.java \
        TeleGPSStatusUpdate.java \
        TeleGPSInfo.java \
+       TeleGPSState.java \
        TeleGPSConfig.java \
        TeleGPSConfigUI.java \
        TeleGPSPreferences.java \
        TeleGPSConfig.java \
        TeleGPSConfigUI.java \
        TeleGPSPreferences.java \
index 1898a668057b363751bb448b74433598407134aa..307b56103091254848b3696dca027ab31adc657a 100644 (file)
@@ -69,6 +69,7 @@ public class TeleGPS
 
        AltosUIMap              map;
        TeleGPSInfo             gps_info;
 
        AltosUIMap              map;
        TeleGPSInfo             gps_info;
+       TeleGPSState            gps_state;
        AltosInfoTable          info_table;
 
        LinkedList<AltosFlightDisplay>  displays;
        AltosInfoTable          info_table;
 
        LinkedList<AltosFlightDisplay>  displays;
@@ -444,13 +445,17 @@ public class TeleGPS
                bag.add(pane, c);
 
                map = new AltosUIMap();
                bag.add(pane, c);
 
                map = new AltosUIMap();
-               pane.add("Map", map);
+               pane.add(map.getName(), map);
                displays.add(map);
 
                gps_info = new TeleGPSInfo();
                displays.add(map);
 
                gps_info = new TeleGPSInfo();
-               pane.add("Info", gps_info);
+               pane.add(gps_info.getName(), gps_info);
                displays.add(gps_info);
 
                displays.add(gps_info);
 
+               gps_state = new TeleGPSState();
+               pane.add(gps_state.getName(), gps_state);
+               displays.add(gps_state);
+
                info_table = new AltosInfoTable();
                pane.add("Table", info_table);
                displays.add(info_table);
                info_table = new AltosInfoTable();
                pane.add("Table", info_table);
                displays.add(info_table);
index 15eb9b75e4fb71628c577d4fa035d03809bdf457..bbf4b47265e1d97eb3f34d6d6b977c857deba962 100644 (file)
@@ -17,6 +17,7 @@
 
 package org.altusmetrum.telegps;
 
 
 package org.altusmetrum.telegps;
 
+import java.util.*;
 import java.awt.*;
 import java.awt.event.*;
 import javax.swing.*;
 import java.awt.*;
 import java.awt.event.*;
 import javax.swing.*;
@@ -24,420 +25,76 @@ import org.altusmetrum.altoslib_4.*;
 import org.altusmetrum.altosuilib_2.*;
 
 public class TeleGPSInfo extends JComponent implements AltosFlightDisplay, HierarchyListener {
 import org.altusmetrum.altosuilib_2.*;
 
 public class TeleGPSInfo extends JComponent implements AltosFlightDisplay, HierarchyListener {
-       GridBagLayout   layout;
-       JLabel                  cur, max;
+
+       JLabel                          cur, max;
 
        private AltosState              last_state;
        private AltosListenerState      last_listener_state;
 
 
        private AltosState              last_state;
        private AltosListenerState      last_listener_state;
 
-       public abstract class Info implements AltosFontListener, AltosUnitsListener {
-               JLabel          label;
-               JTextField      value;
-               AltosLights     lights;
-               double          v;
-               AltosUnits      units;
-
-               void show() {
-                       value.setVisible(true);
-                       lights.setVisible(true);
-                       label.setVisible(true);
-               }
-
-               void hide() {
-                       value.setVisible(false);
-                       lights.setVisible(false);
-                       label.setVisible(false);
-               }
-
-               abstract void show(AltosState state, AltosListenerState listener_state);
-
-               void show(String s) {
-                       show();
-                       value.setText(s);
-               }
-
-               void show(double v) {
-                       this.v = v;
-                       show(units.show(8, v));
-               }
-
-               void show(String format, double v) {
-                       show(String.format(format, v));
-               }
-
-               void show(String format, int v) {
-                       show(String.format(format, v));
-               }
-
-               void reset() {
-                       lights.set(false);
-                       value.setText("");
-               }
-
-               public void font_size_changed(int font_size) {
-                       label.setFont(AltosUILib.label_font);
-                       value.setFont(AltosUILib.value_font);
-               }
+       abstract class Value extends AltosUIUnitsIndicator {
+               public abstract void show(AltosState state, AltosListenerState listener_state);
 
 
-               public void units_changed(boolean imperial_units) {
-                       if (units != null)
-                               show(v);
-               }
-
-               public Info (GridBagLayout layout, int y, AltosUnits units, String text) {
-                       this.units = units;
-
-                       GridBagConstraints      c = new GridBagConstraints();
-                       c.weighty = 1;
-
-                       lights = new AltosLights();
-                       c.gridx = 0; c.gridy = y;
-                       c.anchor = GridBagConstraints.CENTER;
-                       c.fill = GridBagConstraints.VERTICAL;
-                       c.weightx = 0;
-                       layout.setConstraints(lights, c);
-                       add(lights);
-
-                       label = new JLabel(text);
-                       label.setFont(AltosUILib.label_font);
-                       label.setHorizontalAlignment(SwingConstants.LEFT);
-                       c.gridx = 1; c.gridy = y;
-                       c.insets = new Insets(AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad);
-                       c.anchor = GridBagConstraints.WEST;
-                       c.fill = GridBagConstraints.VERTICAL;
-                       c.weightx = 0;
-                       layout.setConstraints(label, c);
-                       add(label);
-
-                       value = new JTextField(AltosUILib.text_width);
-                       value.setFont(AltosUILib.value_font);
-                       value.setHorizontalAlignment(SwingConstants.RIGHT);
-                       c.gridx = 2; c.gridy = y;
-                       c.gridwidth = 2;
-                       c.anchor = GridBagConstraints.WEST;
-                       c.fill = GridBagConstraints.BOTH;
-                       c.weightx = 1;
-                       layout.setConstraints(value, c);
-                       add(value);
-               }
-
-               public Info (GridBagLayout layout, int y, String text) {
-                       this(layout, y, null, text);
+               public Value (Container container, int y, AltosUnits units, String text) {
+                       super(container, y, units, text, 1, false, 2);
                }
        }
 
                }
        }
 
-       public abstract class Value implements AltosFontListener, AltosUnitsListener {
-               JLabel          label;
-               JTextField      value;
-               AltosUnits      units;
-               double          v = AltosLib.MISSING;
-
-               abstract void show(AltosState state, AltosListenerState listener_state);
-
-               void reset() {
-                       value.setText("");
-               }
-
-               void show() {
-                       label.setVisible(true);
-                       value.setVisible(true);
-               }
-
-               void show(String s) {
-                       show();
-                       value.setText(s);
-               }
-
-               void show(double v) {
-                       this.v = v;
-                       show(units.show(8, v));
-               }
-
-               void show(String format, double v) {
-                       show(String.format(format, v));
-               }
-
-               void hide() {
-                       label.setVisible(false);
-                       value.setVisible(false);
-               }
-               public void font_size_changed(int font_size) {
-                       label.setFont(AltosUILib.label_font);
-                       value.setFont(AltosUILib.value_font);
-               }
-               public void units_changed(boolean imperial_units) {
-                       if (units != null)
-                               show(v);
-               }
-
-               public Value (GridBagLayout layout, int y, String text) {
-                       GridBagConstraints      c = new GridBagConstraints();
-                       c.weighty = 1;
-
-                       label = new JLabel(text);
-                       label.setFont(AltosUILib.label_font);
-                       label.setHorizontalAlignment(SwingConstants.LEFT);
-                       c.gridx = 1; c.gridy = y;
-                       c.insets = new Insets(AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad);
-                       c.anchor = GridBagConstraints.WEST;
-                       c.fill = GridBagConstraints.VERTICAL;
-                       c.weightx = 0;
-                       layout.setConstraints(label, c);
-                       add(label);
-
-                       value = new JTextField(AltosUILib.text_width);
-                       value.setFont(AltosUILib.value_font);
-                       value.setHorizontalAlignment(SwingConstants.RIGHT);
-                       c.gridx = 2; c.gridy = y;
-                       c.anchor = GridBagConstraints.WEST;
-                       c.fill = GridBagConstraints.BOTH;
-                       c.gridwidth = 2;
-                       c.weightx = 1;
-                       layout.setConstraints(value, c);
-                       add(value);
+       abstract class DualValue extends AltosUIUnitsIndicator {
+               public DualValue (Container container, int y, AltosUnits units, String text) {
+                       super(container, y, units, text, 2, false, 1);
                }
        }
 
                }
        }
 
-       public abstract class DualValue implements AltosFontListener, AltosUnitsListener {
-               AltosLights     lights;
-               JLabel          label;
-               JTextField      value1;
-               JTextField      value2;
-
-               void reset() {
-                       if (lights != null)
-                               lights.set(false);
-                       value1.setText("");
-                       value2.setText("");
-               }
-
-               void show() {
-                       if (lights != null)
-                               lights.setVisible(true);
-                       label.setVisible(true);
-                       value1.setVisible(true);
-                       value2.setVisible(true);
-               }
-
-               void hide() {
-                       if (lights != null)
-                               lights.setVisible(false);
-                       label.setVisible(false);
-                       value1.setVisible(false);
-                       value2.setVisible(false);
-               }
-
-               public void font_size_changed(int font_size) {
-                       label.setFont(AltosUILib.label_font);
-                       value1.setFont(AltosUILib.value_font);
-                       value2.setFont(AltosUILib.value_font);
-               }
-
-               public void units_changed(boolean imperial_units) {
-               }
-
-               abstract void show(AltosState state, AltosListenerState listener_state);
-
-               void show(String v1, String v2) {
-                       show();
-                       value1.setText(v1);
-                       value2.setText(v2);
-               }
-
-               void show(String f1, double v1, String f2, double v2) {
-                       show();
-                       value1.setText(String.format(f1, v1));
-                       value2.setText(String.format(f2, v2));
+       abstract class ValueHold extends DualValue {
+               public void reset() {
+                       super.reset();
+                       last_values[1] = AltosLib.MISSING;
                }
                }
-
-               void show(String f1, int v1, String f2, int v2) {
-                       show();
-                       value1.setText(String.format(f1, v1));
-                       value2.setText(String.format(f2, v2));
-               }
-
-               public DualValue (GridBagLayout layout, int y, String text, boolean want_lights) {
-                       GridBagConstraints      c = new GridBagConstraints();
-                       c.weighty = 1;
-
-                       if (want_lights) {
-                               lights = new AltosLights();
-                               c.gridx = 0; c.gridy = y;
-                               c.anchor = GridBagConstraints.CENTER;
-                               c.fill = GridBagConstraints.VERTICAL;
-                               c.weightx = 0;
-                               layout.setConstraints(lights, c);
-                               add(lights);
-                       }
-
-                       label = new JLabel(text);
-                       label.setFont(AltosUILib.label_font);
-                       label.setHorizontalAlignment(SwingConstants.LEFT);
-                       c.gridx = 1; c.gridy = y;
-                       c.insets = new Insets(AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad);
-                       c.anchor = GridBagConstraints.WEST;
-                       c.fill = GridBagConstraints.VERTICAL;
-                       c.weightx = 0;
-                       layout.setConstraints(label, c);
-                       add(label);
-
-                       value1 = new JTextField(AltosUILib.text_width);
-                       value1.setFont(AltosUILib.value_font);
-                       value1.setHorizontalAlignment(SwingConstants.RIGHT);
-                       value1.setEditable(false);
-                       c.gridx = 2; c.gridy = y;
-                       c.anchor = GridBagConstraints.WEST;
-                       c.fill = GridBagConstraints.BOTH;
-                       c.weightx = 1;
-                       layout.setConstraints(value1, c);
-                       add(value1);
-
-                       value2 = new JTextField(AltosUILib.text_width);
-                       value2.setFont(AltosUILib.value_font);
-                       value2.setHorizontalAlignment(SwingConstants.RIGHT);
-                       value1.setEditable(false);
-                       c.gridx = 3; c.gridy = y;
-                       c.anchor = GridBagConstraints.WEST;
-                       c.fill = GridBagConstraints.BOTH;
-                       c.weightx = 1;
-                       c.gridwidth = 1;
-                       layout.setConstraints(value2, c);
-                       add(value2);
+               public ValueHold (Container container, int y, AltosUnits units, String text) {
+                       super(container, y, units, text);
                }
        }
 
                }
        }
 
-       abstract public class ValueHold implements AltosFontListener, AltosUnitsListener {
-               JLabel          label;
-               JTextField      value;
-               JTextField      max_value;
-               double          v;
-               double          max;
-               AltosUnits      units;
-
-               abstract void show(AltosState state, AltosListenerState listener_state);
-
-               void reset() {
-                       value.setText("");
-                       max_value.setText("");
-                       max = AltosLib.MISSING;
-               }
-
-               public void font_size_changed(int font_size) {
-                       label.setFont(AltosUILib.label_font);
-                       value.setFont(AltosUILib.value_font);
-                       max_value.setFont(AltosUILib.value_font);
-               }
-
-               public void units_changed(boolean imperial_units) {
-                       show(v, max);
-               }
-
-               void show(double v, double max) {
-                       this.v = v;
-                       this.max = max;
-                       if (v == AltosLib.MISSING)
-                               value.setText("Missing");
-                       else
-                               value.setText(units.show(8, v));
-                       if (max == AltosLib.MISSING)
-                               max_value.setText("Missing");
+       class Altitude extends ValueHold {
+               public double value(AltosState state, int i) {
+                       if (i == 0)
+                               return state.altitude();
                        else
                        else
-                               max_value.setText(units.show(8, max));
-               }
-
-               void hide() {
-                       label.setVisible(false);
-                       value.setVisible(false);
-                       max_value.setVisible(false);
+                               return state.max_altitude();
                }
 
                }
 
-               public ValueHold (GridBagLayout layout, int y, AltosUnits units, String text) {
-                       this.units = units;
-                       GridBagConstraints      c = new GridBagConstraints();
-                       c.weighty = 1;
-
-                       label = new JLabel(text);
-                       label.setFont(AltosUILib.label_font);
-                       label.setHorizontalAlignment(SwingConstants.LEFT);
-                       c.gridx = 1; c.gridy = y;
-                       c.insets = new Insets(AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad);
-                       c.anchor = GridBagConstraints.WEST;
-                       c.fill = GridBagConstraints.VERTICAL;
-                       c.weightx = 0;
-                       layout.setConstraints(label, c);
-                       add(label);
-
-                       value = new JTextField(AltosUILib.text_width);
-                       value.setEditable(false);
-                       value.setFont(AltosUILib.value_font);
-                       value.setHorizontalAlignment(SwingConstants.RIGHT);
-                       c.gridx = 2; c.gridy = y;
-                       c.anchor = GridBagConstraints.EAST;
-                       c.fill = GridBagConstraints.BOTH;
-                       c.weightx = 1;
-                       layout.setConstraints(value, c);
-                       add(value);
-
-                       max_value = new JTextField(AltosUILib.text_width);
-                       max_value.setEditable(false);
-                       max_value.setFont(AltosUILib.value_font);
-                       max_value.setHorizontalAlignment(SwingConstants.RIGHT);
-                       c.gridx = 3; c.gridy = y;
-                       c.anchor = GridBagConstraints.EAST;
-                       c.fill = GridBagConstraints.BOTH;
-                       c.weightx = 1;
-                       layout.setConstraints(max_value, c);
-                       add(max_value);
+               public Altitude (Container container, int y) {
+                       super (container, y, AltosConvert.height, "Altitude");
                }
        }
 
                }
        }
 
-
-       class Altitude extends ValueHold {
-               void show (AltosState state, AltosListenerState listener_state) {
-                       show(state.altitude(), state.max_altitude());
-               }
-               public Altitude (GridBagLayout layout, int y) {
-                       super (layout, y, AltosConvert.height, "Altitude");
-               }
-       }
-
-       Altitude        altitude;
-
        class AscentRate extends ValueHold {
        class AscentRate extends ValueHold {
-               void show (AltosState state, AltosListenerState listener_state) {
-                       show(state.gps_ascent_rate(), state.max_gps_ascent_rate());
+               public double value(AltosState state, int i) {
+                       if (i == 0)
+                               return state.gps_ascent_rate();
+                       else
+                               return state.max_gps_ascent_rate();
                }
                }
-               public AscentRate (GridBagLayout layout, int y) {
-                       super (layout, y, AltosConvert.speed, "Ascent Rate");
+               public AscentRate (Container container, int y) {
+                       super (container, y, AltosConvert.speed, "Ascent Rate");
                }
        }
 
                }
        }
 
-       AscentRate      ascent_rate;
-
        class GroundSpeed extends ValueHold {
        class GroundSpeed extends ValueHold {
-               void show (AltosState state, AltosListenerState listener_state) {
-                       show(state.gps_ground_speed(), state.max_gps_ground_speed());
+               public double value(AltosState state, int i) {
+                       if (i == 0)
+                               return state.gps_ground_speed();
+                       else
+                               return state.max_gps_ground_speed();
                }
                }
-               public GroundSpeed (GridBagLayout layout, int y) {
-                       super (layout, y, AltosConvert.speed, "Ground Speed");
+               public GroundSpeed (Container container, int y) {
+                       super (container, y, AltosConvert.speed, "Ground Speed");
                }
        }
 
                }
        }
 
-       GroundSpeed     ground_speed;
+       class Course extends AltosUIIndicator {
 
 
-       String pos(double p, String pos, String neg) {
-               String  h = pos;
-               if (p < 0) {
-                       h = neg;
-                       p = -p;
-               }
-               int deg = (int) Math.floor(p);
-               double min = (p - Math.floor(p)) * 60.0;
-               return String.format("%s %4d° %9.6f", h, deg, min);
-       }
-
-       class Course extends DualValue {
-               void show (AltosState state, AltosListenerState listener_state) {
+               public void show (AltosState state, AltosListenerState listener_state) {
                        double  course = state.gps_course();
                        if (course != AltosLib.MISSING)
                                show( String.format("%3.0f°", course),
                        double  course = state.gps_course();
                        if (course != AltosLib.MISSING)
                                show( String.format("%3.0f°", course),
@@ -445,43 +102,62 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay, Hiera
                                              AltosConvert.BEARING_LONG,
                                              course));
                }
                                              AltosConvert.BEARING_LONG,
                                              course));
                }
-               public Course (GridBagLayout layout, int y) {
-                       super (layout, y, "Course", false);
+               public Course (Container container, int y) {
+                       super (container, y, "Course", 2, false, 1);
                }
        }
 
                }
        }
 
-       Course          course;
+       class Lat extends AltosUIIndicator {
+
+               String pos(double p, String pos, String neg) {
+                       String  h = pos;
+                       if (p < 0) {
+                               h = neg;
+                               p = -p;
+                       }
+                       int deg = (int) Math.floor(p);
+                       double min = (p - Math.floor(p)) * 60.0;
+                       return String.format("%s %4d° %9.6f", h, deg, min);
+               }
 
 
-       class Lat extends Value {
-               void show (AltosState state, AltosListenerState listener_state) {
+               public void show (AltosState state, AltosListenerState listener_state) {
                        if (state.gps != null && state.gps.connected && state.gps.lat != AltosLib.MISSING)
                                show(pos(state.gps.lat,"N", "S"));
                        else
                                show("???");
                }
                        if (state.gps != null && state.gps.connected && state.gps.lat != AltosLib.MISSING)
                                show(pos(state.gps.lat,"N", "S"));
                        else
                                show("???");
                }
-               public Lat (GridBagLayout layout, int y) {
-                       super (layout, y, "Latitude");
+               public Lat (Container container, int y) {
+                       super (container, y, "Latitude", 1, false, 2);
                }
        }
 
                }
        }
 
-       Lat lat;
+       class Lon extends AltosUIIndicator {
 
 
-       class Lon extends Value {
-               void show (AltosState state, AltosListenerState listener_state) {
+               String pos(double p, String pos, String neg) {
+                       String  h = pos;
+                       if (p < 0) {
+                               h = neg;
+                               p = -p;
+                       }
+                       int deg = (int) Math.floor(p);
+                       double min = (p - Math.floor(p)) * 60.0;
+                       return String.format("%s %4d° %9.6f", h, deg, min);
+               }
+
+               public void show (AltosState state, AltosListenerState listener_state) {
                        if (state.gps != null && state.gps.connected && state.gps.lon != AltosLib.MISSING)
                                show(pos(state.gps.lon,"E", "W"));
                        else
                                show("???");
                }
                        if (state.gps != null && state.gps.connected && state.gps.lon != AltosLib.MISSING)
                                show(pos(state.gps.lon,"E", "W"));
                        else
                                show("???");
                }
-               public Lon (GridBagLayout layout, int y) {
-                       super (layout, y, "Longitude");
+               public Lon (Container container, int y) {
+                       super (container, y, "Longitude", 1, false, 2);
                }
        }
 
                }
        }
 
-       Lon lon;
+       class GPSLocked extends AltosUIIndicator {
 
 
-       class GPSLocked extends DualValue {
-               void show (AltosState state, AltosListenerState listener_state) {
+               public void show (AltosState state, AltosListenerState listener_state) {
                        if (state == null || state.gps == null)
                                hide();
                        else {
                        if (state == null || state.gps == null)
                                hide();
                        else {
@@ -489,46 +165,31 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay, Hiera
                                int nsat = state.gps.cc_gps_sat != null ? state.gps.cc_gps_sat.length : 0;
                                show("%4d in solution", soln,
                                     "%4d in view", nsat);
                                int nsat = state.gps.cc_gps_sat != null ? state.gps.cc_gps_sat.length : 0;
                                show("%4d in solution", soln,
                                     "%4d in view", nsat);
-                               lights.set(state.gps.locked && soln >= 4);
+                               set_lights(state.gps.locked && soln >= 4);
                        }
                }
                        }
                }
-               public GPSLocked (GridBagLayout layout, int y) {
-                       super (layout, y, "GPS Locked", true);
+               public GPSLocked (Container container, int y) {
+                       super (container, y, "GPS Locked", 2, true, 1);
                }
        }
 
                }
        }
 
-       GPSLocked gps_locked;
+       LinkedList<AltosUIIndicator> indicators = new LinkedList<AltosUIIndicator>();
 
        public void reset() {
 
        public void reset() {
-               lat.reset();
-               lon.reset();
-               altitude.reset();
-               ground_speed.reset();
-               ascent_rate.reset();
-               course.reset();
-               gps_locked.reset();
+               for (AltosUIIndicator i : indicators)
+                       i.reset();
        }
 
        public void font_size_changed(int font_size) {
                cur.setFont(AltosUILib.label_font);
                max.setFont(AltosUILib.label_font);
        }
 
        public void font_size_changed(int font_size) {
                cur.setFont(AltosUILib.label_font);
                max.setFont(AltosUILib.label_font);
-               lat.font_size_changed(font_size);
-               lon.font_size_changed(font_size);
-               altitude.font_size_changed(font_size);
-               ground_speed.font_size_changed(font_size);
-               ascent_rate.font_size_changed(font_size);
-               course.font_size_changed(font_size);
-               gps_locked.font_size_changed(font_size);
+               for (AltosUIIndicator i : indicators)
+                       i.font_size_changed(font_size);
        }
 
        public void units_changed(boolean imperial_units) {
        }
 
        public void units_changed(boolean imperial_units) {
-               lat.units_changed(imperial_units);
-               lon.units_changed(imperial_units);
-               altitude.units_changed(imperial_units);
-               ground_speed.units_changed(imperial_units);
-               ascent_rate.units_changed(imperial_units);
-               course.units_changed(imperial_units);
-               gps_locked.units_changed(imperial_units);
+               for (AltosUIIndicator i : indicators)
+                       i.units_changed(imperial_units);
        }
 
        public void show(AltosState state, AltosListenerState listener_state) {
        }
 
        public void show(AltosState state, AltosListenerState listener_state) {
@@ -538,21 +199,12 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay, Hiera
                        return;
                }
 
                        return;
                }
 
-               if (state.gps != null && state.gps.connected) {
-                       lat.show(state, listener_state);
-                       lon.show(state, listener_state);
-               } else {
-                       lat.hide();
-                       lon.hide();
-               }
-               altitude.show(state, listener_state);
-               ground_speed.show(state, listener_state);
-               ascent_rate.show(state, listener_state);
-               course.show(state, listener_state);
-               gps_locked.show(state, listener_state);
+               for (AltosUIIndicator i : indicators)
+                       i.show(state, listener_state);
        }
 
        }
 
-       public void labels(GridBagLayout layout, int y) {
+       public void labels(Container container, int y) {
+               GridBagLayout           layout = (GridBagLayout)(container.getLayout());
                GridBagConstraints      c;
 
                cur = new JLabel("Current");
                GridBagConstraints      c;
 
                cur = new JLabel("Current");
@@ -571,7 +223,7 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay, Hiera
        }
 
        public String getName() {
        }
 
        public String getName() {
-               return "Info";
+               return "Location";
        }
 
        public void hierarchyChanged(HierarchyEvent e) {
        }
 
        public void hierarchyChanged(HierarchyEvent e) {
@@ -586,25 +238,17 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay, Hiera
        }
 
        public TeleGPSInfo() {
        }
 
        public TeleGPSInfo() {
-               layout = new GridBagLayout();
-
-               setLayout(layout);
+               setLayout(new GridBagLayout());
 
 
-               /* Elements in ascent display:
-                *
-                * lat
-                * lon
-                * height
-                */
                int y = 0;
                int y = 0;
-               labels(layout, y++);
-               altitude = new Altitude(layout, y++);
-               ground_speed = new GroundSpeed(layout, y++);
-               ascent_rate = new AscentRate(layout, y++);
-               course = new Course(layout, y++);
-               lat = new Lat(layout, y++);
-               lon = new Lon(layout, y++);
-               gps_locked = new GPSLocked(layout, y++);
+               labels(this, y++);
+               indicators.add(new Altitude(this, y++));
+               indicators.add(new GroundSpeed(this, y++));
+               indicators.add(new AscentRate(this, y++));
+               indicators.add(new Course(this, y++));
+               indicators.add(new Lat(this, y++));
+               indicators.add(new Lon(this, y++));
+               indicators.add(new GPSLocked(this, y++));
                addHierarchyListener(this);
        }
 }
                addHierarchyListener(this);
        }
 }
diff --git a/telegps/TeleGPSState.java b/telegps/TeleGPSState.java
new file mode 100644 (file)
index 0000000..b10e8e7
--- /dev/null
@@ -0,0 +1,254 @@
+/*
+ * Copyright © 2014 Keith Packard <keithp@keithp.com>
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+package org.altusmetrum.telegps;
+
+import java.util.*;
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+import org.altusmetrum.altoslib_4.*;
+import org.altusmetrum.altosuilib_2.*;
+
+public class TeleGPSState extends JComponent implements AltosFlightDisplay, HierarchyListener {
+       GridBagLayout                   layout;
+       JLabel                          cur, max;
+
+       private AltosState              last_state;
+       private AltosListenerState      last_listener_state;
+
+       abstract class Value extends AltosUIUnitsIndicator {
+               public Value (Container container, int y, AltosUnits units, String text) {
+                       super(container, y, units, text, 1, false, 2);
+               }
+       }
+
+       abstract class DualValue extends AltosUIUnitsIndicator {
+               public DualValue (Container container, int y, AltosUnits units, String text) {
+                       super(container, y, units, text, 2, false, 1);
+               }
+       }
+
+       abstract class ValueHold extends DualValue {
+               public void reset() {
+                       super.reset();
+                       last_values[1] = AltosLib.MISSING;
+               }
+               public ValueHold (Container container, int y, AltosUnits units, String text) {
+                       super(container, y, units, text);
+               }
+       }
+
+       class Height extends ValueHold {
+               public double value(AltosState state, int i) {
+                       if (i == 0)
+                               return state.height();
+                       else
+                               return state.max_height();
+               }
+
+               public Height(Container container, int y) {
+                       super(container, y, AltosConvert.height, "Height");
+               }
+       }
+
+       class Speed extends ValueHold {
+               public double value(AltosState state, int i) {
+                       if (i == 0)
+                               return state.gps_speed();
+                       else
+                               return state.max_gps_speed();
+               }
+
+               public Speed(Container container, int y) {
+                       super(container, y, AltosConvert.speed, "Speed");
+               }
+       }
+
+       class Distance extends Value {
+               public double value(AltosState state, int i) {
+                       if (state.from_pad != null)
+                               return state.from_pad.distance;
+                       else
+                               return AltosLib.MISSING;
+               }
+
+               public Distance(Container container, int y) {
+                       super(container, y, AltosConvert.distance, "Distance");
+               }
+       }
+
+       class Range extends Value {
+               public double value(AltosState state, int i) {
+                       return state.range;
+               }
+               public Range (Container container, int y) {
+                       super (container, y, AltosConvert.distance, "Range");
+               }
+       }
+
+       class Bearing extends AltosUIIndicator {
+               public void show (AltosState state, AltosListenerState listener_state) {
+                       if (state.from_pad != null) {
+                               show( String.format("%3.0f°", state.from_pad.bearing),
+                                     state.from_pad.bearing_words(
+                                             AltosGreatCircle.BEARING_LONG));
+                       } else {
+                               show("???", "???");
+                       }
+               }
+               public Bearing (Container container, int y) {
+                       super (container, y, "Bearing", 2, false, 1);
+               }
+       }
+
+       class Elevation extends AltosUIIndicator {
+               public void show (AltosState state, AltosListenerState listener_state) {
+                       show("%3.0f°", state.elevation);
+               }
+               public Elevation (Container container, int y) {
+                       super (container, y, "Elevation", 1, false, 2);
+               }
+       }
+
+       class FirmwareVersion extends AltosUIIndicator {
+               public void show(AltosState state, AltosListenerState listener_state) {
+                       if (state.firmware_version == null)
+                               show("Missing");
+                       else
+                               show(state.firmware_version);
+               }
+
+               public FirmwareVersion(Container container, int y) {
+                       super(container, y, "Firmware Version", 1, false, 2);
+               }
+       }
+
+       class FlightLogMax extends AltosUIIndicator {
+               public void show(AltosState state, AltosListenerState listener_state) {
+                       if (state.flight_log_max == AltosLib.MISSING)
+                               show("Missing");
+                       else
+                               show(String.format("%dkB", state.flight_log_max));
+               }
+
+               public FlightLogMax(Container container, int y) {
+                       super(container, y, "Flight Log Storage", 1, false, 2);
+               }
+       }
+
+       class BatteryVoltage extends AltosUIVoltageIndicator {
+               public double voltage(AltosState state) {
+                       return state.battery_voltage;
+               }
+
+               public double good() {
+                       return AltosLib.ao_battery_good;
+               }
+
+               public BatteryVoltage(Container container, int y) {
+                       super(container, y, "Battery Voltage", 2);
+               }
+       }
+
+       LinkedList<AltosUIIndicator> indicators = new LinkedList<AltosUIIndicator>();
+
+       public void labels(Container container, int y) {
+               GridBagLayout           layout = (GridBagLayout)(container.getLayout());
+               GridBagConstraints      c;
+
+               cur = new JLabel("Current");
+               cur.setFont(AltosUILib.label_font);
+               c = new GridBagConstraints();
+               c.gridx = 2; c.gridy = y;
+               c.insets = new Insets(AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad);
+               layout.setConstraints(cur, c);
+               add(cur);
+
+               max = new JLabel("Maximum");
+               max.setFont(AltosUILib.label_font);
+               c.gridx = 3; c.gridy = y;
+               layout.setConstraints(max, c);
+               add(max);
+       }
+
+       public void reset() {
+               for (AltosUIIndicator i : indicators)
+                       i.reset();
+       }
+
+       public void font_size_changed(int font_size) {
+               for (AltosUIIndicator i : indicators)
+                       i.font_size_changed(font_size);
+       }
+
+       public void units_changed(boolean imperial_units) {
+               for (AltosUIIndicator i : indicators)
+                       i.units_changed(imperial_units);
+       }
+
+       public void show(AltosState state, AltosListenerState listener_state) {
+               if (!isShowing()) {
+                       last_state = state;
+                       last_listener_state = listener_state;
+                       return;
+               }
+
+               for (AltosUIIndicator i : indicators)
+                       i.show(state, listener_state);
+       }
+
+       public String getName() {
+               return "Status";
+       }
+
+       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 TeleGPSState() {
+               layout = new GridBagLayout();
+
+               setLayout(layout);
+
+               /* Elements in state display:
+                *
+                * config_version;
+                * lon
+                * height
+                */
+               int y = 0;
+               labels(this, y++);
+               indicators.add(new Height(this, y++));
+               indicators.add(new Speed(this, y++));
+               indicators.add(new Distance(this, y++));
+               indicators.add(new Range(this, y++));
+               indicators.add(new Bearing(this, y++));
+               indicators.add(new Elevation(this, y++));
+               indicators.add(new FirmwareVersion(this, y++));
+               indicators.add(new FlightLogMax(this, y++));
+               indicators.add(new BatteryVoltage(this, y++));
+               addHierarchyListener(this);
+       }
+}