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