telegps: Add graph display
[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; version 2 or any later version of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 package altosui;
19
20 import java.io.*;
21 import java.util.ArrayList;
22
23 import java.awt.*;
24 import javax.swing.*;
25 import org.altusmetrum.altoslib_4.*;
26 import org.altusmetrum.altosuilib_2.*;
27
28 import org.jfree.chart.ChartPanel;
29 import org.jfree.chart.JFreeChart;
30 import org.jfree.ui.RefineryUtilities;
31
32 public class AltosGraphUI extends AltosUIFrame
33 {
34         JTabbedPane             pane;
35         AltosGraph              graph;
36         AltosUIEnable           enable;
37         AltosSiteMap            map;
38         AltosState              state;
39         AltosGraphDataSet       graphDataSet;
40         AltosFlightStats        stats;
41         AltosFlightStatsTable   statsTable;
42         boolean                 has_gps;
43
44         void fill_map(AltosStateIterable states) {
45                 boolean         any_gps = false;
46                 for (AltosState state : states) {
47                         if (state.gps != null && state.gps.locked && state.gps.nsat >= 4) {
48                                 if (map == null)
49                                         map = new AltosSiteMap();
50                                 map.show(state, null);
51                                 has_gps = true;
52                         }
53                 }
54         }
55
56         AltosGraphUI(AltosStateIterable states, File file) throws InterruptedException, IOException {
57                 super(file.getName());
58                 state = null;
59
60                 pane = new JTabbedPane();
61
62                 enable = new AltosUIEnable();
63
64                 stats = new AltosFlightStats(states);
65                 graphDataSet = new AltosGraphDataSet(states);
66
67                 graph = new AltosGraph(enable, stats, graphDataSet);
68
69                 statsTable = new AltosFlightStatsTable(stats);
70
71                 pane.add("Flight Graph", graph.panel);
72                 pane.add("Configure Graph", enable);
73                 pane.add("Flight Statistics", statsTable);
74
75                 has_gps = false;
76                 fill_map(states);
77                 if (has_gps)
78                         pane.add("Map", map);
79
80                 setContentPane (pane);
81
82                 pack();
83
84                 setDefaultCloseOperation(DISPOSE_ON_CLOSE);
85                 setVisible(true);
86                 if (state != null && has_gps)
87                         map.centre(state);
88         }
89 }