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.*;
24 import java.util.concurrent.*;
25 import org.altusmetrum.AltosLib.*;
26 import org.altusmetrum.altosuilib.*;
28 public class AltosIdleMonitorUI extends AltosUIFrame implements AltosFlightDisplay, AltosFontListener, AltosIdleMonitorListener {
32 AltosInfoTable flightInfo;
33 AltosFlightStatus flightStatus;
34 AltosIdleMonitor thread;
39 if (thread != null && thread.isAlive()) {
43 } catch (InterruptedException ie) {}
57 public void set_font() {
59 flightInfo.set_font();
62 public void font_size_changed(int font_size) {
66 AltosFlightStatusUpdate status_update;
68 public void show(AltosState state, int crc_errors) {
69 status_update.saved_state = state;
71 pad.show(state, crc_errors);
72 flightStatus.show(state, crc_errors);
73 flightInfo.show(state, crc_errors);
74 } catch (Exception e) {
75 System.out.print("Show exception" + e);
79 public void update(final AltosState state) {
80 Runnable r = new Runnable() {
85 SwingUtilities.invokeLater(r);
89 AltosFreqList frequencies;
91 public AltosIdleMonitorUI(JFrame in_owner)
92 throws FileNotFoundException, AltosSerialInUseException, TimeoutException, InterruptedException {
94 device = AltosDeviceUIDialog.show(in_owner, Altos.product_any);
96 if (!device.matchProduct(Altos.product_altimeter))
99 serial = device.getSerial();
100 bag = getContentPane();
101 bag.setLayout(new GridBagLayout());
103 GridBagConstraints c = new GridBagConstraints();
105 setTitle(String.format("AltOS %s", device.toShortString()));
107 /* Stick frequency selector at top of table for telemetry monitoring */
108 if (remote && serial >= 0) {
110 frequencies = new AltosFreqList(AltosUIPreferences.frequency(serial));
111 frequencies.addActionListener(new ActionListener() {
112 public void actionPerformed(ActionEvent e) {
113 double frequency = frequencies.frequency();
114 thread.set_frequency(frequency);
115 AltosUIPreferences.set_frequency(device.getSerial(),
121 c.insets = new Insets(3, 3, 3, 3);
122 c.anchor = GridBagConstraints.WEST;
123 bag.add (frequencies, c);
127 /* Flight status is always visible */
128 flightStatus = new AltosFlightStatus();
131 c.fill = GridBagConstraints.HORIZONTAL;
134 bag.add(flightStatus, c);
137 /* The rest of the window uses a tabbed pane to
138 * show one of the alternate data views
140 pane = new JTabbedPane();
142 pad = new AltosPad();
143 pane.add("Launch Pad", pad);
145 flightInfo = new AltosInfoTable();
146 pane.add("Table", new JScrollPane(flightInfo));
148 /* Make the tabbed pane use the rest of the window space */
151 c.fill = GridBagConstraints.BOTH;
157 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
159 AltosUIPreferences.register_font_listener(this);
161 addWindowListener(new WindowAdapter() {
163 public void windowClosing(WindowEvent e) {
167 AltosUIPreferences.unregister_font_listener(AltosIdleMonitorUI.this);
174 thread = new AltosIdleMonitor((AltosIdleMonitorListener) this, (AltosLink) new AltosSerial (device), (boolean) remote);
176 status_update = new AltosFlightStatusUpdate(flightStatus);
178 new javax.swing.Timer(100, status_update).start();