altos/test: Adjust CRC error rate after FEC fix
[fw/altos] / telegps / TeleGPSGraphUI.java
1 /*
2  * Copyright © 2010 Anthony Towns
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 package org.altusmetrum.telegps;
20
21 import java.io.*;
22 import java.util.ArrayList;
23
24 import java.awt.*;
25 import java.awt.event.*;
26 import javax.swing.*;
27 import java.io.*;
28 import java.util.concurrent.*;
29 import java.util.*;
30 import org.altusmetrum.altoslib_14.*;
31 import org.altusmetrum.altosuilib_14.*;
32
33 import org.jfree.chart.ChartPanel;
34 import org.jfree.chart.JFreeChart;
35 import org.jfree.ui.RefineryUtilities;
36
37 public class TeleGPSGraphUI extends AltosUIFrame implements AltosFontListener, AltosUnitsListener, AltosFilterListener
38 {
39         JTabbedPane             pane;
40         AltosGraph              graph;
41         AltosUIEnable           enable;
42         AltosUIMap              map;
43         AltosState              state;
44         AltosFlightStats        stats;
45         AltosFlightStatsTable   statsTable;
46         AltosGPS                gps;
47         boolean                 has_gps;
48
49         void fill_map(AltosFlightSeries flight_series) {
50                 boolean                 any_gps = false;
51                 AltosGPSTimeValue       gtv_last = null;
52                 double gps_pad_altitude = flight_series.cal_data().gps_pad_altitude;;
53
54                 if (flight_series.gps_series != null) {
55                         for (AltosGPSTimeValue gtv : flight_series.gps_series) {
56                                 gtv_last = gtv;
57                                 AltosGPS gps = gtv.gps;
58                                 if (gps != null &&
59                                     gps.locked &&
60                                     gps.nsat >= 4) {
61                                         if (map == null)
62                                                 map = new AltosUIMap();
63                                         double gps_height = gps.alt - gps_pad_altitude;
64                                         int state = (int) flight_series.value_before(AltosFlightSeries.state_name, gtv.time);
65                                         map.show(gps, gtv.time, state, gps_height);
66                                         this.gps = gps;
67                                         has_gps = true;
68                                 }
69                         }
70                 }
71                 if (gtv_last != null) {
72                         int state = (int) flight_series.value_after(AltosFlightSeries.state_name, gtv_last.time);
73                         double gps_height = gps.alt - gps_pad_altitude;
74                         if (state == AltosLib.ao_flight_landed)
75                                 map.show(gtv_last.gps, gtv_last.time, state, gps_height);
76                 }
77         }
78
79         private void close() {
80                 setVisible(false);
81                 dispose();
82                 TeleGPS.subtract_window();
83         }
84
85         public void font_size_changed(int font_size) {
86                 if (map != null)
87                         map.font_size_changed(font_size);
88                 if (statsTable != null)
89                         statsTable.font_size_changed(font_size);
90         }
91
92         public void units_changed(boolean imperial_units) {
93                 if (map != null)
94                         map.units_changed(imperial_units);
95                 if (enable != null)
96                         enable.units_changed(imperial_units);
97         }
98
99         AltosUIFlightSeries flight_series;
100
101         public void filter_changed(double speed_filter, double accel_filter) {
102                 flight_series.set_filter(speed_filter, accel_filter);
103                 graph.filter_changed();
104                 stats = new AltosFlightStats(flight_series);
105                 statsTable.filter_changed(stats);
106         }
107
108         public double speed_filter() {
109                 return flight_series.speed_filter_width;
110         }
111
112         public double accel_filter() {
113                 return flight_series.accel_filter_width;
114         }
115
116         TeleGPSGraphUI(AltosRecordSet set, File file) throws InterruptedException, IOException {
117                 super(file.getName());
118                 AltosCalData cal_data = set.cal_data();
119
120                 pane = new JTabbedPane();
121
122                 flight_series = new AltosUIFlightSeries(cal_data);
123
124                 enable = new AltosUIEnable(this);
125
126                 set.capture_series(flight_series);
127
128                 flight_series.finish();
129
130                 stats = new AltosFlightStats(flight_series);
131
132                 graph = new AltosGraph(enable, stats, flight_series);
133
134                 statsTable = new AltosFlightStatsTable(stats);
135
136                 map = new AltosUIMap();
137
138                 pane.add("Graph", graph.panel);
139                 pane.add("Configure Graph", enable);
140                 pane.add("Statistics", statsTable);
141                 fill_map(flight_series);
142                 pane.add("Map", map);
143
144                 setContentPane (pane);
145
146                 AltosUIPreferences.register_font_listener(this);
147                 AltosPreferences.register_units_listener(this);
148
149                 addWindowListener(new WindowAdapter() {
150                                 @Override
151                                 public void windowClosing(WindowEvent e) {
152                                         close();
153                                 }
154                         });
155
156                 pack();
157
158                 setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
159
160                 TeleGPS.add_window();
161
162                 setVisible(true);
163
164                 if (state != null)
165                         map.centre(state);
166
167         }
168 }