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 class AltosFlightStatusUpdate implements ActionListener {
33 public AltosState saved_state;
34 AltosFlightStatus flightStatus;
36 public void actionPerformed (ActionEvent e) {
37 if (saved_state != null)
38 flightStatus.show(saved_state, 0);
41 public AltosFlightStatusUpdate (AltosFlightStatus in_flightStatus) {
42 flightStatus = in_flightStatus;
46 public class AltosFlightUI extends AltosFrame implements AltosFlightDisplay, AltosFontListener {
48 AltosFlightReader reader;
49 AltosDisplayThread thread;
57 AltosCompanionInfo companion;
60 boolean has_companion;
62 private AltosFlightStatus flightStatus;
63 private AltosInfoTable flightInfo;
65 boolean exit_on_close = false;
67 JComponent cur_tab = null;
68 JComponent which_tab(AltosState state) {
69 if (state.state < Altos.ao_flight_boost)
71 if (state.state <= Altos.ao_flight_coast)
73 if (state.state <= Altos.ao_flight_main)
79 if (thread != null && thread.isAlive()) {
83 } catch (InterruptedException ie) {}
101 public void set_font() {
106 flightStatus.set_font();
107 flightInfo.set_font();
109 companion.set_font();
112 public void font_size_changed(int font_size) {
117 AltosFlightStatusUpdate status_update;
119 public void show(AltosState state, int crc_errors) {
120 status_update.saved_state = state;
121 JComponent tab = which_tab(state);
123 pad.show(state, crc_errors);
124 ascent.show(state, crc_errors);
125 descent.show(state, crc_errors);
126 landed.show(state, crc_errors);
127 if (tab != cur_tab) {
128 if (cur_tab == pane.getSelectedComponent()) {
129 pane.setSelectedComponent(tab);
133 flightStatus.show(state, crc_errors);
134 flightInfo.show(state, crc_errors);
136 if (state.data.companion != null) {
137 if (!has_companion) {
138 pane.add("Companion", companion);
141 companion.show(state, crc_errors);
144 pane.remove(companion);
145 has_companion = false;
148 if (state.gps != null && state.gps.connected) {
150 pane.add("Site Map", sitemap);
153 sitemap.show(state, crc_errors);
156 pane.remove(sitemap);
160 } catch (Exception e) {
161 System.out.print("Show exception" + e);
165 public void set_exit_on_close() {
166 exit_on_close = true;
170 AltosFreqList frequencies;
171 JComboBox telemetries;
174 ActionListener show_timer;
176 public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) {
177 AltosPreferences.set_component(this);
182 bag = getContentPane();
183 bag.setLayout(new GridBagLayout());
185 GridBagConstraints c = new GridBagConstraints();
187 java.net.URL imgURL = AltosUI.class.getResource("/altus-metrum-16x16.jpg");
189 setIconImage(new ImageIcon(imgURL).getImage());
191 setTitle(String.format("AltOS %s", reader.name));
193 /* Stick channel selector at top of table for telemetry monitoring */
196 frequencies = new AltosFreqList(AltosPreferences.frequency(serial));
197 frequencies.set_product("Monitor");
198 frequencies.set_serial(serial);
199 frequencies.addActionListener(new ActionListener() {
200 public void actionPerformed(ActionEvent e) {
201 double frequency = frequencies.frequency();
203 reader.set_frequency(frequency);
204 } catch (TimeoutException te) {
205 } catch (InterruptedException ie) {
207 reader.save_frequency();
214 c.insets = new Insets(3, 3, 3, 3);
215 c.fill = GridBagConstraints.NONE;
216 c.anchor = GridBagConstraints.WEST;
217 bag.add (frequencies, c);
219 // Telemetry format menu
220 if (reader.supports_telemetry(Altos.ao_telemetry_standard)) {
221 telemetries = new JComboBox();
222 for (int i = 1; i <= Altos.ao_telemetry_max; i++)
223 telemetries.addItem(Altos.telemetry_name(i));
224 int telemetry = AltosPreferences.telemetry(serial);
225 if (telemetry <= Altos.ao_telemetry_off ||
226 telemetry > Altos.ao_telemetry_max)
227 telemetry = Altos.ao_telemetry_standard;
228 telemetries.setSelectedIndex(telemetry - 1);
229 telemetries.setMaximumRowCount(Altos.ao_telemetry_max);
230 telemetries.setPreferredSize(null);
231 telemetries.revalidate();
232 telemetries.addActionListener(new ActionListener() {
233 public void actionPerformed(ActionEvent e) {
234 int telemetry = telemetries.getSelectedIndex() + 1;
235 reader.set_telemetry(telemetry);
236 reader.save_telemetry();
243 c.fill = GridBagConstraints.NONE;
244 c.anchor = GridBagConstraints.WEST;
245 bag.add (telemetries, c);
246 c.insets = new Insets(0, 0, 0, 0);
250 if (reader.supports_telemetry(Altos.ao_telemetry_0_9))
251 version = "Telemetry: 0.9";
252 else if (reader.supports_telemetry(Altos.ao_telemetry_0_8))
253 version = "Telemetry: 0.8";
255 version = "Telemetry: None";
257 telemetry = new JLabel(version);
262 c.fill = GridBagConstraints.NONE;
263 c.anchor = GridBagConstraints.WEST;
264 bag.add (telemetry, c);
265 c.insets = new Insets(0, 0, 0, 0);
269 /* Flight status is always visible */
270 flightStatus = new AltosFlightStatus();
273 c.fill = GridBagConstraints.HORIZONTAL;
276 bag.add(flightStatus, c);
279 /* The rest of the window uses a tabbed pane to
280 * show one of the alternate data views
282 pane = new JTabbedPane();
284 pad = new AltosPad();
285 pane.add("Launch Pad", pad);
287 ascent = new AltosAscent();
288 pane.add("Ascent", ascent);
290 descent = new AltosDescent();
291 pane.add("Descent", descent);
293 landed = new AltosLanded(reader);
294 pane.add("Landed", landed);
296 flightInfo = new AltosInfoTable();
297 pane.add("Table", new JScrollPane(flightInfo));
299 companion = new AltosCompanionInfo();
300 has_companion = false;
302 sitemap = new AltosSiteMap();
305 /* Make the tabbed pane use the rest of the window space */
308 c.fill = GridBagConstraints.BOTH;
314 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
316 AltosPreferences.register_font_listener(this);
318 addWindowListener(new WindowAdapter() {
320 public void windowClosing(WindowEvent e) {
324 AltosPreferences.unregister_font_listener(AltosFlightUI.this);
333 thread = new AltosDisplayThread(this, voice, this, reader);
335 status_update = new AltosFlightStatusUpdate(flightStatus);
337 new javax.swing.Timer(100, status_update).start();
342 public AltosFlightUI (AltosVoice in_voice, AltosFlightReader in_reader) {
343 this(in_voice, in_reader, -1);