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;
44 boolean has_companion;
48 private AltosFlightStatus flightStatus;
49 private AltosInfoTable flightInfo;
51 boolean exit_on_close = false;
53 JComponent cur_tab = null;
54 JComponent which_tab(AltosState state) {
55 if (state.state() < Altos.ao_flight_boost)
61 if (thread != null && thread.isAlive()) {
65 } catch (InterruptedException ie) {}
75 for (AltosFlightDisplay d : displays)
79 public void font_size_changed(int font_size) {
80 for (AltosFlightDisplay d : displays)
81 d.font_size_changed(font_size);
84 public void units_changed(boolean imperial_units) {
85 for (AltosFlightDisplay d : displays)
86 d.units_changed(imperial_units);
89 AltosFlightStatusUpdate status_update;
91 public void show(AltosState state, AltosListenerState listener_state) {
92 status_update.saved_state = state;
93 status_update.saved_listener_state = listener_state;
96 state = new AltosState(new AltosCalData());
98 if (state.state() != Altos.ao_flight_startup) {
100 pane.setTitleAt(0, "Launch Pad");
106 JComponent tab = which_tab(state);
107 if (tab != cur_tab) {
108 if (cur_tab == pane.getSelectedComponent())
109 pane.setSelectedComponent(tab);
113 if (igniter.should_show(state)) {
115 pane.add("Ignitor", igniter);
120 pane.remove(igniter);
125 if (state.companion != null) {
126 if (!has_companion) {
127 pane.add("Companion", companion);
132 pane.remove(companion);
133 has_companion = false;
137 if (state.gps != null) {
139 pane.add("Site Map", sitemap);
144 pane.remove(sitemap);
149 for (AltosFlightDisplay d : displays) {
151 d.show(state, listener_state);
152 } catch (Exception e) {
153 System.out.printf("Exception showing %s\n", d.getName());
159 public void set_exit_on_close() {
160 exit_on_close = true;
164 AltosUIFreqList frequencies;
165 AltosUIRateList rates;
166 AltosUITelemetryList telemetries;
169 ActionListener show_timer;
171 public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) {
172 AltosUIPreferences.set_component(this);
174 displays = new LinkedList<AltosFlightDisplay>();
179 bag = getContentPane();
180 bag.setLayout(new GridBagLayout());
182 setTitle(String.format("AltOS %s", reader.name));
184 /* Stick channel selector at top of table for telemetry monitoring */
189 frequencies = new AltosUIFreqList(AltosUIPreferences.frequency(serial));
190 frequencies.set_product("Monitor");
191 frequencies.set_serial(serial);
192 frequencies.addActionListener(new ActionListener() {
193 public void actionPerformed(ActionEvent e) {
194 double frequency = frequencies.frequency();
196 reader.set_frequency(frequency);
197 } catch (TimeoutException te) {
198 } catch (InterruptedException ie) {
200 reader.save_frequency();
203 bag.add (frequencies, constraints(0, 1));
205 // Telemetry rate list
206 rates = new AltosUIRateList(AltosUIPreferences.telemetry_rate(serial));
207 rates.addActionListener(new ActionListener() {
208 public void actionPerformed(ActionEvent e) {
209 int rate = rates.rate();
211 reader.set_telemetry_rate(rate);
212 } catch (TimeoutException te) {
213 } catch (InterruptedException ie) {
215 reader.save_telemetry_rate();
218 rates.setEnabled(reader.supports_telemetry_rate(AltosLib.ao_telemetry_rate_2400));
219 bag.add (rates, constraints(1, 1));
221 // Telemetry format list
222 if (reader.supports_telemetry(Altos.ao_telemetry_standard)) {
223 telemetries = new AltosUITelemetryList(serial);
224 telemetries.addActionListener(new ActionListener() {
225 public void actionPerformed(ActionEvent e) {
226 int telemetry = telemetries.get_selected();
227 reader.set_telemetry(telemetry);
228 reader.save_telemetry();
231 bag.add (telemetries, constraints(2, 1));
235 if (reader.supports_telemetry(Altos.ao_telemetry_0_9))
236 version = "Telemetry: 0.9";
237 else if (reader.supports_telemetry(Altos.ao_telemetry_0_8))
238 version = "Telemetry: 0.8";
240 version = "Telemetry: None";
242 telemetry = new JLabel(version);
243 bag.add (telemetry, constraints(2, 1));
249 /* Flight status is always visible */
250 flightStatus = new AltosFlightStatus();
251 displays.add(flightStatus);
252 bag.add(flightStatus, constraints(0, 4, GridBagConstraints.HORIZONTAL));
255 /* The rest of the window uses a tabbed pane to
256 * show one of the alternate data views
258 pane = new JTabbedPane();
260 pad = new AltosPad();
262 pane.add("Status", pad);
264 igniter = new AltosIgnitor();
265 displays.add(igniter);
266 landed = new AltosLanded(reader);
267 displays.add(landed);
269 flightInfo = new AltosInfoTable();
270 displays.add(flightInfo);
271 pane.add("Table", new JScrollPane(flightInfo));
273 companion = new AltosCompanionInfo();
274 displays.add(companion);
275 has_companion = false;
278 sitemap = new AltosUIMap();
279 displays.add(sitemap);
282 /* Make the tabbed pane use the rest of the window space */
283 bag.add(pane, constraints(0, 4, GridBagConstraints.BOTH));
285 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
287 AltosUIPreferences.register_font_listener(this);
288 AltosPreferences.register_units_listener(this);
290 status_update = new AltosFlightStatusUpdate(flightStatus);
292 flightStatus.start(status_update);
294 addWindowListener(new WindowAdapter() {
296 public void windowClosing(WindowEvent e) {
301 AltosUIPreferences.unregister_font_listener(AltosFlightUI.this);
302 AltosPreferences.unregister_units_listener(AltosFlightUI.this);
311 thread = new AltosDisplayThread(this, voice, this, reader);
316 public AltosFlightUI (AltosVoice in_voice, AltosFlightReader in_reader) {
317 this(in_voice, in_reader, -1);