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 java.net.URL imgURL = AltosUI.class.getResource("/altus-metrum-16x16.jpg");
175 setIconImage(new ImageIcon(imgURL).getImage());
177 setTitle(String.format("AltOS %s", reader.name));
179 /* Stick channel selector at top of table for telemetry monitoring */
182 frequencies = new AltosFreqList(AltosUIPreferences.frequency(serial));
183 frequencies.set_product("Monitor");
184 frequencies.set_serial(serial);
185 frequencies.addActionListener(new ActionListener() {
186 public void actionPerformed(ActionEvent e) {
187 double frequency = frequencies.frequency();
189 reader.set_frequency(frequency);
190 } catch (TimeoutException te) {
191 } catch (InterruptedException ie) {
193 reader.save_frequency();
200 c.insets = new Insets(3, 3, 3, 3);
201 c.fill = GridBagConstraints.NONE;
202 c.anchor = GridBagConstraints.WEST;
203 bag.add (frequencies, c);
205 // Telemetry format menu
206 if (reader.supports_telemetry(Altos.ao_telemetry_standard)) {
207 telemetries = new JComboBox();
208 for (int i = 1; i <= Altos.ao_telemetry_max; i++)
209 telemetries.addItem(Altos.telemetry_name(i));
210 int telemetry = AltosPreferences.telemetry(serial);
211 if (telemetry <= Altos.ao_telemetry_off ||
212 telemetry > Altos.ao_telemetry_max)
213 telemetry = Altos.ao_telemetry_standard;
214 telemetries.setSelectedIndex(telemetry - 1);
215 telemetries.setMaximumRowCount(Altos.ao_telemetry_max);
216 telemetries.setPreferredSize(null);
217 telemetries.revalidate();
218 telemetries.addActionListener(new ActionListener() {
219 public void actionPerformed(ActionEvent e) {
220 int telemetry = telemetries.getSelectedIndex() + 1;
221 reader.set_telemetry(telemetry);
222 reader.save_telemetry();
229 c.fill = GridBagConstraints.NONE;
230 c.anchor = GridBagConstraints.WEST;
231 bag.add (telemetries, c);
232 c.insets = new Insets(0, 0, 0, 0);
236 if (reader.supports_telemetry(Altos.ao_telemetry_0_9))
237 version = "Telemetry: 0.9";
238 else if (reader.supports_telemetry(Altos.ao_telemetry_0_8))
239 version = "Telemetry: 0.8";
241 version = "Telemetry: None";
243 telemetry = new JLabel(version);
248 c.fill = GridBagConstraints.NONE;
249 c.anchor = GridBagConstraints.WEST;
250 bag.add (telemetry, c);
251 c.insets = new Insets(0, 0, 0, 0);
255 /* Flight status is always visible */
256 flightStatus = new AltosFlightStatus();
259 c.fill = GridBagConstraints.HORIZONTAL;
262 bag.add(flightStatus, c);
265 /* The rest of the window uses a tabbed pane to
266 * show one of the alternate data views
268 pane = new JTabbedPane();
270 pad = new AltosPad();
271 pane.add("Launch Pad", pad);
273 ascent = new AltosAscent();
274 pane.add("Ascent", ascent);
276 descent = new AltosDescent();
277 pane.add("Descent", descent);
279 landed = new AltosLanded(reader);
280 pane.add("Landed", landed);
282 flightInfo = new AltosInfoTable();
283 pane.add("Table", new JScrollPane(flightInfo));
285 companion = new AltosCompanionInfo();
286 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);