altosui: Add map and GPS data to graph window. Trac #50
[fw/altos] / altosui / AltosGraphUI.java
1
2 // Copyright (c) 2010 Anthony Towns
3 // GPL v2 or later
4
5 package altosui;
6
7 import java.io.*;
8 import java.util.ArrayList;
9
10 import java.awt.*;
11 import javax.swing.*;
12 import org.altusmetrum.altoslib_1.*;
13 import org.altusmetrum.altosuilib_1.*;
14
15 import org.jfree.chart.ChartPanel;
16 import org.jfree.chart.JFreeChart;
17 import org.jfree.ui.RefineryUtilities;
18
19 public class AltosGraphUI extends AltosUIFrame 
20 {
21         JTabbedPane             pane;
22         AltosGraph              graph;
23         AltosUIEnable           enable;
24         AltosSiteMap            map;
25         AltosState              state;
26
27         boolean fill_map(AltosRecordIterable records) {
28                 boolean         any_gps = false;
29                 for (AltosRecord record : records) {
30                         state = new AltosState(record, state);
31                         if (state.data.gps != null) {
32                                 map.show(state, 0);
33                                 any_gps = true;
34                         }
35                 }
36                 return any_gps;
37         }
38
39         AltosGraphUI(AltosRecordIterable records, String file) throws InterruptedException, IOException {
40                 state = null;
41
42                 pane = new JTabbedPane();
43
44                 enable = new AltosUIEnable();
45
46                 AltosGraph graph = new AltosGraph(enable);
47
48                 graph.setDataSet(new AltosGraphDataSet(records));
49
50                 map = new AltosSiteMap();
51
52                 pane.add("Flight Graph", graph.panel);
53                 pane.add("Configure Graph", enable);
54
55                 AltosFlightStatsTable stats = new AltosFlightStatsTable(new AltosFlightStats(records));
56                 pane.add("Flight Statistics", stats);
57
58                 if (fill_map(records))
59                         pane.add("Map", map);
60
61                 setContentPane (pane);
62
63                 pack();
64
65                 setDefaultCloseOperation(DISPOSE_ON_CLOSE);
66                 setVisible(true);
67                 if (state != null)
68                         map.centre(state);
69         }
70 }