altosui/telegps: Switch to AltosUIIndicator and AltosUIFlightTab
authorKeith Packard <keithp@keithp.com>
Sat, 14 Jun 2014 21:41:13 +0000 (14:41 -0700)
committerKeith Packard <keithp@keithp.com>
Sat, 14 Jun 2014 21:42:11 +0000 (14:42 -0700)
Removes replicated code across all flight tabs

Signed-off-by: Keith Packard <keithp@keithp.com>
12 files changed:
altosui/AltosAscent.java
altosui/AltosCompanionInfo.java
altosui/AltosDescent.java
altosui/AltosFlightStatus.java
altosui/AltosFlightUI.java
altosui/AltosIgnitor.java
altosui/AltosLanded.java
altosui/AltosPad.java
telegps/TeleGPS.java
telegps/TeleGPSInfo.java
telegps/TeleGPSState.java
telegps/TeleGPSStatus.java

index c3225709c21f651fd10423ecfbcef902698c9009..3bc804068fef165716cb60686fd70dc5df0deebf 100644 (file)
 
 package altosui;
 
+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 AltosAscent extends JComponent implements AltosFlightDisplay, HierarchyListener {
-       GridBagLayout   layout;
-       JLabel                  cur, max;
+public class AltosAscent extends AltosUIFlightTab {
+       JLabel  cur, max;
 
-       private AltosState              last_state;
-       private AltosListenerState      last_listener_state;
+       class Height extends AltosUIUnitsIndicator {
 
-       public class AscentStatus 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);
-               }
-
-               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 reset() {
-                       value.setText("");
-                       lights.set(false);
-               }
-
-               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);
+               public double value(AltosState state, int i) {
+                       if (i == 0)
+                               return state.height();
+                       else
+                               return state.max_height();
                }
 
