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 {
32 String[] statusNames = { "Height (m)", "State", "RSSI (dBm)", "Speed (m/s)" };
33 Object[][] statusData = { { "0", "pad", "-50", "0" } };
36 AltosFlightReader reader;
37 AltosDisplayThread thread;
49 private AltosFlightStatus flightStatus;
50 private JScrollPane flightInfoPane;
51 private JScrollPane sitemapPane;
52 private AltosInfoTable flightInfo;
54 static final int tab_pad = 1;
55 static final int tab_ascent = 2;
56 static final int tab_descent = 3;
57 static final int tab_landed = 4;
61 boolean exit_on_close = false;
63 int which_tab(AltosState state) {
64 if (state.state < Altos.ao_flight_boost)
66 if (state.state <= Altos.ao_flight_coast)
68 if (state.state <= Altos.ao_flight_main)
74 return flightInfo.width();
78 return flightStatus.height() + flightInfo.height();
82 if (thread != null && thread.isAlive()) {
86 } catch (InterruptedException ie) {}
104 public void show(AltosState state, int crc_errors) {
105 int tab = which_tab(state);
106 pad.show(state, crc_errors);
107 ascent.show(state, crc_errors);
108 descent.show(state, crc_errors);
109 landed.show(state, crc_errors);
110 if (tab != cur_tab) {
113 pane.setSelectedComponent(pad);
116 pane.setSelectedComponent(ascent);
119 pane.setSelectedComponent(descent);
122 pane.setSelectedComponent(landed);
126 flightStatus.show(state, crc_errors);
127 flightInfo.show(state, crc_errors);
128 sitemap.show(state, crc_errors);
131 public void set_exit_on_close() {
132 exit_on_close = true;
135 public AltosFlightUI(AltosVoice in_voice, AltosFlightReader in_reader, final int serial) {
136 AltosPreferences.init(this);
141 java.net.URL imgURL = AltosUI.class.getResource("/altus-metrum-16x16.jpg");
143 setIconImage(new ImageIcon(imgURL).getImage());
145 setTitle(String.format("AltOS %s", reader.name));
147 flightStatus = new AltosFlightStatus();
149 vbox = new Box (BoxLayout.Y_AXIS);
150 vbox.add(flightStatus);
152 pane = new JTabbedPane();
154 pad = new AltosPad();
155 pane.add("Launch Pad", pad);
157 ascent = new AltosAscent();
158 pane.add("Ascent", ascent);
160 descent = new AltosDescent();
161 pane.add("Descent", descent);
163 landed = new AltosLanded();
164 pane.add("Landed", landed);
166 flightInfo = new AltosInfoTable();
167 flightInfoPane = new JScrollPane(flightInfo.box());
168 pane.add("Table", flightInfoPane);
170 sitemap = new AltosSiteMap();
171 sitemapPane = new JScrollPane(sitemap);
172 pane.add("Site Map", sitemapPane);
179 JMenuBar menubar = new JMenuBar();
183 JMenu menu = new AltosChannelMenu(AltosPreferences.channel(serial));
184 menu.addActionListener(new ActionListener() {
185 public void actionPerformed(ActionEvent e) {
186 int channel = Integer.parseInt(e.getActionCommand());
187 reader.set_channel(channel);
188 AltosPreferences.set_channel(serial, channel);
191 menu.setMnemonic(KeyEvent.VK_C);
195 this.setJMenuBar(menubar);
198 this.setSize(this.getPreferredSize());
201 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
202 addWindowListener(new WindowAdapter() {
204 public void windowClosing(WindowEvent e) {
213 this.setVisible(true);
215 thread = new AltosDisplayThread(this, voice, this, reader);
220 public AltosFlightUI (AltosVoice in_voice, AltosFlightReader in_reader) {
221 this(in_voice, in_reader, -1);