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.*;
23 import java.util.concurrent.*;
24 import org.altusmetrum.altoslib_1.*;
25 import org.altusmetrum.altosuilib_1.*;
27 public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay, AltosFontListener {
29 AltosFlightReader reader;
30 AltosDisplayThread thread;
38 AltosCompanionInfo companion;
41 boolean has_companion;
44 private AltosFlightStatus flightStatus;
45 private AltosInfoTable flightInfo;
47 boolean exit_on_close = false;
49 JComponent cur_tab = null;
50 JComponent which_tab(AltosState state) {
51 if (state.state < Altos.ao_flight_boost)
53 if (state.state <= Altos.ao_flight_coast)
55 if (state.state <= Altos.ao_flight_main)
61 if (thread != null && thread.isAlive()) {
65 } catch (InterruptedException ie) {}
83 public void set_font() {
88 flightStatus.set_font();
89 flightInfo.set_font();
94 public void font_size_changed(int font_size) {
99 AltosFlightStatusUpdate status_update;
101 public void show(AltosState state, AltosListenerState listener_state) {
102 status_update.saved_state = state;
105 System.out.printf ("no state provided\n");
106 state = new AltosState(new AltosRecord());
109 pad.show(state, listener_state);
111 if (state.state != Altos.ao_flight_startup) {
113 pane.setTitleAt(0, "Launch Pad");
115 pane.add(descent, 2);
121 ascent.show(state, listener_state);
122 descent.show(state, listener_state);
123 landed.show(state, listener_state);
125 JComponent tab = which_tab(state);
126 if (tab != cur_tab) {
127 if (cur_tab == pane.getSelectedComponent()) {
128 pane.setSelectedComponent(tab);
132 flightStatus.show(state, listener_state);
133 flightInfo.show(state, listener_state);
135 if (state.data.companion != null) {
136 if (!has_companion) {
137 pane.add("Companion", companion);
140 companion.show(state, listener_state);
143 pane.remove(companion);
144 has_companion = false;
147 if (state.gps != null && state.gps.connected) {
149 pane.add("Site Map", sitemap);
152 sitemap.show(state, listener_state);
155 pane.remove(sitemap);
161 public void set_exit_on_close() {
162 exit_on_close = true;
166 AltosFreqList frequencies;
167 JComboBox telemetries;
170 ActionListener show_timer;
172 public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) {
173 AltosUIPreferences.set_component(this);
178 bag = getContentPane();
179 bag.setLayout(new GridBagLayout());
181 GridBagConstraints c = new GridBagConstraints();
183 setTitle(String.format("AltOS %s", reader.name));
185 /* Stick channel selector at top of table for telemetry monitoring */
188 frequencies = new AltosFreqList(AltosUIPreferences.frequency(serial));
189 frequencies.set_product("Monitor");
190 frequencies.set_serial(serial);
191 frequencies.addActionListener(new ActionListener() {
192 public void actionPerformed(ActionEvent e) {
193 double frequency = frequencies.frequency();
195 reader.set_frequency(frequency);
196 } catch (TimeoutException te) {
197 } catch (InterruptedException ie) {
199 reader.save_frequency();
206 c.insets = new Insets(3, 3, 3, 3);
207 c.fill = GridBagConstraints.NONE;
208 c.anchor = GridBagConstraints.WEST;
209 bag.add (frequencies, c);
211 // Telemetry format menu
212 if (reader.supports_telemetry(Altos.ao_telemetry_standard)) {
213 telemetries = new JComboBox();
214 for (int i = 1; i <= Altos.ao_telemetry_max; i++)
215 telemetries.addItem(Altos.telemetry_name(i));
216 int telemetry = AltosPreferences.telemetry(serial);
217 if (telemetry <= Altos.ao_telemetry_off ||
218 telemetry > Altos.ao_telemetry_max)
219 telemetry = Altos.ao_telemetry_standard;
220 telemetries.setSelectedIndex(telemetry - 1);
221 telemetries.setMaximumRowCount(Altos.ao_telemetry_max);
222 telemetries.setPreferredSize(null);
223 telemetries.revalidate();
224 telemetries.addActionListener(new ActionListener() {
225 public void actionPerformed(ActionEvent e) {
226 int telemetry = telemetries.getSelectedIndex() + 1;
227 reader.set_telemetry(telemetry);
228 reader.save_telemetry();
235 c.fill = GridBagConstraints.NONE;
236 c.anchor = GridBagConstraints.WEST;
237 bag.add (telemetries, c);
238 c.insets = new Insets(0, 0, 0, 0);
242 if (reader.supports_telemetry(Altos.ao_telemetry_0_9))
243 version = "Telemetry: 0.9";
244 else if (reader.supports_telemetry(Altos.ao_telemetry_0_8))
245 version = "Telemetry: 0.8";
247 version = "Telemetry: None";
249 telemetry = new JLabel(version);
254 c.fill = GridBagConstraints.NONE;
255 c.anchor = GridBagConstraints.WEST;
256 bag.add (telemetry, c);
257 c.insets = new Insets(0, 0, 0, 0);
261 /* Flight status is always visible */
262 flightStatus = new AltosFlightStatus();
265 c.fill = GridBagConstraints.HORIZONTAL;
268 bag.add(flightStatus, c);
271 /* The rest of the window uses a tabbed pane to
272 * show one of the alternate data views
274 pane = new JTabbedPane();
276 pad = new AltosPad();
277 pane.add("Status", pad);
279 ascent = new AltosAscent();
280 descent = new AltosDescent();
281 landed = new AltosLanded(reader);
283 flightInfo = new AltosInfoTable();
284 pane.add("Table", new JScrollPane(flightInfo));
286 companion = new AltosCompanionInfo();
287 has_companion = false;
290 sitemap = new AltosSiteMap();
293 /* Make the tabbed pane use the rest of the window space */
296 c.fill = GridBagConstraints.BOTH;
302 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
304 AltosUIPreferences.register_font_listener(this);
306 addWindowListener(new WindowAdapter() {
308 public void windowClosing(WindowEvent e) {
312 AltosUIPreferences.unregister_font_listener(AltosFlightUI.this);
321 thread = new AltosDisplayThread(this, voice, this, reader);
323 status_update = new AltosFlightStatusUpdate(flightStatus);
325 new javax.swing.Timer(100, status_update).start();
330 public AltosFlightUI (AltosVoice in_voice, AltosFlightReader in_reader) {
331 this(in_voice, in_reader, -1);