Merge branch 'master' of ssh://git.gag.com/scm/git/fw/altos
[fw/altos] / altosui / AltosFlightStatsTable.java
1 /*
2  * Copyright © 2011 Keith Packard <keithp@keithp.com>
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 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.awt.*;
21 import java.awt.event.*;
22 import javax.swing.*;
23 import javax.swing.filechooser.FileNameExtensionFilter;
24 import javax.swing.table.*;
25 import java.io.*;
26 import java.util.*;
27 import java.text.*;
28 import java.util.prefs.*;
29 import java.util.concurrent.*;
30 import org.altusmetrum.AltosLib.*;
31
32 public class AltosFlightStatsTable extends JComponent {
33         GridBagLayout   layout;
34
35         class FlightStat {
36                 JLabel          label;
37                 JTextField      value;
38
39                 public FlightStat(GridBagLayout layout, int y, String label_text, String ... values) {
40                         GridBagConstraints      c = new GridBagConstraints();
41                         c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
42                         c.weighty = 1;
43
44                         label = new JLabel(label_text);
45                         label.setFont(Altos.label_font);
46                         label.setHorizontalAlignment(SwingConstants.LEFT);
47                         c.gridx = 0; c.gridy = y;
48                         c.anchor = GridBagConstraints.WEST;
49                         c.fill = GridBagConstraints.VERTICAL;
50                         c.weightx = 0;
51                         layout.setConstraints(label, c);
52                         add(label);
53
54                         for (int j = 0; j < values.length; j++) {
55                                 value = new JTextField(values[j]);
56                                 value.setFont(Altos.value_font);
57                                 value.setHorizontalAlignment(SwingConstants.RIGHT);
58                                 c.gridx = j+1; c.gridy = y;
59                                 c.anchor = GridBagConstraints.EAST;
60                                 c.fill = GridBagConstraints.BOTH;
61                                 c.weightx = 1;
62                                 layout.setConstraints(value, c);
63                                 add(value);
64                         }
65                 }
66
67         }
68
69         public AltosFlightStatsTable(AltosFlightStats stats) {
70                 layout = new GridBagLayout();
71
72                 setLayout(layout);
73                 int y = 0;
74                 new FlightStat(layout, y++, "Serial", String.format("%d", stats.serial));
75                 new FlightStat(layout, y++, "Flight", String.format("%d", stats.flight));
76                 if (stats.year > 0)
77                         new FlightStat(layout, y++, "Date",
78                                        String.format("%04d-%02d-%02d", stats.year, stats.month, stats.day));
79                 if (stats.hour > 0)
80                         new FlightStat(layout, y++, "Time",
81                                        String.format("%02d:%02d:%02d UTC", stats.hour, stats.minute, stats.second));
82                 new FlightStat(layout, y++, "Maximum height",
83                                String.format("%5.0f m", stats.max_height),
84                                String.format("%5.0f ft", AltosConvert.meters_to_feet(stats.max_height)));
85                 new FlightStat(layout, y++, "Maximum speed",
86                                String.format("%5.0f m/s", stats.max_speed),
87                                String.format("%5.0f mph", AltosConvert.meters_to_mph(stats.max_speed)),
88                                String.format("Mach %4.1f", AltosConvert.meters_to_mach(stats.max_speed)));
89                 if (stats.max_acceleration != AltosRecord.MISSING) {
90                         new FlightStat(layout, y++, "Maximum boost acceleration",
91                                        String.format("%5.0f m/s²", stats.max_acceleration),
92                                        String.format("%5.0f ft/s²", AltosConvert.meters_to_feet(stats.max_acceleration)),
93                                        String.format("%5.0f G", AltosConvert.meters_to_g(stats.max_acceleration)));
94                         new FlightStat(layout, y++, "Average boost acceleration",
95                                        String.format("%5.0f m/s²", stats.state_accel[Altos.ao_flight_boost]),
96                                        String.format("%5.0f ft/s²", AltosConvert.meters_to_feet(stats.state_accel[Altos.ao_flight_boost])),
97                                        String.format("%5.0f G", AltosConvert.meters_to_g(stats.state_accel[Altos.ao_flight_boost])));
98                 }
99                 new FlightStat(layout, y++, "Drogue descent rate",
100                                String.format("%5.0f m/s", stats.state_baro_speed[Altos.ao_flight_drogue]),
101                                String.format("%5.0f ft/s", AltosConvert.meters_to_feet(stats.state_baro_speed[Altos.ao_flight_drogue])));
102                 new FlightStat(layout, y++, "Main descent rate",
103                                String.format("%5.0f m/s", stats.state_baro_speed[Altos.ao_flight_main]),
104                                String.format("%5.0f ft/s", AltosConvert.meters_to_feet(stats.state_baro_speed[Altos.ao_flight_main])));
105                 for (int s = Altos.ao_flight_boost; s <= Altos.ao_flight_main; s++) {
106                         new FlightStat(layout, y++, String.format("%s time", AltosLib.state_name_capital(s)),
107                                        String.format("%6.0f s", stats.state_end[s] - stats.state_start[s]));
108                 }
109                 new FlightStat(layout, y++, "Flight Time",
110                                String.format("%6.0f s", stats.state_end[Altos.ao_flight_main] -
111                                              stats.state_start[Altos.ao_flight_boost]));
112                 
113         }
114         
115 }