-               public AscentStatus (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(Altos.label_font);
-                       label.setHorizontalAlignment(SwingConstants.LEFT);
-                       c.gridx = 1; c.gridy = y;
-                       c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
-                       c.anchor = GridBagConstraints.WEST;
-                       c.fill = GridBagConstraints.VERTICAL;
-                       c.weightx = 0;
-                       layout.setConstraints(label, c);
-                       add(label);
-
-                       value = new JTextField(Altos.text_width);
-                       value.setEditable(false);
-                       value.setFont(Altos.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 Height(Container container, int y) {
+                       super(container, y, AltosConvert.height, "Height", 2, false, 1);
                }
        }
 
-       public abstract class AscentValue implements AltosFontListener, AltosUnitsListener {
-               JLabel          label;
-               JTextField      value;
-               double          v;
-               AltosUnits      units;
-
-               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);
+       class Speed extends AltosUIUnitsIndicator {
+               public double value(AltosState state, int i) {
+                       if (i == 0)
+                               return state.speed();
+                       else
+                               return state.max_speed();
                }
 
-               public void font_size_changed(int font_size) {
-                       label.setFont(Altos.label_font);
-                       value.setFont(Altos.value_font);
+               public Speed(Container container, int y) {
+                       super(container, y, AltosConvert.speed, "Speed", 2, false, 1);
                }
+       }
 
-               public void units_changed(boolean imperial_units) {
-                       if (units != null)
-                               show(v);
-               }
+       class Accel extends AltosUIUnitsIndicator {
+               public boolean hide(double v) { return v == AltosLib.MISSING; }
 
-               public AscentValue (GridBagLayout layout, int y, AltosUnits units, String text) {
-                       GridBagConstraints      c = new GridBagConstraints();
-                       c.weighty = 1;
-
-                       label = new JLabel(text);
-                       label.setFont(Altos.label_font);
-                       label.setHorizontalAlignment(SwingConstants.LEFT);
-                       c.gridx = 1; c.gridy = y;
-                       c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
-                       c.anchor = GridBagConstraints.WEST;
-                       c.fill = GridBagConstraints.VERTICAL;
-                       c.weightx = 0;
-                       layout.setConstraints(label, c);
-                       add(label);
-
-                       value = new JTextField(Altos.text_width);
-                       value.setEditable(false);
-                       value.setFont(Altos.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);
+               public double value(AltosState state, int i) {
+                       if (i == 0)
+                               return state.acceleration();
+                       else
+                               return state.max_acceleration();
                }
 
-               public AscentValue (GridBagLayout layout, int y, String text) {
-                       this(layout, y, null, text);
+               public Accel(Container container, int y) {
+                       super(container, y, AltosConvert.accel, "Acceleration", 2, false, 1);
                }
        }
 
-       public class AscentValueHold implements AltosFontListener, AltosUnitsListener {
-               JLabel          label;
-               JTextField      value;
-               JTextField      max_value;
-               double          max;
-               AltosUnits      units;
-               double          v;
+       class Orient extends AltosUIUnitsIndicator {
 
-               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(Altos.label_font);
-                       value.setFont(Altos.value_font);
-                       max_value.setFont(Altos.value_font);
-               }
+               public boolean hide(double v) { return v == AltosLib.MISSING; }
 
-               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");
+               public double value(AltosState state, int i) {
+                       if (i == 0)
+                               return state.orient();
                        else
-                               max_value.setText(units.show(8, max));
+                               return state.max_orient();
                }
 
-               void hide() {
-                       label.setVisible(false);
-                       value.setVisible(false);
-                       max_value.setVisible(false);
+               public Orient(Container container, int y) {
+                       super(container, y, AltosConvert.orient, "Tilt Angle", 2, false, 1);
                }
 
-               public AscentValueHold (GridBagLayout layout, int y, AltosUnits units, String text) {
-                       this.units = units;
-                       GridBagConstraints      c = new GridBagConstraints();
-                       c.weighty = 1;
-
-                       label = new JLabel(text);
-                       label.setFont(Altos.label_font);
-                       label.setHorizontalAlignment(SwingConstants.LEFT);
-                       c.gridx = 1; c.gridy = y;
-                       c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
-                       c.anchor = GridBagConstraints.WEST;
-                       c.fill = GridBagConstraints.VERTICAL;
-                       c.weightx = 0;
-                       layout.setConstraints(label, c);
-                       add(label);
-
-                       value = new JTextField(Altos.text_width);
-                       value.setEditable(false);
-                       value.setFont(Altos.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(Altos.text_width);
-                       max_value.setEditable(false);
-                       max_value.setFont(Altos.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);
-               }
        }
 
-       class Height extends AscentValueHold {
-               void show (AltosState state, AltosListenerState listener_state) {
-                       show(state.height(), state.max_height());
-               }
-               public Height (GridBagLayout layout, int y) {
-                       super (layout, y, AltosConvert.height, "Height");
+       class Apogee extends AltosUIUnitsIndicator {
+
+               public double value(AltosState state, int i) {
+                       return state.apogee_voltage;
                }
-       }
 
-       Height  height;
+               public boolean good(double v) { return v >= AltosLib.ao_igniter_good; }
+               public boolean hide(double v) { return v == AltosLib.MISSING; }
 
-       class Speed extends AscentValueHold {
-               void show (AltosState state, AltosListenerState listener_state) {
-                       show(state.speed(), state.max_speed());
-               }
-               public Speed (GridBagLayout layout, int y) {
-                       super (layout, y, AltosConvert.speed, "Speed");
+               public Apogee (Container container, int y) {
+                       super(container, y, AltosConvert.voltage, "Apogee Igniter Voltage", 1, true, 2);
                }
        }
 
-       Speed   speed;
-
-       class Accel extends AscentValueHold {
-               void show (AltosState state, AltosListenerState listener_state) {
-                       show(state.acceleration(), state.max_acceleration());
+       class Main extends AltosUIUnitsIndicator {
+               public double value(AltosState state, int i) {
+                       return state.main_voltage;
                }
-               public Accel (GridBagLayout layout, int y) {
-                       super (layout, y, AltosConvert.accel, "Acceleration");
-               }
-       }
 
-       Accel   accel;
+               public boolean good(double v) { return v >= AltosLib.ao_igniter_good; }
+               public boolean hide(double v) { return v == AltosLib.MISSING; }
 
-       class Orient extends AscentValueHold {
-               void show (AltosState state, AltosListenerState listener_state) {
-                       show(state.orient(), state.max_orient());
-               }
-               public Orient (GridBagLayout layout, int y) {
-                       super (layout, y, AltosConvert.orient, "Tilt Angle");
+               public Main (Container container, int y) {
+                       super(container, y, AltosConvert.voltage, "Main Igniter Voltage", 1, true, 2);
                }
        }
 
-       Orient  orient;
+       class Lat extends AltosUIUnitsIndicator {
 
-       String pos(double p, String pos, String neg) {
-               String  h = pos;
-               if (p < 0) {
-                       h = neg;
-                       p = -p;
+               public boolean hide(AltosState state, int i) {
+                       return state.gps == null || !state.gps.connected;
                }
-               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 Apogee extends AscentStatus {
-               void show (AltosState state, AltosListenerState listener_state) {
-                       show("%4.2f V", state.apogee_voltage);
-                       lights.set(state.apogee_voltage >= AltosLib.ao_igniter_good);
-               }
-               public Apogee (GridBagLayout layout, int y) {
-                       super(layout, y, null, "Apogee Igniter Voltage");
+               public double value(AltosState state, int i) {
+                       if (state.gps == null)
+                               return AltosLib.MISSING;
+                       if (!state.gps.connected)
+                               return AltosLib.MISSING;
+                       return state.gps.lat;
                }
-       }
-
-       Apogee apogee;
 
-       class Main extends AscentStatus {
-               void show (AltosState state, AltosListenerState listener_state) {
-                       show("%4.2f V", state.main_voltage);
-                       lights.set(state.main_voltage >= AltosLib.ao_igniter_good);
-               }
-               public Main (GridBagLayout layout, int y) {
-                       super(layout, y, null, "Main Igniter Voltage");
+               Lat (Container container, int y) {
+                       super (container, y, AltosConvert.latitude, "Latitude", 1, false, 2);
                }
        }
 
-       Main main;
+       class Lon extends AltosUIUnitsIndicator {
 
-       class Lat extends AscentValue {
-               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("???");
+               public boolean hide(AltosState state, int i) {
+                       return state.gps == null || !state.gps.connected;
                }
-               public Lat (GridBagLayout layout, int y) {
-                       super (layout, y, "Latitude");
-               }
-       }
 
-       Lat lat;
-
-       class Lon extends AscentValue {
-               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("???");
-               }
-               public Lon (GridBagLayout layout, int y) {
-                       super (layout, y, "Longitude");
+               public double value(AltosState state, int i) {
+                       if (state.gps == null)
+                               return AltosLib.MISSING;
+                       if (!state.gps.connected)
+                               return AltosLib.MISSING;
+                       return state.gps.lon;
                }
-       }
 
-       Lon lon;
-
-       public void reset() {
-               lat.reset();
-               lon.reset();
-               main.reset();
-               apogee.reset();
-               height.reset();
-               speed.reset();
-               accel.reset();
-               orient.reset();
+               Lon (Container container, int y) {
+                       super (container, y, AltosConvert.longitude, "Longitude", 1, false, 2);
+               }
        }
 
        public void font_size_changed(int font_size) {
-               cur.setFont(Altos.label_font);
-               max.setFont(Altos.label_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) {
-               if (!isShowing()) {
-                       last_state = state;
-                       last_listener_state = listener_state;
-                       return;
-               }
-
-               if (state.gps != null && state.gps.connected) {
-                       lat.show(state, listener_state);
-                       lon.show(state, listener_state);
-               } else {
-                       lat.hide();
-                       lon.hide();
-               }
-               height.show(state, listener_state);
-               if (state.main_voltage != AltosLib.MISSING)
-                       main.show(state, listener_state);
-               else
-                       main.hide();
-               if (state.apogee_voltage != AltosLib.MISSING)
-                       apogee.show(state, listener_state);
-               else
-                       apogee.hide();
-               speed.show(state, listener_state);
-               accel.show(state, listener_state);
-               if (state.orient() != AltosLib.MISSING)
-                       orient.show(state, listener_state);
-               else
-                       orient.hide();
+               super.font_size_changed(font_size);
+               cur.setFont(AltosUILib.label_font);
+               max.setFont(AltosUILib.label_font);
        }
 
        public void labels(GridBagLayout layout, int y) {
                GridBagConstraints      c;
 
                cur = new JLabel("Current");
-               cur.setFont(Altos.label_font);
+               cur.setFont(AltosUILib.label_font);
                c = new GridBagConstraints();
                c.gridx = 2; c.gridy = y;
                c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
@@ -469,7 +169,7 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay, Hiera
                add(cur);
 
                max = new JLabel("Maximum");
-               max.setFont(Altos.label_font);
+               max.setFont(AltosUILib.label_font);
                c.gridx = 3; c.gridy = y;
                layout.setConstraints(max, c);
                add(max);
@@ -479,38 +179,16 @@ public class AltosAscent extends JComponent implements AltosFlightDisplay, Hiera
                return "Ascent";
        }
 
-       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 AltosAscent() {
-               layout = new GridBagLayout();
-
-               setLayout(layout);
-
-               /* Elements in ascent display:
-                *
-                * lat
-                * lon
-                * height
-                */
                int y = 0;
                labels(layout, y++);
-               height = new Height(layout, y++);
-               speed = new Speed(layout, y++);
-               accel = new Accel(layout, y++);
-               orient = new Orient(layout, y++);
-               lat = new Lat(layout, y++);
-               lon = new Lon(layout, y++);
-               apogee = new Apogee(layout, y++);
-               main = new Main(layout, y++);
-               addHierarchyListener(this);
+               add(new Height(this, y++));
+               add(new Speed(this, y++));
+               add(new Accel(this, y++));
+               add(new Orient(this, y++));
+               add(new Lat(this, y++));
+               add(new Lon(this, y++));
+               add(new Apogee(this, y++));
+               add(new Main(this, y++));
        }
 }
index 514ce61126483dc07ac1e9a6311fa22f972d5e04..e7b335ac7f6fcc32168e3c0c7cedb08b5928d674 100644 (file)
@@ -87,6 +87,8 @@ public class AltosCompanionInfo extends JTable implements AltosFlightDisplay {
                }
        }
 
+       public String getName() { return "Companion"; }
+
        public void show(AltosState state, AltosListenerState listener_state) {
                if (state == null)
                        return;
index 11bd6dbf2c331c16461f8bad396a2b6b6475902c..36fc16138c2b81c4c285eb842d4e32c571707c65 100644 (file)
 
 package altosui;
 
+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 AltosDescent extends JComponent implements AltosFlightDisplay, HierarchyListener {
-       GridBagLayout   layout;
+public class AltosDescent extends AltosUIFlightTab {
 
-       private AltosState              last_state;
-       private AltosListenerState      last_listener_state;
-
-       public abstract class DescentStatus implements AltosFontListener, AltosUnitsListener {
-               JLabel          label;
-               JTextField      value;
-               AltosLights     lights;
-
-               abstract void show(AltosState state, AltosListenerState listener_state);
-
-               void show() {
-                       label.setVisible(true);
-                       value.setVisible(true);
-                       lights.setVisible(true);
-               }
-
-               void show(String s) {
-                       show();
-                       value.setText(s);
-               }
-
-               void show(String format, double value) {
-                       show(String.format(format, value));
-               }
-
-               void hide() {
-                       label.setVisible(false);
-                       value.setVisible(false);
-                       lights.setVisible(false);
-               }
-
-               void reset() {
-                       value.setText("");
-                       lights.set(false);
-               }
-
-               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;
-
-                       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(Altos.label_font);
-                       label.setHorizontalAlignment(SwingConstants.LEFT);
-                       c.gridx = 1; c.gridy = y;
-                       c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
-                       c.anchor = GridBagConstraints.WEST;
-                       c.fill = GridBagConstraints.VERTICAL;
-                       c.gridwidth = 3;
-                       c.weightx = 0;
-                       layout.setConstraints(label, c);
-                       add(label);
-
-                       value = new JTextField(Altos.text_width);
-                       value.setEditable(false);
-                       value.setFont(Altos.value_font);
-                       value.setHorizontalAlignment(SwingConstants.RIGHT);
-                       c.gridx = 4; c.gridy = y;
-                       c.gridwidth = 1;
-                       c.anchor = GridBagConstraints.WEST;
-                       c.fill = GridBagConstraints.BOTH;
-                       c.weightx = 1;
-                       layout.setConstraints(value, c);
-                       add(value);
+       class Height extends AltosUIUnitsIndicator {
+               public double value(AltosState state, int i) { return state.height(); }
 
+               public Height (Container container, int x, int y) {
+                       super (container, x, y, AltosConvert.height, "Height");
                }
        }
 
-       public abstract class DescentValue implements AltosFontListener, AltosUnitsListener {
-               JLabel          label;
-               JTextField      value;
-               AltosUnits      units;
-               double          v;
-               String          last_value = "";
-
-               void reset() {
-                       value.setText("");
-               }
-
-               abstract void show(AltosState state, AltosListenerState listener_state);
-
-               void show() {
-                       label.setVisible(true);
-                       value.setVisible(true);
-               }
+       class Speed extends AltosUIUnitsIndicator {
+               public double value(AltosState state, int i) { return state.speed(); }
 
-               void hide() {
-                       label.setVisible(false);
-                       value.setVisible(false);
-               }
-
-               void show(String v) {
-                       show();
-
-                       if (!last_value.equals(v)) {
-                               value.setText(v);
-                               last_value = v;
-                       }
-               }
-
-               void show(double v) {
-                       this.v = v;
-                       if (v == AltosLib.MISSING)
-                               show("Missing");
-                       else
-                               show(units.show(8, v));
-               }
-
-               void show(String format, double v) {
-                       if (v == AltosLib.MISSING)
-                               show("Missing");
-                       else
-                               show(String.format(format, v));
-               }
-
-               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);
-               }
-
-               public DescentValue (GridBagLayout layout, int x, int y, AltosUnits units, String text) {
-                       this.units = units;
-                       GridBagConstraints      c = new GridBagConstraints();
-                       c.weighty = 1;
-
-                       label = new JLabel(text);
-                       label.setFont(Altos.label_font);
-                       label.setHorizontalAlignment(SwingConstants.LEFT);
-                       c.gridx = x + 1; c.gridy = y;
-                       c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
-                       c.anchor = GridBagConstraints.WEST;
-                       c.fill = GridBagConstraints.VERTICAL;
-                       c.weightx = 0;
-                       add(label, c);
-
-                       value = new JTextField(Altos.text_width);
-                       value.setEditable(false);
-                       value.setFont(Altos.value_font);
-                       value.setHorizontalAlignment(SwingConstants.RIGHT);
-                       c.gridx = x + 2; c.gridy = y;
-                       c.gridwidth = 1;
-                       c.anchor = GridBagConstraints.WEST;
-                       c.fill = GridBagConstraints.BOTH;
-                       c.weightx = 1;
-                       add(value, c);
-               }
-
-               public DescentValue (GridBagLayout layout, int x, int y, String text) {
-                       this(layout, x, y, null, text);
+               public Speed (Container container, int x, int y) {
+                       super (container, x, y, AltosConvert.speed, "Speed");
                }
        }
 
-       public abstract class DescentDualValue implements AltosFontListener, AltosUnitsListener {
-               JLabel          label;
-               JTextField      value1;
-               JTextField      value2;
+       class Lat extends AltosUIUnitsIndicator {
 
-               void reset() {
-                       value1.setText("");
-                       value2.setText("");
-               }
+               public boolean hide (AltosState state, int i) { return state.gps == null || !state.gps.connected; }
 
-               void show() {
-                       label.setVisible(true);
-                       value1.setVisible(true);
-                       value2.setVisible(true);
+               public double value(AltosState state, int i) {
+                       if (state.gps == null)
+                               return AltosLib.MISSING;
+                       if (!state.gps.connected)
+                               return AltosLib.MISSING;
+                       return state.gps.lat;
                }
 
-               void hide() {
-                       label.setVisible(false);
-                       value1.setVisible(false);
-                       value2.setVisible(false);
-               }
-
-               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) {
-                       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));
-               }
-
-               public DescentDualValue (GridBagLayout layout, int x, int y, String text) {
-                       GridBagConstraints      c = new GridBagConstraints();
-                       c.weighty = 1;
-
-                       label = new JLabel(text);
-                       label.setFont(Altos.label_font);
-                       label.setHorizontalAlignment(SwingConstants.LEFT);
-                       c.gridx = x + 1; c.gridy = y;
-                       c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
-                       c.anchor = GridBagConstraints.WEST;
-                       c.fill = GridBagConstraints.VERTICAL;
-                       c.weightx = 0;
-                       layout.setConstraints(label, c);
-                       add(label);
-
-                       value1 = new JTextField(Altos.text_width);
-                       value1.setEditable(false);
-                       value1.setFont(Altos.value_font);
-                       value1.setHorizontalAlignment(SwingConstants.RIGHT);
-                       c.gridx = x + 2; c.gridy = y;
-                       c.anchor = GridBagConstraints.WEST;
-                       c.fill = GridBagConstraints.BOTH;
-                       c.weightx = 1;
-                       layout.setConstraints(value1, c);
-                       add(value1);
-
-                       value2 = new JTextField(Altos.text_width);
-                       value2.setEditable(false);
-                       value2.setFont(Altos.value_font);
-                       value2.setHorizontalAlignment(SwingConstants.RIGHT);
-                       c.gridx = x + 4; c.gridy = y;
-                       c.anchor = GridBagConstraints.WEST;
-                       c.fill = GridBagConstraints.BOTH;
-                       c.weightx = 1;
-                       c.gridwidth = 1;
-                       layout.setConstraints(value2, c);
-                       add(value2);
-               }
-       }
-
-       class Height extends DescentValue {
-               void show (AltosState state, AltosListenerState listener_state) {
-                       show(state.height());
-               }
-               public Height (GridBagLayout layout, int x, int y) {
-                       super (layout, x, y, AltosConvert.height, "Height");
+               public Lat (Container container, int x, int y) {
+                       super (container, x, y, AltosConvert.latitude, "Latitude");
                }
        }
 
-       Height  height;
+       class Lon extends AltosUIUnitsIndicator {
+               public boolean hide (AltosState state, int i) { return state.gps == null || !state.gps.connected; }
 
-       class Speed extends DescentValue {
-               void show (AltosState state, AltosListenerState listener_state) {
-                       show(state.speed());
-               }
-               public Speed (GridBagLayout layout, int x, int y) {
-                       super (layout, x, y, AltosConvert.speed, "Speed");
+               public double value(AltosState state, int i) {
+                       if (state.gps == null)
+                               return AltosLib.MISSING;
+                       if (!state.gps.connected)
+                               return AltosLib.MISSING;
+                       return state.gps.lon;
                }
-       }
-
-       Speed   speed;
 
-       String pos(double p, String pos, String neg) {
-               String  h = pos;
-               if (p < 0) {
-                       h = neg;
-                       p = -p;
+               public Lon (Container container, int x, int y) {
+                       super (container, x, y, AltosConvert.longitude, "Longitude");
                }
-               int deg = (int) Math.floor(p);
-               double min = (p - Math.floor(p)) * 60.0;
-               return String.format("%s %d° %9.6f", h, deg, min);
        }
 
-       class Lat extends DescentValue {
-               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("???");
-               }
-               public Lat (GridBagLayout layout, int x, int y) {
-                       super (layout, x, y, "Latitude");
+       class Apogee extends AltosUIUnitsIndicator {
+               public boolean hide(double v) { return v == AltosLib.MISSING; }
+               public double value(AltosState state, int i) { return state.apogee_voltage; }
+               public double good() { return AltosLib.ao_igniter_good; }
+
+               public Apogee (Container container, int y) {
+                       super(container, 0, y, 3, AltosConvert.voltage, "Apogee Igniter Voltage", 1, true, 3);
                }
        }
 
-       Lat lat;
+       class Main extends AltosUIUnitsIndicator {
+               public boolean hide(double v) { return v == AltosLib.MISSING; }
+               public double value(AltosState state, int i) { return state.main_voltage; }
+               public double good() { return AltosLib.ao_igniter_good; }
 
-       class Lon extends DescentValue {
-               void show (AltosState state, AltosListenerState listener_state) {
-                       if (state.gps != null && state.gps.connected && state.gps.lon != AltosLib.MISSING)
-                               show(pos(state.gps.lon,"W", "E"));
-                       else
-                               show("???");
-               }
-               public Lon (GridBagLayout layout, int x, int y) {
-                       super (layout, x, y, "Longitude");
+               public Main (Container container, int y) {
+                       super(container, 0, y, 3, AltosConvert.voltage, "Main Igniter Voltage", 1, true, 3);
                }
        }
 
-       Lon lon;
-
-       class Distance extends DescentValue {
-               void show(AltosState state, AltosListenerState listener_state) {
+       class Distance extends AltosUIUnitsIndicator {
+               public double value(AltosState state, int i) {
                        if (state.from_pad != null)
-                               show(state.from_pad.distance);
+                               return state.from_pad.distance;
                        else
-                               show("???");
+                               return AltosLib.MISSING;
                }
 
-               public Distance (GridBagLayout layout, int x, int y) {
-                       super(layout, x, y, AltosConvert.distance, "Ground Distance");
+               public Distance(Container container, int x, int y) {
+                       super(container, x, y, AltosConvert.distance, "Ground Distance");
                }
        }
 
-       Distance distance;
-
-
-       class Apogee extends DescentStatus {
-               void show (AltosState state, AltosListenerState listener_state) {
-                       show("%4.2f V", state.apogee_voltage);
-                       lights.set(state.apogee_voltage >= AltosLib.ao_igniter_good);
+       class Range extends AltosUIUnitsIndicator {
+               public double value(AltosState state, int i) {
+                       return state.range;
                }
-               public Apogee (GridBagLayout layout, int y) {
-                       super(layout, y, "Apogee Igniter Voltage");
+               public Range (Container container, int x, int y) {
+                       super (container, x, y, AltosConvert.distance, "Range");
                }
        }
 
-       Apogee apogee;
-
-       class Main extends DescentStatus {
-               void show (AltosState state, AltosListenerState listener_state) {
-                       show("%4.2f V", state.main_voltage);
-                       lights.set(state.main_voltage >= AltosLib.ao_igniter_good);
-               }
-               public Main (GridBagLayout layout, int y) {
-                       super(layout, y, "Main Igniter Voltage");
-               }
-       }
-
-       Main main;
-
-       class Bearing extends DescentDualValue {
-               void show (AltosState state, AltosListenerState listener_state) {
-                       if (state.from_pad != null) {
+       class Bearing extends AltosUIIndicator {
+               public void show (AltosState state, AltosListenerState listener_state) {
+                       if (state.from_pad != null && state.from_pad.bearing != AltosLib.MISSING) {
                                show( String.format("%3.0f°", state.from_pad.bearing),
                                      state.from_pad.bearing_words(
                                              AltosGreatCircle.BEARING_LONG));
                        } else {
-                               show("???", "???");
+                               show("Missing", "Missing");
                        }
                }
-               public Bearing (GridBagLayout layout, int x, int y) {
-                       super (layout, x, y, "Bearing");
+               public Bearing (Container container, int x, int y) {
+                       super (container, x, y, 1, "Bearing", 2, false, 1, 2);
                }
        }
 
-       Bearing bearing;
-
-       class Range extends DescentValue {
-               void show (AltosState state, AltosListenerState listener_state) {
-                       show(state.range);
-               }
-               public Range (GridBagLayout layout, int x, int y) {
-                       super (layout, x, y, AltosConvert.distance, "Range");
-               }
-       }
-
-       Range range;
-
-       class Elevation extends DescentValue {
-               void show (AltosState state, AltosListenerState listener_state) {
-                       show("%3.0f°", state.elevation);
-               }
-               public Elevation (GridBagLayout layout, int x, int y) {
-                       super (layout, x, y, "Elevation");
-               }
-       }
-
-       Elevation elevation;
-
-       public void reset() {
-               lat.reset();
-               lon.reset();
-               height.reset();
-               speed.reset();
-               bearing.reset();
-               range.reset();
-               distance.reset();
-               elevation.reset();
-               main.reset();
-               apogee.reset();
-       }
-
-       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) {
-               if (!isShowing()) {
-                       last_state = state;
-                       last_listener_state = listener_state;
-                       return;
+       class Elevation extends AltosUIIndicator {
+               public void show (AltosState state, AltosListenerState listener_state) {
+                       if (state.elevation == AltosLib.MISSING)
+                               show("Missing");
+                       else
+                               show("%3.0f°", state.elevation);
                }
-
-               height.show(state, listener_state);
-               speed.show(state, listener_state);
-               if (state.gps != null && state.gps.connected) {
-                       bearing.show(state, listener_state);
-                       range.show(state, listener_state);
-                       distance.show(state, listener_state);
-                       elevation.show(state, listener_state);
-                       lat.show(state, listener_state);
-                       lon.show(state, listener_state);
-               } else {
-                       bearing.hide();
-                       range.hide();
-                       distance.hide();
-                       elevation.hide();
-                       lat.hide();
-                       lon.hide();
+               public Elevation (Container container, int x, int y) {
+                       super (container, x, y, "Elevation", 1, false, 1);
                }
-               if (state.main_voltage != AltosLib.MISSING)
-                       main.show(state, listener_state);
-               else
-                       main.hide();
-               if (state.apogee_voltage != AltosLib.MISSING)
-                       apogee.show(state, listener_state);
-               else
-                       apogee.hide();
        }
 
        public String getName() {
                return "Descent";
        }
 
-       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 AltosDescent() {
-               layout = new GridBagLayout();
-
-               setLayout(layout);
-
                /* Elements in descent display */
-               speed = new Speed(layout, 0, 0);
-               height = new Height(layout, 2, 0);
-               elevation = new Elevation(layout, 0, 1);
-               range = new Range(layout, 2, 1);
-               bearing = new Bearing(layout, 0, 2);
-               distance = new Distance(layout, 0, 3);
-               lat = new Lat(layout, 0, 4);
-               lon = new Lon(layout, 2, 4);
-
-               apogee = new Apogee(layout, 5);
-               main = new Main(layout, 6);
-               addHierarchyListener(this);
+               add(new Speed(this, 0, 0));
+               add(new Height(this, 2, 0));
+               add(new Elevation(this, 0, 1));
+               add(new Range(this, 2, 1));
+               add(new Bearing(this, 0, 2));
+               add(new Distance(this, 0, 3));
+               add(new Lat(this, 0, 4));
+               add(new Lon(this, 2, 4));
+               add(new Apogee(this, 5));
+               add(new Main(this, 6));
        }
 }
index b27deba903a589af3c3b86cb29c23920ed886083..46c0b38736d5c9d4c53bf1c1519634ebee9765b4 100644 (file)
@@ -25,11 +25,21 @@ import org.altusmetrum.altosuilib_2.*;
 public class AltosFlightStatus extends JComponent implements AltosFlightDisplay {
        GridBagLayout   layout;
 
-       public class FlightValue {
+       public abstract class FlightValue {
                JLabel          label;
                JTextField      value;
 
-               void show(AltosState state, AltosListenerState listener_state) {}
+               void show() {
+                       label.setVisible(true);
+                       value.setVisible(true);
+               }
+
+               void hide() {
+                       label.setVisible(false);
+                       value.setVisible(false);
+               }
+
+               abstract void show(AltosState state, AltosListenerState listener_state);
 
                void reset() {
                        value.setText("");
@@ -83,6 +93,7 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay
 
                void show(AltosState state, AltosListenerState listener_state) {
                        if (!same_call(state.callsign)) {
+                               show();
                                value.setText(state.callsign);
                                if (state.callsign == null)
                                        setVisible(false);
@@ -91,6 +102,12 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay
                                last_call = state.callsign;
                        }
                }
+
+               public void reset() {
+                       super.reset();
+                       last_call = "";
+               }
+
                public Call (GridBagLayout layout, int x) {
                        super (layout, x, "Callsign");
                }
@@ -103,6 +120,7 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay
                int     last_serial = -1;
                void show(AltosState state, AltosListenerState listener_state) {
                        if (state.serial != last_serial) {
+                               show();
                                if (state.serial == AltosLib.MISSING)
                                        value.setText("none");
                                else
@@ -110,6 +128,12 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay
                                last_serial = state.serial;
                        }
                }
+
+               public void reset() {
+                       super.reset();
+                       last_serial = -1;
+               }
+
                public Serial (GridBagLayout layout, int x) {
                        super (layout, x, "Serial");
                }
@@ -123,6 +147,7 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay
 
                void show(AltosState state, AltosListenerState listener_state) {
                        if (state.flight != last_flight) {
+                               show();
                                if (state.flight == AltosLib.MISSING)
                                        value.setText("none");
                                else
@@ -130,6 +155,12 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay
                                last_flight = state.flight;
                        }
                }
+
+               public void reset() {
+                       super.reset();
+                       last_flight = -1;
+               }
+
                public Flight (GridBagLayout layout, int x) {
                        super (layout, x, "Flight");
                }
@@ -143,10 +174,21 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay
 
                void show(AltosState state, AltosListenerState listener_state) {
                        if (state.state != last_state) {
-                               value.setText(state.state_name());
+                               if (state.state == AltosLib.ao_flight_stateless)
+                                       hide();
+                               else {
+                                       show();
+                                       value.setText(state.state_name());
+                               }
                                last_state = state.state;
                        }
                }
+
+               public void reset() {
+                       super.reset();
+                       last_state = -1;
+               }
+
                public FlightState (GridBagLayout layout, int x) {
                        super (layout, x, "State");
                }
@@ -160,6 +202,7 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay
 
                void show(AltosState state, AltosListenerState listener_state) {
                        if (state.rssi() != last_rssi) {
+                               show();
                                value.setText(String.format("%d", state.rssi()));
                                if (state.rssi == AltosLib.MISSING)
                                        setVisible(false);
@@ -168,6 +211,12 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay
                                last_rssi = state.rssi();
                        }
                }
+
+               public void reset() {
+                       super.reset();
+                       last_rssi = 10000;
+               }
+
                public RSSI (GridBagLayout layout, int x) {
                        super (layout, x, "RSSI");
                }
@@ -186,6 +235,12 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay
                                last_secs = secs;
                        }
                }
+
+               public void reset() {
+                       super.reset();
+                       last_secs = -1;
+               }
+
                public LastPacket(GridBagLayout layout, int x) {
                        super (layout, x, "Age");
                }
@@ -228,6 +283,8 @@ public class AltosFlightStatus extends JComponent implements AltosFlightDisplay
                return d.height;
        }
 
+       public String getName() { return "Flight Status"; }
+
        public AltosFlightStatus() {
                layout = new GridBagLayout();
 
index f2bd70a0c5b44e10b9c10b7952b44d3ca1b73940..43deb631705f86abc30dd5f072570daeb6e3a7ba 100644 (file)
@@ -20,6 +20,7 @@ package altosui;
 import java.awt.*;
 import java.awt.event.*;
 import javax.swing.*;
+import java.util.*;
 import java.util.concurrent.*;
 import org.altusmetrum.altoslib_4.*;
 import org.altusmetrum.altosuilib_2.*;
@@ -29,6 +30,8 @@ public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay {
        AltosFlightReader       reader;
        AltosDisplayThread      thread;
 
+       LinkedList<AltosFlightDisplay> displays;
+
        JTabbedPane     pane;
 
        AltosPad        pad;
@@ -56,6 +59,8 @@ public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay {
                        return ascent;
                if (state.state <= Altos.ao_flight_main)
                        return descent;
+               if (state.state == AltosLib.ao_flight_stateless)
+                       return descent;
                return landed;
        }
 
@@ -74,37 +79,18 @@ public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay {
        }
 
        public void reset() {
-               pad.reset();
-               ignitor.reset();
-               ascent.reset();
-               descent.reset();
-               landed.reset();
-               flightInfo.clear();
-               sitemap.reset();
+               for (AltosFlightDisplay d : displays)
+                       d.reset();
        }
 
        public void font_size_changed(int font_size) {
-               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);
+               for (AltosFlightDisplay d : displays)
+                       d.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);
+               for (AltosFlightDisplay d : displays)
+                       d.units_changed(imperial_units);
        }
 
        AltosFlightStatusUpdate status_update;
@@ -115,8 +101,6 @@ public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay {
                if (state == null)
                        state = new AltosState();
 
-               pad.show(state, listener_state);
-
                if (state.state != Altos.ao_flight_startup) {
                        if (!has_state) {
                                pane.setTitleAt(0, "Launch Pad");
@@ -127,10 +111,6 @@ public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay {
                        }
                }
 
-               ascent.show(state, listener_state);
-               descent.show(state, listener_state);
-               landed.show(state, listener_state);
-
                JComponent tab = which_tab(state);
                if (tab != cur_tab) {
                        if (cur_tab == pane.getSelectedComponent()) {
@@ -138,15 +118,12 @@ public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay {
                        }
                        cur_tab = tab;
                }
-               flightStatus.show(state, listener_state);
-               flightInfo.show(state, listener_state);
 
                if (ignitor.should_show(state)) {
                        if (!has_ignitor) {
                                pane.add("Ignitor", ignitor);
                                has_ignitor = true;
                        }
-                       ignitor.show(state, listener_state);
                } else {
                        if (has_ignitor) {
                                pane.remove(ignitor);
@@ -159,25 +136,33 @@ public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay {
                                pane.add("Companion", companion);
                                has_companion= true;
                        }
-                       companion.show(state, listener_state);
                } else {
                        if (has_companion) {
                                pane.remove(companion);
                                has_companion = false;
                        }
                }
+
                if (state.gps != null && state.gps.connected) {
                        if (!has_map) {
                                pane.add("Site Map", sitemap);
                                has_map = true;
                        }
-                       sitemap.show(state, listener_state);
                } else {
                        if (has_map) {
                                pane.remove(sitemap);
                                has_map = false;
                        }
                }
+
+               for (AltosFlightDisplay d : displays) {
+                       try {
+                               d.show(state, listener_state);
+                       } catch (Exception e) {
+                               System.out.printf("Exception showing %s\n", d.getName());
+                               e.printStackTrace();
+                       }
+               }
        }
 
        public void set_exit_on_close() {
@@ -194,6 +179,8 @@ public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay {
        public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) {
                AltosUIPreferences.set_component(this);
 
+               displays = new LinkedList<AltosFlightDisplay>();
+
                voice = in_voice;
                reader = in_reader;
 
@@ -282,6 +269,7 @@ public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay {
 
                /* Flight status is always visible */
                flightStatus = new AltosFlightStatus();
+               displays.add(flightStatus);
                c.gridx = 0;
                c.gridy = 1;
                c.fill = GridBagConstraints.HORIZONTAL;
@@ -296,21 +284,29 @@ public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay {
                pane = new JTabbedPane();
 
                pad = new AltosPad();
+               displays.add(pad);
                pane.add("Status", pad);
 
                ignitor = new AltosIgnitor();
+               displays.add(ignitor);
                ascent = new AltosAscent();
+               displays.add(ascent);
                descent = new AltosDescent();
+               displays.add(descent);
                landed = new AltosLanded(reader);
+               displays.add(landed);
 
                flightInfo = new AltosInfoTable();
+               displays.add(flightInfo);
                pane.add("Table", new JScrollPane(flightInfo));
 
                companion = new AltosCompanionInfo();
+               displays.add(companion);
                has_companion = false;
                has_state = false;
 
                sitemap = new AltosUIMap();
+               displays.add(sitemap);
                has_map = false;
 
                /* Make the tabbed pane use the rest of the window space */
index 73318117bc7985152f7c9730c6b081b73661d088..990a87e681775710eb66ceaa13d261e1c24d5ba6 100644 (file)
 package altosui;
 
 import java.awt.*;
+import java.awt.event.*;
 import javax.swing.*;
 import org.altusmetrum.altoslib_4.*;
 import org.altusmetrum.altosuilib_2.*;
 
-public class AltosIgnitor extends JComponent implements AltosFlightDisplay {
-       GridBagLayout   layout;
+public class AltosIgnitor extends AltosUIFlightTab {
 
-       public class LaunchStatus implements AltosFontListener, AltosUnitsListener {
-               JLabel          label;
-               JTextField      value;
-               AltosLights     lights;
-
-               void show(AltosState state, AltosListenerState listener_state) {}
-
-               void reset() {
-                       value.setText("");
-                       lights.set(false);
-               }
-
-               public void show() {
-                       label.setVisible(true);
-                       value.setVisible(true);
-                       lights.setVisible(true);
-               }
-
-               void show(String s) {
-                       show();
-                       value.setText(s);
-               }
-
-               void show(String format, double value) {
-                       show(String.format(format, value));
-               }
-
-               void show(String format, int value) {
-                       show(String.format(format, value));
-               }
-
-               public void hide() {
-                       label.setVisible(false);
-                       value.setVisible(false);
-                       lights.setVisible(false);
-               }
-
-               public void dispose() {
-                       hide();
-               }
-
-               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);
-               }
-
-               public LaunchStatus (GridBagLayout layout, int y, String text) {
-                       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(Altos.label_font);
-                       label.setHorizontalAlignment(SwingConstants.LEFT);
-                       c.gridx = 1; c.gridy = y;
-                       c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
-                       c.anchor = GridBagConstraints.WEST;
-                       c.fill = GridBagConstraints.VERTICAL;
-                       c.weightx = 0;
-                       layout.setConstraints(label, c);
-                       add(label);
-
-                       value = new JTextField(Altos.text_width);
-                       value.setEditable(false);
-                       value.setFont(Altos.value_font);
-                       value.setHorizontalAlignment(SwingConstants.RIGHT);
-                       c.gridx = 2; c.gridy = y;
-                       c.anchor = GridBagConstraints.WEST;
-                       c.fill = GridBagConstraints.BOTH;
-                       c.weightx = 1;
-                       layout.setConstraints(value, c);
-                       add(value);
+       public class Ignitor extends AltosUIUnitsIndicator {
+               int             ignitor;
 
+               public double value(AltosState state, int i) {
+                       if (state.ignitor_voltage == null ||
+                           state.ignitor_voltage.length < ignitor)
+                               return AltosLib.MISSING;
+                       return state.ignitor_voltage[ignitor];
                }
-       }
 
-       class Ignitor extends LaunchStatus {
-               int ignitor;
+               public double good() { return AltosLib.ao_igniter_good; }
 
-               void show (AltosState state, AltosListenerState listener_state) {
-                       if (state == null || state.ignitor_voltage[ignitor] == AltosLib.MISSING) {
-                               hide();
-                       } else {
-                               show("%4.2f V", state.ignitor_voltage[ignitor]);
-                               lights.set(state.ignitor_voltage[ignitor] >= AltosLib.ao_igniter_good);
-                       }
-               }
-
-               public Ignitor (GridBagLayout layout, int y) {
-                       super(layout, y, String.format ("%s Voltage", AltosLib.ignitor_name(y)));
+               public Ignitor (AltosUIFlightTab container, int y) {
+                       super(container, y, AltosConvert.voltage, String.format ("%s Voltage", AltosLib.ignitor_name(y)), 1, true, 1);
                        ignitor = y;
                }
        }
 
        Ignitor[] ignitors;
 
-       public void reset() {
-               if (ignitors == null)
-                       return;
-               for (int i = 0; i < ignitors.length; i++)
-                       ignitors[i].reset();
-       }
-
-       public void font_size_changed(int font_size) {
-               if (ignitors == null)
-                       return;
-               for (int i = 0; i < ignitors.length; i++)
-                       ignitors[i].font_size_changed(font_size);
-       }
-
-       public void units_changed(boolean imperial_units) {
-       }
-
        public void show(AltosState state, AltosListenerState listener_state) {
-               make_ignitors(state);
-               if (ignitors == null)
-                       return;
-               for (int i = 0; i < ignitors.length; i++)
-                       ignitors[i].show(state, listener_state);
-               return;
+               if (isShowing())
+                       make_ignitors(state);
+               super.show(state, listener_state);
        }
 
        public boolean should_show(AltosState state) {
@@ -170,33 +60,32 @@ public class AltosIgnitor extends JComponent implements AltosFlightDisplay {
        }
 
        void make_ignitors(AltosState state) {
-               int n = state == null ? 0 : state.ignitor_voltage.length;
+               int n = (state == null || state.ignitor_voltage == null) ? 0 : state.ignitor_voltage.length;
+               int old_n = ignitors == null ? 0 : ignitors.length;
 
-               if (n > 0) {
+               if (n != old_n) {
 
-                       if (ignitors == null || ignitors.length != n) {
-                               layout = new GridBagLayout();
+                       if (ignitors != null) {
+                               for (int i = 0; i < ignitors.length; i++) {
+                                       remove(ignitors[i]);
+                                       ignitors[i].remove(this);
+                                       ignitors = null;
+                               }
+                       }
 
-                               setLayout(layout);
+                       if (n > 0) {
+                               setVisible(true);
                                ignitors = new Ignitor[n];
-                               for (int i = 0; i < n; i++)
-                                       ignitors[i] = new Ignitor(layout, i);
-                       }
-               } else {
-                       if (ignitors != null) {
-                               for (int i = 0; i < n; i++)
-                                       ignitors[i].dispose();
-                               ignitors = null;
+                               for (int i = 0; i < n; i++) {
+                                       ignitors[i] = new Ignitor(this, i);
+                                       add(ignitors[i]);
+                               }
+                       } else
                                setVisible(false);
-                       }
                }
        }
 
        public String getName() {
                return "Ignitors";
        }
-
-       public AltosIgnitor() {
-               make_ignitors(null);
-       }
 }
index 760b2d64e1456a6ebb4ddccf68414b4621eac4c8..dd5cf9ab827842aae003d620eeadadb944f6436c 100644 (file)
@@ -24,256 +24,91 @@ import java.io.*;
 import org.altusmetrum.altoslib_4.*;
 import org.altusmetrum.altosuilib_2.*;
 
-public class AltosLanded extends JComponent implements AltosFlightDisplay, ActionListener, HierarchyListener {
-       GridBagLayout   layout;
-
-       private AltosState              last_state;
-       private AltosListenerState      last_listener_state;
-
-       public abstract class LandedValue implements AltosFontListener, AltosUnitsListener {
-               JLabel          label;
-               JTextField      value;
-               AltosUnits      units;
-               double          v;
-               String          last_value = "";
-
-               abstract void show(AltosState state, AltosListenerState listener_state);
-
-               void reset() {
-                       value.setText("");
-               }
-
-               void show() {
-                       label.setVisible(true);
-                       value.setVisible(true);
-               }
-
-               void show(String s) {
-                       show();
-                       if (!last_value.equals(s)) {
-                               value.setText(s);
-                               last_value = s;
+public class AltosLanded extends AltosUIFlightTab implements ActionListener {
+
+       class Bearing extends AltosUIIndicator {
+               public void show (AltosState state, AltosListenerState listener_state) {
+                       if (state.from_pad != null && state.from_pad.bearing != AltosLib.MISSING) {
+                               show( String.format("%3.0f°", state.from_pad.bearing),
+                                     state.from_pad.bearing_words(
+                                             AltosGreatCircle.BEARING_LONG));
+                       } else {
+                               show("Missing", "Missing");
                        }
                }
-
-               void show(double v) {
-                       this.v = v;
-                       if (v == AltosLib.MISSING)
-                               show("Missing");
-                       else
-                               show(units.show(8, v));
-               }
-
-               void show(String format, double v) {
-                       show(String.format(format, v));
-               }
-
-               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, AltosUnits units, String text) {
-                       this.units = units;
-
-                       GridBagConstraints      c = new GridBagConstraints();
-                       c.weighty = 1;
-
-                       label = new JLabel(text);
-                       label.setFont(Altos.label_font);
-                       label.setHorizontalAlignment(SwingConstants.LEFT);
-                       c.gridx = 0; c.gridy = y;
-                       c.insets = new Insets(10, 10, 10, 10);
-                       c.anchor = GridBagConstraints.WEST;
-                       c.weightx = 0;
-                       c.fill = GridBagConstraints.VERTICAL;
-                       layout.setConstraints(label, c);
-                       add(label);
-
-                       value = new JTextField(Altos.text_width);
-                       value.setEditable(false);
-                       value.setFont(Altos.value_font);
-                       value.setHorizontalAlignment(SwingConstants.RIGHT);
-                       c.gridx = 1; c.gridy = y;
-                       c.anchor = GridBagConstraints.WEST;
-                       c.weightx = 1;
-                       c.fill = GridBagConstraints.BOTH;
-                       layout.setConstraints(value, c);
-                       add(value);
-               }
-
-               public LandedValue (GridBagLayout layout, int y, String text) {
-                       this(layout, y, null, text);
+               public Bearing (Container container, int y) {
+                       super (container, y, "Bearing", 2);
                }
        }
 
-       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 LandedValue {
-               void show (AltosState state, AltosListenerState listener_state) {
-                       show();
-                       if (state.gps != null && state.gps.connected && state.gps.lat != AltosLib.MISSING)
-                               show(pos(state.gps.lat,"N", "S"));
+       class Distance extends AltosUIUnitsIndicator {
+               public double value(AltosState state, int i) {
+                       if (state.from_pad != null)
+                               return state.from_pad.distance;
                        else
-                               show("???");
-               }
-               public Lat (GridBagLayout layout, int y) {
-                       super (layout, y, "Latitude");
+                               return AltosLib.MISSING;
                }
-       }
-
-       Lat lat;
 
-       class Lon extends LandedValue {
-               void show (AltosState state, AltosListenerState listener_state) {
-                       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 Distance(Container container, int y) {
+                       super(container, y, AltosConvert.distance, "Ground Distance", 2);
                }
        }
 
-       Lon lon;
+       class Lat extends AltosUIUnitsIndicator {
 
-       class Bearing extends LandedValue {
-               void show (AltosState state, AltosListenerState listener_state) {
-                       show();
-                       if (state.from_pad != null)
-                               show("%3.0f°", state.from_pad.bearing);
-                       else
-                               show("???");
-               }
-               public Bearing (GridBagLayout layout, int y) {
-                       super (layout, y, "Bearing");
-               }
-       }
-
-       Bearing bearing;
+               public boolean hide (AltosState state, int i) { return state.gps == null || !state.gps.connected; }
 
-       class Distance extends LandedValue {
-               void show (AltosState state, AltosListenerState listener_state) {
-                       show();
-                       if (state.from_pad != null)
-                               show(state.from_pad.distance);
-                       else
-                               show("???");
+               public double value(AltosState state, int i) {
+                       if (state.gps == null)
+                               return AltosLib.MISSING;
+                       if (!state.gps.connected)
+                               return AltosLib.MISSING;
+                       return state.gps.lat;
                }
-               public Distance (GridBagLayout layout, int y) {
-                       super (layout, y, AltosConvert.distance, "Distance");
-               }
-       }
-
-       Distance distance;
 
-       class Height extends LandedValue {
-               void show (AltosState state, AltosListenerState listener_state) {
-                       show(state.max_height());
-               }
-               public Height (GridBagLayout layout, int y) {
-                       super (layout, y, AltosConvert.height, "Maximum Height");
+               public Lat (Container container, int y) {
+                       super (container, y, AltosConvert.latitude, "Latitude", 2);
                }
        }
 
-       Height  height;
+       class Lon extends AltosUIUnitsIndicator {
+               public boolean hide (AltosState state, int i) { return state.gps == null || !state.gps.connected; }
 
-       class Speed extends LandedValue {
-               void show (AltosState state, AltosListenerState listener_state) {
-                       show(state.max_speed());
+               public double value(AltosState state, int i) {
+                       if (state.gps == null)
+                               return AltosLib.MISSING;
+                       if (!state.gps.connected)
+                               return AltosLib.MISSING;
+                       return state.gps.lon;
                }
-               public Speed (GridBagLayout layout, int y) {
-                       super (layout, y, AltosConvert.speed, "Maximum Speed");
+
+               public Lon (Container container, int y) {
+                       super (container, y, AltosConvert.longitude, "Longitude", 2);
                }
        }
 
-       Speed   speed;
+       class MaxHeight extends AltosUIUnitsIndicator {
+               public double value(AltosState state, int i) { return state.max_height(); }
 
-       class Accel extends LandedValue {
-               void show (AltosState state, AltosListenerState listener_state) {
-                       show(state.max_acceleration());
-               }
-               public Accel (GridBagLayout layout, int y) {
-                       super (layout, y, AltosConvert.accel, "Maximum Acceleration");
+               public MaxHeight (Container container, int y) {
+                       super (container, y, AltosConvert.height, "Maximum Height", 2);
                }
        }
 
-       Accel   accel;
-
-       public void reset() {
-               lat.reset();
-               lon.reset();
-               bearing.reset();
-               distance.reset();
-               height.reset();
-               speed.reset();
-               accel.reset();
-       }
+       class MaxSpeed extends AltosUIUnitsIndicator {
+               public double value(AltosState state, int i) { return state.max_speed(); }
 
-       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 MaxSpeed (Container container, int y) {
+                       super (container, y, AltosConvert.speed, "Maximum Speed", 2);
+               }
        }
 
-       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);
-       }
+       class MaxAccel extends AltosUIUnitsIndicator {
+               public double value(AltosState state, int i) { return state.max_acceleration(); }
 
-       public void show(AltosState state, AltosListenerState listener_state) {
-               if (!isShowing()) {
-                       last_state = state;
-                       last_listener_state = listener_state;
-                       return;
+               public MaxAccel (Container container, int y) {
+                       super (container, y, AltosConvert.speed, "Maximum acceleration", 2);
                }
-
-               if (state.gps != null && state.gps.connected) {
-                       bearing.show(state, listener_state);
-                       distance.show(state, listener_state);
-                       lat.show(state, listener_state);
-                       lon.show(state, listener_state);
-               } else {
-                       bearing.hide();
-                       distance.hide();
-                       lat.hide();
-                       lon.hide();
-               }
-               height.show(state, listener_state);
-               speed.show(state, listener_state);
-               accel.show(state, listener_state);
-               if (reader.backing_file() != null)
-                       graph.setEnabled(true);
        }
 
        JButton graph;
@@ -316,32 +151,17 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio
                return "Landed";
        }
 
-       public void hierarchyChanged(HierarchyEvent e) {
-               if (last_state != null && isShowing()) {
-                       AltosState              state = last_state;
-                       AltosListenerState      listener_state = last_listener_state;
-
-                       last_state = null;
-                       last_listener_state = null;
-                       show(state, listener_state);
-               }
-       }
-
        public AltosLanded(AltosFlightReader in_reader) {
-               layout = new GridBagLayout();
-
                reader = in_reader;
 
-               setLayout(layout);
-
                /* Elements in descent display */
-               bearing = new Bearing(layout, 0);
-               distance = new Distance(layout, 1);
-               lat = new Lat(layout, 2);
-               lon = new Lon(layout, 3);
-               height = new Height(layout, 4);
-               speed = new Speed(layout, 5);
-               accel = new Accel(layout, 6);
+               add(new Bearing(this, 0));
+               add(new Distance(this, 1));
+               add(new Lat(this, 2));
+               add(new Lon(this, 3));
+               add(new MaxHeight(this, 4));
+               add(new MaxSpeed(this, 5));
+               add(new MaxAccel(this, 6));
 
                graph = new JButton ("Graph Flight");
                graph.setActionCommand("graph");
@@ -350,7 +170,7 @@ public class AltosLanded extends JComponent implements AltosFlightDisplay, Actio
 
                GridBagConstraints      c = new GridBagConstraints();
 
-               c.gridx = 0; c.gridy = 7;
+               c.gridx = 1; c.gridy = 7;
                c.insets = new Insets(10, 10, 10, 10);
                c.anchor = GridBagConstraints.WEST;
                c.weightx = 0;
index 3294949c395628f9f8e98587bac784da20ea28f8..6b5fd1500618edf63a4f8fc818bd90b11b1db57a 100644 (file)
 
 package altosui;
 
-import java.awt.*;
-import javax.swing.*;
+import java.util.*;
 import org.altusmetrum.altoslib_4.*;
 import org.altusmetrum.altosuilib_2.*;
 
-public class AltosPad extends JComponent implements AltosFlightDisplay {
-       GridBagLayout   layout;
+public class AltosPad extends AltosUIFlightTab {
 
-       public class LaunchStatus implements AltosFontListener, AltosUnitsListener {
-               JLabel          label;
-               JTextField      value;
-               AltosLights     lights;
-
-               void show(AltosState state, AltosListenerState listener_state) {}
-
-               void reset() {
-                       value.setText("");
-                       lights.set(false);
-               }
-
-               public void show() {
-                       label.setVisible(true);
-                       value.setVisible(true);
-                       lights.setVisible(true);
-               }
-
-               void show(String s) {
-                       show();
-                       value.setText(s);
-               }
-
-               void show(String format, double value) {
-                       show(String.format(format, value));
-               }
-
-               void show(String format, int value) {
-                       show(String.format(format, value));
-               }
-
-               public void hide() {
-                       label.setVisible(false);
-                       value.setVisible(false);
-                       lights.setVisible(false);
-               }
-
-               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);
-               }
-
-               public LaunchStatus (GridBagLayout layout, int y, String text) {
-                       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(Altos.label_font);
-                       label.setHorizontalAlignment(SwingConstants.LEFT);
-                       c.gridx = 1; c.gridy = y;
-                       c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
-                       c.anchor = GridBagConstraints.WEST;
-                       c.fill = GridBagConstraints.VERTICAL;
-                       c.weightx = 0;
-                       layout.setConstraints(label, c);
-                       add(label);
-
-                       value = new JTextField(Altos.text_width);
-                       value.setEditable(false);
-                       value.setFont(Altos.value_font);
-                       value.setHorizontalAlignment(SwingConstants.RIGHT);
-                       c.gridx = 2; c.gridy = y;
-                       c.anchor = GridBagConstraints.WEST;
-                       c.fill = GridBagConstraints.BOTH;
-                       c.weightx = 1;
-                       layout.setConstraints(value, c);
-                       add(value);
-
-               }
+       class Battery extends AltosUIVoltageIndicator {
+               public double voltage(AltosState state) { return state.battery_voltage; }
+               public double good() { return AltosLib.ao_battery_good; }
+               public Battery (AltosUIFlightTab container, int y) { super(container, y, "Battery Voltage", 2); }
        }
 
-       public abstract class LaunchValue implements AltosFontListener, AltosUnitsListener {
-               JLabel          label;
-               JTextField      value;
-               AltosUnits      units;
-               double          v;
-
-               abstract void show(AltosState state, AltosListenerState listener_state);
-
-               void show() {
-                       label.setVisible(true);
-                       value.setVisible(true);
-               }
-
-               void hide() {
-                       label.setVisible(false);
-                       value.setVisible(false);
-               }
-
-               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(double v) {
-                       this.v = v;
-                       show(units.show(8, v));
-               }
-
-               void show(String format, double v) {
-                       show(String.format(format, v));
-               }
-
-               public void set_label(String text) {
-                       label.setText(text);
-               }
-
-               void reset() {
-                       value.setText("");
-               }
-
-               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;
-
-                       label = new JLabel(text);
-                       label.setFont(Altos.label_font);
-                       label.setHorizontalAlignment(SwingConstants.LEFT);
-                       c.gridx = 1; c.gridy = y;
-                       c.anchor = GridBagConstraints.WEST;
-                       c.fill = GridBagConstraints.VERTICAL;
-                       c.weightx = 0;
-                       layout.setConstraints(label, c);
-                       add(label);
-
-                       value = new JTextField(Altos.text_width);
-                       value.setEditable(false);
-                       value.setFont(Altos.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);
-               }
-
-               public LaunchValue (GridBagLayout layout, int y, String text) {
-                       this(layout, y, null, text);
-               }
+       class Apogee extends AltosUIVoltageIndicator {
+               public boolean hide(double v) { return v == AltosLib.MISSING; }
+               public double voltage(AltosState state) { return state.apogee_voltage; }
+               public double good() { return AltosLib.ao_igniter_good; }
+               public Apogee (AltosUIFlightTab container, int y) { super(container, y, "Apogee Igniter Voltage", 2); }
        }
 
-       class Voltage extends LaunchStatus {
-
-               double voltage(AltosState state) { return AltosLib.MISSING; };
-               double good() { return 0; };
-
-               double  last_voltage = -1;
-
-               void show (AltosState state, AltosListenerState listener_state) {
-                       double  voltage = AltosLib.MISSING;
-                       if (state != null)
-                               voltage = voltage(state);
-
-                       if (voltage != last_voltage) {
-                               if (voltage == AltosLib.MISSING)
-                                       hide();
-                               else {
-                                       show("%4.2f V", voltage);
-                                       lights.set(voltage >= good());
-                               }
-                               last_voltage = voltage;
-                       }
-               }
-               public Voltage (GridBagLayout layout, int y, String name) { super(layout, y, name); }
-       }
-
-
-       class Battery extends Voltage {
-               double voltage(AltosState state) { return state.battery_voltage; }
-               double good() { return AltosLib.ao_battery_good; }
-
-               public Battery (GridBagLayout layout, int y) {
-                       super(layout, y, "Battery Voltage");
-               }
-
+       class Main extends AltosUIVoltageIndicator {
+               public boolean hide(double v) { return v == AltosLib.MISSING; }
+               public double voltage(AltosState state) { return state.main_voltage; }
+               public double good() { return AltosLib.ao_igniter_good; }
+               public Main (AltosUIFlightTab container, int y) { super(container, y, "Main Igniter Voltage", 2); }
        }
 
-       Battery battery;
-
-       class Apogee extends Voltage {
-               double voltage(AltosState state) { return state.apogee_voltage; }
-               double good() { return AltosLib.ao_igniter_good; }
-               public Apogee (GridBagLayout layout, int y) { super(layout, y, "Apogee Igniter Voltage"); }
-       }
-
-       Apogee apogee;
-
-       class Main extends  Voltage {
-               double voltage(AltosState state) { return state.main_voltage; }
-               double good() { return AltosLib.ao_igniter_good; }
-               public Main (GridBagLayout layout, int y) { super(layout, y, "Main Igniter Voltage"); }
-       }
-
-       Main main;
-
-       class LoggingReady extends LaunchStatus {
-               void show (AltosState state, AltosListenerState listener_state) {
+       class LoggingReady extends AltosUIIndicator {
+               public void show (AltosState state, AltosListenerState listener_state) {
                        if (state == null || state.flight == AltosLib.MISSING) {
                                hide();
                        } else {
                                if (state.flight != 0) {
                                        if (state.state <= Altos.ao_flight_pad)
                                                show("Ready to record");
-                                       else if (state.state < Altos.ao_flight_landed)
+                                       else if (state.state < Altos.ao_flight_landed ||
+                                                state.state == AltosLib.ao_flight_stateless)
                                                show("Recording data");
                                        else
                                                show("Recorded data");
                                } else
                                        show("Storage full");
-                               lights.set(state.flight != 0);
+                               set_lights(state.flight != 0);
                        }
                }
-               public LoggingReady (GridBagLayout layout, int y) {
-                       super(layout, y, "On-board Data Logging");
+               public LoggingReady (AltosUIFlightTab container, int y) {
+                       super(container, y, "On-board Data Logging", 1, true, 2);
                }
        }
 
-       LoggingReady logging_ready;
-
-       class GPSLocked extends LaunchStatus {
-               void show (AltosState state, AltosListenerState listener_state) {
+       class GPSLocked extends AltosUIIndicator {
+               public 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     sol = state.gps.nsat;
+                               int     sat = state.gps.cc_gps_sat == null ? 0 : state.gps.cc_gps_sat.length;
+                               show("%d in solution", sol, "%d in view", sat);
+                               set_lights(state.gps.locked && sol >= 4);
                        }
                }
-               public GPSLocked (GridBagLayout layout, int y) {
-                       super (layout, y, "GPS Locked");
+               public GPSLocked (AltosUIFlightTab container, int y) {
+                       super (container, y, "GPS Locked", 2, true, 1);
                }
        }
 
-       GPSLocked gps_locked;
-
-       class GPSReady extends LaunchStatus {
-               void show (AltosState state, AltosListenerState listener_state) {
+       class GPSReady extends AltosUIIndicator {
+               public void show (AltosState state, AltosListenerState listener_state) {
                        if (state == null || state.gps == null)
                                hide();
                        else {
@@ -298,48 +91,37 @@ public class AltosPad extends JComponent implements AltosFlightDisplay {
                                        show("Ready");
                                else
                                        show("Waiting %d", state.gps_waiting);
-                               lights.set(state.gps_ready);
+                               set_lights(state.gps_ready);
                        }
                }
-               public GPSReady (GridBagLayout layout, int y) {
-                       super (layout, y, "GPS Ready");
+               public GPSReady (AltosUIFlightTab container, int y) {
+                       super (container, y, "GPS Ready", 1, true, 2);
                }
        }
 
-       GPSReady gps_ready;
+       class ReceiverBattery extends AltosUIVoltageIndicator {
 
-       class ReceiverBattery extends LaunchStatus {
-               void show (AltosState state, AltosListenerState listener_state) {
-                       if (listener_state == null || listener_state.battery == AltosLib.MISSING)
-                               hide();
-                       else {
-                               show("%4.2f V", listener_state.battery);
-                               lights.set(listener_state.battery > AltosLib.ao_battery_good);
-                       }
-               }
-               public ReceiverBattery (GridBagLayout layout, int y) {
-                       super(layout, y, "Receiver Battery");
-               }
-       }
+               public double voltage(AltosState state) { return AltosLib.MISSING; }
+
+               public boolean hide(double v) { return v == AltosLib.MISSING; }
+               public double good() { return AltosLib.ao_battery_good; }
 
-       ReceiverBattery receiver_battery;
+               public double value(AltosState state, AltosListenerState listener_state, int i) {
+                       if (listener_state == null)
+                               return AltosLib.MISSING;
+                       return listener_state.battery;
+               }
 
-       String pos(double p, String pos, String neg) {
-               String  h = pos;
-               if (p < 0) {
-                       h = neg;
-                       p = -p;
+               public ReceiverBattery (AltosUIFlightTab container, int y) {
+                       super(container, y, "Receiver Battery", 2);
                }
-               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 PadLat extends LaunchValue {
+       class PadLat extends AltosUIIndicator {
 
-               double  last_lat = 1000;
+               double  last_lat = AltosLib.MISSING - 1;
 
-               void show (AltosState state, AltosListenerState listener_state) {
+               public void show (AltosState state, AltosListenerState listener_state) {
                        double lat = AltosLib.MISSING;
                        String label = null;
 
@@ -354,25 +136,29 @@ public class AltosPad extends JComponent implements AltosFlightDisplay {
                        }
                        if (lat != last_lat) {
                                if (lat != AltosLib.MISSING) {
-                                       show(pos(lat,"N", "S"));
+                                       show(AltosConvert.latitude.show(10, lat));
                                        set_label(label);
                                } else
                                        hide();
                                last_lat = lat;
                        }
                }
-               public PadLat (GridBagLayout layout, int y) {
-                       super (layout, y, "Pad Latitude");
+
+               public void reset() {
+                       super.reset();
+                       last_lat = AltosLib.MISSING - 1;
                }
-       }
 
-       PadLat pad_lat;
+               public PadLat (AltosUIFlightTab container, int y) {
+                       super (container, y, "Pad Latitude", 1, false, 2);
+               }
+       }
 
-       class PadLon extends LaunchValue {
+       class PadLon extends AltosUIIndicator {
 
-               double last_lon = 1000;
+               double last_lon = AltosLib.MISSING - 1;
 
-               void show (AltosState state, AltosListenerState listener_state) {
+               public void show (AltosState state, AltosListenerState listener_state) {
                        double lon = AltosLib.MISSING;
                        String label = null;
 
@@ -387,25 +173,29 @@ public class AltosPad extends JComponent implements AltosFlightDisplay {
                        }
                        if (lon != last_lon) {
                                if (lon != AltosLib.MISSING) {
-                                       show(pos(lon,"E", "W"));
+                                       show(AltosConvert.longitude.show(10, lon));
                                        set_label(label);
                                } else
                                        hide();
                                last_lon = lon;
                        }
                }
-               public PadLon (GridBagLayout layout, int y) {
-                       super (layout, y, "Pad Longitude");
+
+               public void reset() {
+                       super.reset();
+                       last_lon = AltosLib.MISSING - 1;
                }
-       }
 
-       PadLon pad_lon;
+               public PadLon (AltosUIFlightTab container, int y) {
+                       super (container, y, "Pad Longitude", 1, false, 2);
+               }
+       }
 
-       class PadAlt extends LaunchValue {
+       class PadAlt extends AltosUIIndicator {
 
-               double  last_alt = -1000000;
+               double  last_alt = AltosLib.MISSING - 1;
 
-               void show (AltosState state, AltosListenerState listener_state) {
+               public void show (AltosState state, AltosListenerState listener_state) {
                        double alt = AltosLib.MISSING;
                        String label = null;
 
@@ -420,97 +210,36 @@ public class AltosPad extends JComponent implements AltosFlightDisplay {
                        }
                        if (alt != last_alt) {
                                if (alt != AltosLib.MISSING) {
-                                       show(alt);
+                                       show(AltosConvert.height.show(5, alt));
                                        set_label(label);
                                } else
                                        hide();
                                last_alt = alt;
                        }
                }
-               public PadAlt (GridBagLayout layout, int y) {
-                       super (layout, y, AltosConvert.height, "Pad Altitude");
-               }
-       }
-
-       PadAlt pad_alt;
-
-       public void reset() {
-               battery.reset();
-               apogee.reset();
-               main.reset();
-               logging_ready.reset();
-               gps_locked.reset();
-               gps_ready.reset();
-               receiver_battery.reset();
-               pad_lat.reset();
-               pad_lon.reset();
-               pad_alt.reset();
-       }
 
-       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 reset() {
+                       super.reset();
+                       last_alt =  AltosLib.MISSING - 1;
+               }
 
-       public void show(AltosState state, AltosListenerState listener_state) {
-               battery.show(state, listener_state);
-               apogee.show(state, listener_state);
-               main.show(state, listener_state);
-               logging_ready.show(state, listener_state);
-               pad_alt.show(state, listener_state);
-               receiver_battery.show(state, listener_state);
-               gps_locked.show(state, listener_state);
-               gps_ready.show(state, listener_state);
-               pad_lat.show(state, listener_state);
-               pad_lon.show(state, listener_state);
+               public PadAlt (AltosUIFlightTab container, int y) {
+                       super (container, y, "Pad Altitude", 1, false, 2);
+               }
        }
+       public String getName() { return "Pad"; }
 
        public AltosPad() {
-               layout = new GridBagLayout();
-
-               setLayout(layout);
-
-               /* Elements in pad display:
-                *
-                * Battery voltage
-                * Igniter continuity
-                * GPS lock status
-                * GPS ready status
-                * GPS location
-                * Pad altitude
-                * RSSI
-                */
-               battery = new Battery(layout, 0);
-               apogee = new Apogee(layout, 1);
-               main = new Main(layout, 2);
-               logging_ready = new LoggingReady(layout, 3);
-               gps_locked = new GPSLocked(layout, 4);
-               gps_ready = new GPSReady(layout, 5);
-               receiver_battery = new ReceiverBattery(layout, 6);
-               pad_lat = new PadLat(layout, 7);
-               pad_lon = new PadLon(layout, 8);
-               pad_alt = new PadAlt(layout, 9);
-               show(null, null);
+               int y = 0;
+               add(new Battery(this, y++));
+               add(new Apogee(this, y++));
+               add(new Main(this, y++));
+               add(new LoggingReady(this, y++));
+               add(new GPSLocked(this, y++));
+               add(new GPSReady(this, y++));
+               add(new ReceiverBattery(this, y++));
+               add(new PadLat(this, y++));
+               add(new PadLon(this, y++));
+               add(new PadAlt(this, y++));
        }
 }
index eddb47d8f2975fc496bd1817aa14c63025a210f5..6e68dd30e5087451d69702a656bddeb2e25bc955 100644 (file)
@@ -59,11 +59,13 @@ public class TeleGPS
        JMenu                   monitor_menu;
        JMenu                   device_menu;
        AltosFreqList           frequencies;
+       ActionListener          frequency_listener;
 
        Container               bag;
 
        TeleGPSStatus           telegps_status;
        TeleGPSStatusUpdate     status_update;
+       javax.swing.Timer       status_timer;
 
        JTabbedPane             pane;
 
@@ -174,7 +176,14 @@ public class TeleGPS
        void disconnect() {
                setTitle("TeleGPS");
                stop_display();
-               remove_frequency_menu();
+               if (status_timer != null) {
+                       status_timer.stop();
+                       status_timer = null;
+                       status_update = null;
+               }
+
+               telegps_status.disable_receive();
+               disable_frequency_menu();
        }
 
        void connect(AltosDevice device) {
@@ -182,8 +191,7 @@ public class TeleGPS
                        disconnect();
                try {
                        AltosFlightReader       reader = new AltosTelemetryReader(new AltosSerial(device));
-                       set_reader(reader);
-                       add_frequency_menu(device.getSerial(), reader);
+                       set_reader(reader, device);
                } catch (FileNotFoundException ee) {
                        JOptionPane.showMessageDialog(this,
                                                      ee.getMessage(),
@@ -322,15 +330,12 @@ public class TeleGPS
                }
        }
 
-       void add_frequency_menu(int serial, final AltosFlightReader reader) {
-               // Channel menu
-               if (frequencies != null)
-                       return;
+       void enable_frequency_menu(int serial, final AltosFlightReader reader) {
 
-               frequencies = new AltosFreqList(AltosUIPreferences.frequency(serial));
-               frequencies.set_product("Monitor");
-               frequencies.set_serial(serial);
-               frequencies.addActionListener(new ActionListener() {
+               if (frequency_listener != null)
+                       disable_frequency_menu();
+
+               frequency_listener = new ActionListener() {
                                public void actionPerformed(ActionEvent e) {
                                        double frequency = frequencies.frequency();
                                        try {
@@ -340,22 +345,37 @@ public class TeleGPS
                                        }
                                        reader.save_frequency();
                                }
-                       });
-               menu_bar.add(frequencies);
+                       };
+
+               frequencies.addActionListener(frequency_listener);
+               frequencies.set_product("Monitor");
+               frequencies.set_serial(serial);
+               frequencies.set_frequency(AltosUIPreferences.frequency(serial));
+               frequencies.setEnabled(true);
+
        }
 
-       void remove_frequency_menu() {
-               if (frequencies != null) {
-                       menu_bar.remove(frequencies);
-                       menu_bar.repaint();
-                       frequencies = null;
+       void disable_frequency_menu() {
+               if (frequency_listener != null) {
+                       frequencies.removeActionListener(frequency_listener);
+                       frequencies.setEnabled(false);
+                       frequency_listener = null;
                }
+
        }
 
-       public void set_reader(AltosFlightReader reader) {
+       public void set_reader(AltosFlightReader reader, AltosDevice device) {
+               status_update = new TeleGPSStatusUpdate(telegps_status);
+
+               status_timer = new javax.swing.Timer(100, status_update);
+               status_timer.start();
+
                setTitle(String.format("TeleGPS %s", reader.name));
                thread = new TeleGPSDisplayThread(this, voice(), this, reader);
                thread.start();
+
+               if (device != null)
+                       enable_frequency_menu(device.getSerial(), reader);
        }
 
        static int      number_of_windows;
@@ -414,6 +434,10 @@ public class TeleGPS
                file_menu = make_menu("File", file_menu_entries);
                monitor_menu = make_menu("Monitor", monitor_menu_entries);
                device_menu = make_menu("Device", device_menu_entries);
+               frequencies = new AltosFreqList();
+               frequencies.setEnabled(false);
+               menu_bar.add(frequencies);
+
                displays = new LinkedList<AltosFlightDisplay>();
 
                int serial = -1;
@@ -476,15 +500,11 @@ public class TeleGPS
                setVisible(true);
 
                add_window();
-
-               status_update = new TeleGPSStatusUpdate(telegps_status);
-
-               new javax.swing.Timer(100, status_update).start();
        }
 
        public TeleGPS(AltosFlightReader reader) {
                this();
-               set_reader(reader);
+               set_reader(reader, null);
        }
 
        public TeleGPS(AltosDevice device) {
index bbf4b47265e1d97eb3f34d6d6b977c857deba962..e87fea90317a2f7a91f3568a66b65888feba2602 100644 (file)
@@ -24,13 +24,10 @@ import javax.swing.*;
 import org.altusmetrum.altoslib_4.*;
 import org.altusmetrum.altosuilib_2.*;
 
-public class TeleGPSInfo extends JComponent implements AltosFlightDisplay, HierarchyListener {
+public class TeleGPSInfo extends AltosUIFlightTab {
 
        JLabel                          cur, max;
 
-       private AltosState              last_state;
-       private AltosListenerState      last_listener_state;
-
        abstract class Value extends AltosUIUnitsIndicator {
                public abstract void show(AltosState state, AltosListenerState listener_state);
 
@@ -48,7 +45,6 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay, Hiera
        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);
@@ -96,7 +92,9 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay, Hiera
 
                public void show (AltosState state, AltosListenerState listener_state) {
                        double  course = state.gps_course();
-                       if (course != AltosLib.MISSING)
+                       if (course == AltosLib.MISSING)
+                               show("Missing", "Missing");
+                       else
                                show( String.format("%3.0f°", course),
                                      AltosConvert.bearing_to_words(
                                              AltosConvert.BEARING_LONG,
@@ -124,7 +122,7 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay, Hiera
                        if (state.gps != null && state.gps.connected && state.gps.lat != AltosLib.MISSING)
                                show(pos(state.gps.lat,"N", "S"));
                        else
-                               show("???");
+                               show("Missing");
                }
                public Lat (Container container, int y) {
                        super (container, y, "Latitude", 1, false, 2);
@@ -148,7 +146,7 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay, Hiera
                        if (state.gps != null && state.gps.connected && state.gps.lon != AltosLib.MISSING)
                                show(pos(state.gps.lon,"E", "W"));
                        else
-                               show("???");
+                               show("Missing");
                }
                public Lon (Container container, int y) {
                        super (container, y, "Longitude", 1, false, 2);
@@ -173,34 +171,10 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay, Hiera
                }
        }
 
-       LinkedList<AltosUIIndicator> indicators = new LinkedList<AltosUIIndicator>();
-
-       public void 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);
-               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);
+               super.font_size_changed(font_size);
        }
 
        public void labels(Container container, int y) {
@@ -226,29 +200,15 @@ public class TeleGPSInfo extends JComponent implements AltosFlightDisplay, Hiera
                return "Location";
        }
 
-       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 TeleGPSInfo() {
-               setLayout(new GridBagLayout());
-
                int y = 0;
                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);
+               add(new Altitude(this, y++));
+               add(new GroundSpeed(this, y++));
+               add(new AscentRate(this, y++));
+               add(new Course(this, y++));
+               add(new Lat(this, y++));
+               add(new Lon(this, y++));
+               add(new GPSLocked(this, y++));
        }
 }
index b10e8e7056e7c1ca583e404255fc0f1022f2c643..a76182ed0e74c07bedcf9752822f11cf2c84b443 100644 (file)
@@ -24,12 +24,9 @@ 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;
+public class TeleGPSState extends AltosUIFlightTab {
 
-       private AltosState              last_state;
-       private AltosListenerState      last_listener_state;
+       JLabel  cur, max;
 
        abstract class Value extends AltosUIUnitsIndicator {
                public Value (Container container, int y, AltosUnits units, String text) {
@@ -44,10 +41,6 @@ public class TeleGPSState extends JComponent implements AltosFlightDisplay, Hier
        }
 
        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);
                }
@@ -103,12 +96,12 @@ public class TeleGPSState extends JComponent implements AltosFlightDisplay, Hier
 
        class Bearing extends AltosUIIndicator {
                public void show (AltosState state, AltosListenerState listener_state) {
-                       if (state.from_pad != null) {
+                       if (state.from_pad != null && state.from_pad.bearing != AltosLib.MISSING) {
                                show( String.format("%3.0f°", state.from_pad.bearing),
                                      state.from_pad.bearing_words(
                                              AltosGreatCircle.BEARING_LONG));
                        } else {
-                               show("???", "???");
+                               show("Missing", "Missing");
                        }
                }
                public Bearing (Container container, int y) {
@@ -118,7 +111,10 @@ public class TeleGPSState extends JComponent implements AltosFlightDisplay, Hier
 
        class Elevation extends AltosUIIndicator {
                public void show (AltosState state, AltosListenerState listener_state) {
-                       show("%3.0f°", state.elevation);
+                       if (state.elevation == AltosLib.MISSING)
+                               show("Missing");
+                       else
+                               show("%3.0f°", state.elevation);
                }
                public Elevation (Container container, int y) {
                        super (container, y, "Elevation", 1, false, 2);
@@ -165,7 +161,6 @@ public class TeleGPSState extends JComponent implements AltosFlightDisplay, Hier
                }
        }
 
-       LinkedList<AltosUIIndicator> indicators = new LinkedList<AltosUIIndicator>();
 
        public void labels(Container container, int y) {
                GridBagLayout           layout = (GridBagLayout)(container.getLayout());
@@ -186,69 +181,27 @@ public class TeleGPSState extends JComponent implements AltosFlightDisplay, Hier
                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);
+               cur.setFont(AltosUILib.label_font);
+               max.setFont(AltosUILib.label_font);
+               super.font_size_changed(font_size);
        }
 
        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);
+               add(new Height(this, y++));
+               add(new Speed(this, y++));
+               add(new Distance(this, y++));
+               add(new Range(this, y++));
+               add(new Bearing(this, y++));
+               add(new Elevation(this, y++));
+               add(new FirmwareVersion(this, y++));
+               add(new FlightLogMax(this, y++));
+               add(new BatteryVoltage(this, y++));
        }
 }
index 14706877e9f71622bdea4fb9b5ecbff89dc29543..f3951a37544dbc80d900024f3d78adb87adf49df 100644 (file)
@@ -83,6 +83,12 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay {
                        else
                                setVisible(true);
                }
+
+               public void reset() {
+                       super.reset();
+                       call = "";
+               }
+
                public Call (GridBagLayout layout, int x) {
                        super (layout, x, "Callsign");
                }
@@ -101,6 +107,12 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay {
                                serial = state.serial;
                        }
                }
+
+               public void reset() {
+                       super.reset();
+                       serial = -1;
+               }
+
                public Serial (GridBagLayout layout, int x) {
                        super (layout, x, "Serial");
                }
@@ -121,6 +133,12 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay {
                                last_flight = state.flight;
                        }
                }
+
+               public void reset() {
+                       super.reset();
+                       last_flight = -1;
+               }
+
                public Flight (GridBagLayout layout, int x) {
                        super (layout, x, "Flight");
                }
@@ -143,6 +161,12 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay {
                                rssi = new_rssi;
                        }
                }
+
+               public void reset() {
+                       super.reset();
+                       rssi = 10000;
+               }
+
                public RSSI (GridBagLayout layout, int x) {
                        super (layout, x, "RSSI");
                }
@@ -162,6 +186,16 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay {
                                last_secs = secs;
                        }
                }
+
+               void reset() {
+                       super.reset();
+                       last_secs = -1;
+               }
+
+               void disable() {
+                       value.setText("");
+               }
+
                public LastPacket(GridBagLayout layout, int x) {
                        super (layout, x, "Age");
                }
@@ -169,6 +203,10 @@ public class TeleGPSStatus extends JComponent implements AltosFlightDisplay {
 
        LastPacket last_packet;
 
+       public void disable_receive() {
+               last_packet.disable();
+       }
+
        public void reset () {
                call.reset();
                serial.reset();