6fd05b269550c572dfda7afbe7bdd64f0d42eef9
[fw/altos] / teststand / 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 teststand;
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_12.*;
28 import org.altusmetrum.altosuilib_12.*;
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         TestStandGraph          graph;
38         AltosUIEnable           enable;
39         TestStats       stats;
40         TestStatsTable          statsTable;
41         AltosGPS                gps;
42         boolean                 has_gps;
43
44         public void font_size_changed(int font_size) {
45                 if (statsTable != null)
46                         statsTable.font_size_changed(font_size);
47         }
48
49         public void units_changed(boolean imperial_units) {
50                 if (enable != null)
51                         enable.units_changed(imperial_units);
52         }
53
54         AltosUIFlightSeries flight_series;
55
56         public void filter_changed(double speed_filter, double accel_filter) {
57                 flight_series.set_filter(speed_filter, accel_filter);
58                 graph.filter_changed();
59                 stats = new TestStats(flight_series);
60                 statsTable.filter_changed(stats);
61         }
62
63         public double speed_filter() {
64                 return flight_series.speed_filter_width;
65         }
66
67         public double accel_filter() {
68                 return flight_series.accel_filter_width;
69         }
70
71         AltosGraphUI(AltosRecordSet set, File file) throws InterruptedException, IOException {
72                 super(file.getName());
73                 AltosCalData    cal_data = set.cal_data();
74
75
76                 pane = new JTabbedPane();
77
78                 flight_series = new AltosUIFlightSeries(cal_data);
79
80                 enable = new AltosUIEnable(this);
81
82                 set.capture_series(flight_series);
83
84                 flight_series.finish();
85
86                 stats = new TestStats(flight_series);
87
88                 graph = new TestStandGraph(enable, stats, flight_series);
89
90                 statsTable = new TestStatsTable(stats);
91
92                 pane.add("Test Graph", graph.panel);
93                 pane.add("Configure Graph", enable);
94                 pane.add("Test Statistics", statsTable);
95
96                 has_gps = false;
97
98                 setContentPane (pane);
99
100                 AltosUIPreferences.register_font_listener(this);
101                 AltosPreferences.register_units_listener(this);
102
103                 addWindowListener(new WindowAdapter() {
104                                 @Override
105                                 public void windowClosing(WindowEvent e) {
106                                         AltosUIPreferences.unregister_font_listener(AltosGraphUI.this);
107                                         AltosPreferences.unregister_units_listener(AltosGraphUI.this);
108                                 }
109                         });
110                 pack();
111
112                 setVisible(true);
113         }
114 }