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_2.*;
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 state = new AltosState();
107 pad.show(state, listener_state);
109 if (state.state != Altos.ao_flight_startup) {
111 pane.setTitleAt(0, "Launch Pad");
113 pane.add(descent, 2);
119 ascent.show(state, listener_state);
120 descent.show(state, listener_state);
121 landed.show(state, listener_state);
123 JComponent tab = which_tab(state);
124 if (tab != cur_tab) {
125 if (cur_tab == pane.getSelectedComponent()) {
126 pane.setSelectedComponent(tab);
130 flightStatus.show(state, listener_state);
131 flightInfo.show(state, listener_state);
133 if (state.companion != null) {
134 if (!has_companion) {
135 pane.add("Companion", companion);
138 companion.show(state, listener_state);
141 pane.remove(companion);
142 has_companion = false;
145 if (state.gps != null && state.gps.connected) {
147 pane.add("Site Map", sitemap);
150 sitemap.show(state, listener_state);
153 pane.remove(sitemap);
159 public void set_exit_on_close() {
160 exit_on_close = true;
164 AltosFreqList frequencies;
165 JComboBox telemetries;
168 ActionListener show_timer;
170 public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) {
171 AltosUIPreferences.set_component(this);
176 bag = getContentPane();
177 bag.setLayout(new GridBagLayout());
179 GridBagConstraints c = new GridBagConstraints();
181 setTitle(String.format("AltOS %s", reader.name));
183 /* Stick channel selector at top of table for telemetry monitoring */
186 frequencies = new AltosFreqList(AltosUIPreferences.frequency(serial));
187 frequencies.set_product("Monitor");
188 frequencies.set_serial(serial);
189 frequencies.addActionListener(new ActionListener() {
190 public void actionPerformed(ActionEvent e) {
191 double frequency = frequencies.frequency();
193 reader.set_frequency(frequency);
194 } catch (TimeoutException te) {
195 } catch (InterruptedException ie) {
197 reader.save_frequency();
204 c.insets = new Insets(3, 3, 3, 3);
205 c.fill = GridBagConstraints.NONE;
206 c.anchor = GridBagConstraints.WEST;
207 bag.add (frequencies, c);
209 // Telemetry format menu
210 if (reader.supports_telemetry(Altos.ao_telemetry_standard)) {
211 telemetries = new JComboBox();
212 for (int i = 1; i <= Altos.ao_telemetry_max; i++)
213 telemetries.addItem(Altos.telemetry_name(i));
214 int telemetry = AltosPreferences.telemetry(serial);
215 if (telemetry <= Altos.ao_telemetry_off ||
216 telemetry > Altos.ao_telemetry_max)
217 telemetry = Altos.ao_telemetry_standard;
218 telemetries.setSelectedIndex(telemetry - 1);
219 telemetries.setMaximumRowCount(Altos.ao_telemetry_max);
220 telemetries.setPreferredSize(null);
221 telemetries.revalidate();
222 telemetries.addActionListener(new ActionListener() {
223 public void actionPerformed(ActionEvent e) {
224 int telemetry = telemetries.getSelectedIndex() + 1;
225 reader.set_telemetry(telemetry);
226 reader.save_telemetry();
233 c.fill = GridBagConstraints.NONE;
234 c.anchor = GridBagConstraints.WEST;
235 bag.add (telemetries, c);
236 c.insets = new Insets(0, 0, 0, 0);
240 if (reader.supports_telemetry(Altos.ao_telemetry_0_9))
241 version = "Telemetry: 0.9";
242 else if (reader.supports_telemetry(Altos.ao_telemetry_0_8))
243 version = "Telemetry: 0.8";
245 version = "Telemetry: None";
247 telemetry = new JLabel(version);
252 c.fill = GridBagConstraints.NONE;
253 c.anchor = GridBagConstraints.WEST;
254 bag.add (telemetry, c);
255 c.insets = new Insets(0, 0, 0, 0);
259 /* Flight status is always visible */
260 flightStatus = new AltosFlightStatus();
263 c.fill = GridBagConstraints.HORIZONTAL;
266 bag.add(flightStatus, c);
269 /* The rest of the window uses a tabbed pane to
270 * show one of the alternate data views
272 pane = new JTabbedPane();
274 pad = new AltosPad();
275 pane.add("Status", pad);
277 ascent = new AltosAscent();
278 descent = new AltosDescent();
279 landed = new AltosLanded(reader);
281 flightInfo = new AltosInfoTable();
282 pane.add("Table", new JScrollPane(flightInfo));
284 companion = new AltosCompanionInfo();
285 has_companion = false;
288 sitemap = new AltosSiteMap();
291 /* Make the tabbed pane use the rest of the window space */
294 c.fill = GridBagConstraints.BOTH;
300 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
302 AltosUIPreferences.register_font_listener(this);
304 addWindowListener(new WindowAdapter() {
306 public void windowClosing(WindowEvent e) {
310 AltosUIPreferences.unregister_font_listener(AltosFlightUI.this);
319 thread = new AltosDisplayThread(this, voice, this, reader);
321 status_update = new AltosFlightStatusUpdate(flightStatus);
323 new javax.swing.Timer(100, status_update).start();
328 public AltosFlightUI (AltosVoice in_voice, AltosFlightReader in_reader) {
329 this(in_voice, in_reader, -1);