From c0af53c03d7945f7400496216ee259d73fb04843 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 27 May 2017 23:35:02 -0700 Subject: [PATCH] micropeak: Use altoslib/altosuilib flight analysis bits Remove custom graph and stats bits and share bits with altosui. Signed-off-by: Keith Packard --- micropeak/Makefile.am | 4 - micropeak/MicroData.java | 285 +++++++++++++-------------------- micropeak/MicroDataPoint.java | 83 ---------- micropeak/MicroGraph.java | 54 ------- micropeak/MicroPeak.java | 24 +-- micropeak/MicroRaw.java | 2 +- micropeak/MicroStats.java | 205 ------------------------ micropeak/MicroStatsTable.java | 165 ------------------- 8 files changed, 130 insertions(+), 692 deletions(-) delete mode 100644 micropeak/MicroDataPoint.java delete mode 100644 micropeak/MicroGraph.java delete mode 100644 micropeak/MicroStats.java delete mode 100644 micropeak/MicroStatsTable.java diff --git a/micropeak/Makefile.am b/micropeak/Makefile.am index 7ad2c102..52b62358 100644 --- a/micropeak/Makefile.am +++ b/micropeak/Makefile.am @@ -14,18 +14,14 @@ micropeakdir=$(datadir)/java micropeak_JAVA= \ MicroPeak.java \ MicroData.java \ - MicroDataPoint.java \ MicroDownload.java \ MicroExport.java \ MicroFile.java \ MicroFrame.java \ - MicroGraph.java \ MicroRaw.java \ MicroSave.java \ MicroSerial.java \ MicroSerialLog.java \ - MicroStats.java \ - MicroStatsTable.java \ MicroFileChooser.java \ MicroDeviceDialog.java \ MicroUSB.java diff --git a/micropeak/MicroData.java b/micropeak/MicroData.java index d502b9f7..09555b8b 100644 --- a/micropeak/MicroData.java +++ b/micropeak/MicroData.java @@ -24,83 +24,18 @@ import java.util.*; import org.altusmetrum.altoslib_11.*; import org.altusmetrum.altosuilib_11.*; -class MicroIterator implements Iterator { - int i; - MicroData data; - - public boolean hasNext() { - return i < data.pressures.length; - } - - public MicroDataPoint next() { - return new MicroDataPoint(data, i++); - } - - public MicroIterator (MicroData data) { - this.data = data; - i = 0; - } - - public void remove() { - } -} - -class MicroIterable implements Iterable { - - MicroData data; - - public Iterator iterator() { - return new MicroIterator(data); - } - - public MicroIterable(MicroData data) { - this.data = data; - } -} - -class MicroUIIterator implements Iterator { - int i; - MicroData data; - - public boolean hasNext() { - return i < data.pressures.length; - } - - public AltosUIDataPoint next() { - return new MicroDataPoint(data, i++); - } - - public MicroUIIterator (MicroData data) { - this.data = data; - i = 0; - } - - public void remove() { - } -} - -class MicroUIIterable implements Iterable { - MicroData data; - - public Iterator iterator() { - return new MicroUIIterator(data); - } - - public MicroUIIterable(MicroData data) { - this.data = data; - } -} - -public class MicroData implements AltosUIDataSet { +public class MicroData { public int ground_pressure; public int min_pressure; - public int[] pressures; + + AltosUIFlightSeries flight_series; + AltosFlightStats flight_stats; + AltosCalData cal_data; + private double time_step; - private double ground_altitude; private ArrayList bytes; public int log_id; String name; - MicroStats stats; public static final int LOG_ID_MICROPEAK = 0; public static final int LOG_ID_MICROKITE = 1; @@ -213,69 +148,45 @@ public class MicroData implements AltosUIDataSet { return Math.abs (target - a) < Math.abs(target - b); } + public double altitude(double time) { + if (flight_series.altitude_series == null) + return 0.0; + return flight_series.altitude_series.value(time); + } + public double altitude(int i) { - return AltosConvert.pressure_to_altitude(pressures[i]); + return altitude(time(i)); } public String name() { return name; } - public Iterable dataPoints() { - return new MicroUIIterable(this); - } - - public Iterable points() { - return new MicroIterable(this); - } - - int fact(int n) { - if (n == 0) - return 1; - return n * fact(n-1); - } + public double pressure(int i) { + if (flight_series.pressure_series == null) + return 0.0; - int choose(int n, int k) { - return fact(n) / (fact(k) * fact(n-k)); + return flight_series.pressure_series.value(time(i)); } + public double height(double time) { + if (flight_series.height_series == null) + return 0.0; - public double avg_altitude(int center, int dist) { - int start = center - dist; - int stop = center + dist; - - if (start < 0) - start = 0; - if (stop >= pressures.length) - stop = pressures.length - 1; - - double sum = 0; - double div = 0; - - int n = dist * 2; - - for (int i = start; i <= stop; i++) { - int k = i - (center - dist); - int c = choose (n, k); - - sum += c * pressures[i]; - div += c; - } - - double pres = sum / div; - - double alt = AltosConvert.pressure_to_altitude(pres); - return alt; + return flight_series.height_series.value(time); } - public double pressure(int i) { - return pressures[i]; + public double height(int i) { + return height(time(i)); } - public double height(int i) { - return altitude(i) - ground_altitude; + public int length() { + if (flight_series.pressure_series == null) + return 0; + return flight_series.pressure_series.size(); } + /* Use the recorded apogee pressure for stats so that it agrees with the device */ public double apogee_pressure() { return min_pressure; } @@ -285,31 +196,27 @@ public class MicroData implements AltosUIDataSet { } public double apogee_height() { - return apogee_altitude() - ground_altitude; + return apogee_altitude() - cal_data.ground_altitude; } - static final int speed_avg = 3; - static final int accel_avg = 5; - - private double avg_speed(int center, int dist) { - if (center == 0) - return 0; - - double ai = avg_altitude(center, dist); - double aj = avg_altitude(center - 1, dist); - double s = (ai - aj) / time_step; - - return s; + public double speed(double time) { + if (flight_series.speed_series == null) + return 0.0; + return flight_series.speed_series.value(time); } public double speed(int i) { - return avg_speed(i, speed_avg); + return speed(time(i)); + } + + public double acceleration(double time) { + if (flight_series.accel_series == null) + return 0.0; + return flight_series.accel_series.value(time); } public double acceleration(int i) { - if (i == 0) - return 0; - return (avg_speed(i, accel_avg) - avg_speed(i-1, accel_avg)) / time_step; + return acceleration(time(i)); } public double time(int i) { @@ -325,18 +232,24 @@ public class MicroData implements AltosUIDataSet { public void export (Writer f) throws IOException { PrintWriter pw = new PrintWriter(f); pw.printf(" Time, Press(Pa), Height(m), Height(f), Speed(m/s), Speed(mph), Speed(mach), Accel(m/s²), Accel(ft/s²), Accel(g)\n"); - for (MicroDataPoint point : points()) { + + for (AltosTimeValue ptv : flight_series.pressure_series) { + + double height = height(ptv.time); + double speed = speed(ptv.time); + double accel = acceleration(ptv.time); + pw.printf("%6.3f,%10.0f,%10.1f,%10.1f,%11.2f,%11.2f,%12.4f,%12.2f,%13.2f,%10.4f\n", - point.time, - point.pressure, - point.height, - AltosConvert.meters_to_feet(point.height), - point.speed, - AltosConvert.meters_to_mph(point.speed), - AltosConvert.meters_to_mach(point.speed), - point.accel, - AltosConvert.meters_to_feet(point.accel), - AltosConvert.meters_to_g(point.accel)); + ptv.time, + ptv.value, + height, + AltosConvert.meters_to_feet(height), + speed, + AltosConvert.meters_to_mph(speed), + AltosConvert.meters_to_mach(speed), + accel, + AltosConvert.meters_to_feet(accel), + AltosConvert.meters_to_g(accel)); } } @@ -344,9 +257,20 @@ public class MicroData implements AltosUIDataSet { this.name = name; } + public MicroData() { + ground_pressure = 101000; + min_pressure = 101000; + cal_data = new AltosCalData(); + flight_series = new AltosUIFlightSeries(cal_data); + } + public MicroData (InputStream f, String name) throws IOException, InterruptedException, NonHexcharException, FileEndedException { this.name = name; bytes = new ArrayList(); + + cal_data = new AltosCalData(); + flight_series = new AltosUIFlightSeries(cal_data); + if (!find_header(f)) throw new IOException("No MicroPeak data header found"); try { @@ -357,11 +281,30 @@ public class MicroData implements AltosUIDataSet { log_id = nsamples >> 12; nsamples &= 0xfff; - pressures = new int[nsamples + 1]; - ground_altitude = AltosConvert.pressure_to_altitude(ground_pressure); + cal_data.set_ground_pressure(ground_pressure); + + switch (log_id) { + case LOG_ID_MICROPEAK: + time_step = 2 * CLOCK_MP1; + break; + case LOG_ID_MICROKITE: + time_step = 200 * CLOCK_MP1; + break; + case LOG_ID_MICROPEAK2: + time_step = CLOCK_MP2; + break; + default: + throw new IOException(String.format("Unknown device type: %d", log_id)); + } + cal_data.set_ticks_per_sec(1/time_step); + cal_data.set_tick(0); + cal_data.set_boost_tick(); + int cur = ground_pressure; - pressures[0] = cur; + cal_data.set_tick(0); + flight_series.set_time(cal_data.time()); + flight_series.set_pressure(cur); for (int i = 0; i < nsamples; i++) { int k = get_16(f); int same = mix_in(cur, k); @@ -380,38 +323,40 @@ public class MicroData implements AltosUIDataSet { cur = down; } - pressures[i+1] = cur; + cal_data.set_tick(i+1); + flight_series.set_time(cal_data.time()); + flight_series.set_pressure(cur); } + flight_series.finish(); + + /* Build states */ + + flight_series.set_time(0); + flight_series.set_state(AltosLib.ao_flight_boost); + + flight_series.set_time(flight_series.speed_series.max().time); + flight_series.set_state(AltosLib.ao_flight_coast); + + flight_series.set_time(flight_series.height_series.max().time); + flight_series.set_state(AltosLib.ao_flight_drogue); + + cal_data.set_tick(nsamples); + flight_series.set_time(cal_data.time()); + flight_series.set_state(AltosLib.ao_flight_landed); + + flight_series.finish(); + + flight_stats = new AltosFlightStats(flight_series); + int current_crc = swap16(~file_crc & 0xffff); int crc = get_16(f); crc_valid = crc == current_crc; - switch (log_id) { - case LOG_ID_MICROPEAK: - time_step = 2 * CLOCK_MP1; - break; - case LOG_ID_MICROKITE: - time_step = 200 * CLOCK_MP1; - break; - case LOG_ID_MICROPEAK2: - time_step = CLOCK_MP2; - break; - default: - throw new IOException(String.format("Unknown device type: %d", log_id)); - } - stats = new MicroStats(this); } catch (FileEndedException fe) { throw new IOException("File Ended Unexpectedly"); } } - public MicroData() { - ground_pressure = 101000; - min_pressure = 101000; - pressures = new int[1]; - pressures[0] = 101000; - } - } diff --git a/micropeak/MicroDataPoint.java b/micropeak/MicroDataPoint.java deleted file mode 100644 index 42079291..00000000 --- a/micropeak/MicroDataPoint.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright © 2012 Keith Packard - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - -package org.altusmetrum.micropeak; - -import org.altusmetrum.altosuilib_11.*; - -public class MicroDataPoint implements AltosUIDataPoint { - public double time; - public double pressure; - public double height; - public double speed; - public double accel; - public MicroStats stats; - - public static final int data_height = 0; - public static final int data_speed = 1; - public static final int data_accel = 2; - public static final int data_state = 3; - - public double x() { - return time; - } - - public double y(int index) { - switch (index) { - case data_height: - return height; - case data_speed: - return speed; - case data_accel: - return accel; - default: - return 0; - } - } - - public int id(int index) { - if (index == data_state) { - return stats.state(time); - } - return 0; - } - - public String id_name(int index) { - if (index == data_state) - return stats.state_name(time); - return ""; - } - - public MicroDataPoint (double pressure, double height, double speed, double accel, double time, MicroStats stats) { - this.pressure = pressure; - this.height = height; - this.speed = speed; - this.accel = accel; - this.time = time; - this.stats = stats; - } - - public MicroDataPoint(MicroData data, int i) { - this(data.pressure(i), - data.height(i), - data.speed(i), - data.acceleration(i), - data.time(i), - data.stats); - } -} \ No newline at end of file diff --git a/micropeak/MicroGraph.java b/micropeak/MicroGraph.java deleted file mode 100644 index 64a43bd8..00000000 --- a/micropeak/MicroGraph.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright © 2012 Keith Packard - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - -package org.altusmetrum.micropeak; - -import java.io.*; -import java.util.ArrayList; - -import java.awt.*; -import javax.swing.*; -import org.altusmetrum.altoslib_11.*; -import org.altusmetrum.altosuilib_11.*; - -import org.jfree.ui.*; -import org.jfree.chart.*; -import org.jfree.chart.plot.*; -import org.jfree.chart.axis.*; -import org.jfree.chart.renderer.*; -import org.jfree.chart.renderer.xy.*; -import org.jfree.chart.labels.*; -import org.jfree.data.xy.*; -import org.jfree.data.*; - -public class MicroGraph extends AltosUIGraph { - - static final private Color height_color = new Color(194,31,31); - static final private Color speed_color = new Color(31,194,31); - static final private Color accel_color = new Color(31,31,194); - static final private Color state_color = new Color(3,3,3); - - public MicroGraph(AltosUIEnable enable) { - super(enable); - - addSeries("Height", MicroDataPoint.data_height, AltosConvert.height, height_color); - addSeries("Speed", MicroDataPoint.data_speed, AltosConvert.speed, speed_color); - addSeries("Acceleration", MicroDataPoint.data_accel, AltosConvert.accel, accel_color); - addMarker("State", MicroDataPoint.data_state, state_color); - } -} \ No newline at end of file diff --git a/micropeak/MicroPeak.java b/micropeak/MicroPeak.java index 9023f452..4ca4dd0f 100644 --- a/micropeak/MicroPeak.java +++ b/micropeak/MicroPeak.java @@ -30,12 +30,11 @@ import org.altusmetrum.altosuilib_11.*; public class MicroPeak extends MicroFrame implements ActionListener, ItemListener { File filename; - MicroGraph graph; + AltosGraphNew graph; AltosUIEnable enable; - MicroStatsTable statsTable; + AltosFlightStatsTable statsTable; MicroRaw raw; MicroData data; - MicroStats stats; Container container; JTabbedPane pane; static int number_of_windows; @@ -47,9 +46,12 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene return mp.SetData(data); } this.data = data; - stats = new MicroStats(data); - graph.setDataSet(data); - statsTable.setStats(stats); + if (data.flight_series == null) + System.out.printf("no data in flight\n"); + if (data.flight_stats == null) + System.out.printf("no stats in flight\n"); + graph.set_data(data.flight_stats, data.flight_series); + statsTable.set_stats(data.flight_stats); raw.setData(data); setTitle(data.name); return this; @@ -265,8 +267,9 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene }); enable = new AltosUIEnable(); - graph = new MicroGraph(enable); - statsTable = new MicroStatsTable(); + + graph = new AltosGraphNew(enable); + statsTable = new AltosFlightStatsTable(); raw = new MicroRaw(); pane.add(graph.panel, "Graph"); pane.add(enable, "Configure Graph"); @@ -324,8 +327,9 @@ public class MicroPeak extends MicroFrame implements ActionListener, ItemListene CommandExport(file); opened = true; } catch (Exception e) { - System.err.printf("Error processing \"%s\": %s\n", - file.getName(), e.getMessage()); + System.err.printf("Error processing \"%s\": %s %s\n", + file.getName(), e.toString(), e.getMessage()); + e.printStackTrace(); } } } diff --git a/micropeak/MicroRaw.java b/micropeak/MicroRaw.java index f00d7ea3..5ff4f6b5 100644 --- a/micropeak/MicroRaw.java +++ b/micropeak/MicroRaw.java @@ -30,7 +30,7 @@ public class MicroRaw extends JTextArea { StringWriter sw = new StringWriter(); try { data.export(sw); - setRows(data.pressures.length + 1); + setRows(data.length()); setText(sw.toString()); } catch (IOException ie) { setText(String.format("Error writing data: %s", ie.getMessage())); diff --git a/micropeak/MicroStats.java b/micropeak/MicroStats.java deleted file mode 100644 index b9637536..00000000 --- a/micropeak/MicroStats.java +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright © 2011 Keith Packard - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - -package org.altusmetrum.micropeak; - -import java.io.*; -import org.altusmetrum.altoslib_11.*; -import org.altusmetrum.altosuilib_11.*; - -public class MicroStats { - double coast_height; - double coast_time; - - double apogee_height; - double apogee_time; - - double landed_height; - double landed_time; - - double max_speed; - double max_accel; - - MicroData data; - - void find_landing() { - landed_height = 0; - - for (MicroDataPoint point : data.points()) { - landed_height = point.height; - landed_time = point.time; - } - - boolean above = false; - for (MicroDataPoint point : data.points()) { - if (point.height > landed_height + 10) { - above = true; - } else { - if (above && point.height < landed_height + 2) { - above = false; - landed_time = point.time; - } - } - } - } - - void find_apogee() { - apogee_height = data.apogee_height(); - double searched_apogee = 0; - apogee_time = 0; - - /* This just finds the apogee time -- we've recorded the - * peak altitude separately in eeprom, and that could - * have occurred after the eeprom was full. - */ - for (MicroDataPoint point : data.points()) { - if (point.height > searched_apogee) { - searched_apogee = point.height; - apogee_time = point.time; - } - } - } - - void find_coast() { - coast_height = 0; - coast_time = 0; - - for (MicroDataPoint point : data.points()) { - if (point.accel < -9.8) - break; - coast_time = point.time; - coast_height = point.height; - } - } - - void find_max_speed() { - max_speed = 0; - for (MicroDataPoint point : data.points()) { - if (point.time > apogee_time) - break; - if (point.speed > max_speed) - max_speed = point.speed; - } - } - - void find_max_accel() { - max_accel = 0; - for (MicroDataPoint point : data.points()) { - if (point.time > apogee_time) - break; - if (point.accel > max_accel) - max_accel = point.accel; - } - } - - double boost_duration() { - return coast_time; - } - - double boost_height() { - return coast_height; - } - - double boost_speed() { - return coast_height / coast_time; - } - - double boost_accel() { - return boost_speed() / boost_duration(); - } - - double coast_duration() { - return apogee_time - coast_time; - } - - double coast_height() { - return apogee_height - coast_height; - } - - double coast_speed() { - return coast_height() / coast_duration(); - } - - double coast_accel() { - return coast_speed() / coast_duration(); - } - - double descent_duration() { - return landed_time - apogee_time; - } - - double descent_height() { - return apogee_height - landed_height; - } - - double descent_speed() { - return descent_height() / descent_duration(); - } - - public static final int state_startup = -1; - public static final int state_pad = 0; - public static final int state_boost = 1; - public static final int state_coast = 2; - public static final int state_descent = 3; - public static final int state_landed = 4; - - static final String state_names[] = { - "pad", - "boost", - "coast", - "descent", - "landed" - }; - - public int state(double t) { - if (t >= landed_time) - return state_landed; - if (t >= apogee_time) - return state_descent; - if (t >= coast_time) - return state_coast; - if (t >= 0) - return state_boost; - return state_pad; - } - - public static String state_name(int state) { - if (state < 0 || state > state_landed) - return "unknown"; - return state_names[state]; - } - - public String state_name(double t) { - return state_name(state(t)); - } - - public MicroStats(MicroData data) { - - this.data = data; - - find_coast(); - find_apogee(); - find_landing(); - find_max_speed(); - find_max_accel(); - } - - public MicroStats() { - this(new MicroData()); - } -} diff --git a/micropeak/MicroStatsTable.java b/micropeak/MicroStatsTable.java deleted file mode 100644 index e095e3a4..00000000 --- a/micropeak/MicroStatsTable.java +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright © 2011 Keith Packard - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. - */ - -package org.altusmetrum.micropeak; - -import java.awt.*; -import javax.swing.*; -import org.altusmetrum.altoslib_11.*; -import org.altusmetrum.altosuilib_11.*; - -public class MicroStatsTable extends JComponent implements AltosFontListener { - GridBagLayout layout; - - class MicroStat { - JLabel label; - JTextField[] texts; - - public void set_values(String ... values) { - for (int j = 0; j < values.length; j++) { - texts[j].setText(values[j]); - } - } - - public void set_font() { - for (int j = 0; j < texts.length; j++) - texts[j].setFont(AltosUILib.value_font); - label.setFont(AltosUILib.label_font); - } - - public MicroStat(GridBagLayout layout, int y, String label_text, String ... values) { - GridBagConstraints c = new GridBagConstraints(); - c.insets = new Insets(AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad); - c.weighty = 1; - - label = new JLabel(label_text); - label.setFont(AltosUILib.label_font); - label.setHorizontalAlignment(SwingConstants.LEFT); - c.gridx = 0; c.gridy = y; - c.anchor = GridBagConstraints.WEST; - c.fill = GridBagConstraints.VERTICAL; - c.weightx = 0; - layout.setConstraints(label, c); - add(label); - - texts = new JTextField[values.length]; - for (int j = 0; j < values.length; j++) { - JTextField value = new JTextField(values[j]); - value.setEditable(false); - value.setFont(AltosUILib.value_font); - value.setHorizontalAlignment(SwingConstants.RIGHT); - texts[j] = value; - c.gridx = j+1; c.gridy = y; - c.anchor = GridBagConstraints.EAST; - c.fill = GridBagConstraints.BOTH; - c.weightx = 1; - layout.setConstraints(value, c); - add(value); - } - } - } - - MicroStat max_height, max_speed; - MicroStat max_accel, avg_accel; - MicroStat boost_duration; - MicroStat coast_duration; - MicroStat descent_speed; - MicroStat descent_duration; - MicroStat flight_time; - - public void setStats(MicroStats stats) { - max_height.set_values(String.format("%7.1f m", stats.apogee_height), - String.format("%7.1f ft", AltosConvert.meters_to_feet(stats.apogee_height))); - max_speed.set_values(String.format("%7.1f m/s", stats.max_speed), - String.format("%7.1f mph", AltosConvert.meters_to_mph(stats.max_speed)), - String.format("Mach %7.3f", AltosConvert.meters_to_mach(stats.max_speed))); - max_accel.set_values(String.format("%7.1f m/s²", stats.max_accel), - String.format("%7.1f ft/s²", AltosConvert.meters_to_feet(stats.max_accel)), - String.format("%7.3f G", AltosConvert.meters_to_g(stats.max_accel))); - avg_accel.set_values(String.format("%7.1f m/s²", stats.boost_accel(), - String.format("%7.1f ft/s²", AltosConvert.meters_to_feet(stats.boost_accel())), - String.format("%7.3f G", AltosConvert.meters_to_g(stats.boost_accel())))); - boost_duration.set_values(String.format("%6.1f s", stats.boost_duration())); - coast_duration.set_values(String.format("%6.1f s", stats.coast_duration())); - descent_speed.set_values(String.format("%7.1f m/s", stats.descent_speed()), - String.format("%7.1f ft/s", AltosConvert.meters_to_feet(stats.descent_speed()))); - descent_duration.set_values(String.format("%6.1f s", stats.descent_duration())); - flight_time.set_values(String.format("%6.1f s", stats.landed_time)); - } - - public void set_font() { - max_height.set_font(); - max_speed.set_font(); - max_accel.set_font(); - avg_accel.set_font(); - boost_duration.set_font(); - coast_duration.set_font(); - descent_speed.set_font(); - descent_duration.set_font(); - flight_time.set_font(); - } - - public void font_size_changed(int font_size) { - set_font(); - } - - public MicroStatsTable(MicroStats stats) { - layout = new GridBagLayout(); - - setLayout(layout); - int y = 0; - max_height = new MicroStat(layout, y++, "Maximum height", - String.format("%7.1f m", stats.apogee_height), - String.format("%7.1f ft", AltosConvert.meters_to_feet(stats.apogee_height))); - max_speed = new MicroStat(layout, y++, "Maximum speed", - String.format("%7.1f m/s", stats.max_speed), - String.format("%7.1f mph", AltosConvert.meters_to_mph(stats.max_speed)), - String.format("Mach %4.1f", AltosConvert.meters_to_mach(stats.max_speed))); - max_accel = new MicroStat(layout, y++, "Maximum boost acceleration", - String.format("%7.1f m/s²", stats.max_accel), - String.format("%7.1f ft/s²", AltosConvert.meters_to_feet(stats.max_accel)), - String.format("%7.3f G", AltosConvert.meters_to_g(stats.max_accel))); - avg_accel = new MicroStat(layout, y++, "Average boost acceleration", - String.format("%7.1f m/s²", stats.boost_accel(), - String.format("%7.1f ft/s²", AltosConvert.meters_to_feet(stats.boost_accel())), - String.format("%7.3f G", AltosConvert.meters_to_g(stats.boost_accel())))); - boost_duration = new MicroStat(layout, y++, "Boost duration", - String.format("%6.1f s", stats.boost_duration())); - coast_duration = new MicroStat(layout, y++, "Coast duration", - String.format("%6.1f s", stats.coast_duration())); - descent_speed = new MicroStat(layout, y++, "Descent rate", - String.format("%7.1f m/s", stats.descent_speed()), - String.format("%7.1f ft/s", AltosConvert.meters_to_feet(stats.descent_speed()))); - descent_duration = new MicroStat(layout, y++, "Descent duration", - String.format("%6.1f s", stats.descent_duration())); - flight_time = new MicroStat(layout, y++, "Flight Time", - String.format("%6.1f s", stats.landed_time)); - set_font(); - - AltosUIPreferences.register_font_listener(this); - } - - public void tell_closing() { - AltosUIPreferences.unregister_font_listener(this); - } - - public MicroStatsTable() { - this(new MicroStats()); - } - -} -- 2.30.2