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 AltosFlightPyroTable extends JComponent
27 implements AltosFontListener, AltosUnitsListener
32 FlightPyro[] flight_pyros;
34 class FlightPyro implements AltosFontListener {
36 JTextField[] text_fields;
38 public void font_size_changed(int font_size) {
39 label.setFont(AltosUILib.label_font);
40 for (int i = 0; i < text_fields.length; i++)
41 text_fields[i].setFont(AltosUILib.value_font);
44 public void set_value(int y, int p, String value) {
45 GridBagConstraints c = new GridBagConstraints();
46 c.insets = new Insets(AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad);
48 JTextField text_field;
50 if (text_fields[p] == null) {
51 text_field = new JTextField(value);
52 text_field.setEditable(false);
53 text_field.setFont(AltosUILib.value_font);
54 text_field.setHorizontalAlignment(SwingConstants.RIGHT);
55 c.gridx = p+1; c.gridy = y;
56 c.anchor = GridBagConstraints.EAST;
57 c.fill = GridBagConstraints.BOTH;
59 layout.setConstraints(text_field, c);
61 text_fields[p] = text_field;
63 text_fields[p].setText(value);
67 public void set_label(String text) {
71 public FlightPyro(GridBagLayout layout, int y, String label_text, int npyro) {
72 GridBagConstraints c = new GridBagConstraints();
73 c.insets = new Insets(AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad, AltosUILib.tab_elt_pad);
76 if (label_text != null) {
77 label = new JLabel(label_text);
78 label.setFont(AltosUILib.label_font);
79 label.setHorizontalAlignment(SwingConstants.LEFT);
80 c.gridx = 0; c.gridy = y;
81 c.anchor = GridBagConstraints.WEST;
82 c.fill = GridBagConstraints.VERTICAL;
84 layout.setConstraints(label, c);
88 text_fields = new JTextField[npyro];
92 public void font_size_changed(int font_size) {
93 for (int i = 0; i < flight_pyros.length; i++)
94 flight_pyros[i].font_size_changed(font_size);
97 public void set_pyros() {
99 for (int flag = 1; flag < AltosPyro.pyro_all; flag <<= 1) {
100 if ((AltosPyro.pyro_all_useful & flag) != 0) {
101 for (int p = 0; p < npyro; p++) {
102 if ((pyros[p].flags & flag) != 0) {
104 double value = pyros[p].get_value(flag);
105 if ((flag & AltosPyro.pyro_state_value) != 0) {
106 text = AltosLib.state_name_capital((int) value);
108 double scale = AltosPyro.pyro_to_scale(flag);
109 double unit_value = value;
110 AltosUnits units = AltosPyro.pyro_to_units(flag);
112 unit_value = units.parse_value(value);
116 else if (scale >= 10)
120 text = String.format(format, unit_value);
122 flight_pyros[nrow].set_value(nrow, p, text);
130 public void units_changed(boolean imperial_units) {
131 System.out.printf("units changed\n");
133 for (int flag = 1; flag < AltosPyro.pyro_all; flag <<= 1) {
134 if ((AltosPyro.pyro_all_useful & flag) != 0) {
135 String name = AltosPyro.pyro_to_name(flag);
136 flight_pyros[nrow].set_label(name);
142 public void tell_closing() {
143 AltosUIPreferences.unregister_font_listener(this);
146 public AltosFlightPyroTable(AltosPyro[] pyros, int npyro) {
147 layout = new GridBagLayout();
151 for (int flag = 1; flag < AltosPyro.pyro_all; flag <<= 1) {
152 if ((AltosPyro.pyro_all_useful & flag) != 0) {
157 flight_pyros = new FlightPyro[nrow + 1];
161 flight_pyros[0] = new FlightPyro(layout, 0, null, npyro);
163 for (int p = 0; p < npyro; p++) {
164 flight_pyros[0].set_value(0, p, String.format("Channel %c", 'A' + p));
167 for (int flag = 1; flag < AltosPyro.pyro_all; flag <<= 1) {
168 if ((AltosPyro.pyro_all_useful & flag) != 0) {
169 String name = AltosPyro.pyro_to_name(flag);
170 flight_pyros[nrow] = new FlightPyro(layout, nrow, name, npyro);
182 AltosUIPreferences.register_font_listener(this);