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_12.*;
28 import org.altusmetrum.altosuilib_12.*;
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;
45 void fill_map(AltosFlightSeries flight_series) {
46 boolean any_gps = false;
47 AltosGPSTimeValue gtv_last = null;
49 if (flight_series.gps_series != null) {
50 for (AltosGPSTimeValue gtv : flight_series.gps_series) {
51 AltosGPS gps = gtv.gps;
56 map = new AltosUIMap();
57 map.show(gps, (int) flight_series.value_before(AltosFlightSeries.state_name, gtv.time));
64 if (gtv_last != null) {
65 int state = (int) flight_series.value_after(AltosFlightSeries.state_name, gtv_last.time);
66 if (state == AltosLib.ao_flight_landed)
67 map.show(gtv_last.gps, state);
71 public void font_size_changed(int font_size) {
73 map.font_size_changed(font_size);
74 if (statsTable != null)
75 statsTable.font_size_changed(font_size);
78 public void units_changed(boolean imperial_units) {
80 map.units_changed(imperial_units);
82 enable.units_changed(imperial_units);
85 AltosUIFlightSeries flight_series;
87 public void filter_changed(double speed_filter, double accel_filter) {
88 flight_series.set_filter(speed_filter, accel_filter);
89 graph.filter_changed();
90 stats = new AltosFlightStats(flight_series);
91 statsTable.filter_changed(stats);
94 public double speed_filter() {
95 return flight_series.speed_filter_width;
98 public double accel_filter() {
99 return flight_series.accel_filter_width;
102 AltosGraphUI(AltosRecordSet set, File file) throws InterruptedException, IOException {
103 super(file.getName());
104 AltosCalData cal_data = set.cal_data();
107 pane = new JTabbedPane();
109 flight_series = new AltosUIFlightSeries(cal_data);
111 enable = new AltosUIEnable(this);
113 set.capture_series(flight_series);
115 flight_series.finish();
117 stats = new AltosFlightStats(flight_series);
119 graph = new AltosGraph(enable, stats, flight_series);
121 statsTable = new AltosFlightStatsTable(stats);
123 pane.add("Flight Graph", graph.panel);
124 pane.add("Configure Graph", enable);
125 pane.add("Flight Statistics", statsTable);
128 fill_map(flight_series);
130 pane.add("Map", map);
132 setContentPane (pane);
134 AltosUIPreferences.register_font_listener(this);
135 AltosPreferences.register_units_listener(this);
137 addWindowListener(new WindowAdapter() {
139 public void windowClosing(WindowEvent e) {
140 AltosUIPreferences.unregister_font_listener(AltosGraphUI.this);
141 AltosPreferences.unregister_units_listener(AltosGraphUI.this);