2 * Copyright © 2011 Keith Packard <keithp@keithp.com>
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.
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.
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.
18 package org.altusmetrum.altosuilib_2;
23 import org.altusmetrum.altoslib_4.*;
25 public class AltosFlightStatsTable extends JComponent implements AltosFontListener {
28 LinkedList<FlightStat> flight_stats = new LinkedList<FlightStat>();
30 class FlightStat implements AltosFontListener {
34 public void font_size_changed(int font_size) {
35 label.setFont(AltosUILib.label_font);
36 for (int i = 0; i < value.length; i++)
37 value[i].setFont(AltosUILib.value_font);
40 public FlightStat(GridBagLayout layout, int y, String label_text, String ... values) {
41 GridBagConstraints c = new GridBagConstraints();
42 c.insets = new Insets(AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad);
45 label = new JLabel(label_text);
46 label.setFont(AltosUILib.label_font);
47 label.setHorizontalAlignment(SwingConstants.LEFT);
48 c.gridx = 0; c.gridy = y;
49 c.anchor = GridBagConstraints.WEST;
50 c.fill = GridBagConstraints.VERTICAL;
52 layout.setConstraints(label, c);
55 value = new JTextField[values.length];
56 for (int j = 0; j < values.length; j++) {
57 value[j] = new JTextField(values[j]);
58 value[j].setFont(AltosUILib.value_font);
59 value[j].setHorizontalAlignment(SwingConstants.RIGHT);
60 c.gridx = j+1; c.gridy = y;
61 c.anchor = GridBagConstraints.EAST;
62 c.fill = GridBagConstraints.BOTH;
64 layout.setConstraints(value[j], c);
67 flight_stats.add(this);
72 public void font_size_changed(int font_size) {
73 for (FlightStat f : flight_stats)
74 f.font_size_changed(font_size);
77 static String pos(double p, String pos, String neg) {
83 int deg = (int) Math.floor(p);
84 double min = (p - Math.floor(p)) * 60.0;
85 return String.format("%s %4d° %9.6f'", h, deg, min);
88 public AltosFlightStatsTable(AltosFlightStats stats) {
89 layout = new GridBagLayout();
93 new FlightStat(layout, y++, "Serial", String.format("%d", stats.serial));
94 new FlightStat(layout, y++, "Flight", String.format("%d", stats.flight));
95 if (stats.year != AltosLib.MISSING && stats.hour != AltosLib.MISSING)
96 new FlightStat(layout, y++, "Date/Time",
97 String.format("%04d-%02d-%02d", stats.year, stats.month, stats.day),
98 String.format("%02d:%02d:%02d UTC", stats.hour, stats.minute, stats.second));
100 if (stats.year != AltosLib.MISSING)
101 new FlightStat(layout, y++, "Date",
102 String.format("%04d-%02d-%02d", stats.year, stats.month, stats.day));
103 if (stats.hour != AltosLib.MISSING)
104 new FlightStat(layout, y++, "Time",
105 String.format("%02d:%02d:%02d UTC", stats.hour, stats.minute, stats.second));
107 if (stats.max_height != AltosLib.MISSING) {
108 new FlightStat(layout, y++, "Maximum height",
109 String.format("%5.0f m", stats.max_height),
110 String.format("%5.0f ft", AltosConvert.meters_to_feet(stats.max_height)));
112 if (stats.max_gps_height != AltosLib.MISSING) {
113 new FlightStat(layout, y++, "Maximum GPS height",
114 String.format("%5.0f m", stats.max_gps_height),
115 String.format("%5.0f ft", AltosConvert.meters_to_feet(stats.max_gps_height)));
117 new FlightStat(layout, y++, "Maximum speed",
118 String.format("%5.0f m/s", stats.max_speed),
119 String.format("%5.0f mph", AltosConvert.meters_to_mph(stats.max_speed)),
120 String.format("Mach %4.1f", AltosConvert.meters_to_mach(stats.max_speed)));
121 if (stats.max_acceleration != AltosLib.MISSING) {
122 new FlightStat(layout, y++, "Maximum boost acceleration",
123 String.format("%5.0f m/s²", stats.max_acceleration),
124 String.format("%5.0f ft/s²", AltosConvert.meters_to_feet(stats.max_acceleration)),
125 String.format("%5.0f G", AltosConvert.meters_to_g(stats.max_acceleration)));
126 new FlightStat(layout, y++, "Average boost acceleration",
127 String.format("%5.0f m/s²", stats.state_accel[AltosLib.ao_flight_boost]),
128 String.format("%5.0f ft/s²", AltosConvert.meters_to_feet(stats.state_accel[AltosLib.ao_flight_boost])),
129 String.format("%5.0f G", AltosConvert.meters_to_g(stats.state_accel[AltosLib.ao_flight_boost])));
131 if (stats.state_speed[AltosLib.ao_flight_drogue] != AltosLib.MISSING)
132 new FlightStat(layout, y++, "Drogue descent rate",
133 String.format("%5.0f m/s", stats.state_speed[AltosLib.ao_flight_drogue]),
134 String.format("%5.0f ft/s", AltosConvert.meters_to_feet(stats.state_speed[AltosLib.ao_flight_drogue])));
135 if (stats.state_speed[AltosLib.ao_flight_main] != AltosLib.MISSING)
136 new FlightStat(layout, y++, "Main descent rate",
137 String.format("%5.0f m/s", stats.state_speed[AltosLib.ao_flight_main]),
138 String.format("%5.0f ft/s", AltosConvert.meters_to_feet(stats.state_speed[AltosLib.ao_flight_main])));
139 if (stats.state_start[AltosLib.ao_flight_boost] < stats.state_end[AltosLib.ao_flight_coast])
140 new FlightStat(layout, y++, "Ascent time",
141 String.format("%6.1f s %s", stats.state_end[AltosLib.ao_flight_boost] - stats.state_start[AltosLib.ao_flight_boost],
142 AltosLib.state_name(AltosLib.ao_flight_boost)),
143 String.format("%6.1f s %s", stats.state_end[AltosLib.ao_flight_fast] - stats.state_start[AltosLib.ao_flight_fast],
144 AltosLib.state_name(AltosLib.ao_flight_fast)),
145 String.format("%6.1f s %s", stats.state_end[AltosLib.ao_flight_coast] - stats.state_start[AltosLib.ao_flight_coast],
146 AltosLib.state_name(AltosLib.ao_flight_coast)));
147 if (stats.state_start[AltosLib.ao_flight_drogue] < stats.state_end[AltosLib.ao_flight_main])
148 new FlightStat(layout, y++, "Descent time",
149 String.format("%6.1f s %s", stats.state_end[AltosLib.ao_flight_drogue] - stats.state_start[AltosLib.ao_flight_drogue],
150 AltosLib.state_name(AltosLib.ao_flight_drogue)),
151 String.format("%6.1f s %s", stats.state_end[AltosLib.ao_flight_main] - stats.state_start[AltosLib.ao_flight_main],
152 AltosLib.state_name(AltosLib.ao_flight_main)));
153 if (stats.state_start[AltosLib.ao_flight_boost] < stats.state_end[AltosLib.ao_flight_main])
154 new FlightStat(layout, y++, "Flight time",
155 String.format("%6.1f s", stats.state_end[AltosLib.ao_flight_main] -
156 stats.state_start[AltosLib.ao_flight_boost]));
158 new FlightStat(layout, y++, "Pad location",
159 pos(stats.pad_lat,"N","S"),
160 pos(stats.pad_lon,"E","W"));
161 new FlightStat(layout, y++, "Last reported location",
162 pos(stats.lat,"N","S"),
163 pos(stats.lon,"E","W"));