altosui: Stick file basename in graph window title
[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, File file) throws InterruptedException, IOException {
40                 super(file.getName());
41                 state = null;
42
43                 pane = new JTabbedPane();
44
45                 enable = new AltosUIEnable();
46
47                 AltosGraph graph = new AltosGraph(enable);
48
49                 graph.setDataSet(new AltosGraphDataSet(records));
50
51                 map = new AltosSiteMap();
52
53                 pane.add("Flight Graph", graph.panel);
54                 pane.add("Configure Graph", enable);
55
56                 AltosFlightStatsTable stats = new AltosFlightStatsTable(new AltosFlightStats(records));
57                 pane.add("Flight Statistics", stats);
58
59                 if (fill_map(records))
60                         pane.add("Map", map);
61
62                 setContentPane (pane);
63
64                 pack();
65
66                 setDefaultCloseOperation(DISPOSE_ON_CLOSE);
67                 setVisible(true);
68                 if (state != null)
69                         map.centre(state);
70         }
71 }