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_4.*;
25 import org.altusmetrum.altosuilib_2.*;
27 public class AltosFlightUI extends AltosUIFrame implements AltosFlightDisplay, AltosFontListener {
29 AltosFlightReader reader;
30 AltosDisplayThread thread;
39 AltosCompanionInfo companion;
42 boolean has_companion;
46 private AltosFlightStatus flightStatus;
47 private AltosInfoTable flightInfo;
49 boolean exit_on_close = false;
51 JComponent cur_tab = null;
52 JComponent which_tab(AltosState state) {
53 if (state.state < Altos.ao_flight_boost)
55 if (state.state <= Altos.ao_flight_coast)
57 if (state.state <= Altos.ao_flight_main)
63 if (thread != null && thread.isAlive()) {
67 } catch (InterruptedException ie) {}
86 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, AltosListenerState listener_state) {
106 status_update.saved_state = state;
109 state = new AltosState();
111 pad.show(state, listener_state);
113 if (state.state != Altos.ao_flight_startup) {
115 pane.setTitleAt(0, "Launch Pad");
117 pane.add(descent, 2);
123 ascent.show(state, listener_state);
124 descent.show(state, listener_state);
125 landed.show(state, listener_state);
127 JComponent tab = which_tab(state);
128 if (tab != cur_tab) {
129 if (cur_tab == pane.getSelectedComponent()) {
130 pane.setSelectedComponent(tab);
134 flightStatus.show(state, listener_state);
135 flightInfo.show(state, listener_state);
137 if (ignitor.should_show(state)) {
139 pane.add("Ignitor", ignitor);
142 ignitor.show(state, listener_state);
145 pane.remove(ignitor);
150 if (state.companion != null) {
151 if (!has_companion) {
152 pane.add("Companion", companion);
155 companion.show(state, listener_state);
158 pane.remove(companion);
159 has_companion = false;
162 if (state.gps != null && state.gps.connected) {
164 pane.add("Site Map", sitemap);
167 sitemap.show(state, listener_state);
170 pane.remove(sitemap);
176 public void set_exit_on_close() {
177 exit_on_close = true;
181 AltosFreqList frequencies;
182 JComboBox<String> telemetries;
185 ActionListener show_timer;
187 public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) {
188 AltosUIPreferences.set_component(this);
193 bag = getContentPane();
194 bag.setLayout(new GridBagLayout());
196 GridBagConstraints c = new GridBagConstraints();
198 setTitle(String.format("AltOS %s", reader.name));
200 /* Stick channel selector at top of table for telemetry monitoring */
203 frequencies = new AltosFreqList(AltosUIPreferences.frequency(serial));
204 frequencies.set_product("Monitor");
205 frequencies.set_serial(serial);
206 frequencies.addActionListener(new ActionListener() {
207 public void actionPerformed(ActionEvent e) {
208 double frequency = frequencies.frequency();
210 reader.set_frequency(frequency);
211 } catch (TimeoutException te) {
212 } catch (InterruptedException ie) {
214 reader.save_frequency();
221 c.insets = new Insets(3, 3, 3, 3);
222 c.fill = GridBagConstraints.NONE;
223 c.anchor = GridBagConstraints.WEST;
224 bag.add (frequencies, c);
226 // Telemetry format menu
227 if (reader.supports_telemetry(Altos.ao_telemetry_standard)) {
228 telemetries = new JComboBox<String>();
229 for (int i = 1; i <= Altos.ao_telemetry_max; i++)
230 telemetries.addItem(Altos.telemetry_name(i));
231 int telemetry = AltosPreferences.telemetry(serial);
232 if (telemetry <= Altos.ao_telemetry_off ||
233 telemetry > Altos.ao_telemetry_max)
234 telemetry = Altos.ao_telemetry_standard;
235 telemetries.setSelectedIndex(telemetry - 1);
236 telemetries.setMaximumRowCount(Altos.ao_telemetry_max);
237 telemetries.setPreferredSize(null);
238 telemetries.revalidate();
239 telemetries.addActionListener(new ActionListener() {
240 public void actionPerformed(ActionEvent e) {
241 int telemetry = telemetries.getSelectedIndex() + 1;
242 reader.set_telemetry(telemetry);
243 reader.save_telemetry();
250 c.fill = GridBagConstraints.NONE;
251 c.anchor = GridBagConstraints.WEST;
252 bag.add (telemetries, c);
253 c.insets = new Insets(0, 0, 0, 0);
257 if (reader.supports_telemetry(Altos.ao_telemetry_0_9))
258 version = "Telemetry: 0.9";
259 else if (reader.supports_telemetry(Altos.ao_telemetry_0_8))
260 version = "Telemetry: 0.8";
262 version = "Telemetry: None";
264 telemetry = new JLabel(version);
269 c.fill = GridBagConstraints.NONE;
270 c.anchor = GridBagConstraints.WEST;
271 bag.add (telemetry, c);
272 c.insets = new Insets(0, 0, 0, 0);
276 /* Flight status is always visible */
277 flightStatus = new AltosFlightStatus();
280 c.fill = GridBagConstraints.HORIZONTAL;
283 bag.add(flightStatus, c);
286 /* The rest of the window uses a tabbed pane to
287 * show one of the alternate data views
289 pane = new JTabbedPane();
291 pad = new AltosPad();
292 pane.add("Status", pad);
294 ignitor = new AltosIgnitor();
295 ascent = new AltosAscent();
296 descent = new AltosDescent();
297 landed = new AltosLanded(reader);
299 flightInfo = new AltosInfoTable();
300 pane.add("Table", new JScrollPane(flightInfo));
302 companion = new AltosCompanionInfo();
303 has_companion = false;
306 sitemap = new AltosSiteMap();
309 /* Make the tabbed pane use the rest of the window space */
312 c.fill = GridBagConstraints.BOTH;
318 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
320 AltosUIPreferences.register_font_listener(this);
322 addWindowListener(new WindowAdapter() {
324 public void windowClosing(WindowEvent e) {
328 AltosUIPreferences.unregister_font_listener(AltosFlightUI.this);
337 thread = new AltosDisplayThread(this, voice, this, reader);
339 status_update = new AltosFlightStatusUpdate(flightStatus);
341 new javax.swing.Timer(100, status_update).start();
346 public AltosFlightUI (AltosVoice in_voice, AltosFlightReader in_reader) {
347 this(in_voice, in_reader, -1);