2 * Copyright © 2024 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; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
19 package org.altusmetrum.altosuilib_14;
24 import org.altusmetrum.altoslib_14.*;
26 public class AltosFlightConfigTable extends JComponent
27 implements AltosFontListener, AltosUnitsListener
31 FlightConfig[] flight_configs;
32 AltosConfigData config_data;
34 class FlightConfig implements AltosFontListener {
38 public void font_size_changed(int font_size) {
39 label.setFont(AltosUILib.label_font);
40 for (int i = 0; i < value.length; i++)
41 value[i].setFont(AltosUILib.value_font);
44 public void set(String l, String[] values) {
46 for (int j = 0; j < values.length; j++)
47 value[j].setText(values[j]);
50 public FlightConfig(GridBagLayout layout, int y, String label_text, String ... values) {
51 GridBagConstraints c = new GridBagConstraints();
52 c.insets = new Insets(AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad);
55 label = new JLabel(label_text);
56 label.setFont(AltosUILib.label_font);
57 label.setHorizontalAlignment(SwingConstants.LEFT);
58 c.gridx = 0; c.gridy = y;
59 c.anchor = GridBagConstraints.WEST;
60 c.fill = GridBagConstraints.VERTICAL;
62 layout.setConstraints(label, c);
65 value = new JLabel[values.length];
66 for (int j = 0; j < values.length; j++) {
67 value[j] = new JLabel(values[j]);
68 value[j].setFont(AltosUILib.value_font);
69 c.gridx = j+1; c.gridy = y;
70 c.anchor = GridBagConstraints.CENTER;
71 c.fill = GridBagConstraints.BOTH;
73 layout.setConstraints(value[j], c);
76 flight_configs[y] = this;
81 private FlightConfig set_config(int y, String label, String ... values) {
82 if (flight_configs[y] == null)
83 flight_configs[y] = new FlightConfig(layout, y, label, values);
85 flight_configs[y].set(label, values);
86 return flight_configs[y];
89 public void font_size_changed(int font_size) {
90 for (int y = 0; flight_configs[y] != null; y++)
91 flight_configs[y].font_size_changed(font_size);
94 private String main_deploy_label() {
95 return String.format("Main Deploy Altitude(%s)", AltosConvert.height.parse_units());
98 private String main_deploy_value() {
99 return String.format("%-6.1f", AltosConvert.height.value(config_data.main_deploy, AltosConvert.imperial_units));
102 public void set_config() {
104 if (config_data.serial != AltosLib.MISSING) {
105 if (config_data.product != null && config_data.version != null)
106 set_config(y++, "Device",
108 String.format("version %s", config_data.version),
109 String.format("serial %d", config_data.serial));
111 set_config(y++, "Serial", String.format("%d", config_data.serial));
113 if (config_data.flight != AltosLib.MISSING)
114 set_config(y++, "Flight", String.format("%d", config_data.flight));
115 if (config_data.main_deploy != AltosLib.MISSING)
116 set_config(y++, main_deploy_label(), main_deploy_value());
117 if (config_data.apogee_delay != AltosLib.MISSING)
118 set_config(y++, "Apogee Delay(s)", String.format("%d", config_data.apogee_delay));
119 if (config_data.apogee_lockout != AltosLib.MISSING)
120 set_config(y++, "Apogee Lockout(s)", String.format("%d", config_data.apogee_lockout));
121 if (config_data.radio_frequency != AltosLib.MISSING)
122 set_config(y++, "Radio Frequency (MHz)", String.format("%-7.3f", config_data.radio_frequency / 1000.0));
123 if (config_data.radio_calibration != AltosLib.MISSING)
124 set_config(y++, "Radio Calibration", String.format("%d", config_data.radio_calibration));
125 if (config_data.radio_enable != AltosLib.MISSING)
126 set_config(y++, "Radio Enable", String.format("%b", config_data.radio_enable != 0));
127 if (config_data.radio_10mw != AltosLib.MISSING)
128 set_config(y++, "Limit transmit to 10mW", String.format("%b", config_data.radio_10mw != 0));
129 if (config_data.report_feet != AltosLib.MISSING)
130 set_config(y++, "Beep max height in", config_data.report_feet == 0 ? "Meters" : "Feet");
131 if (config_data.gps_receiver != AltosLib.MISSING)
132 set_config(y++, "GPS Receiver", AltosLib.gps_receiver_names[config_data.gps_receiver]);
133 if (config_data.telemetry_rate != AltosLib.MISSING)
134 set_config(y++, "Telemetry baud rate", String.format("%d", AltosLib.ao_telemetry_rate_values[config_data.telemetry_rate]));
135 if (config_data.aprs_interval != AltosLib.MISSING)
136 set_config(y++, "APRS Interval(s)", String.format("%d", config_data.aprs_interval));
137 if (config_data.aprs_ssid != AltosLib.MISSING)
138 set_config(y++, "APRS SSID", String.format("%d", config_data.aprs_ssid));
139 if (config_data.aprs_format != AltosLib.MISSING)
140 set_config(y++, "APRS Format", AltosLib.ao_aprs_format_name[config_data.aprs_format]);
141 if (config_data.callsign != null)
142 set_config(y++, "Callsign", config_data.callsign);
143 if (config_data.flight_log_max != AltosLib.MISSING)
144 set_config(y++, "Maximum Flight Log Size(kB)", String.format("%d", config_data.flight_log_max));
145 if (config_data.ignite_mode != AltosLib.MISSING)
146 set_config(y++, "Igniter Firing Mode", AltosLib.ignite_mode_values[config_data.ignite_mode]);
147 if (config_data.pad_orientation != AltosLib.MISSING)
148 set_config(y++, "Pad Orientation", AltosLib.pad_orientation_values(config_data.has_radio())[config_data.pad_orientation]);
149 if (config_data.accel_cal_plus != AltosLib.MISSING)
150 set_config(y++, "Accel Calibration",
151 String.format("Plus %d", config_data.accel_cal_plus),
152 String.format("Minus %d", config_data.accel_cal_minus));
153 if (config_data.beep != AltosLib.MISSING)
154 set_config(y++, "Beeper(Hz)",
155 config_data.beep == 0 ? "Disabled" :
156 String.format("%-7.1f", AltosConvert.beep_value_to_freq(config_data.beep)));
157 if (config_data.tracker_motion != AltosLib.MISSING)
159 String.format("Logging Trigger Motion (%s):", AltosConvert.height.parse_units()),
160 String.format("%-6.1f",
161 AltosConvert.height.value(config_data.tracker_motion, AltosConvert.imperial_units)));
162 if (config_data.tracker_interval != AltosLib.MISSING)
163 set_config(y++, "Position Reporting Interval(s)",
164 String.format("%d", config_data.tracker_interval));
167 public void units_changed(boolean imperial_units) {
171 public void tell_closing() {
172 AltosUIPreferences.unregister_font_listener(this);
175 public AltosFlightConfigTable() {
176 layout = new GridBagLayout();
180 AltosUIPreferences.register_font_listener(this);
183 public AltosFlightConfigTable(AltosConfigData config_data) {
185 this.config_data = config_data;
186 flight_configs = new FlightConfig[30];