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.LinkedBlockingQueue;
31 public class AltosFlightUI extends JFrame implements AltosFlightDisplay {
33 AltosFlightReader reader;
34 AltosDisplayThread thread;
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) {}
85 public void show(AltosState state, int crc_errors) {
86 JComponent tab = which_tab(state);
88 pad.show(state, crc_errors);
89 ascent.show(state, crc_errors);
90 descent.show(state, crc_errors);
91 landed.show(state, crc_errors);
94 if (cur_tab == pane.getSelectedComponent()) {
95 pane.setSelectedComponent(tab);
99 flightStatus.show(state, crc_errors);
100 flightInfo.show(state, crc_errors);
101 if (state.gps != null) {
103 pane.add("Site Map", sitemap);
106 sitemap.show(state, crc_errors);
109 pane.remove(sitemap);
113 } catch (Exception e) {
114 System.out.print("Show exception" + e);
118 public void set_exit_on_close() {
119 exit_on_close = true;
124 JComboBox telemetries;
126 public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) {
127 AltosPreferences.set_component(this);
132 bag = getContentPane();
133 bag.setLayout(new GridBagLayout());
135 GridBagConstraints c = new GridBagConstraints();
137 java.net.URL imgURL = AltosUI.class.getResource("/altus-metrum-16x16.jpg");
139 setIconImage(new ImageIcon(imgURL).getImage());
141 setTitle(String.format("AltOS %s", reader.name));
143 /* Stick channel selector at top of table for telemetry monitoring */
146 channels = new AltosChannelMenu(AltosPreferences.channel(serial));
147 channels.addActionListener(new ActionListener() {
148 public void actionPerformed(ActionEvent e) {
149 int channel = channels.getSelectedIndex();
150 reader.set_channel(channel);
155 c.insets = new Insets(3, 3, 3, 3);
156 c.anchor = GridBagConstraints.WEST;
157 bag.add (channels, c);
159 // Telemetry format menu
160 telemetries = new JComboBox();
161 telemetries.addItem("TeleMetrum");
162 telemetries.addItem("TeleMini/TeleNano");
163 telemetries.setSelectedIndex(AltosPreferences.telemetry(serial) - 1);
164 telemetries.setMaximumRowCount(2);
165 telemetries.addActionListener(new ActionListener() {
166 public void actionPerformed(ActionEvent e) {
167 int telemetry = telemetries.getSelectedIndex() + 1;
168 reader.set_telemetry(telemetry);
173 c.fill = GridBagConstraints.NONE;
174 c.anchor = GridBagConstraints.WEST;
175 bag.add (telemetries, c);
176 c.insets = new Insets(0, 0, 0, 0);
179 /* Flight status is always visible */
180 flightStatus = new AltosFlightStatus();
183 c.fill = GridBagConstraints.HORIZONTAL;
186 bag.add(flightStatus, c);
189 /* The rest of the window uses a tabbed pane to
190 * show one of the alternate data views
192 pane = new JTabbedPane();
194 pad = new AltosPad();
195 pane.add("Launch Pad", pad);
197 ascent = new AltosAscent();
198 pane.add("Ascent", ascent);
200 descent = new AltosDescent();
201 pane.add("Descent", descent);
203 landed = new AltosLanded();
204 pane.add("Landed", landed);
206 flightInfo = new AltosInfoTable();
207 pane.add("Table", new JScrollPane(flightInfo));
209 sitemap = new AltosSiteMap();
212 /* Make the tabbed pane use the rest of the window space */
215 c.fill = GridBagConstraints.BOTH;
221 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
222 addWindowListener(new WindowAdapter() {
224 public void windowClosing(WindowEvent e) {
236 terra = new AltosTerra(this);
237 terra.setVisible(true);
239 thread = new AltosDisplayThread(this, voice, this, reader);
244 public AltosFlightUI (AltosVoice in_voice, AltosFlightReader in_reader) {
245 this(in_voice, in_reader, -1);