Bump java lib versions in preparation for 1.9.2
[fw/altos] / altosui / AltosGraphUI.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 altosui;
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 org.altusmetrum.altoslib_14.*;
28 import org.altusmetrum.altosuilib_14.*;
29
30 import org.jfree.chart.ChartPanel;
31 import org.jfree.chart.JFreeChart;
32 import org.jfree.ui.RefineryUtilities;
33
34 public class AltosGraphUI extends AltosUIFrame implements AltosFontListener, AltosUnitsListener, AltosFilterListener
35 {
36         JTabbedPane             pane;
37         AltosGraph              graph;
38         AltosUIEnable           enable;
39         AltosUIMap              map;
40         AltosFlightStats        stats;
41         AltosFlightStatsTable   statsTable;
42         AltosGPS                gps;
43         boolean                 has_gps;
44
45         void fill_map(AltosFlightSeries flight_series) {
46                 boolean                 any_gps = false;
47                 AltosGPSTimeValue       gtv_last = null;
48                 double gps_pad_altitude = flight_series.cal_data().gps_pad_altitude;;
49
50                 if (flight_series.gps_series != null) {
51                         for (AltosGPSTimeValue gtv : flight_series.gps_series) {
52                                 AltosGPS gps = gtv.gps;
53                                 if (gps != null &&
54                                     gps.locked &&
55                                     gps.nsat >= 4) {
56                                         if (map == null)
57                                                 map = new AltosUIMap();
58                                         double gps_height = gps.alt - gps_pad_altitude;
59                                         int state = (int) flight_series.value_before(AltosFlightSeries.state_name, gtv.time);
60                                         map.show(gps, gtv.time, state, gps_height);
61                                         this.gps = gps;
62                                         gtv_last = gtv;
63                                         has_gps = true;
64                                 }
65                         }
66                 }
67                 if (gtv_last != null) {
68                         int state = (int) flight_series.value_after(AltosFlightSeries.state_name, gtv_last.time);
69                         double gps_height = gps.alt - gps_pad_altitude;
70                         if (state == AltosLib.ao_flight_landed)
71                                 map.show(gtv_last.gps, gtv_last.time, state,gps_height);
72                 }
73         }
74
75         public void font_size_changed(int font_size) {
76                 if (map != null)
77                         map.font_size_changed(font_size);
78                 if (statsTable != null)
79                         statsTable.font_size_changed(font_size);
80         }
81
82         public void units_changed(boolean imperial_units) {
83                 if (map != null)
84                         map.units_changed(imperial_units);
85                 if (enable != null)
86                         enable.units_changed(imperial_units);
87         }
88
89         AltosUIFlightSeries flight_series;
90
91         public void filter_changed(double speed_filter, double accel_filter) {
92                 flight_series.set_filter(speed_filter, accel_filter);
93                 graph.filter_changed();
94                 stats = new AltosFlightStats(flight_series);
95                 statsTable.filter_changed(stats);
96         }
97
98         public double speed_filter() {
99                 return flight_series.speed_filter_width;
100         }
101
102         public double accel_filter() {
103                 return flight_series.accel_filter_width;
104         }
105
106         AltosGraphUI(AltosRecordSet set, File file) throws InterruptedException, IOException {
107                 super(file.getName());
108                 AltosCalData    cal_data = set.cal_data();
109
110
111                 pane = new JTabbedPane();
112
113                 flight_series = new AltosUIFlightSeries(cal_data);
114
115                 enable = new AltosUIEnable(this);
116
117                 set.capture_series(flight_series);
118
119                 flight_series.finish();
120
121                 stats = new AltosFlightStats(flight_series);
122
123                 graph = new AltosGraph(enable, stats, flight_series);
124
125                 statsTable = new AltosFlightStatsTable(stats);
126
127                 pane.add("Flight Graph", graph.panel);
128                 pane.add("Configure Graph", enable);
129                 pane.add("Flight Statistics", statsTable);
130
131                 has_gps = false;
132                 fill_map(flight_series);
133                 if (has_gps)
134                         pane.add("Map", map);
135
136                 setContentPane (pane);
137
138                 AltosUIPreferences.register_font_listener(this);
139                 AltosPreferences.register_units_listener(this);
140
141                 addWindowListener(new WindowAdapter() {
142                                 @Override
143                                 public void windowClosing(WindowEvent e) {
144                                         AltosUIPreferences.unregister_font_listener(AltosGraphUI.this);
145                                         AltosPreferences.unregister_units_listener(AltosGraphUI.this);
146                                 }
147                         });
148                 pack();
149
150                 setVisible(true);
151                 if (gps != null)
152                         map.centre(gps);
153         }
154 }