a stab at turning on rudimentary logging for telefiretwo
[fw/altos] / altosui / AltosGraphUI.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 altosui;
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 org.altusmetrum.altoslib_11.*;
28 import org.altusmetrum.altosuilib_11.*;
29
30 import org.jfree.chart.ChartPanel;
31 import org.jfree.chart.JFreeChart;
32 import org.jfree.ui.RefineryUtilities;
33
34 public class AltosGraphUI extends AltosUIFrame implements AltosFontListener, AltosUnitsListener
35 {
36         JTabbedPane             pane;
37         AltosGraph              graph;
38         AltosUIEnable           enable;
39         AltosUIMap              map;
40         AltosState              state;
41         AltosGraphDataSet       graphDataSet;
42         AltosFlightStats        stats;
43         AltosFlightStatsTable   statsTable;
44         boolean                 has_gps;
45
46         void fill_map(AltosStateIterable states) {
47                 boolean         any_gps = false;
48                 for (AltosState state : states) {
49                         if (state.gps != null && state.gps.locked && state.gps.nsat >= 4) {
50                                 if (map == null)
51                                         map = new AltosUIMap();
52                                 map.show(state, null);
53                                 has_gps = true;
54                         }
55                 }
56         }
57
58         public void font_size_changed(int font_size) {
59                 if (map != null)
60                         map.font_size_changed(font_size);
61                 if (statsTable != null)
62                         statsTable.font_size_changed(font_size);
63         }
64
65         public void units_changed(boolean imperial_units) {
66                 if (map != null)
67                         map.units_changed(imperial_units);
68                 if (enable != null)
69                         enable.units_changed(imperial_units);
70         }
71
72         AltosGraphUI(AltosStateIterable states, File file) throws InterruptedException, IOException {
73                 super(file.getName());
74                 state = null;
75
76                 pane = new JTabbedPane();
77
78                 enable = new AltosUIEnable();
79
80                 stats = new AltosFlightStats(states);
81                 graphDataSet = new AltosGraphDataSet(states);
82
83                 graph = new AltosGraph(enable, stats, graphDataSet);
84
85                 statsTable = new AltosFlightStatsTable(stats);
86
87                 pane.add("Flight Graph", graph.panel);
88                 pane.add("Configure Graph", enable);
89                 pane.add("Flight Statistics", statsTable);
90
91                 has_gps = false;
92                 fill_map(states);
93                 if (has_gps)
94                         pane.add("Map", map);
95
96                 setContentPane (pane);
97
98                 AltosUIPreferences.register_font_listener(this);
99                 AltosPreferences.register_units_listener(this);
100
101                 addWindowListener(new WindowAdapter() {
102                                 @Override
103                                 public void windowClosing(WindowEvent e) {
104                                         AltosUIPreferences.unregister_font_listener(AltosGraphUI.this);
105                                         AltosPreferences.unregister_units_listener(AltosGraphUI.this);
106                                 }
107                         });
108                 pack();
109
110                 setVisible(true);
111                 if (state != null && has_gps)
112                         map.centre(state);
113         }
114 }