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 javax.swing.filechooser.FileNameExtensionFilter;
24 import javax.swing.table.*;
28 import java.util.prefs.*;
29 import java.util.concurrent.*;
30 import org.altusmetrum.AltosLib.*;
32 public class AltosFlightUI extends AltosFrame implements AltosFlightDisplay, AltosFontListener {
34 AltosFlightReader reader;
35 AltosDisplayThread thread;
43 AltosCompanionInfo companion;
46 boolean has_companion;
48 private AltosFlightStatus flightStatus;
49 private AltosInfoTable flightInfo;
51 boolean exit_on_close = false;
53 JComponent cur_tab = null;
54 JComponent which_tab(AltosState state) {
55 if (state.state < Altos.ao_flight_boost)
57 if (state.state <= Altos.ao_flight_coast)
59 if (state.state <= Altos.ao_flight_main)
65 if (thread != null && thread.isAlive()) {
69 } catch (InterruptedException ie) {}
87 public void set_font() {
92 flightStatus.set_font();
93 flightInfo.set_font();
98 public void font_size_changed(int font_size) {
103 AltosFlightStatusUpdate status_update;
105 public void show(AltosState state, int crc_errors) {
106 status_update.saved_state = state;
107 JComponent tab = which_tab(state);
109 pad.show(state, crc_errors);
110 ascent.show(state, crc_errors);
111 descent.show(state, crc_errors);
112 landed.show(state, crc_errors);
113 if (tab != cur_tab) {
114 if (cur_tab == pane.getSelectedComponent()) {
115 pane.setSelectedComponent(tab);
119 flightStatus.show(state, crc_errors);
120 flightInfo.show(state, crc_errors);
122 if (state.data.companion != null) {
123 if (!has_companion) {
124 pane.add("Companion", companion);
127 companion.show(state, crc_errors);
130 pane.remove(companion);
131 has_companion = false;
134 if (state.gps != null && state.gps.connected) {
136 pane.add("Site Map", sitemap);
139 sitemap.show(state, crc_errors);
142 pane.remove(sitemap);
146 } catch (Exception e) {
147 System.out.print("Show exception" + e);
151 public void set_exit_on_close() {
152 exit_on_close = true;
156 AltosFreqList frequencies;
157 JComboBox telemetries;
160 ActionListener show_timer;
162 public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) {
163 AltosUIPreferences.set_component(this);
168 bag = getContentPane();
169 bag.setLayout(new GridBagLayout());
171 GridBagConstraints c = new GridBagConstraints();
173 setTitle(String.format("AltOS %s", reader.name));
175 /* Stick channel selector at top of table for telemetry monitoring */
178 frequencies = new AltosFreqList(AltosUIPreferences.frequency(serial));
179 frequencies.set_product("Monitor");
180 frequencies.set_serial(serial);
181 frequencies.addActionListener(new ActionListener() {
182 public void actionPerformed(ActionEvent e) {
183 double frequency = frequencies.frequency();
185 reader.set_frequency(frequency);
186 } catch (TimeoutException te) {
187 } catch (InterruptedException ie) {
189 reader.save_frequency();
196 c.insets = new Insets(3, 3, 3, 3);
197 c.fill = GridBagConstraints.NONE;
198 c.anchor = GridBagConstraints.WEST;
199 bag.add (frequencies, c);
201 // Telemetry format menu
202 if (reader.supports_telemetry(Altos.ao_telemetry_standard)) {
203 telemetries = new JComboBox();
204 for (int i = 1; i <= Altos.ao_telemetry_max; i++)
205 telemetries.addItem(Altos.telemetry_name(i));
206 int telemetry = AltosPreferences.telemetry(serial);
207 if (telemetry <= Altos.ao_telemetry_off ||
208 telemetry > Altos.ao_telemetry_max)
209 telemetry = Altos.ao_telemetry_standard;
210 telemetries.setSelectedIndex(telemetry - 1);
211 telemetries.setMaximumRowCount(Altos.ao_telemetry_max);
212 telemetries.setPreferredSize(null);
213 telemetries.revalidate();
214 telemetries.addActionListener(new ActionListener() {
215 public void actionPerformed(ActionEvent e) {
216 int telemetry = telemetries.getSelectedIndex() + 1;
217 reader.set_telemetry(telemetry);
218 reader.save_telemetry();
225 c.fill = GridBagConstraints.NONE;
226 c.anchor = GridBagConstraints.WEST;
227 bag.add (telemetries, c);
228 c.insets = new Insets(0, 0, 0, 0);
232 if (reader.supports_telemetry(Altos.ao_telemetry_0_9))
233 version = "Telemetry: 0.9";
234 else if (reader.supports_telemetry(Altos.ao_telemetry_0_8))
235 version = "Telemetry: 0.8";
237 version = "Telemetry: None";
239 telemetry = new JLabel(version);
244 c.fill = GridBagConstraints.NONE;
245 c.anchor = GridBagConstraints.WEST;
246 bag.add (telemetry, c);
247 c.insets = new Insets(0, 0, 0, 0);
251 /* Flight status is always visible */
252 flightStatus = new AltosFlightStatus();
255 c.fill = GridBagConstraints.HORIZONTAL;
258 bag.add(flightStatus, c);
261 /* The rest of the window uses a tabbed pane to
262 * show one of the alternate data views
264 pane = new JTabbedPane();
266 pad = new AltosPad();
267 pane.add("Launch Pad", pad);
269 ascent = new AltosAscent();
270 pane.add("Ascent", ascent);
272 descent = new AltosDescent();
273 pane.add("Descent", descent);
275 landed = new AltosLanded(reader);
276 pane.add("Landed", landed);
278 flightInfo = new AltosInfoTable();
279 pane.add("Table", new JScrollPane(flightInfo));
281 companion = new AltosCompanionInfo();
282 has_companion = false;
284 sitemap = new AltosSiteMap();
287 /* Make the tabbed pane use the rest of the window space */
290 c.fill = GridBagConstraints.BOTH;
296 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
298 AltosUIPreferences.register_font_listener(this);
300 addWindowListener(new WindowAdapter() {
302 public void windowClosing(WindowEvent e) {
306 AltosUIPreferences.unregister_font_listener(AltosFlightUI.this);
315 thread = new AltosDisplayThread(this, voice, this, reader);
317 status_update = new AltosFlightStatusUpdate(flightStatus);
319 new javax.swing.Timer(100, status_update).start();
324 public AltosFlightUI (AltosVoice in_voice, AltosFlightReader in_reader) {
325 this(in_voice, in_reader, -1);