2 * Copyright © 2010 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.
22 import java.awt.event.*;
25 import java.util.concurrent.*;
26 import org.altusmetrum.altoslib_12.*;
27 import org.altusmetrum.altosuilib_12.*;
29 public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay {
31 AltosFlightReader reader;
32 AltosDisplayThread thread;
34 LinkedList<AltosFlightDisplay> displays;
41 AltosCompanionInfo companion;
42 boolean has_companion;
46 private AltosFlightStatus flightStatus;
47 private AltosInfoTable flightInfo;
49 boolean exit_on_close = false;
51 JComponent cur_tab = null;
52 JComponent which_tab(AltosState state) {
53 if (state.state() < Altos.ao_flight_boost)
59 if (thread != null && thread.isAlive()) {
63 } catch (InterruptedException ie) {}
73 for (AltosFlightDisplay d : displays)
77 public void font_size_changed(int font_size) {
78 for (AltosFlightDisplay d : displays)
79 d.font_size_changed(font_size);
82 public void units_changed(boolean imperial_units) {
83 for (AltosFlightDisplay d : displays)
84 d.units_changed(imperial_units);
87 AltosFlightStatusUpdate status_update;
89 public void show(AltosState state, AltosListenerState listener_state) {
90 status_update.saved_state = state;
91 status_update.saved_listener_state = listener_state;
94 state = new AltosState(new AltosCalData());
96 if (state.state() != Altos.ao_flight_startup) {
98 pane.setTitleAt(0, "Launch Pad");
104 JComponent tab = which_tab(state);
105 if (tab != cur_tab) {
106 if (cur_tab == pane.getSelectedComponent())
107 pane.setSelectedComponent(tab);
111 if (igniter.should_show(state)) {
113 pane.add("Ignitor", igniter);
118 pane.remove(igniter);
123 if (state.companion != null) {
124 if (!has_companion) {
125 pane.add("Companion", companion);
130 pane.remove(companion);
131 has_companion = false;
135 for (AltosFlightDisplay d : displays) {
137 d.show(state, listener_state);
138 } catch (Exception e) {
139 System.out.printf("Exception showing %s\n", d.getName());
145 public void set_exit_on_close() {
146 exit_on_close = true;
150 AltosUIFreqList frequencies;
151 AltosUIRateList rates;
152 AltosUITelemetryList telemetries;
155 ActionListener show_timer;
157 public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) {
158 AltosUIPreferences.set_component(this);
160 displays = new LinkedList<AltosFlightDisplay>();
165 bag = getContentPane();
166 bag.setLayout(new GridBagLayout());
168 setTitle(String.format("AltOS %s", reader.name));
170 /* Stick channel selector at top of table for telemetry monitoring */
175 frequencies = new AltosUIFreqList(AltosUIPreferences.frequency(serial));
176 frequencies.set_product("Monitor");
177 frequencies.set_serial(serial);
178 frequencies.addActionListener(new ActionListener() {
179 public void actionPerformed(ActionEvent e) {
180 double frequency = frequencies.frequency();
182 reader.set_frequency(frequency);
183 } catch (TimeoutException te) {
184 } catch (InterruptedException ie) {
186 reader.save_frequency();
189 bag.add (frequencies, constraints(0, 1));
191 // Telemetry rate list
192 rates = new AltosUIRateList(AltosUIPreferences.telemetry_rate(serial));
193 rates.addActionListener(new ActionListener() {
194 public void actionPerformed(ActionEvent e) {
195 int rate = rates.rate();
197 reader.set_telemetry_rate(rate);
198 } catch (TimeoutException te) {
199 } catch (InterruptedException ie) {
201 reader.save_telemetry_rate();
204 rates.setEnabled(reader.supports_telemetry_rate(AltosLib.ao_telemetry_rate_2400));
205 bag.add (rates, constraints(1, 1));
207 // Telemetry format list
208 if (reader.supports_telemetry(Altos.ao_telemetry_standard)) {
209 telemetries = new AltosUITelemetryList(serial);
210 telemetries.addActionListener(new ActionListener() {
211 public void actionPerformed(ActionEvent e) {
212 int telemetry = telemetries.get_selected();
213 reader.set_telemetry(telemetry);
214 reader.save_telemetry();
217 bag.add (telemetries, constraints(2, 1));
221 if (reader.supports_telemetry(Altos.ao_telemetry_0_9))
222 version = "Telemetry: 0.9";
223 else if (reader.supports_telemetry(Altos.ao_telemetry_0_8))
224 version = "Telemetry: 0.8";
226 version = "Telemetry: None";
228 telemetry = new JLabel(version);
229 bag.add (telemetry, constraints(2, 1));
235 /* Flight status is always visible */
236 flightStatus = new AltosFlightStatus();
237 displays.add(flightStatus);
238 bag.add(flightStatus, constraints(0, 4, GridBagConstraints.HORIZONTAL));
241 /* The rest of the window uses a tabbed pane to
242 * show one of the alternate data views
244 pane = new JTabbedPane();
246 pad = new AltosPad();
248 pane.add("Status", pad);
250 igniter = new AltosIgnitor();
251 displays.add(igniter);
252 landed = new AltosLanded(reader);
253 displays.add(landed);
255 flightInfo = new AltosInfoTable();
256 displays.add(flightInfo);
257 pane.add("Table", new JScrollPane(flightInfo));
259 companion = new AltosCompanionInfo();
260 displays.add(companion);
261 has_companion = false;
264 /* Make the tabbed pane use the rest of the window space */
265 bag.add(pane, constraints(0, 4, GridBagConstraints.BOTH));
267 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
269 AltosUIPreferences.register_font_listener(this);
270 AltosPreferences.register_units_listener(this);
272 status_update = new AltosFlightStatusUpdate(flightStatus);
274 flightStatus.start(status_update);
276 addWindowListener(new WindowAdapter() {
278 public void windowClosing(WindowEvent e) {
283 AltosUIPreferences.unregister_font_listener(AltosFlightUI.this);
284 AltosPreferences.unregister_units_listener(AltosFlightUI.this);
293 thread = new AltosDisplayThread(this, voice, this, reader);
298 public AltosFlightUI (AltosVoice in_voice, AltosFlightReader in_reader) {
299 this(in_voice, in_reader, -1);