2 * Copyright © 2010 Anthony Towns
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.
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.
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.
19 package org.altusmetrum.telegps;
22 import java.util.ArrayList;
25 import java.awt.event.*;
28 import java.util.concurrent.*;
30 import org.altusmetrum.altoslib_14.*;
31 import org.altusmetrum.altosuilib_14.*;
33 import org.jfree.chart.ChartPanel;
34 import org.jfree.chart.JFreeChart;
35 import org.jfree.ui.RefineryUtilities;
37 public class TeleGPSGraphUI extends AltosUIFrame implements AltosFontListener, AltosUnitsListener, AltosFilterListener
44 AltosFlightStats stats;
45 AltosFlightStatsTable statsTable;
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;;
54 if (flight_series.gps_series != null) {
55 for (AltosGPSTimeValue gtv : flight_series.gps_series) {
57 AltosGPS gps = gtv.gps;
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);
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);
79 private void close() {
82 TeleGPS.subtract_window();
85 public void font_size_changed(int font_size) {
87 map.font_size_changed(font_size);
88 if (statsTable != null)
89 statsTable.font_size_changed(font_size);
92 public void units_changed(boolean imperial_units) {
94 map.units_changed(imperial_units);
96 enable.units_changed(imperial_units);
99 AltosUIFlightSeries flight_series;
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);
108 public double speed_filter() {
109 return flight_series.speed_filter_width;
112 public double accel_filter() {
113 return flight_series.accel_filter_width;
116 TeleGPSGraphUI(AltosRecordSet set, File file) throws InterruptedException, IOException {
117 super(file.getName());
118 AltosCalData cal_data = set.cal_data();
120 pane = new JTabbedPane();
122 flight_series = new AltosUIFlightSeries(cal_data);
124 enable = new AltosUIEnable(this);
126 set.capture_series(flight_series);
128 flight_series.finish();
130 stats = new AltosFlightStats(flight_series);
132 graph = new AltosGraph(enable, stats, flight_series);
134 statsTable = new AltosFlightStatsTable(stats);
136 map = new AltosUIMap();
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);
144 setContentPane (pane);
146 AltosUIPreferences.register_font_listener(this);
147 AltosPreferences.register_units_listener(this);
149 addWindowListener(new WindowAdapter() {
151 public void windowClosing(WindowEvent e) {
158 setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
160 TeleGPS.add_window();