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