Bump Java library versions
[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; version 2 or any later version of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 package altosui;
19
20 import java.io.*;
21 import java.util.ArrayList;
22
23 import java.awt.*;
24 import java.awt.event.*;
25 import javax.swing.*;
26 import org.altusmetrum.altoslib_8.*;
27 import org.altusmetrum.altosuilib_8.*;
28
29 import org.jfree.chart.ChartPanel;
30 import org.jfree.chart.JFreeChart;
31 import org.jfree.ui.RefineryUtilities;
32
33 public class AltosGraphUI extends AltosUIFrame implements AltosFontListener, AltosUnitsListener
34 {
35         JTabbedPane             pane;
36         AltosGraph              graph;
37         AltosUIEnable           enable;
38         AltosUIMapNew           map;
39         AltosState              state;
40         AltosGraphDataSet       graphDataSet;
41         AltosFlightStats        stats;
42         AltosFlightStatsTable   statsTable;
43         boolean                 has_gps;
44
45         void fill_map(AltosStateIterable states) {
46                 boolean         any_gps = false;
47                 for (AltosState state : states) {
48                         if (state.gps != null && state.gps.locked && state.gps.nsat >= 4) {
49                                 if (map == null)
50                                         map = new AltosUIMapNew();
51                                 map.show(state, null);
52                                 has_gps = true;
53                         }
54                 }
55         }
56
57         public void font_size_changed(int font_size) {
58                 if (map != null)
59                         map.font_size_changed(font_size);
60                 if (statsTable != null)
61                         statsTable.font_size_changed(font_size);
62         }
63
64         public void units_changed(boolean imperial_units) {
65                 if (map != null)
66                         map.units_changed(imperial_units);
67                 if (enable != null)
68                         enable.units_changed(imperial_units);
69         }
70
71         AltosGraphUI(AltosStateIterable states, File file) throws InterruptedException, IOException {
72                 super(file.getName());
73                 state = null;
74
75                 pane = new JTabbedPane();
76
77                 enable = new AltosUIEnable();
78
79                 stats = new AltosFlightStats(states);
80                 graphDataSet = new AltosGraphDataSet(states);
81
82                 graph = new AltosGraph(enable, stats, graphDataSet);
83
84                 statsTable = new AltosFlightStatsTable(stats);
85
86                 pane.add("Flight Graph", graph.panel);
87                 pane.add("Configure Graph", enable);
88                 pane.add("Flight Statistics", statsTable);
89
90                 has_gps = false;
91                 fill_map(states);
92                 if (has_gps)
93                         pane.add("Map", map);
94
95                 setContentPane (pane);
96
97                 AltosUIPreferences.register_font_listener(this);
98                 AltosPreferences.register_units_listener(this);
99
100                 addWindowListener(new WindowAdapter() {
101                                 @Override
102                                 public void windowClosing(WindowEvent e) {
103                                         setVisible(false);
104                                         dispose();
105                                         AltosUIPreferences.unregister_font_listener(AltosGraphUI.this);
106                                         AltosPreferences.unregister_units_listener(AltosGraphUI.this);
107                                 }
108                         });
109                 pack();
110
111                 setVisible(true);
112                 if (state != null && has_gps)
113                         map.centre(state);
114         }
115 }