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 setTitle(String.format("AltOS %s", device.toShortString()));
111 /* Stick frequency selector at top of table for telemetry monitoring */
112 if (remote && serial >= 0) {
114 frequencies = new AltosFreqList(AltosUIPreferences.frequency(serial));
115 frequencies.addActionListener(new ActionListener() {
116 public void actionPerformed(ActionEvent e) {
117 double frequency = frequencies.frequency();
118 thread.set_frequency(frequency);
119 AltosUIPreferences.set_frequency(device.getSerial(),
125 c.insets = new Insets(3, 3, 3, 3);
126 c.anchor = GridBagConstraints.WEST;
127 bag.add (frequencies, c);
131 /* Flight status is always visible */
132 flightStatus = new AltosFlightStatus();
135 c.fill = GridBagConstraints.HORIZONTAL;
138 bag.add(flightStatus, c);
141 /* The rest of the window uses a tabbed pane to
142 * show one of the alternate data views
144 pane = new JTabbedPane();
146 pad = new AltosPad();
147 pane.add("Launch Pad", pad);
149 flightInfo = new AltosInfoTable();
150 pane.add("Table", new JScrollPane(flightInfo));
152 /* Make the tabbed pane use the rest of the window space */
155 c.fill = GridBagConstraints.BOTH;
161 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
163 AltosUIPreferences.register_font_listener(this);
165 addWindowListener(new WindowAdapter() {
167 public void windowClosing(WindowEvent e) {
171 AltosUIPreferences.unregister_font_listener(AltosIdleMonitorUI.this);
178 thread = new AltosIdleMonitor((AltosIdleMonitorListener) this, (AltosLink) new AltosSerial (device), (boolean) remote);
180 status_update = new AltosFlightStatusUpdate(flightStatus);
182 new javax.swing.Timer(100, status_update).start();