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_3.*;
24 public class AltosIgnitor extends JComponent implements AltosFlightDisplay {
27 public class LaunchStatus {
32 void show(AltosState state, AltosListenerState listener_state) {}
40 label.setVisible(true);
41 value.setVisible(true);
42 lights.setVisible(true);
50 void show(String format, double value) {
51 show(String.format(format, value));
54 void show(String format, int value) {
55 show(String.format(format, value));
59 label.setVisible(false);
60 value.setVisible(false);
61 lights.setVisible(false);
64 public void dispose() {
68 public void set_font() {
69 label.setFont(Altos.label_font);
70 value.setFont(Altos.value_font);
73 public void set_label(String text) {
77 public LaunchStatus (GridBagLayout layout, int y, String text) {
78 GridBagConstraints c = new GridBagConstraints();
81 lights = new AltosLights();
82 c.gridx = 0; c.gridy = y;
83 c.anchor = GridBagConstraints.CENTER;
84 c.fill = GridBagConstraints.VERTICAL;
86 layout.setConstraints(lights, c);
89 label = new JLabel(text);
90 label.setFont(Altos.label_font);
91 label.setHorizontalAlignment(SwingConstants.LEFT);
92 c.gridx = 1; c.gridy = y;
93 c.insets = new Insets(Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad, Altos.tab_elt_pad);
94 c.anchor = GridBagConstraints.WEST;
95 c.fill = GridBagConstraints.VERTICAL;
97 layout.setConstraints(label, c);
100 value = new JTextField(Altos.text_width);
101 value.setFont(Altos.value_font);
102 value.setHorizontalAlignment(SwingConstants.RIGHT);
103 c.gridx = 2; c.gridy = y;
104 c.anchor = GridBagConstraints.WEST;
105 c.fill = GridBagConstraints.BOTH;
107 layout.setConstraints(value, c);
113 public static String ignitor_name(int i) {
114 return String.format("Ignitor %c", 'A' + i);
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", ignitor_name(y)));
137 public void reset() {
138 if (ignitors == null)
140 for (int i = 0; i < ignitors.length; i++)
144 public void set_font() {
145 if (ignitors == null)
147 for (int i = 0; i < ignitors.length; i++)
148 ignitors[i].set_font();
151 public void show(AltosState state, AltosListenerState listener_state) {
152 make_ignitors(state);
153 if (ignitors == null)
155 for (int i = 0; i < ignitors.length; i++)
156 ignitors[i].show(state, listener_state);
160 public boolean should_show(AltosState state) {
163 if (state.ignitor_voltage == null)
165 return state.ignitor_voltage.length > 0;
168 void make_ignitors(AltosState state) {
169 int n = state == null ? 0 : state.ignitor_voltage.length;
173 if (ignitors == null || ignitors.length != n) {
174 layout = new GridBagLayout();
177 ignitors = new Ignitor[n];
178 for (int i = 0; i < n; i++)
179 ignitors[i] = new Ignitor(layout, i);
182 if (ignitors != null) {
183 for (int i = 0; i < n; i++)
184 ignitors[i].dispose();
191 public String getName() {
195 public AltosIgnitor() {