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.*;
26 public class AltosFlightUI extends AltosFrame implements AltosFlightDisplay, AltosFontListener {
28 AltosFlightReader reader;
29 AltosDisplayThread thread;
37 AltosCompanionInfo companion;
40 boolean has_companion;
42 private AltosFlightStatus flightStatus;
43 private AltosInfoTable flightInfo;
45 boolean exit_on_close = false;
47 JComponent cur_tab = null;
48 JComponent which_tab(AltosState state) {
49 if (state.state < Altos.ao_flight_boost)
51 if (state.state <= Altos.ao_flight_coast)
53 if (state.state <= Altos.ao_flight_main)
59 if (thread != null && thread.isAlive()) {
63 } catch (InterruptedException ie) {}
81 public void set_font() {
86 flightStatus.set_font();
87 flightInfo.set_font();
92 public void font_size_changed(int font_size) {
97 AltosFlightStatusUpdate status_update;
99 public void show(AltosState state, int crc_errors) {
100 status_update.saved_state = state;
101 JComponent tab = which_tab(state);
103 pad.show(state, crc_errors);
104 ascent.show(state, crc_errors);
105 descent.show(state, crc_errors);
106 landed.show(state, crc_errors);
107 if (tab != cur_tab) {
108 if (cur_tab == pane.getSelectedComponent()) {
109 pane.setSelectedComponent(tab);
113 flightStatus.show(state, crc_errors);
114 flightInfo.show(state, crc_errors);
116 if (state.data.companion != null) {
117 if (!has_companion) {
118 pane.add("Companion", companion);
121 companion.show(state, crc_errors);
124 pane.remove(companion);
125 has_companion = false;
128 if (state.gps != null && state.gps.connected) {
130 pane.add("Site Map", sitemap);
133 sitemap.show(state, crc_errors);
136 pane.remove(sitemap);
140 } catch (Exception e) {
141 System.out.print("Show exception " + e + "\n");
146 public void set_exit_on_close() {
147 exit_on_close = true;
151 AltosFreqList frequencies;
152 JComboBox telemetries;
155 ActionListener show_timer;
157 public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) {
158 AltosUIPreferences.set_component(this);
163 bag = getContentPane();
164 bag.setLayout(new GridBagLayout());
166 GridBagConstraints c = new GridBagConstraints();
168 setTitle(String.format("AltOS %s", reader.name));
170 /* Stick channel selector at top of table for telemetry monitoring */
173 frequencies = new AltosFreqList(AltosUIPreferences.frequency(serial));
174 frequencies.set_product("Monitor");
175 frequencies.set_serial(serial);
176 frequencies.addActionListener(new ActionListener() {
177 public void actionPerformed(ActionEvent e) {
178 double frequency = frequencies.frequency();
180 reader.set_frequency(frequency);
181 } catch (TimeoutException te) {
182 } catch (InterruptedException ie) {
184 reader.save_frequency();
191 c.insets = new Insets(3, 3, 3, 3);
192 c.fill = GridBagConstraints.NONE;
193 c.anchor = GridBagConstraints.WEST;
194 bag.add (frequencies, c);
196 // Telemetry format menu
197 if (reader.supports_telemetry(Altos.ao_telemetry_standard)) {
198 telemetries = new JComboBox();
199 for (int i = 1; i <= Altos.ao_telemetry_max; i++)
200 telemetries.addItem(Altos.telemetry_name(i));
201 int telemetry = AltosPreferences.telemetry(serial);
202 if (telemetry <= Altos.ao_telemetry_off ||
203 telemetry > Altos.ao_telemetry_max)
204 telemetry = Altos.ao_telemetry_standard;
205 telemetries.setSelectedIndex(telemetry - 1);
206 telemetries.setMaximumRowCount(Altos.ao_telemetry_max);
207 telemetries.setPreferredSize(null);
208 telemetries.revalidate();
209 telemetries.addActionListener(new ActionListener() {
210 public void actionPerformed(ActionEvent e) {
211 int telemetry = telemetries.getSelectedIndex() + 1;
212 reader.set_telemetry(telemetry);
213 reader.save_telemetry();
220 c.fill = GridBagConstraints.NONE;
221 c.anchor = GridBagConstraints.WEST;
222 bag.add (telemetries, c);
223 c.insets = new Insets(0, 0, 0, 0);
227 if (reader.supports_telemetry(Altos.ao_telemetry_0_9))
228 version = "Telemetry: 0.9";
229 else if (reader.supports_telemetry(Altos.ao_telemetry_0_8))
230 version = "Telemetry: 0.8";
232 version = "Telemetry: None";
234 telemetry = new JLabel(version);
239 c.fill = GridBagConstraints.NONE;
240 c.anchor = GridBagConstraints.WEST;
241 bag.add (telemetry, c);
242 c.insets = new Insets(0, 0, 0, 0);
246 /* Flight status is always visible */
247 flightStatus = new AltosFlightStatus();
250 c.fill = GridBagConstraints.HORIZONTAL;
253 bag.add(flightStatus, c);
256 /* The rest of the window uses a tabbed pane to
257 * show one of the alternate data views
259 pane = new JTabbedPane();
261 pad = new AltosPad();
262 pane.add("Launch Pad", pad);
264 ascent = new AltosAscent();
265 pane.add("Ascent", ascent);
267 descent = new AltosDescent();
268 pane.add("Descent", descent);
270 landed = new AltosLanded(reader);
271 pane.add("Landed", landed);
273 flightInfo = new AltosInfoTable();
274 pane.add("Table", new JScrollPane(flightInfo));
276 companion = new AltosCompanionInfo();
277 has_companion = false;
279 sitemap = new AltosSiteMap();
282 /* Make the tabbed pane use the rest of the window space */
285 c.fill = GridBagConstraints.BOTH;
291 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
293 AltosUIPreferences.register_font_listener(this);
295 addWindowListener(new WindowAdapter() {
297 public void windowClosing(WindowEvent e) {
301 AltosUIPreferences.unregister_font_listener(AltosFlightUI.this);
310 thread = new AltosDisplayThread(this, voice, this, reader);
312 status_update = new AltosFlightStatusUpdate(flightStatus);
314 new javax.swing.Timer(100, status_update).start();
319 public AltosFlightUI (AltosVoice in_voice, AltosFlightReader in_reader) {
320 this(in_voice, in_reader, -1);