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 AltosIdleMonitorUI extends AltosFrame implements AltosFlightDisplay, AltosFontListener, AltosIdleMonitorListener {
36 AltosInfoTable flightInfo;
37 AltosFlightStatus flightStatus;
38 AltosIdleMonitor thread;
43 if (thread != null && thread.isAlive()) {
47 } catch (InterruptedException ie) {}
61 public void set_font() {
63 flightInfo.set_font();
66 public void font_size_changed(int font_size) {
70 AltosFlightStatusUpdate status_update;
72 public void show(AltosState state, int crc_errors) {
73 status_update.saved_state = state;
75 pad.show(state, crc_errors);
76 flightStatus.show(state, crc_errors);
77 flightInfo.show(state, crc_errors);
78 } catch (Exception e) {
79 System.out.print("Show exception" + e);
83 public void update(final AltosState state) {
84 Runnable r = new Runnable() {
89 SwingUtilities.invokeLater(r);
93 AltosFreqList frequencies;
95 public AltosIdleMonitorUI(JFrame in_owner)
96 throws FileNotFoundException, AltosSerialInUseException, TimeoutException, InterruptedException {
98 device = AltosDeviceDialog.show(in_owner, Altos.product_any);
100 if (!device.matchProduct(Altos.product_altimeter))
103 serial = device.getSerial();
104 bag = getContentPane();
105 bag.setLayout(new GridBagLayout());
107 GridBagConstraints c = new GridBagConstraints();
109 java.net.URL imgURL = AltosUI.class.getResource("/altus-metrum-16x16.jpg");
111 setIconImage(new ImageIcon(imgURL).getImage());
113 setTitle(String.format("AltOS %s", device.toShortString()));
115 /* Stick frequency selector at top of table for telemetry monitoring */
116 if (remote && serial >= 0) {
118 frequencies = new AltosFreqList(AltosUIPreferences.frequency(serial));
119 frequencies.addActionListener(new ActionListener() {
120 public void actionPerformed(ActionEvent e) {
121 double frequency = frequencies.frequency();
122 thread.set_frequency(frequency);
123 AltosUIPreferences.set_frequency(device.getSerial(),
129 c.insets = new Insets(3, 3, 3, 3);
130 c.anchor = GridBagConstraints.WEST;
131 bag.add (frequencies, c);
135 /* Flight status is always visible */
136 flightStatus = new AltosFlightStatus();
139 c.fill = GridBagConstraints.HORIZONTAL;
142 bag.add(flightStatus, c);
145 /* The rest of the window uses a tabbed pane to
146 * show one of the alternate data views
148 pane = new JTabbedPane();
150 pad = new AltosPad();
151 pane.add("Launch Pad", pad);
153 flightInfo = new AltosInfoTable();
154 pane.add("Table", new JScrollPane(flightInfo));
156 /* Make the tabbed pane use the rest of the window space */
159 c.fill = GridBagConstraints.BOTH;
165 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
167 AltosUIPreferences.register_font_listener(this);
169 addWindowListener(new WindowAdapter() {
171 public void windowClosing(WindowEvent e) {
175 AltosUIPreferences.unregister_font_listener(AltosIdleMonitorUI.this);
182 thread = new AltosIdleMonitor((AltosIdleMonitorListener) this, (AltosLink) new AltosSerial (device), (boolean) remote);
184 status_update = new AltosFlightStatusUpdate(flightStatus);
186 new javax.swing.Timer(100, status_update).start();