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.micropeak;
22 import org.altusmetrum.AltosLib.*;
23 import org.altusmetrum.altosuilib.*;
25 public class MicroStatsTable extends JComponent {
32 public void set_values(String ... values) {
33 for (int j = 0; j < values.length; j++) {
34 texts[j].setText(values[j]);
38 public MicroStat(GridBagLayout layout, int y, String label_text, String ... values) {
39 GridBagConstraints c = new GridBagConstraints();
40 c.insets = new Insets(AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad);
43 label = new JLabel(label_text);
44 label.setFont(AltosUILib.label_font);
45 label.setHorizontalAlignment(SwingConstants.LEFT);
46 c.gridx = 0; c.gridy = y;
47 c.anchor = GridBagConstraints.WEST;
48 c.fill = GridBagConstraints.VERTICAL;
50 layout.setConstraints(label, c);
53 texts = new JTextField[values.length];
54 for (int j = 0; j < values.length; j++) {
55 JTextField value = new JTextField(values[j]);
56 value.setFont(AltosUILib.value_font);
57 value.setHorizontalAlignment(SwingConstants.RIGHT);
59 c.gridx = j+1; c.gridy = y;
60 c.anchor = GridBagConstraints.EAST;
61 c.fill = GridBagConstraints.BOTH;
63 layout.setConstraints(value, c);
69 MicroStat max_height, max_speed;
70 MicroStat max_accel, avg_accel;
71 MicroStat boost_duration;
72 MicroStat coast_duration;
73 MicroStat descent_speed;
74 MicroStat descent_duration;
75 MicroStat flight_time;
77 public void setStats(MicroStats stats) {
78 max_height.set_values(String.format("%5.0f m", stats.apogee_height),
79 String.format("%5.0f ft", AltosConvert.meters_to_feet(stats.apogee_height)));
80 max_speed.set_values(String.format("%5.0f m/s", stats.max_speed),
81 String.format("%5.0f mph", AltosConvert.meters_to_mph(stats.max_speed)),
82 String.format("Mach %4.1f", AltosConvert.meters_to_mach(stats.max_speed)));
83 max_accel.set_values(String.format("%5.0f m/s²", stats.max_accel),
84 String.format("%5.0f ft/s²", AltosConvert.meters_to_feet(stats.max_accel)),
85 String.format("%5.0f G", AltosConvert.meters_to_g(stats.max_accel)));
86 avg_accel.set_values(String.format("%5.0f m/s²", stats.boost_accel(),
87 String.format("%5.0f ft/s²", AltosConvert.meters_to_feet(stats.boost_accel())),
88 String.format("%5.0f G", AltosConvert.meters_to_g(stats.boost_accel()))));
89 boost_duration.set_values(String.format("%6.1f s", stats.boost_duration()));
90 coast_duration.set_values(String.format("%6.1f s", stats.coast_duration()));
91 descent_speed.set_values(String.format("%5.0f m/s", stats.descent_speed()),
92 String.format("%5.0f ft/s", AltosConvert.meters_to_feet(stats.descent_speed())));
93 descent_duration.set_values(String.format("%6.1f s", stats.descent_duration()));
94 flight_time.set_values(String.format("%6.1f s", stats.landed_time));
97 public void setData(MicroData data) {
98 setStats(new MicroStats(data));
101 public MicroStatsTable(MicroStats stats) {
102 layout = new GridBagLayout();
106 max_height = new MicroStat(layout, y++, "Maximum height",
107 String.format("%5.0f m", stats.apogee_height),
108 String.format("%5.0f ft", AltosConvert.meters_to_feet(stats.apogee_height)));
109 max_speed = new MicroStat(layout, y++, "Maximum speed",
110 String.format("%5.0f m/s", stats.max_speed),
111 String.format("%5.0f mph", AltosConvert.meters_to_mph(stats.max_speed)),
112 String.format("Mach %4.1f", AltosConvert.meters_to_mach(stats.max_speed)));
113 max_accel = new MicroStat(layout, y++, "Maximum boost acceleration",
114 String.format("%5.0f m/s²", stats.max_accel),
115 String.format("%5.0f ft/s²", AltosConvert.meters_to_feet(stats.max_accel)),
116 String.format("%5.0f G", AltosConvert.meters_to_g(stats.max_accel)));
117 avg_accel = new MicroStat(layout, y++, "Average boost acceleration",
118 String.format("%5.0f m/s²", stats.boost_accel(),
119 String.format("%5.0f ft/s²", AltosConvert.meters_to_feet(stats.boost_accel())),
120 String.format("%5.0f G", AltosConvert.meters_to_g(stats.boost_accel()))));
121 boost_duration = new MicroStat(layout, y++, "Boost duration",
122 String.format("%6.0f s", stats.boost_duration()));
123 coast_duration = new MicroStat(layout, y++, "Coast duration",
124 String.format("%6.1f s", stats.coast_duration()));
125 descent_speed = new MicroStat(layout, y++, "Descent rate",
126 String.format("%5.0f m/s", stats.descent_speed()),
127 String.format("%5.0f ft/s", AltosConvert.meters_to_feet(stats.descent_speed())));
128 descent_duration = new MicroStat(layout, y++, "Descent duration",
129 String.format("%6.1f s", stats.descent_duration()));
130 flight_time = new MicroStat(layout, y++, "Flight Time",
131 String.format("%6.0f s", stats.landed_time));
134 public MicroStatsTable() {
135 this(new MicroStats());