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.*;
31 public class AltosFlightUI extends AltosFrame implements AltosFlightDisplay, AltosFontListener {
33 AltosFlightReader reader;
34 AltosDisplayThread thread;
42 AltosCompanionInfo companion;
45 boolean has_companion;
47 private AltosFlightStatus flightStatus;
48 private AltosInfoTable flightInfo;
50 boolean exit_on_close = false;
52 JComponent cur_tab = null;
53 JComponent which_tab(AltosState state) {
54 if (state.state < Altos.ao_flight_boost)
56 if (state.state <= Altos.ao_flight_coast)
58 if (state.state <= Altos.ao_flight_main)
64 if (thread != null && thread.isAlive()) {
68 } catch (InterruptedException ie) {}
86 public void set_font() {
91 flightStatus.set_font();
92 flightInfo.set_font();
97 public void font_size_changed(int font_size) {
101 public void show(AltosState state, int crc_errors) {
102 JComponent tab = which_tab(state);
104 pad.show(state, crc_errors);
105 ascent.show(state, crc_errors);
106 descent.show(state, crc_errors);
107 landed.show(state, crc_errors);
108 if (tab != cur_tab) {
109 if (cur_tab == pane.getSelectedComponent()) {
110 pane.setSelectedComponent(tab);
114 flightStatus.show(state, crc_errors);
115 flightInfo.show(state, crc_errors);
117 if (state.data.companion != null) {
118 if (!has_companion) {
119 pane.add("Companion", companion);
122 companion.show(state, crc_errors);
125 pane.remove(companion);
126 has_companion = false;
129 if (state.gps != null && state.gps.connected) {
131 pane.add("Site Map", sitemap);
134 sitemap.show(state, crc_errors);
137 pane.remove(sitemap);
141 } catch (Exception e) {
142 System.out.print("Show exception" + e);
146 public void set_exit_on_close() {
147 exit_on_close = true;
151 AltosFreqList frequencies;
152 JComboBox telemetries;
154 public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) {
155 AltosPreferences.set_component(this);
160 bag = getContentPane();
161 bag.setLayout(new GridBagLayout());
163 GridBagConstraints c = new GridBagConstraints();
165 java.net.URL imgURL = AltosUI.class.getResource("/altus-metrum-16x16.jpg");
167 setIconImage(new ImageIcon(imgURL).getImage());
169 setTitle(String.format("AltOS %s", reader.name));
171 /* Stick channel selector at top of table for telemetry monitoring */
174 frequencies = new AltosFreqList(AltosPreferences.frequency(serial));
175 frequencies.set_product("Monitor");
176 frequencies.set_serial(serial);
177 frequencies.addActionListener(new ActionListener() {
178 public void actionPerformed(ActionEvent e) {
179 double frequency = frequencies.frequency();
181 reader.set_frequency(frequency);
182 } catch (TimeoutException te) {
183 } catch (InterruptedException ie) {
185 reader.save_frequency();
192 c.insets = new Insets(3, 3, 3, 3);
193 c.fill = GridBagConstraints.NONE;
194 c.anchor = GridBagConstraints.WEST;
195 bag.add (frequencies, c);
197 // Telemetry format menu
198 telemetries = new JComboBox();
199 for (int i = 1; i <= Altos.ao_telemetry_max; i++)
200 telemetries.addItem(Altos.telemetry_name(i));
201 int telemetry = AltosPreferences.telemetry(serial);
202 if (telemetry <= Altos.ao_telemetry_off ||
203 telemetry > Altos.ao_telemetry_max)
204 telemetry = Altos.ao_telemetry_standard;
205 telemetries.setSelectedIndex(telemetry - 1);
206 telemetries.setMaximumRowCount(Altos.ao_telemetry_max);
207 telemetries.setPreferredSize(null);
208 telemetries.revalidate();
209 telemetries.addActionListener(new ActionListener() {
210 public void actionPerformed(ActionEvent e) {
211 int telemetry = telemetries.getSelectedIndex() + 1;
212 reader.set_telemetry(telemetry);
213 reader.save_telemetry();
220 c.fill = GridBagConstraints.NONE;
221 c.anchor = GridBagConstraints.WEST;
222 bag.add (telemetries, c);
223 c.insets = new Insets(0, 0, 0, 0);
226 /* Flight status is always visible */
227 flightStatus = new AltosFlightStatus();
230 c.fill = GridBagConstraints.HORIZONTAL;
233 bag.add(flightStatus, c);
236 /* The rest of the window uses a tabbed pane to
237 * show one of the alternate data views
239 pane = new JTabbedPane();
241 pad = new AltosPad();
242 pane.add("Launch Pad", pad);
244 ascent = new AltosAscent();
245 pane.add("Ascent", ascent);
247 descent = new AltosDescent();
248 pane.add("Descent", descent);
250 landed = new AltosLanded(reader);
251 pane.add("Landed", landed);
253 flightInfo = new AltosInfoTable();
254 pane.add("Table", new JScrollPane(flightInfo));
256 companion = new AltosCompanionInfo();
257 has_companion = false;
259 sitemap = new AltosSiteMap();
262 /* Make the tabbed pane use the rest of the window space */
265 c.fill = GridBagConstraints.BOTH;
271 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
273 AltosPreferences.register_font_listener(this);
275 addWindowListener(new WindowAdapter() {
277 public void windowClosing(WindowEvent e) {
281 AltosPreferences.unregister_font_listener(AltosFlightUI.this);
290 thread = new AltosDisplayThread(this, voice, this, reader);
295 public AltosFlightUI (AltosVoice in_voice, AltosFlightReader in_reader) {
296 this(in_voice, in_reader, -1);