ao-tools/ao-flash-lpc: Adapt to current openocd LPC support
[fw/altos] / telegps / TeleGPSGraphUI.java
1 /*
2  * Copyright © 2010 Anthony Towns
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 package org.altusmetrum.telegps;
20
21 import java.io.*;
22 import java.util.ArrayList;
23
24 import java.awt.*;
25 import java.awt.event.*;
26 import javax.swing.*;
27 import java.io.*;
28 import java.util.concurrent.*;
29 import java.util.*;
30 import org.altusmetrum.altoslib_11.*;
31 import org.altusmetrum.altosuilib_11.*;
32
33 import org.jfree.chart.ChartPanel;
34 import org.jfree.chart.JFreeChart;
35 import org.jfree.ui.RefineryUtilities;
36
37 public class TeleGPSGraphUI extends AltosUIFrame
38 {
39         JTabbedPane             pane;
40         AltosGraph              graph;
41         AltosUIEnable           enable;
42         AltosUIMap              map;
43         AltosState              state;
44         AltosFlightStats        stats;
45         AltosGraphDataSet       graphDataSet;
46         AltosFlightStatsTable   statsTable;
47
48         void fill_map(AltosStateIterable states) {
49                 for (AltosState state : states) {
50                         if (state.gps != null && state.gps.locked && state.gps.nsat >= 4)
51                                 map.show(state, null);
52                 }
53         }
54
55         private void close() {
56                 setVisible(false);
57                 dispose();
58                 TeleGPS.subtract_window();
59         }
60
61         TeleGPSGraphUI(AltosStateIterable states, File file) throws InterruptedException, IOException {
62                 super(file.getName());
63                 state = null;
64
65                 pane = new JTabbedPane();
66
67                 enable = new AltosUIEnable();
68                 stats = new AltosFlightStats(states);
69                 graphDataSet = new AltosGraphDataSet(states);
70                 graph = new AltosGraph(enable, stats, graphDataSet);
71                 statsTable = new AltosFlightStatsTable(stats);
72
73                 map = new AltosUIMap();
74
75                 pane.add("Graph", graph.panel);
76                 pane.add("Configure Graph", enable);
77                 pane.add("Statistics", statsTable);
78                 fill_map(states);
79                 pane.add("Map", map);
80
81                 setContentPane (pane);
82
83                 addWindowListener(new WindowAdapter() {
84                                 @Override
85                                 public void windowClosing(WindowEvent e) {
86                                         close();
87                                 }
88                         });
89
90                 pack();
91
92                 setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
93
94                 TeleGPS.add_window();
95
96                 setVisible(true);
97
98                 if (state != null)
99                         map.centre(state);
100
101         }
102 }