altosui: Fix Landed tab units
[fw/altos] / altosui / AltosAscent.java
index 8a4aa58b02de03234e4d070886ceaf208f84dcb6..3fe517aa6bb08388aeef0874e11ff2577dac8e89 100644 (file)
@@ -27,21 +27,54 @@ import java.util.*;
 import java.text.*;
 import java.util.prefs.*;
 import java.util.concurrent.LinkedBlockingQueue;
+import org.altusmetrum.AltosLib.*;
 
 public class AltosAscent extends JComponent implements AltosFlightDisplay {
        GridBagLayout   layout;
+       JLabel                  cur, max;
 
        public class AscentStatus {
                JLabel          label;
                JTextField      value;
                AltosLights     lights;
 
+               void show() {
+                       value.setVisible(true);
+                       lights.setVisible(true);
+                       label.setVisible(true);
+               }
+
+               void hide() {
+                       value.setVisible(false);
+                       lights.setVisible(false);
+                       label.setVisible(false);
+               }
+
                void show(AltosState state, int crc_errors) {}
+
+               void show(String s) {
+                       show();
+                       value.setText(s);
+               }
+               
+               void show(AltosUnits units, double v) {
+                       show(units.show(8, v));
+               }
+
+               void show(String format, double v) {
+                       show(String.format(format, v));
+               }
+
                void reset() {
                        value.setText("");
                        lights.set(false);
                }
 
+               void set_font() {
+                       label.setFont(Altos.label_font);
+                       value.setFont(Altos.value_font);
+               }
+
                public AscentStatus (GridBagLayout layout, int y, String text) {
                        GridBagConstraints      c = new GridBagConstraints();
                        c.weighty = 1;
@@ -93,10 +126,28 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
                        value.setVisible(true);
                }
 
+               void show(String s) {
+                       show();
+                       value.setText(s);
+               }
+               
+               void show(AltosUnits units, double 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);
                }
+               void set_font() {
+                       label.setFont(Altos.label_font);
+                       value.setFont(Altos.value_font);
+               }
+
                public AscentValue (GridBagLayout layout, int y, String text) {
                        GridBagConstraints      c = new GridBagConstraints();
                        c.weighty = 1;
@@ -136,14 +187,25 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
                void reset() {
                        value.setText("");
                        max_value.setText("");
-                       max = 0;
+                       max = AltosRecord.MISSING;
                }
 
-               void show(String format, double v) {
-                       value.setText(String.format(format, v));
-                       if (v > max) {
-                               max_value.setText(String.format(format, v));
-                               max = v;
+               void set_font() {
+                       label.setFont(Altos.label_font);
+                       value.setFont(Altos.value_font);
+                       max_value.setFont(Altos.value_font);
+               }
+
+               void show(AltosUnits units, double v) {
+                       if (v == AltosRecord.MISSING) {
+                               value.setText("Missing");
+                               max_value.setText("Missing");
+                       } else {
+                               value.setText(units.show(8, v));
+                               if (v > max || max == AltosRecord.MISSING) {
+                                       max_value.setText(units.show(8, v));
+                                       max = v;
+                               }
                        }
                }
                public AscentValueHold (GridBagLayout layout, int y, String text) {
@@ -186,7 +248,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
 
        class Height extends AscentValueHold {
                void show (AltosState state, int crc_errors) {
-                       show("%6.0f m", state.height);
+                       show(AltosConvert.height, state.height);
                }
                public Height (GridBagLayout layout, int y) {
                        super (layout, y, "Height");
@@ -200,7 +262,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
                        double speed = state.speed;
                        if (!state.ascent)
                                speed = state.baro_speed;
-                       show("%6.0f m/s", speed);
+                       show(AltosConvert.speed, speed);
                }
                public Speed (GridBagLayout layout, int y) {
                        super (layout, y, "Speed");
@@ -211,7 +273,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
 
        class Accel extends AscentValueHold {
                void show (AltosState state, int crc_errors) {
-                       show("%6.0f m/s²", state.acceleration);
+                       show(AltosConvert.accel, state.acceleration);
                }
                public Accel (GridBagLayout layout, int y) {
                        super (layout, y, "Acceleration");
@@ -233,7 +295,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
 
        class Apogee extends AscentStatus {
                void show (AltosState state, int crc_errors) {
-                       value.setText(String.format("%4.2f V", state.drogue_sense));
+                       show("%4.2f V", state.drogue_sense);
                        lights.set(state.drogue_sense > 3.2);
                }
                public Apogee (GridBagLayout layout, int y) {
@@ -245,7 +307,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
 
        class Main extends AscentStatus {
                void show (AltosState state, int crc_errors) {
-                       value.setText(String.format("%4.2f V", state.main_sense));
+                       show("%4.2f V", state.main_sense);
                        lights.set(state.main_sense > 3.2);
                }
                public Main (GridBagLayout layout, int y) {
@@ -257,11 +319,10 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
 
        class Lat extends AscentValue {
                void show (AltosState state, int crc_errors) {
-                       show();
                        if (state.gps != null)
-                               value.setText(pos(state.gps.lat,"N", "S"));
+                               show(pos(state.gps.lat,"N", "S"));
                        else
-                               value.setText("???");
+                               show("???");
                }
                public Lat (GridBagLayout layout, int y) {
                        super (layout, y, "Latitude");
@@ -272,11 +333,10 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
 
        class Lon extends AscentValue {
                void show (AltosState state, int crc_errors) {
-                       show();
                        if (state.gps != null)
-                               value.setText(pos(state.gps.lon,"E", "W"));
+                               show(pos(state.gps.lon,"E", "W"));
                        else
-                               value.setText("???");
+                               show("???");
                }
                public Lon (GridBagLayout layout, int y) {
                        super (layout, y, "Longitude");
@@ -295,8 +355,20 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
                accel.reset();
        }
 
+       public void set_font() {
+               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();
+       }
+
        public void show(AltosState state, int crc_errors) {
-               if (state.gps != null) {
+               if (state.gps != null && state.gps.connected) {
                        lat.show(state, crc_errors);
                        lon.show(state, crc_errors);
                } else {
@@ -304,15 +376,20 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay {
                        lon.hide();
                }
                height.show(state, crc_errors);
-               main.show(state, crc_errors);
-               apogee.show(state, crc_errors);
+               if (state.main_sense != AltosRecord.MISSING)
+                       main.show(state, crc_errors);
+               else
+                       main.hide();
+               if (state.drogue_sense != AltosRecord.MISSING)
+                       apogee.show(state, crc_errors);
+               else
+                       apogee.hide();
                speed.show(state, crc_errors);
                accel.show(state, crc_errors);
        }
 
        public void labels(GridBagLayout layout, int y) {
                GridBagConstraints      c;
-               JLabel                  cur, max;
 
                cur = new JLabel("Current");
                cur.setFont(Altos.label_font);