java: Refactor AltosFlightDisplay units and font update handling
authorKeith Packard <keithp@keithp.com>
Thu, 29 May 2014 21:03:58 +0000 (14:03 -0700)
committerKeith Packard <keithp@keithp.com>
Thu, 29 May 2014 21:03:58 +0000 (14:03 -0700)
Make AltosFlightDisplay explicitly implement AltosFontListener and
AltosUnitsListener interfaces to make everyone use the same API. Then,
actually go implement units listeners so that changing units updates
all of the active displays immediately

Signed-off-by: Keith Packard <keithp@keithp.com>
15 files changed:
altosui/AltosAscent.java
altosui/AltosCompanionInfo.java
altosui/AltosDescent.java
altosui/AltosFlightStatus.java
altosui/AltosFlightUI.java
altosui/AltosIdleMonitorUI.java
altosui/AltosIgnitor.java
altosui/AltosLanded.java
altosui/AltosPad.java
altosuilib/AltosFlightDisplay.java
altosuilib/AltosInfoTable.java
altosuilib/AltosSiteMap.java
telegps/TeleGPS.java
telegps/TeleGPSInfo.java
telegps/TeleGPSStatus.java

index f6ccbf0..fb05fe1 100644 (file)
@@ -26,10 +26,12 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
        GridBagLayout   layout;
        JLabel                  cur, max;
 
