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;
43 private AltosFlightStatus flightStatus;
44 private AltosInfoTable flightInfo;
46 boolean exit_on_close = false;
48 JComponent cur_tab = null;
49 JComponent which_tab(AltosState state) {
50 if (state.state < Altos.ao_flight_boost)
52 if (state.state <= Altos.ao_flight_coast)
54 if (state.state <= Altos.ao_flight_main)
60 if (thread != null && thread.isAlive()) {
64 } catch (InterruptedException ie) {}
82 public void set_font() {
87 flightStatus.set_font();
88 flightInfo.set_font();
93 public void font_size_changed(int font_size) {
98 AltosFlightStatusUpdate status_update;
100 public void show(AltosState state, int crc_errors) {
101 status_update.saved_state = state;
102 JComponent tab = which_tab(state);
104 pad.show(state, crc_errors);
105 ascent.show(state, crc_errors);
106 descent.show(state, crc_errors);
107 landed.show(state, crc_errors);
108 if (tab != cur_tab) {
109 if (cur_tab == pane.getSelectedComponent()) {
110 pane.setSelectedComponent(tab);
114 flightStatus.show(state, crc_errors);
115 flightInfo.show(state, crc_errors);
117 if (state.data.companion != null) {
118 if (!has_companion) {
119 pane.add("Companion", companion);
122 companion.show(state, crc_errors);
125 pane.remove(companion);
126 has_companion = false;
129 if (state.gps != null && state.gps.connected) {
131 pane.add("Site Map", sitemap);
134 sitemap.show(state, crc_errors);
137 pane.remove(sitemap);
141 } catch (Exception e) {
142 System.out.print("Show exception " + e + "\n");
147 public void set_exit_on_close() {
148 exit_on_close = true;
152 AltosFreqList frequencies;
153 JComboBox telemetries;
156 ActionListener show_timer;
158 public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) {
159 AltosUIPreferences.set_component(this);
164 bag = getContentPane();
165 bag.setLayout(new GridBagLayout());
167 GridBagConstraints c = new GridBagConstraints();
169 setTitle(String.format("AltOS %s", reader.name));
171 /* Stick channel selector at top of table for telemetry monitoring */
174 frequencies = new AltosFreqList(AltosUIPreferences.frequency(serial));
175 frequencies.set_product("Monitor");
176 frequencies.set_serial(serial);
177 frequencies.addActionListener(new ActionListener() {
178 public void actionPerformed(ActionEvent e) {
179 double frequency = frequencies.frequency();
181 reader.set_frequency(frequency);
182 } catch (TimeoutException te) {
183 } catch (InterruptedException ie) {
185 reader.save_frequency();
192 c.insets = new Insets(3, 3, 3, 3);
193 c.fill = GridBagConstraints.NONE;
194 c.anchor = GridBagConstraints.WEST;
195 bag.add (frequencies, c);
197 // Telemetry format menu
198 if (reader.supports_telemetry(Altos.ao_telemetry_standard)) {
199 telemetries = new JComboBox();
200 for (int i = 1; i <= Altos.ao_telemetry_max; i++)
201 telemetries.addItem(Altos.telemetry_name(i));
202 int telemetry = AltosPreferences.telemetry(serial);
203 if (telemetry <= Altos.ao_telemetry_off ||
204 telemetry > Altos.ao_telemetry_max)
205 telemetry = Altos.ao_telemetry_standard;
206 telemetries.setSelectedIndex(telemetry - 1);
207 telemetries.setMaximumRowCount(Altos.ao_telemetry_max);
208 telemetries.setPreferredSize(null);
209 telemetries.revalidate();
210 telemetries.addActionListener(new ActionListener() {
211 public void actionPerformed(ActionEvent e) {
212 int telemetry = telemetries.getSelectedIndex() + 1;
213 reader.set_telemetry(telemetry);
214 reader.save_telemetry();
221 c.fill = GridBagConstraints.NONE;
222 c.anchor = GridBagConstraints.WEST;
223 bag.add (telemetries, c);
224 c.insets = new Insets(0, 0, 0, 0);
228 if (reader.supports_telemetry(Altos.ao_telemetry_0_9))
229 version = "Telemetry: 0.9";
230 else if (reader.supports_telemetry(Altos.ao_telemetry_0_8))
231 version = "Telemetry: 0.8";
233 version = "Telemetry: None";
235 telemetry = new JLabel(version);
240 c.fill = GridBagConstraints.NONE;
241 c.anchor = GridBagConstraints.WEST;
242 bag.add (telemetry, c);
243 c.insets = new Insets(0, 0, 0, 0);
247 /* Flight status is always visible */
248 flightStatus = new AltosFlightStatus();
251 c.fill = GridBagConstraints.HORIZONTAL;
254 bag.add(flightStatus, c);
257 /* The rest of the window uses a tabbed pane to
258 * show one of the alternate data views
260 pane = new JTabbedPane();
262 pad = new AltosPad();
263 pane.add("Launch Pad", pad);
265 ascent = new AltosAscent();
266 pane.add("Ascent", ascent);
268 descent = new AltosDescent();
269 pane.add("Descent", descent);
271 landed = new AltosLanded(reader);
272 pane.add("Landed", landed);
274 flightInfo = new AltosInfoTable();
275 pane.add("Table", new JScrollPane(flightInfo));
277 companion = new AltosCompanionInfo();
278 has_companion = false;
280 sitemap = new AltosSiteMap();
283 /* Make the tabbed pane use the rest of the window space */
286 c.fill = GridBagConstraints.BOTH;
292 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
294 AltosUIPreferences.register_font_listener(this);
296 addWindowListener(new WindowAdapter() {
298 public void windowClosing(WindowEvent e) {
302 AltosUIPreferences.unregister_font_listener(AltosFlightUI.this);
311 thread = new AltosDisplayThread(this, voice, this, reader);
313 status_update = new AltosFlightStatusUpdate(flightStatus);
315 new javax.swing.Timer(100, status_update).start();
320 public AltosFlightUI (AltosVoice in_voice, AltosFlightReader in_reader) {
321 this(in_voice, in_reader, -1);