2 * Copyright © 2014 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.
22 import org.altusmetrum.altoslib_4.*;
23 import org.altusmetrum.altosuilib_2.*;
25 public class AltosIgnitor extends JComponent implements AltosFlightDisplay {
28 public class LaunchStatus implements AltosFontListener, AltosUnitsListener {
33 void show(AltosState state, AltosListenerState listener_state) {}
41 label.setVisible(true);
42 value.setVisible(true);
43 lights.setVisible(true);
51 void show(String format, double value) {
52 show(String.format(format, value));
55 void show(String format, int value) {
56 show(String.format(format, value));
60 label.setVisible(false);
61 value.setVisible(false);
62 lights.setVisible(false);
65 public void dispose() {
69 public void font_size_changed(int font_size) {
70 label.setFont(Altos.label_font);
71 value.setFont(Altos.value_font);
74 public void units_changed(boolean imperial_units) {
77 public void set_label(String text) {
81 public LaunchStatus (GridBagLayout layout, int y, String text) {
82 GridBagConstraints c = new GridBagConstraints();
85 lights = new AltosLights();
86 c.gridx = 0; c.gridy = y;
87 c.anchor = GridBagConstraints.CENTER;
88 c.fill = GridBagConstraints.VERTICAL;
90 layout.setConstraints(lights, c);
93 label = new JLabel(text);
94 label.setFont(Altos.label_font);
95 label.setHorizontalAlignment(SwingConstants.LEFT);
96 c.gridx = 1; c.gridy = y;
97 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
98 c.anchor = GridBagConstraints.WEST;
99 c.fill = GridBagConstraints.VERTICAL;
101 layout.setConstraints(label, c);
104 value = new JTextField(Altos.text_width);
105 value.setFont(Altos.value_font);
106 value.setHorizontalAlignment(SwingConstants.RIGHT);
107 c.gridx = 2; c.gridy = y;
108 c.anchor = GridBagConstraints.WEST;
109 c.fill = GridBagConstraints.BOTH;
111 layout.setConstraints(value, c);
117 class Ignitor extends LaunchStatus {
120 void show (AltosState state, AltosListenerState listener_state) {
121 if (state == null || state.ignitor_voltage[ignitor] == AltosLib.MISSING) {
124 show("%4.2f V", state.ignitor_voltage[ignitor]);
125 lights.set(state.ignitor_voltage[ignitor] >= AltosLib.ao_igniter_good);
129 public Ignitor (GridBagLayout layout, int y) {
130 super(layout, y, String.format ("%s Voltage", AltosLib.ignitor_name(y)));
137 public void reset() {
138 if (ignitors == null)
140 for (int i = 0; i < ignitors.length; i++)
144 public void font_size_changed(int font_size) {
145 if (ignitors == null)
147 for (int i = 0; i < ignitors.length; i++)
148 ignitors[i].font_size_changed(font_size);
151 public void units_changed(boolean imperial_units) {
154 public void show(AltosState state, AltosListenerState listener_state) {
155 make_ignitors(state);
156 if (ignitors == null)
158 for (int i = 0; i < ignitors.length; i++)
159 ignitors[i].show(state, listener_state);
163 public boolean should_show(AltosState state) {
166 if (state.ignitor_voltage == null)
168 return state.ignitor_voltage.length > 0;
171 void make_ignitors(AltosState state) {
172 int n = state == null ? 0 : state.ignitor_voltage.length;
176 if (ignitors == null || ignitors.length != n) {
177 layout = new GridBagLayout();
180 ignitors = new Ignitor[n];
181 for (int i = 0; i < n; i++)
182 ignitors[i] = new Ignitor(layout, i);
185 if (ignitors != null) {
186 for (int i = 0; i < n; i++)
187 ignitors[i].dispose();
194 public String getName() {
198 public AltosIgnitor() {