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);
145 public void set_exit_on_close() {
146 exit_on_close = true;
150 AltosFreqList frequencies;
151 JComboBox telemetries;
154 ActionListener show_timer;
156 public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) {
157 AltosUIPreferences.set_component(this);
162 bag = getContentPane();
163 bag.setLayout(new GridBagLayout());
165 GridBagConstraints c = new GridBagConstraints();
167 setTitle(String.format("AltOS %s", reader.name));
169 /* Stick channel selector at top of table for telemetry monitoring */
172 frequencies = new AltosFreqList(AltosUIPreferences.frequency(serial));
173 frequencies.set_product("Monitor");
174 frequencies.set_serial(serial);
175 frequencies.addActionListener(new ActionListener() {
176 public void actionPerformed(ActionEvent e) {
177 double frequency = frequencies.frequency();
179 reader.set_frequency(frequency);
180 } catch (TimeoutException te) {
181 } catch (InterruptedException ie) {
183 reader.save_frequency();
190 c.insets = new Insets(3, 3, 3, 3);
191 c.fill = GridBagConstraints.NONE;
192 c.anchor = GridBagConstraints.WEST;
193 bag.add (frequencies, c);
195 // Telemetry format menu
196 if (reader.supports_telemetry(Altos.ao_telemetry_standard)) {
197 telemetries = new JComboBox();
198 for (int i = 1; i <= Altos.ao_telemetry_max; i++)
199 telemetries.addItem(Altos.telemetry_name(i));
200 int telemetry = AltosPreferences.telemetry(serial);
201 if (telemetry <= Altos.ao_telemetry_off ||
202 telemetry > Altos.ao_telemetry_max)
203 telemetry = Altos.ao_telemetry_standard;
204 telemetries.setSelectedIndex(telemetry - 1);
205 telemetries.setMaximumRowCount(Altos.ao_telemetry_max);
206 telemetries.setPreferredSize(null);
207 telemetries.revalidate();
208 telemetries.addActionListener(new ActionListener() {
209 public void actionPerformed(ActionEvent e) {
210 int telemetry = telemetries.getSelectedIndex() + 1;
211 reader.set_telemetry(telemetry);
212 reader.save_telemetry();
219 c.fill = GridBagConstraints.NONE;
220 c.anchor = GridBagConstraints.WEST;
221 bag.add (telemetries, c);
222 c.insets = new Insets(0, 0, 0, 0);
226 if (reader.supports_telemetry(Altos.ao_telemetry_0_9))
227 version = "Telemetry: 0.9";
228 else if (reader.supports_telemetry(Altos.ao_telemetry_0_8))
229 version = "Telemetry: 0.8";
231 version = "Telemetry: None";
233 telemetry = new JLabel(version);
238 c.fill = GridBagConstraints.NONE;
239 c.anchor = GridBagConstraints.WEST;
240 bag.add (telemetry, c);
241 c.insets = new Insets(0, 0, 0, 0);
245 /* Flight status is always visible */
246 flightStatus = new AltosFlightStatus();
249 c.fill = GridBagConstraints.HORIZONTAL;
252 bag.add(flightStatus, c);
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();
261 pane.add("Launch Pad", pad);
263 ascent = new AltosAscent();
264 pane.add("Ascent", ascent);
266 descent = new AltosDescent();
267 pane.add("Descent", descent);
269 landed = new AltosLanded(reader);
270 pane.add("Landed", landed);
272 flightInfo = new AltosInfoTable();
273 pane.add("Table", new JScrollPane(flightInfo));
275 companion = new AltosCompanionInfo();
276 has_companion = false;
278 sitemap = new AltosSiteMap();
281 /* Make the tabbed pane use the rest of the window space */
284 c.fill = GridBagConstraints.BOTH;
290 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
292 AltosUIPreferences.register_font_listener(this);
294 addWindowListener(new WindowAdapter() {
296 public void windowClosing(WindowEvent e) {
300 AltosUIPreferences.unregister_font_listener(AltosFlightUI.this);
309 thread = new AltosDisplayThread(this, voice, this, reader);
311 status_update = new AltosFlightStatusUpdate(flightStatus);
313 new javax.swing.Timer(100, status_update).start();
318 public AltosFlightUI (AltosVoice in_voice, AltosFlightReader in_reader) {
319 this(in_voice, in_reader, -1);