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; 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.
21 import java.awt.event.*;
24 import java.util.concurrent.*;
25 import org.altusmetrum.altoslib_5.*;
26 import org.altusmetrum.altosuilib_3.*;
28 public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay {
30 AltosFlightReader reader;
31 AltosDisplayThread thread;
33 LinkedList<AltosFlightDisplay> displays;
42 AltosCompanionInfo companion;
45 boolean has_companion;
49 private AltosFlightStatus flightStatus;
50 private AltosInfoTable flightInfo;
52 boolean exit_on_close = false;
54 JComponent cur_tab = null;
55 JComponent which_tab(AltosState state) {
56 if (state.state < Altos.ao_flight_boost)
58 if (state.state <= Altos.ao_flight_coast)
60 if (state.state <= Altos.ao_flight_main)
62 if (state.state == AltosLib.ao_flight_stateless)
68 if (thread != null && thread.isAlive()) {
72 } catch (InterruptedException ie) {}
82 for (AltosFlightDisplay d : displays)
86 public void font_size_changed(int font_size) {
87 for (AltosFlightDisplay d : displays)
88 d.font_size_changed(font_size);
91 public void units_changed(boolean imperial_units) {
92 for (AltosFlightDisplay d : displays)
93 d.units_changed(imperial_units);
96 AltosFlightStatusUpdate status_update;
98 public void show(AltosState state, AltosListenerState listener_state) {
99 status_update.saved_state = state;
102 state = new AltosState();
104 if (state.state != Altos.ao_flight_startup) {
106 pane.setTitleAt(0, "Launch Pad");
108 pane.add(descent, 2);
114 JComponent tab = which_tab(state);
115 if (tab != cur_tab) {
116 if (cur_tab == pane.getSelectedComponent()) {
117 pane.setSelectedComponent(tab);
122 if (ignitor.should_show(state)) {
124 pane.add("Ignitor", ignitor);
129 pane.remove(ignitor);
134 if (state.companion != null) {
135 if (!has_companion) {
136 pane.add("Companion", companion);
141 pane.remove(companion);
142 has_companion = false;
146 if (state.gps != null && state.gps.connected) {
148 pane.add("Site Map", sitemap);
153 pane.remove(sitemap);
158 for (AltosFlightDisplay d : displays) {
160 d.show(state, listener_state);
161 } catch (Exception e) {
162 System.out.printf("Exception showing %s\n", d.getName());
168 public void set_exit_on_close() {
169 exit_on_close = true;
175 AltosFreqList frequencies;
176 AltosUITelemetryMenu telemetries;
179 ActionListener show_timer;
181 public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) {
184 AltosUIPreferences.set_component(this);
186 displays = new LinkedList<AltosFlightDisplay>();
191 bag = getContentPane();
192 bag.setLayout(new GridBagLayout());
194 GridBagConstraints c = new GridBagConstraints();
196 setTitle(String.format("AltOS %s", reader.name));
198 /* Stick channel selector at top of table for telemetry monitoring */
201 menu_bar = new JMenuBar();
202 setJMenuBar(menu_bar);
205 frequencies = new AltosFreqList(AltosUIPreferences.frequency(serial));
206 frequencies.set_product("Monitor");
207 frequencies.set_serial(serial);
208 frequencies.addActionListener(new ActionListener() {
209 public void actionPerformed(ActionEvent e) {
210 double frequency = frequencies.frequency();
212 reader.set_frequency(frequency);
213 } catch (TimeoutException te) {
214 } catch (InterruptedException ie) {
216 reader.save_frequency();
219 menu_bar.add (frequencies);
221 // Telemetry format menu
222 if (reader.supports_telemetry(AltosLib.ao_telemetry_standard)) {
223 telemetries = new AltosUITelemetryMenu(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 menu_bar.add(telemetries);
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 menu_bar.add(telemetry);
247 /* Flight status is always visible */
248 flightStatus = new AltosFlightStatus();
249 displays.add(flightStatus);
252 c.fill = GridBagConstraints.HORIZONTAL;
255 bag.add(flightStatus, c);
258 /* The rest of the window uses a tabbed pane to
259 * show one of the alternate data views
261 pane = new JTabbedPane();
263 pad = new AltosPad();
265 pane.add("Status", pad);
267 ignitor = new AltosIgnitor();
268 displays.add(ignitor);
269 ascent = new AltosAscent();
270 displays.add(ascent);
271 descent = new AltosDescent();
272 displays.add(descent);
273 landed = new AltosLanded(reader);
274 displays.add(landed);
276 flightInfo = new AltosInfoTable();
277 displays.add(flightInfo);
278 pane.add("Table", new JScrollPane(flightInfo));
280 companion = new AltosCompanionInfo();
281 displays.add(companion);
282 has_companion = false;
285 sitemap = new AltosUIMap();
286 displays.add(sitemap);
289 /* Make the tabbed pane use the rest of the window space */
292 c.fill = GridBagConstraints.BOTH;
298 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
300 AltosUIPreferences.register_font_listener(this);
301 AltosPreferences.register_units_listener(this);
303 addWindowListener(new WindowAdapter() {
305 public void windowClosing(WindowEvent e) {
309 AltosUIPreferences.unregister_font_listener(AltosFlightUI.this);
310 AltosPreferences.unregister_units_listener(AltosFlightUI.this);
319 thread = new AltosDisplayThread(this, voice, this, reader);
321 status_update = new AltosFlightStatusUpdate(flightStatus);
323 new javax.swing.Timer(100, status_update).start();
328 public AltosFlightUI (AltosVoice in_voice, AltosFlightReader in_reader) {
329 this(in_voice, in_reader, -1);