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