altosui, telegps: Add TeleBT v4.0 firmware to app packages
[fw/altos] / telegps / TeleGPSGraphUI.java
index b59b122cd4faa11d377e78c9cfec3787082c7247..9d8c6bf5a4ae1444ae616d7c3cbf1f6c19ebdba0 100644 (file)
@@ -3,7 +3,8 @@
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 or any later version of the License.
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -26,14 +27,14 @@ import javax.swing.*;
 import java.io.*;
 import java.util.concurrent.*;
 import java.util.*;
-import org.altusmetrum.altoslib_5.*;
-import org.altusmetrum.altosuilib_3.*;
+import org.altusmetrum.altoslib_12.*;
+import org.altusmetrum.altosuilib_12.*;
 
 import org.jfree.chart.ChartPanel;
 import org.jfree.chart.JFreeChart;
 import org.jfree.ui.RefineryUtilities;
 
-public class TeleGPSGraphUI extends AltosUIFrame
+public class TeleGPSGraphUI extends AltosUIFrame implements AltosFontListener, AltosUnitsListener
 {
        JTabbedPane             pane;
        AltosGraph              graph;
@@ -41,13 +42,33 @@ public class TeleGPSGraphUI extends AltosUIFrame
        AltosUIMap              map;
        AltosState              state;
        AltosFlightStats        stats;
-       AltosGraphDataSet       graphDataSet;
        AltosFlightStatsTable   statsTable;
-
-       void fill_map(AltosStateIterable states) {
-               for (AltosState state : states) {
-                       if (state.gps != null && state.gps.locked && state.gps.nsat >= 4)
-                               map.show(state, null);
+       AltosGPS                gps;
+       boolean                 has_gps;
+
+       void fill_map(AltosFlightSeries flight_series) {
+               boolean                 any_gps = false;
+               AltosGPSTimeValue       gtv_last = null;
+
+               if (flight_series.gps_series != null) {
+                       for (AltosGPSTimeValue gtv : flight_series.gps_series) {
+                               gtv_last = gtv;
+                               AltosGPS gps = gtv.gps;
+                               if (gps != null &&
+                                   gps.locked &&
+                                   gps.nsat >= 4) {
+                                       if (map == null)
+                                               map = new AltosUIMap();
+                                       map.show(gps, (int) flight_series.value_before(AltosFlightSeries.state_name, gtv.time));
+                                       this.gps = gps;
+                                       has_gps = true;
+                               }
+                       }
+               }
+               if (gtv_last != null) {
+                       int state = (int) flight_series.value_after(AltosFlightSeries.state_name, gtv_last.time);
+                       if (state == AltosLib.ao_flight_landed)
+                               map.show(gtv_last.gps, state);
                }
        }
 
@@ -57,16 +78,35 @@ public class TeleGPSGraphUI extends AltosUIFrame
                TeleGPS.subtract_window();
        }
 
-       TeleGPSGraphUI(AltosStateIterable states, File file) throws InterruptedException, IOException {
+       public void font_size_changed(int font_size) {
+               if (map != null)
+                       map.font_size_changed(font_size);
+               if (statsTable != null)
+                       statsTable.font_size_changed(font_size);
+       }
+
+       public void units_changed(boolean imperial_units) {
+               if (map != null)
+                       map.units_changed(imperial_units);
+               if (enable != null)
+                       enable.units_changed(imperial_units);
+       }
+
+       TeleGPSGraphUI(AltosRecordSet set, File file) throws InterruptedException, IOException {
                super(file.getName());
-               state = null;
+               AltosCalData cal_data = set.cal_data();
+
+               AltosUIFlightSeries flight_series = new AltosUIFlightSeries(cal_data);
+               set.capture_series(flight_series);
+               flight_series.finish();
 
                pane = new JTabbedPane();
 
                enable = new AltosUIEnable();
-               stats = new AltosFlightStats(states);
-               graphDataSet = new AltosGraphDataSet(states);
-               graph = new AltosGraph(enable, stats, graphDataSet);
+               stats = new AltosFlightStats(flight_series);
+
+               graph = new AltosGraph(enable, stats, flight_series);
+
                statsTable = new AltosFlightStatsTable(stats);
 
                map = new AltosUIMap();
@@ -74,11 +114,14 @@ public class TeleGPSGraphUI extends AltosUIFrame
                pane.add("Graph", graph.panel);
                pane.add("Configure Graph", enable);
                pane.add("Statistics", statsTable);
-               fill_map(states);
+               fill_map(flight_series);
                pane.add("Map", map);
 
                setContentPane (pane);
 
+               AltosUIPreferences.register_font_listener(this);
+               AltosPreferences.register_units_listener(this);
+
                addWindowListener(new WindowAdapter() {
                                @Override
                                public void windowClosing(WindowEvent e) {