-       public class AscentStatus {
+       public class AscentStatus implements AltosFontListener, AltosUnitsListener {
                JLabel          label;
                JTextField      value;
                AltosLights     lights;
+               double          v;
+               AltosUnits      units;
 
                void show() {
                        value.setVisible(true);
@@ -50,7 +52,8 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
                        value.setText(s);
                }
 
-               void show(AltosUnits units, double v) {
+               void show(double v) {
+                       this.v = v;
                        show(units.show(8, v));
                }
 
@@ -63,12 +66,18 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
                        lights.set(false);
                }
 
-               void set_font() {
+               public void font_size_changed(int font_size) {
                        label.setFont(Altos.label_font);
                        value.setFont(Altos.value_font);
                }
 
-               public AscentStatus (GridBagLayout layout, int y, String text) {
+               public void units_changed(boolean imperial_units) {
+                       if (units != null)
+                               show(v);
+               }
+
+               public AscentStatus (GridBagLayout layout, int y, AltosUnits units, String text) {
+                       this.units = units;
                        GridBagConstraints      c = new GridBagConstraints();
                        c.weighty = 1;
 
@@ -105,10 +114,13 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
                }
        }
 
-       public class AscentValue {
+       public abstract class AscentValue implements AltosFontListener, AltosUnitsListener {
                JLabel          label;
                JTextField      value;
-               void show(AltosState state, AltosListenerState listener_state) {}
+               double          v;
+               AltosUnits      units;
+
+               abstract void show(AltosState state, AltosListenerState listener_state);
 
                void reset() {
                        value.setText("");
@@ -124,7 +136,8 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
                        value.setText(s);
                }
 
-               void show(AltosUnits units, double v) {
+               void show(double v) {
+                       this.v = v;
                        show(units.show(8, v));
                }
 
@@ -136,12 +149,18 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
                        label.setVisible(false);
                        value.setVisible(false);
                }
-               void set_font() {
+
+               public void font_size_changed(int font_size) {
                        label.setFont(Altos.label_font);
                        value.setFont(Altos.value_font);
                }
 
-               public AscentValue (GridBagLayout layout, int y, String text) {
+               public void units_changed(boolean imperial_units) {
+                       if (units != null)
+                               show(v);
+               }
+
+               public AscentValue (GridBagLayout layout, int y, AltosUnits units, String text) {
                        GridBagConstraints      c = new GridBagConstraints();
                        c.weighty = 1;
 
@@ -167,13 +186,19 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
                        layout.setConstraints(value, c);
                        add(value);
                }
+
+               public AscentValue (GridBagLayout layout, int y, String text) {
+                       this(layout, y, null, text);
+               }
        }
 
-       public class AscentValueHold {
+       public class AscentValueHold implements AltosFontListener, AltosUnitsListener {
                JLabel          label;
                JTextField      value;
                JTextField      max_value;
                double          max;
+               AltosUnits      units;
+               double          v;
 
                void show(AltosState state, AltosListenerState listener_state) {}
 
@@ -183,23 +208,29 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
                        max = AltosLib.MISSING;
                }
 
-               void set_font() {
+               public void font_size_changed(int font_size) {
                        label.setFont(Altos.label_font);
                        value.setFont(Altos.value_font);
                        max_value.setFont(Altos.value_font);
                }
 
-               void show(AltosUnits units, double v) {
+               public void units_changed(boolean imperial_units) {
+                       show(v);
+               }
+
+               void show(double v) {
+                       this.v = v;
                        if (v == AltosLib.MISSING) {
                                value.setText("Missing");
-                               max_value.setText("Missing");
                        } else {
                                value.setText(units.show(8, v));
-                               if (v > max || max == AltosLib.MISSING) {
-                                       max_value.setText(units.show(8, v));
+                               if (v > max || max == AltosLib.MISSING)
                                        max = v;
-                               }
                        }
+                       if (max == AltosLib.MISSING)
+                               max_value.setText("Missing");
+                       else
+                               max_value.setText(units.show(8, v));
                }
 
                void hide() {
@@ -208,7 +239,8 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
                        max_value.setVisible(false);
                }
 
-               public AscentValueHold (GridBagLayout layout, int y, String text) {
+               public AscentValueHold (GridBagLayout layout, int y, AltosUnits units, String text) {
+                       this.units = units;
                        GridBagConstraints      c = new GridBagConstraints();
                        c.weighty = 1;
 
@@ -245,13 +277,12 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
                }
        }
 
-
        class Height extends AscentValueHold {
                void show (AltosState state, AltosListenerState listener_state) {
-                       show(AltosConvert.height, state.height());
+                       show(state.height());
                }
                public Height (GridBagLayout layout, int y) {
-                       super (layout, y, "Height");
+                       super (layout, y, AltosConvert.height, "Height");
                }
        }
 
@@ -259,10 +290,10 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
 
        class Speed extends AscentValueHold {
                void show (AltosState state, AltosListenerState listener_state) {
-                       show(AltosConvert.speed, state.speed());
+                       show(state.speed());
                }
                public Speed (GridBagLayout layout, int y) {
-                       super (layout, y, "Speed");
+                       super (layout, y, AltosConvert.speed, "Speed");
                }
        }
 
@@ -270,10 +301,10 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
 
        class Accel extends AscentValueHold {
                void show (AltosState state, AltosListenerState listener_state) {
-                       show(AltosConvert.accel, state.acceleration());
+                       show(state.acceleration());
                }
                public Accel (GridBagLayout layout, int y) {
-                       super (layout, y, "Acceleration");
+                       super (layout, y, AltosConvert.accel, "Acceleration");
                }
        }
 
@@ -281,10 +312,10 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
 
        class Orient extends AscentValueHold {
                void show (AltosState state, AltosListenerState listener_state) {
-                       show(AltosConvert.orient, state.orient());
+                       show(state.orient());
                }
                public Orient (GridBagLayout layout, int y) {
-                       super (layout, y, "Tilt Angle");
+                       super (layout, y, AltosConvert.orient, "Tilt Angle");
                }
        }
 
@@ -307,7 +338,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
                        lights.set(state.apogee_voltage >= AltosLib.ao_igniter_good);
                }
                public Apogee (GridBagLayout layout, int y) {
-                       super(layout, y, "Apogee Igniter Voltage");
+                       super(layout, y, null, "Apogee Igniter Voltage");
                }
        }
 
@@ -319,7 +350,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
                        lights.set(state.main_voltage >= AltosLib.ao_igniter_good);
                }
                public Main (GridBagLayout layout, int y) {
-                       super(layout, y, "Main Igniter Voltage");
+                       super(layout, y, null, "Main Igniter Voltage");
                }
        }
 
@@ -364,17 +395,28 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
                orient.reset();
        }
 
-       public void set_font() {
+       public void font_size_changed(int font_size) {
                cur.setFont(Altos.label_font);
                max.setFont(Altos.label_font);
-               lat.set_font();
-               lon.set_font();
-               main.set_font();
-               apogee.set_font();
-               height.set_font();
-               speed.set_font();
-               accel.set_font();
-               orient.set_font();
+               lat.font_size_changed(font_size);
+               lon.font_size_changed(font_size);
+               main.font_size_changed(font_size);
+               apogee.font_size_changed(font_size);
+               height.font_size_changed(font_size);
+               speed.font_size_changed(font_size);
+               accel.font_size_changed(font_size);
+               orient.font_size_changed(font_size);
+       }
+
+       public void units_changed(boolean imperial_units) {
+               lat.units_changed(imperial_units);
+               lon.units_changed(imperial_units);
+               main.units_changed(imperial_units);
+               apogee.units_changed(imperial_units);
+               height.units_changed(imperial_units);
+               speed.units_changed(imperial_units);
+               accel.units_changed(imperial_units);
+               orient.units_changed(imperial_units);
        }
 
        public void show(AltosState state, AltosListenerState listener_state) {
index f8d033a..514ce61 100644 (file)
@@ -33,18 +33,21 @@ public class AltosCompanionInfo extends JTable implements AltosFlightDisplay {
                return (infoValueMetrics.getHeight() + infoValueMetrics.getLeading()) * 18 / 10;
        }
 
-       public void set_font() {
+       public void font_size_changed(int font_size) {
                setFont(Altos.table_value_font);
                setRowHeight(desired_row_height());
                doLayout();
        }
 
+       public void units_changed(boolean imperial_units) {
+       }
+
        public AltosCompanionInfo() {
                super(new AltosFlightInfoTableModel(info_rows, info_columns));
                model = (AltosFlightInfoTableModel) getModel();
                setAutoResizeMode(AUTO_RESIZE_ALL_COLUMNS);
                setShowGrid(true);
-               set_font();
+               font_size_changed(AltosUIPreferences.font_size());
        }
 
        public Dimension getPreferredScrollableViewportSize() {
index 5cb693f..e671052 100644 (file)
@@ -25,7 +25,7 @@ import org.altusmetrum.altosuilib_2.*;
 public class AltosDescent extends JComponent implements AltosFlightDisplay {
        GridBagLayout   layout;
 
-       public abstract class DescentStatus {
+       public abstract class DescentStatus implements AltosFontListener, AltosUnitsListener {
                JLabel          label;
                JTextField      value;
                AltosLights     lights;
@@ -58,11 +58,14 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay {
                        lights.set(false);
                }
 
-               void set_font() {
+               public void font_size_changed(int font_size) {
                        label.setFont(Altos.label_font);
                        value.setFont(Altos.value_font);
                }
 
+               public void units_changed(boolean imperial_units) {
+               }
+
                public DescentStatus (GridBagLayout layout, int y, String text) {
                        GridBagConstraints      c = new GridBagConstraints();
                        c.weighty = 1;
@@ -101,9 +104,11 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay {
                }
        }
 
-       public abstract class DescentValue {
+       public abstract class DescentValue implements AltosFontListener, AltosUnitsListener {
                JLabel          label;
                JTextField      value;
+               AltosUnits      units;
+               double          v;
 
                void reset() {
                        value.setText("");
@@ -126,7 +131,8 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay {
                        value.setText(v);
                }
 
-               void show(AltosUnits units, double v) {
+               void show(double v) {
+                       this.v = v;
                        show(units.show(8, v));
                }
 
@@ -134,12 +140,18 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay {
                        show(String.format(format, v));
                }
 
-               void set_font() {
+               public void font_size_changed(int font_size) {
                        label.setFont(Altos.label_font);
                        value.setFont(Altos.value_font);
                }
 
-               public DescentValue (GridBagLayout layout, int x, int y, String text) {
+               public void units_changed(boolean imperial_units) {
+                       if (units != null)
+                               show(v);
+               }
+
+               public DescentValue (GridBagLayout layout, int x, int y, AltosUnits units, String text) {
+                       this.units = units;
                        GridBagConstraints      c = new GridBagConstraints();
                        c.weighty = 1;
 
@@ -163,9 +175,13 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay {
                        c.weightx = 1;
                        add(value, c);
                }
+
+               public DescentValue (GridBagLayout layout, int x, int y, String text) {
+                       this(layout, x, y, null, text);
+               }
        }
 
-       public abstract class DescentDualValue {
+       public abstract class DescentDualValue implements AltosFontListener, AltosUnitsListener {
                JLabel          label;
                JTextField      value1;
                JTextField      value2;
@@ -187,12 +203,15 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay {
                        value2.setVisible(false);
                }
 
-               void set_font() {
+               public void font_size_changed(int font_size) {
                        label.setFont(Altos.label_font);
                        value1.setFont(Altos.value_font);
                        value2.setFont(Altos.value_font);
                }
 
+               public void units_changed(boolean imperial_units) {
+               }
+
                abstract void show(AltosState state, AltosListenerState listener_state);
 
                void show(String v1, String v2) {
@@ -246,10 +265,10 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay {
 
        class Height extends DescentValue {
                void show (AltosState state, AltosListenerState listener_state) {
-                       show(AltosConvert.height, state.height());
+                       show(state.height());
                }
                public Height (GridBagLayout layout, int x, int y) {
-                       super (layout, x, y, "Height");
+                       super (layout, x, y, AltosConvert.height, "Height");
                }
        }
 
@@ -257,10 +276,10 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay {
 
        class Speed extends DescentValue {
                void show (AltosState state, AltosListenerState listener_state) {
-                       show(AltosConvert.speed, state.speed());
+                       show(state.speed());
                }
                public Speed (GridBagLayout layout, int x, int y) {
-                       super (layout, x, y, "Speed");
+                       super (layout, x, y, AltosConvert.speed, "Speed");
                }
        }
 
@@ -308,13 +327,13 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay {
        class Distance extends DescentValue {
                void show(AltosState state, AltosListenerState listener_state) {
                        if (state.from_pad != null)
-                               show(AltosConvert.distance, state.from_pad.distance);
+                               show(state.from_pad.distance);
                        else
                                show("???");
                }
 
                public Distance (GridBagLayout layout, int x, int y) {
-                       super(layout, x, y, "Ground Distance");
+                       super(layout, x, y, AltosConvert.distance, "Ground Distance");
                }
        }
 
@@ -364,10 +383,10 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay {
 
        class Range extends DescentValue {
                void show (AltosState state, AltosListenerState listener_state) {
-                       show(AltosConvert.distance, state.range);
+                       show(state.range);
                }
                public Range (GridBagLayout layout, int x, int y) {
-                       super (layout, x, y, "Range");
+                       super (layout, x, y, AltosConvert.distance, "Range");
                }
        }
 
@@ -397,17 +416,30 @@ public class AltosDescent extends JComponent implements AltosFlightDisplay {
                apogee.reset();
        }
 
-       public void set_font() {
-               lat.set_font();
-               lon.set_font();
-               height.set_font();
-               speed.set_font();
-               bearing.set_font();
-               range.set_font();
-               distance.set_font();
-               elevation.set_font();
-               main.set_font();
-               apogee.set_font();
+       public void font_size_changed(int font_size) {
+               lat.font_size_changed(font_size);
+               lon.font_size_changed(font_size);
+               height.font_size_changed(font_size);
+               speed.font_size_changed(font_size);
+               bearing.font_size_changed(font_size);
+               range.font_size_changed(font_size);
+               distance.font_size_changed(font_size);
+               elevation.font_size_changed(font_size);
+               main.font_size_changed(font_size);
+               apogee.font_size_changed(font_size);
+       }
+
+       public void units_changed(boolean imperial_units) {
+               lat.units_changed(imperial_units);
+               lon.units_changed(imperial_units);
+               height.units_changed(imperial_units);
+               speed.units_changed(imperial_units);
+               bearing.units_changed(imperial_units);
+               range.units_changed(imperial_units);
+               distance.units_changed(imperial_units);
+               elevation.units_changed(imperial_units);
+               main.units_changed(imperial_units);
+               apogee.units_changed(imperial_units);
        }
 
        public void show(AltosState state, AltosListenerState listener_state) {
index 73b84f8..459b049 100644 (file)
@@ -159,7 +159,7 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay
                last_packet.reset();
        }
 
-       public void set_font () {
+       public void font_size_changed(int font_size) {
                call.set_font();
                serial.set_font();
                flight.set_font();
@@ -168,6 +168,9 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay
                last_packet.set_font();
        }
 
+       public void units_changed(boolean imperial_units) {
+       }
+
        public void show (AltosState state, AltosListenerState listener_state) {
                call.show(state, listener_state);
                serial.show(state, listener_state);
index 2bd60d6..baa1868 100644 (file)
@@ -24,7 +24,7 @@ import java.util.concurrent.*;
 import org.altusmetrum.altoslib_4.*;
 import org.altusmetrum.altosuilib_2.*;
 
-public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay, AltosFontListener {
+public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay {
        AltosVoice              voice;
        AltosFlightReader       reader;
        AltosDisplayThread      thread;
@@ -83,22 +83,29 @@ public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay, A
                sitemap.reset();
        }
 
-       public void set_font() {
-               pad.set_font();
-               ignitor.set_font();
-               ascent.set_font();
-               descent.set_font();
-               landed.set_font();
-               flightStatus.set_font();
-               flightInfo.set_font();
-               sitemap.set_font();
-               companion.set_font();
-       }
-
        public void font_size_changed(int font_size) {
-               set_font();
+               pad.font_size_changed(font_size);
+               ignitor.font_size_changed(font_size);
+               ascent.font_size_changed(font_size);
+               descent.font_size_changed(font_size);
+               landed.font_size_changed(font_size);
+               flightStatus.font_size_changed(font_size);
+               flightInfo.font_size_changed(font_size);
+               sitemap.font_size_changed(font_size);
+               companion.font_size_changed(font_size);
        }
 
+       public void units_changed(boolean imperial_units) {
+               pad.units_changed(imperial_units);
+               ignitor.units_changed(imperial_units);
+               ascent.units_changed(imperial_units);
+               descent.units_changed(imperial_units);
+               landed.units_changed(imperial_units);
+               flightStatus.units_changed(imperial_units);
+               flightInfo.units_changed(imperial_units);
+               sitemap.units_changed(imperial_units);
+               companion.units_changed(imperial_units);
+       }
 
        AltosFlightStatusUpdate status_update;
 
@@ -318,6 +325,7 @@ public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay, A
                setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
 
                AltosUIPreferences.register_font_listener(this);
+               AltosPreferences.register_units_listener(this);
 
                addWindowListener(new WindowAdapter() {
                                @Override
@@ -326,6 +334,7 @@ public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay, A
                                        setVisible(false);
                                        dispose();
                                        AltosUIPreferences.unregister_font_listener(AltosFlightUI.this);
+                                       AltosPreferences.unregister_units_listener(AltosFlightUI.this);
                                        if (exit_on_close)
                                                System.exit(0);
                                }
index b5652df..042111e 100644 (file)
@@ -27,7 +27,7 @@ import java.util.Arrays;
 import org.altusmetrum.altoslib_4.*;
 import org.altusmetrum.altosuilib_2.*;
 
-public class AltosIdleMonitorUI extends AltosUIFrame implements AltosFlightDisplay, AltosFontListener, AltosIdleMonitorListener, DocumentListener {
+public class AltosIdleMonitorUI extends AltosUIFrame implements AltosFlightDisplay, AltosIdleMonitorListener, DocumentListener {
        AltosDevice             device;
        JTabbedPane             pane;
        AltosPad                pad;
@@ -56,13 +56,14 @@ public class AltosIdleMonitorUI extends AltosUIFrame implements AltosFlightDispl
                flightInfo.clear();
        }
 
-       public void set_font() {
-               pad.set_font();
-               flightInfo.set_font();
+       public void font_size_changed(int font_size) {
+               pad.font_size_changed(font_size);
+               flightInfo.font_size_changed(font_size);
        }
 
-       public void font_size_changed(int font_size) {
-               set_font();
+       public void units_changed(boolean imperial_units) {
+               pad.units_changed(imperial_units);
+               flightInfo.units_changed(imperial_units);
        }
 
        AltosFlightStatusUpdate status_update;
@@ -235,8 +236,8 @@ public class AltosIdleMonitorUI extends AltosUIFrame implements AltosFlightDispl
                                                disconnect();
                                        } catch (Exception ex) {
                                                System.out.printf("Exception %s\n", ex.toString());
-                                               for (StackTraceElement e : ex.getStackTrace())
-                                                       System.out.printf("%s\n", e.toString());
+                                               for (StackTraceElement el : ex.getStackTrace())
+                                                       System.out.printf("%s\n", el.toString());
                                        }
                                        setVisible(false);
                                        dispose();
index 7f79f42..27917b3 100644 (file)
@@ -25,7 +25,7 @@ import org.altusmetrum.altosuilib_2.*;
 public class AltosIgnitor extends JComponent implements AltosFlightDisplay {
        GridBagLayout   layout;
 
-       public class LaunchStatus {
+       public class LaunchStatus implements AltosFontListener, AltosUnitsListener {
                JLabel          label;
                JTextField      value;
                AltosLights     lights;
@@ -66,11 +66,14 @@ public class AltosIgnitor extends JComponent implements AltosFlightDisplay {
                        hide();
                }
 
-               public void set_font() {
+               public void font_size_changed(int font_size) {
                        label.setFont(Altos.label_font);
                        value.setFont(Altos.value_font);
                }
 
+               public void units_changed(boolean imperial_units) {
+               }
+
                public void set_label(String text) {
                        label.setText(text);
                }
@@ -142,11 +145,14 @@ public class AltosIgnitor extends JComponent implements AltosFlightDisplay {
                        ignitors[i].reset();
        }
 
-       public void set_font() {
+       public void font_size_changed(int font_size) {
                if (ignitors == null)
                        return;
                for (int i = 0; i < ignitors.length; i++)
-                       ignitors[i].set_font();
+                       ignitors[i].font_size_changed(font_size);
+       }
+
+       public void units_changed(boolean imperial_units) {
        }
 
        public void show(AltosState state, AltosListenerState listener_state) {
index 707d8fc..bb52fe2 100644 (file)
@@ -27,10 +27,13 @@ import org.altusmetrum.altosuilib_2.*;
 public class AltosLanded extends JComponent implements AltosFlightDisplay, ActionListener {
        GridBagLayout   layout;
 
-       public class LandedValue {
+       public abstract class LandedValue implements AltosFontListener, AltosUnitsListener {
                JLabel          label;
                JTextField      value;
-               void show(AltosState state, AltosListenerState listener_state) {}
+               AltosUnits      units;
+               double          v;
+
+               abstract void show(AltosState state, AltosListenerState listener_state);
 
                void reset() {
                        value.setText("");
@@ -46,7 +49,8 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio
                        value.setText(s);
                }
 
-               void show(AltosUnits units, double v) {
+               void show(double v) {
+                       this.v = v;
                        show(units.show(8, v));
                }
 
@@ -54,17 +58,24 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio
                        show(String.format(format, v));
                }
 
-               public void set_font() {
+               public void font_size_changed(int font_size) {
                        label.setFont(Altos.label_font);
                        value.setFont(Altos.value_font);
                }
 
+               public void units_changed(boolean imperial_units) {
+                       if (units != null)
+                               show(v);
+               }
+
                void hide() {
                        label.setVisible(false);
                        value.setVisible(false);
                }
 
-               public LandedValue (GridBagLayout layout, int y, String text) {
+               public LandedValue (GridBagLayout layout, int y, AltosUnits units, String text) {
+                       this.units = units;
+
                        GridBagConstraints      c = new GridBagConstraints();
                        c.weighty = 1;
 
@@ -89,6 +100,10 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio
                        layout.setConstraints(value, c);
                        add(value);
                }
+
+               public LandedValue (GridBagLayout layout, int y, String text) {
+                       this(layout, y, null, text);
+               }
        }
 
        String pos(double p, String pos, String neg) {
@@ -151,12 +166,12 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio
                void show (AltosState state, AltosListenerState listener_state) {
                        show();
                        if (state.from_pad != null)
-                               show(AltosConvert.distance, state.from_pad.distance);
+                               show(state.from_pad.distance);
                        else
                                show("???");
                }
                public Distance (GridBagLayout layout, int y) {
-                       super (layout, y, "Distance");
+                       super (layout, y, AltosConvert.distance, "Distance");
                }
        }
 
@@ -164,10 +179,10 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio
 
        class Height extends LandedValue {
                void show (AltosState state, AltosListenerState listener_state) {
-                       show(AltosConvert.height, state.max_height());
+                       show(state.max_height());
                }
                public Height (GridBagLayout layout, int y) {
-                       super (layout, y, "Maximum Height");
+                       super (layout, y, AltosConvert.height, "Maximum Height");
                }
        }
 
@@ -175,10 +190,10 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio
 
        class Speed extends LandedValue {
                void show (AltosState state, AltosListenerState listener_state) {
-                       show(AltosConvert.speed, state.max_speed());
+                       show(state.max_speed());
                }
                public Speed (GridBagLayout layout, int y) {
-                       super (layout, y, "Maximum Speed");
+                       super (layout, y, AltosConvert.speed, "Maximum Speed");
                }
        }
 
@@ -186,10 +201,10 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio
 
        class Accel extends LandedValue {
                void show (AltosState state, AltosListenerState listener_state) {
-                       show(AltosConvert.accel, state.max_acceleration());
+                       show(state.max_acceleration());
                }
                public Accel (GridBagLayout layout, int y) {
-                       super (layout, y, "Maximum Acceleration");
+                       super (layout, y, AltosConvert.accel, "Maximum Acceleration");
                }
        }
 
@@ -205,14 +220,24 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio
                accel.reset();
        }
 
-       public void set_font() {
-               lat.set_font();
-               lon.set_font();
-               bearing.set_font();
-               distance.set_font();
-               height.set_font();
-               speed.set_font();
-               accel.set_font();
+       public void font_size_changed(int font_size) {
+               lat.font_size_changed(font_size);
+               lon.font_size_changed(font_size);
+               bearing.font_size_changed(font_size);
+               distance.font_size_changed(font_size);
+               height.font_size_changed(font_size);
+               speed.font_size_changed(font_size);
+               accel.font_size_changed(font_size);
+       }
+
+       public void units_changed(boolean imperial_units) {
+               lat.units_changed(imperial_units);
+               lon.units_changed(imperial_units);
+               bearing.units_changed(imperial_units);
+               distance.units_changed(imperial_units);
+               height.units_changed(imperial_units);
+               speed.units_changed(imperial_units);
+               accel.units_changed(imperial_units);
        }
 
        public void show(AltosState state, AltosListenerState listener_state) {
index a6ac70d..ce1f2ab 100644 (file)
@@ -25,7 +25,7 @@ import org.altusmetrum.altosuilib_2.*;
 public class AltosPad extends JComponent implements AltosFlightDisplay {
        GridBagLayout   layout;
 
-       public class LaunchStatus {
+       public class LaunchStatus implements AltosFontListener, AltosUnitsListener {
                JLabel          label;
                JTextField      value;
                AltosLights     lights;
@@ -62,11 +62,14 @@ public class AltosPad extends JComponent implements AltosFlightDisplay {
                        lights.setVisible(false);
                }
 
-               public void set_font() {
+               public void font_size_changed(int font_size) {
                        label.setFont(Altos.label_font);
                        value.setFont(Altos.value_font);
                }
 
+               public void units_changed(boolean imperial_units) {
+               }
+
                public void set_label(String text) {
                        label.setText(text);
                }
@@ -107,10 +110,13 @@ public class AltosPad extends JComponent implements AltosFlightDisplay {
                }
        }
 
-       public class LaunchValue {
+       public abstract class LaunchValue implements AltosFontListener, AltosUnitsListener {
                JLabel          label;
                JTextField      value;
-               void show(AltosState state, AltosListenerState listener_state) {}
+               AltosUnits      units;
+               double          v;
+
+               abstract void show(AltosState state, AltosListenerState listener_state);
 
                void show() {
                        label.setVisible(true);
@@ -122,17 +128,23 @@ public class AltosPad extends JComponent implements AltosFlightDisplay {
                        value.setVisible(false);
                }
 
-               public void set_font() {
+               public void font_size_changed(int font_size) {
                        label.setFont(Altos.label_font);
                        value.setFont(Altos.value_font);
                }
 
+               public void units_changed(boolean imperial_units) {
+                       if (units != null)
+                               show(v);
+               }
+
                void show(String s) {
                        show();
                        value.setText(s);
                }
 
-               void show(AltosUnits units, double v) {
+               void show(double v) {
+                       this.v = v;
                        show(units.show(8, v));
                }
 
@@ -148,7 +160,9 @@ public class AltosPad extends JComponent implements AltosFlightDisplay {
                        value.setText("");
                }
 
-               public LaunchValue (GridBagLayout layout, int y, String text) {
+               public LaunchValue (GridBagLayout layout, int y, AltosUnits units, String text) {
+                       this.units = units;
+
                        GridBagConstraints      c = new GridBagConstraints();
                        c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
                        c.weighty = 1;
@@ -173,6 +187,10 @@ public class AltosPad extends JComponent implements AltosFlightDisplay {
                        layout.setConstraints(value, c);
                        add(value);
                }
+
+               public LaunchValue (GridBagLayout layout, int y, String text) {
+                       this(layout, y, null, text);
+               }
        }
 
        class Battery extends LaunchStatus {
@@ -378,13 +396,13 @@ public class AltosPad extends JComponent implements AltosFlightDisplay {
                                }
                        }
                        if (alt != AltosLib.MISSING) {
-                               show("%4.0f m", state.gps.alt);
+                               show(alt);
                                set_label(label);
                        } else
                                hide();
                }
                public PadAlt (GridBagLayout layout, int y) {
-                       super (layout, y, "Pad Altitude");
+                       super (layout, y, AltosConvert.height, "Pad Altitude");
                }
        }
 
@@ -403,17 +421,30 @@ public class AltosPad extends JComponent implements AltosFlightDisplay {
                pad_alt.reset();
        }
 
-       public void set_font() {
-               battery.set_font();
-               apogee.set_font();
-               main.set_font();
-               logging_ready.set_font();
-               gps_locked.set_font();
-               gps_ready.set_font();
-               receiver_battery.set_font();
-               pad_lat.set_font();
-               pad_lon.set_font();
-               pad_alt.set_font();
+       public void font_size_changed(int font_size) {
+               battery.font_size_changed(font_size);
+               apogee.font_size_changed(font_size);
+               main.font_size_changed(font_size);
+               logging_ready.font_size_changed(font_size);
+               gps_locked.font_size_changed(font_size);
+               gps_ready.font_size_changed(font_size);
+               receiver_battery.font_size_changed(font_size);
+               pad_lat.font_size_changed(font_size);
+               pad_lon.font_size_changed(font_size);
+               pad_alt.font_size_changed(font_size);
+       }
+
+       public void units_changed(boolean imperial_units) {
+               battery.units_changed(imperial_units);
+               apogee.units_changed(imperial_units);
+               main.units_changed(imperial_units);
+               logging_ready.units_changed(imperial_units);
+               gps_locked.units_changed(imperial_units);
+               gps_ready.units_changed(imperial_units);
+               receiver_battery.units_changed(imperial_units);
+               pad_lat.units_changed(imperial_units);
+               pad_lon.units_changed(imperial_units);
+               pad_alt.units_changed(imperial_units);
        }
 
        public void show(AltosState state, AltosListenerState listener_state) {
index 5695a01..5fb0cab 100644 (file)
@@ -19,10 +19,8 @@ package org.altusmetrum.altosuilib_2;
 
 import org.altusmetrum.altoslib_4.*;
 
-public interface AltosFlightDisplay {
+public interface AltosFlightDisplay extends AltosUnitsListener, AltosFontListener {
        void reset();
 
        void show(AltosState state, AltosListenerState listener_state);
-
-       void set_font();
 }
index 0d8779d..24a895e 100644 (file)
@@ -62,12 +62,15 @@ public class AltosInfoTable extends JTable implements AltosFlightDisplay {
                doLayout();
        }
 
-       public void set_font() {
+       public void font_size_changed(int font_size) {
                setFont(AltosUILib.table_value_font);
                set_layout();
                doLayout();
        }
 
+       public void units_changed(boolean imperial_units) {
+       }
+
        public Dimension getPreferredScrollableViewportSize() {
                return getPreferredSize();
        }
index 7f0e184..ed77bef 100644 (file)
@@ -192,11 +192,15 @@ public class AltosSiteMap extends JComponent implements AltosFlightDisplay, Mous
                // nothing
        }
 
-       public void set_font() {
+       public void font_size_changed(int font_size) {
                for (AltosSiteMapTile tile : mapTiles.values())
                        tile.set_font(AltosUILib.value_font);
        }
 
+       public void units_changed(boolean imperial_units) {
+               set_line();
+       }
+
        static final int load_mode_cached = 1;
        static final int load_mode_uncached = 2;
 
index d30d8dc..bef0bbc 100644 (file)
@@ -26,7 +26,10 @@ import java.util.*;
 import org.altusmetrum.altoslib_4.*;
 import org.altusmetrum.altosuilib_2.*;
 
-public class TeleGPS extends AltosUIFrame implements AltosFlightDisplay, AltosFontListener, ActionListener {
+public class TeleGPS
+       extends AltosUIFrame
+       implements AltosFlightDisplay, AltosFontListener, AltosUnitsListener, ActionListener
+{
 
        static String[] telegps_icon_names = {
                "/telegps-16.png",
@@ -126,13 +129,14 @@ public class TeleGPS extends AltosUIFrame implements AltosFlightDisplay, AltosFo
                        display.reset();
        }
 
-       public void set_font() {
+       public void font_size_changed(int font_size) {
                for (AltosFlightDisplay display : displays)
-                       display.set_font();
+                       display.font_size_changed(font_size);
        }
 
-       public void font_size_changed(int font_size) {
-               set_font();
+       public void units_changed(boolean imperial_units) {
+               for (AltosFlightDisplay display : displays)
+                       display.units_changed(imperial_units);
        }
 
        public void show(AltosState state, AltosListenerState listener_state) {
@@ -343,6 +347,7 @@ public class TeleGPS extends AltosUIFrame implements AltosFlightDisplay, AltosFo
 
        private void close() {
                AltosUIPreferences.unregister_font_listener(this);
+               AltosPreferences.unregister_units_listener(this);
                setVisible(false);
                dispose();
                --number_of_windows;
@@ -430,6 +435,7 @@ public class TeleGPS extends AltosUIFrame implements AltosFlightDisplay, AltosFo
                setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
 
                AltosUIPreferences.register_font_listener(this);
+               AltosPreferences.register_units_listener(this);
 
                addWindowListener(new WindowAdapter() {
                                @Override
index da3df44..2765f5a 100644 (file)
@@ -26,10 +26,12 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay {
        GridBagLayout   layout;
        JLabel                  cur, max;
 
-       public class Info {
+       public abstract class Info implements AltosFontListener, AltosUnitsListener {
                JLabel          label;
                JTextField      value;
                AltosLights     lights;
+               double          v;
+               AltosUnits      units;
 
                void show() {
                        value.setVisible(true);
@@ -43,14 +45,15 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay {
                        label.setVisible(false);
                }
 
-               void show(AltosState state, AltosListenerState listener_state) {}
+               abstract void show(AltosState state, AltosListenerState listener_state);
 
                void show(String s) {
                        show();
                        value.setText(s);
                }
 
-               void show(AltosUnits units, double v) {
+               void show(double v) {
+                       this.v = v;
                        show(units.show(8, v));
                }
 
@@ -67,12 +70,19 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay {
                        value.setText("");
                }
 
-               void set_font() {
+               public void font_size_changed(int font_size) {
                        label.setFont(AltosUILib.label_font);
                        value.setFont(AltosUILib.value_font);
                }
 
-               public Info (GridBagLayout layout, int y, String text) {
+               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;
 
@@ -106,12 +116,19 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay {
                        layout.setConstraints(value, c);
                        add(value);
                }
+
+               public Info (GridBagLayout layout, int y, String text) {
+                       this(layout, y, null, text);
+               }
        }
 
-       public class Value {
+       public abstract class Value implements AltosFontListener, AltosUnitsListener {
                JLabel          label;
                JTextField      value;
-               void show(AltosState state, AltosListenerState listener_state) {}
+               AltosUnits      units;
+               double          v = AltosLib.MISSING;
+
+               abstract void show(AltosState state, AltosListenerState listener_state);
 
                void reset() {
                        value.setText("");
@@ -127,7 +144,8 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay {
                        value.setText(s);
                }
 
-               void show(AltosUnits units, double v) {
+               void show(double v) {
+                       this.v = v;
                        show(units.show(8, v));
                }
 
@@ -139,10 +157,14 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay {
                        label.setVisible(false);
                        value.setVisible(false);
                }
-               void set_font() {
+               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();
@@ -172,34 +194,44 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay {
                }
        }
 
-       public abstract class DualValue {
+       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);
                }
 
-               void set_font() {
+               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) {
@@ -207,20 +239,37 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay {
                        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));
                }
 
-               public DualValue (GridBagLayout layout, int x, int y, String text) {
+               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 = x + 1; c.gridy = y;
+                       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;
@@ -231,7 +280,7 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay {
                        value1 = new JTextField(AltosUILib.text_width);
                        value1.setFont(AltosUILib.value_font);
                        value1.setHorizontalAlignment(SwingConstants.RIGHT);
-                       c.gridx = x + 2; c.gridy = y;
+                       c.gridx = 2; c.gridy = y;
                        c.anchor = GridBagConstraints.WEST;
                        c.fill = GridBagConstraints.BOTH;
                        c.weightx = 1;
@@ -241,7 +290,7 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay {
                        value2 = new JTextField(AltosUILib.text_width);
                        value2.setFont(AltosUILib.value_font);
                        value2.setHorizontalAlignment(SwingConstants.RIGHT);
-                       c.gridx = x + 3; c.gridy = y;
+                       c.gridx = 3; c.gridy = y;
                        c.anchor = GridBagConstraints.WEST;
                        c.fill = GridBagConstraints.BOTH;
                        c.weightx = 1;
@@ -251,13 +300,15 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay {
                }
        }
 
-       public class ValueHold {
+       abstract public class ValueHold implements AltosFontListener, AltosUnitsListener {
                JLabel          label;
                JTextField      value;
                JTextField      max_value;
+               double          v;
                double          max;
+               AltosUnits      units;
 
-               void show(AltosState state, AltosListenerState listener_state) {}
+               abstract void show(AltosState state, AltosListenerState listener_state);
 
                void reset() {
                        value.setText("");
@@ -265,23 +316,29 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay {
                        max = AltosLib.MISSING;
                }
 
-               void set_font() {
+               public void font_size_changed(int font_size) {
                        label.setFont(AltosUILib.label_font);
                        value.setFont(AltosUILib.value_font);
                        max_value.setFont(AltosUILib.value_font);
                }
 
-               void show(AltosUnits units, double v) {
+               public void units_changed(boolean imperial_units) {
+                       show(v);
+               }
+
+               void show(double v) {
+                       this.v = v;
                        if (v == AltosLib.MISSING) {
                                value.setText("Missing");
-                               max_value.setText("Missing");
                        } else {
                                value.setText(units.show(8, v));
-                               if (v > max || max == AltosLib.MISSING) {
-                                       max_value.setText(units.show(8, v));
+                               if (v > max || max == AltosLib.MISSING)
                                        max = v;
-                               }
                        }
+                       if (max == AltosLib.MISSING)
+                               max_value.setText("Missing");
+                       else
+                               max_value.setText(units.show(8, max));
                }
 
                void hide() {
@@ -290,7 +347,8 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay {
                        max_value.setVisible(false);
                }
 
-               public ValueHold (GridBagLayout layout, int y, String text) {
+               public ValueHold (GridBagLayout layout, int y, AltosUnits units, String text) {
+                       this.units = units;
                        GridBagConstraints      c = new GridBagConstraints();
                        c.weighty = 1;
 
@@ -330,10 +388,10 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay {
 
        class Altitude extends ValueHold {
                void show (AltosState state, AltosListenerState listener_state) {
-                       show(AltosConvert.height, state.altitude());
+                       show(state.altitude());
                }
                public Altitude (GridBagLayout layout, int y) {
-                       super (layout, y, "Altitude");
+                       super (layout, y, AltosConvert.height, "Altitude");
                }
        }
 
@@ -341,10 +399,10 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay {
 
        class AscentRate extends ValueHold {
                void show (AltosState state, AltosListenerState listener_state) {
-                       show(AltosConvert.speed, state.gps_ascent_rate());
+                       show(state.gps_ascent_rate());
                }
                public AscentRate (GridBagLayout layout, int y) {
-                       super (layout, y, "Ascent Rate");
+                       super (layout, y, AltosConvert.speed, "Ascent Rate");
                }
        }
 
@@ -352,10 +410,10 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay {
 
        class GroundSpeed extends ValueHold {
                void show (AltosState state, AltosListenerState listener_state) {
-                       show(AltosConvert.speed, state.gps_ground_speed());
+                       show(state.gps_ground_speed());
                }
                public GroundSpeed (GridBagLayout layout, int y) {
-                       super (layout, y, "Ground Speed");
+                       super (layout, y, AltosConvert.speed, "Ground Speed");
                }
        }
 
@@ -382,7 +440,7 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay {
                                              course));
                }
                public Course (GridBagLayout layout, int y) {
-                       super (layout, 0, y, "Course");
+                       super (layout, y, "Course", false);
                }
        }
 
@@ -416,17 +474,20 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay {
 
        Lon lon;
 
-       class GPSLocked extends Info {
+       class GPSLocked extends DualValue {
                void show (AltosState state, AltosListenerState listener_state) {
                        if (state == null || state.gps == null)
                                hide();
                        else {
-                               show("%4d sats", state.gps.nsat);
-                               lights.set(state.gps.locked && state.gps.nsat >= 4);
+                               int soln = state.gps.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);
                        }
                }
                public GPSLocked (GridBagLayout layout, int y) {
-                       super (layout, y, "GPS Locked");
+                       super (layout, y, "GPS Locked", true);
                }
        }
 
@@ -442,16 +503,26 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay {
                gps_locked.reset();
        }
 
-       public void set_font() {
+       public void font_size_changed(int font_size) {
                cur.setFont(AltosUILib.label_font);
                max.setFont(AltosUILib.label_font);
-               lat.set_font();
-               lon.set_font();
-               altitude.set_font();
-               ground_speed.set_font();
-               ascent_rate.set_font();
-               course.set_font();
-               gps_locked.set_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);
+       }
+
+       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);
        }
 
        public void show(AltosState state, AltosListenerState listener_state) {
index fd66b27..37cfae3 100644 (file)
@@ -25,7 +25,7 @@ import org.altusmetrum.altosuilib_2.*;
 public class TeleGPSStatus extends JComponent implements AltosFlightDisplay {
        GridBagLayout   layout;
 
-       public class FlightValue {
+       public class Value {
                JLabel          label;
                JTextField      value;
 
@@ -45,7 +45,7 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay {
                        value.setVisible(visible);
                }
 
-               public FlightValue (GridBagLayout layout, int x, String text) {
+               public Value (GridBagLayout layout, int x, String text) {
                        GridBagConstraints      c = new GridBagConstraints();
                        c.insets = new Insets(5, 5, 5, 5);
                        c.anchor = GridBagConstraints.CENTER;
@@ -69,7 +69,7 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay {
                }
        }
 
-       class Call extends FlightValue {
+       class Call extends Value {
                void show(AltosState state, AltosListenerState listener_state) {
                        value.setText(state.callsign);
                        if (state.callsign == null)
@@ -84,7 +84,7 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay {
 
        Call call;
 
-       class Serial extends FlightValue {
+       class Serial extends Value {
                void show(AltosState state, AltosListenerState listener_state) {
                        if (state.serial == AltosLib.MISSING)
                                value.setText("none");
@@ -98,7 +98,7 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay {
 
        Serial serial;
 
-       class RSSI extends FlightValue {
+       class RSSI extends Value {
                void show(AltosState state, AltosListenerState listener_state) {
                        value.setText(String.format("%d", state.rssi()));
                        if (state.rssi == AltosLib.MISSING)
@@ -113,7 +113,7 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay {
 
        RSSI rssi;
 
-       class LastPacket extends FlightValue {
+       class LastPacket extends Value {
                void show(AltosState state, AltosListenerState listener_state) {
                        long secs = (System.currentTimeMillis() - state.received_time + 500) / 1000;
                        value.setText(String.format("%d", secs));
@@ -132,13 +132,16 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay {
                last_packet.reset();
        }
 
-       public void set_font () {
+       public void font_size_changed(int font_size) {
                call.set_font();
                serial.set_font();
                rssi.set_font();
                last_packet.set_font();
        }
 
+       public void units_changed(boolean imperial_units) {
+       }
+
        public void show (AltosState state, AltosListenerState listener_state) {
                call.show(state, listener_state);
                serial.show(state, listener_state);