altosdroid: initial implementation of telemetry logging.
[fw/altos] / altosui / AltosInfoTable.java
index 723f830169f6722298a593cf6ce8f8972bae850b..86e02ab1ddcbe07733f6063fefc44086f6d4fdc1 100644 (file)
 package altosui;
 
 import java.awt.*;
-import java.awt.event.*;
 import javax.swing.*;
-import javax.swing.filechooser.FileNameExtensionFilter;
 import javax.swing.table.*;
-import java.io.*;
-import java.util.*;
-import java.text.*;
-import java.util.prefs.*;
-import java.util.concurrent.LinkedBlockingQueue;
+import org.altusmetrum.AltosLib.*;
 
 public class AltosInfoTable extends JTable {
        private AltosFlightInfoTableModel model;
 
-       private Font infoLabelFont = new Font("SansSerif", Font.PLAIN, 14);
-       private Font infoValueFont = new Font("Monospaced", Font.PLAIN, 14);
-
        static final int info_columns = 3;
        static final int info_rows = 17;
 
        int desired_row_height() {
-               FontMetrics     infoValueMetrics = getFontMetrics(infoValueFont);
+               FontMetrics     infoValueMetrics = getFontMetrics(Altos.table_value_font);
                return (infoValueMetrics.getHeight() + infoValueMetrics.getLeading()) * 18 / 10;
        }
 
+       int text_width(String t) {
+               FontMetrics     infoValueMetrics = getFontMetrics(Altos.table_value_font);
+
+               return infoValueMetrics.stringWidth(t);
+       }
+
+       void set_layout() {
+               setRowHeight(desired_row_height());
+               for (int i = 0; i < info_columns * 2; i++)
+               {
+                       TableColumn column = getColumnModel().getColumn(i);
+
+                       if ((i & 1) == 0)
+                               column.setPreferredWidth(text_width(" Satellites Visible "));
+                       else
+                               column.setPreferredWidth(text_width(" 179°59.99999' "));
+               }
+       }
+
        public AltosInfoTable() {
                super(new AltosFlightInfoTableModel(info_rows, info_columns));
                model = (AltosFlightInfoTableModel) getModel();
-               setFont(infoValueFont);
+               setFont(Altos.table_value_font);
                setAutoResizeMode(AUTO_RESIZE_ALL_COLUMNS);
                setShowGrid(true);
-               setRowHeight(desired_row_height());
+               set_layout();
+               doLayout();
+       }
+
+       public void set_font() {
+               setFont(Altos.table_value_font);
+               set_layout();
                doLayout();
        }
 
@@ -69,9 +85,9 @@ public class AltosInfoTable extends JTable {
        }
 
        void info_add_deg(int col, String name, double v, int pos, int neg) {
-               int     c = pos;
+               //int   c = pos;
                if (v < 0) {
-                       c = neg;
+                       //c = neg;
                        v = -v;
                }
                double  deg = Math.floor(v);
@@ -92,13 +108,8 @@ public class AltosInfoTable extends JTable {
                if (state == null)
                        return;
                info_reset();
-               info_add_row(0, "Rocket state", "%s", state.data.state());
-               info_add_row(0, "Callsign", "%s", state.data.callsign);
-               info_add_row(0, "Rocket serial", "%6d", state.data.serial);
-               info_add_row(0, "Rocket flight", "%6d", state.data.flight);
-
-               info_add_row(0, "RSSI", "%6d    dBm", state.data.rssi);
-               info_add_row(0, "CRC Errors", "%6d", crc_errors);
+               info_add_row(0, "Altitude", "%6.0f    m", state.altitude);
+               info_add_row(0, "Pad altitude", "%6.0f    m", state.ground_altitude);
                info_add_row(0, "Height", "%6.0f    m", state.height);
                info_add_row(0, "Max height", "%6.0f    m", state.max_height);
                info_add_row(0, "Acceleration", "%8.1f  m/s²", state.acceleration);
@@ -107,10 +118,13 @@ public class AltosInfoTable extends JTable {
                info_add_row(0, "Max Speed", "%8.1f  m/s", state.max_speed);
                info_add_row(0, "Temperature", "%9.2f °C", state.temperature);
                info_add_row(0, "Battery", "%9.2f V", state.battery);
-               info_add_row(0, "Drogue", "%9.2f V", state.drogue_sense);
-               info_add_row(0, "Main", "%9.2f V", state.main_sense);
-               info_add_row(0, "Pad altitude", "%6.0f    m", state.ground_altitude);
-               if (state.gps == null) {
+               if (state.drogue_sense != AltosRecord.MISSING)
+                       info_add_row(0, "Drogue", "%9.2f V", state.drogue_sense);
+               if (state.main_sense != AltosRecord.MISSING)
+                       info_add_row(0, "Main", "%9.2f V", state.main_sense);
+               info_add_row(0, "CRC Errors", "%6d", crc_errors);
+
+               if (state.gps == null || !state.gps.connected) {
                        info_add_row(1, "GPS", "not available");
                } else {
                        if (state.gps_ready)
@@ -131,6 +145,7 @@ public class AltosInfoTable extends JTable {
                        info_add_row(1, "GPS height", "%6.0f", state.gps_height);
 
                        /* The SkyTraq GPS doesn't report these values */
+                       /*
                        if (false) {
                                info_add_row(1, "GPS ground speed", "%8.1f m/s %3d°",
                                             state.gps.ground_speed,
@@ -140,6 +155,8 @@ public class AltosInfoTable extends JTable {
                                info_add_row(1, "GPS error", "%6d m(h)%3d m(v)",
                                             state.gps.h_error, state.gps.v_error);
                        }
+                       */
+
                        info_add_row(1, "GPS hdop", "%8.1f", state.gps.hdop);
 
                        if (state.npad > 0) {
@@ -170,7 +187,7 @@ public class AltosInfoTable extends JTable {
                                       state.gps.hour,
                                       state.gps.minute,
                                       state.gps.second);
-                       int     nsat_vis = 0;
+                       //int   nsat_vis = 0;
                        int     c;
 
                        if (state.gps.cc_gps_sat == null)