d8b8f6dd282d41b1bbce8b4724f7dac3212714a5
[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         AltosGraphDataSet       graphDataSet;
27         AltosFlightStats        stats;
28         AltosFlightStatsTable   statsTable;
29         boolean                 has_gps;
30
31         void fill_map(AltosRecordIterable records) {
32                 boolean         any_gps = false;
33                 for (AltosRecord record : records) {
34                         state = new AltosState(record, state);
35                         if (state.gps != null && state.gps.locked && state.gps.nsat >= 4) {
36                                 if (map == null)
37                                         map = new AltosSiteMap();
38                                 map.show(state, null);
39                                 has_gps = true;
40                         }
41                 }
42         }
43
44         AltosGraphUI(AltosRecordIterable records, File file) throws InterruptedException, IOException {
45                 super(file.getName());
46                 state = null;
47
48                 pane = new JTabbedPane();
49
50                 enable = new AltosUIEnable();
51
52                 stats = new AltosFlightStats(records);
53                 graphDataSet = new AltosGraphDataSet(records);
54
55                 graph = new AltosGraph(enable, stats, graphDataSet);
56
57                 statsTable = new AltosFlightStatsTable(stats);
58
59                 pane.add("Flight Graph", graph.panel);
60                 pane.add("Configure Graph", enable);
61                 pane.add("Flight Statistics", statsTable);
62
63                 has_gps = false;
64                 fill_map(records);
65                 if (has_gps)
66                         pane.add("Map", map);
67
68                 setContentPane (pane);
69
70                 pack();
71
72                 setDefaultCloseOperation(DISPOSE_ON_CLOSE);
73                 setVisible(true);
74                 if (state != null && has_gps)
75                         map.centre(state);
76         }
77 }