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.
22 import java.util.ArrayList;
25 import java.awt.event.*;
27 import org.altusmetrum.altoslib_14.*;
28 import org.altusmetrum.altosuilib_14.*;
30 import org.jfree.chart.ChartPanel;
31 import org.jfree.chart.JFreeChart;
32 import org.jfree.ui.RefineryUtilities;
34 public class AltosGraphUI extends AltosUIFrame implements AltosFontListener, AltosUnitsListener, AltosFilterListener
40 AltosFlightStats stats;
41 AltosFlightStatsTable statsTable;
42 AltosFlightConfigTable configTable;
43 AltosFlightPyroTable pyroTable;
47 void fill_map(AltosFlightSeries flight_series) {
48 boolean any_gps = false;
49 AltosGPSTimeValue gtv_last = null;
50 double gps_pad_altitude = flight_series.cal_data().gps_pad_altitude;;
52 if (flight_series.gps_series != null) {
53 for (AltosGPSTimeValue gtv : flight_series.gps_series) {
54 AltosGPS gps = gtv.gps;
59 map = new AltosUIMap();
60 double gps_height = gps.alt - gps_pad_altitude;
61 int state = (int) flight_series.value_before(AltosFlightSeries.state_name, gtv.time);
62 map.show(gps, gtv.time, state, gps_height);
69 if (gtv_last != null) {
70 int state = (int) flight_series.value_after(AltosFlightSeries.state_name, gtv_last.time);
71 double gps_height = gps.alt - gps_pad_altitude;
72 if (state == AltosLib.ao_flight_landed)
73 map.show(gtv_last.gps, gtv_last.time, state,gps_height);
77 public void font_size_changed(int font_size) {
79 map.font_size_changed(font_size);
80 if (statsTable != null)
81 statsTable.font_size_changed(font_size);
82 if (configTable != null)
83 configTable.font_size_changed(font_size);
84 if (pyroTable != null)
85 pyroTable.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);
93 if (configTable != null)
94 configTable.units_changed(imperial_units);
95 if (pyroTable != null)
96 pyroTable.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 AltosGraphUI(AltosRecordSet set, File file) throws InterruptedException, IOException {
117 super(file.getName());
118 AltosCalData cal_data = set.cal_data();
119 AltosConfigData config_data = set.config_data();
121 pane = new JTabbedPane();
123 flight_series = new AltosUIFlightSeries(cal_data);
125 enable = new AltosUIEnable(this);
127 set.capture_series(flight_series);
129 flight_series.finish();
131 stats = new AltosFlightStats(flight_series);
133 graph = new AltosGraph(enable, stats, flight_series);
135 statsTable = new AltosFlightStatsTable(stats);
137 pane.add("Flight Graph", graph.panel);
138 pane.add("Configure Graph", enable);
139 pane.add("Flight Statistics", statsTable);
140 if (config_data != null) {
141 configTable = new AltosFlightConfigTable(config_data);
142 pane.add("Configuration", configTable);
143 if (config_data.npyro > 0 && config_data.npyro != AltosLib.MISSING) {
144 pyroTable = new AltosFlightPyroTable(config_data.pyros, config_data.npyro);
145 pane.add("Pyros", pyroTable);
150 fill_map(flight_series);
152 pane.add("Map", map);
154 setContentPane (pane);
156 AltosUIPreferences.register_font_listener(this);
157 AltosPreferences.register_units_listener(this);
159 addWindowListener(new WindowAdapter() {
161 public void windowClosing(WindowEvent e) {
162 AltosUIPreferences.unregister_font_listener(AltosGraphUI.this);
163 AltosPreferences.unregister_units_listener(AltosGraphUI.this);