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_12.*;
31 import org.altusmetrum.altosuilib_12.*;
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
44 AltosFlightStats stats;
45 AltosFlightStatsTable statsTable;
49 void fill_map(AltosFlightSeries flight_series) {
50 boolean any_gps = false;
51 AltosGPSTimeValue gtv_last = null;
53 if (flight_series.gps_series != null) {
54 for (AltosGPSTimeValue gtv : flight_series.gps_series) {
56 AltosGPS gps = gtv.gps;
61 map = new AltosUIMap();
62 map.show(gps, (int) flight_series.value_before(AltosFlightSeries.state_name, gtv.time));
68 if (gtv_last != null) {
69 int state = (int) flight_series.value_after(AltosFlightSeries.state_name, gtv_last.time);
70 if (state == AltosLib.ao_flight_landed)
71 map.show(gtv_last.gps, state);
75 private void close() {
78 TeleGPS.subtract_window();
81 public void font_size_changed(int font_size) {
83 map.font_size_changed(font_size);
84 if (statsTable != null)
85 statsTable.font_size_changed(font_size);
88 public void units_changed(boolean imperial_units) {
90 map.units_changed(imperial_units);
92 enable.units_changed(imperial_units);
95 TeleGPSGraphUI(AltosRecordSet set, File file) throws InterruptedException, IOException {
96 super(file.getName());
97 AltosCalData cal_data = set.cal_data();
99 AltosUIFlightSeries flight_series = new AltosUIFlightSeries(cal_data);
100 set.capture_series(flight_series);
101 flight_series.finish();
103 pane = new JTabbedPane();
105 enable = new AltosUIEnable();
106 stats = new AltosFlightStats(flight_series);
108 graph = new AltosGraph(enable, stats, flight_series);
110 statsTable = new AltosFlightStatsTable(stats);
112 map = new AltosUIMap();
114 pane.add("Graph", graph.panel);
115 pane.add("Configure Graph", enable);
116 pane.add("Statistics", statsTable);
117 fill_map(flight_series);
118 pane.add("Map", map);
120 setContentPane (pane);
122 AltosUIPreferences.register_font_listener(this);
123 AltosPreferences.register_units_listener(this);
125 addWindowListener(new WindowAdapter() {
127 public void windowClosing(WindowEvent e) {
134 setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
136 TeleGPS.add_window();