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.*;
27 public class AltosIdleMonitorUI extends AltosFrame implements AltosFlightDisplay, AltosFontListener, AltosIdleMonitorListener {
31 AltosInfoTable flightInfo;
32 AltosFlightStatus flightStatus;
33 AltosIdleMonitor thread;
38 if (thread != null && thread.isAlive()) {
42 } catch (InterruptedException ie) {}
56 public void set_font() {
58 flightInfo.set_font();
61 public void font_size_changed(int font_size) {
65 AltosFlightStatusUpdate status_update;
67 public void show(AltosState state, int crc_errors) {
68 status_update.saved_state = state;
70 pad.show(state, crc_errors);
71 flightStatus.show(state, crc_errors);
72 flightInfo.show(state, crc_errors);
73 } catch (Exception e) {
74 System.out.print("Show exception" + e);
78 public void update(final AltosState state) {
79 Runnable r = new Runnable() {
84 SwingUtilities.invokeLater(r);
88 AltosFreqList frequencies;
90 public AltosIdleMonitorUI(JFrame in_owner)
91 throws FileNotFoundException, AltosSerialInUseException, TimeoutException, InterruptedException {
93 device = AltosDeviceDialog.show(in_owner, Altos.product_any);
95 if (!device.matchProduct(Altos.product_altimeter))
98 serial = device.getSerial();
99 bag = getContentPane();
100 bag.setLayout(new GridBagLayout());
102 GridBagConstraints c = new GridBagConstraints();
104 setTitle(String.format("AltOS %s", device.toShortString()));
106 /* Stick frequency selector at top of table for telemetry monitoring */
107 if (remote && serial >= 0) {
109 frequencies = new AltosFreqList(AltosUIPreferences.frequency(serial));
110 frequencies.addActionListener(new ActionListener() {
111 public void actionPerformed(ActionEvent e) {
112 double frequency = frequencies.frequency();
113 thread.set_frequency(frequency);
114 AltosUIPreferences.set_frequency(device.getSerial(),
120 c.insets = new Insets(3, 3, 3, 3);
121 c.anchor = GridBagConstraints.WEST;
122 bag.add (frequencies, c);
126 /* Flight status is always visible */
127 flightStatus = new AltosFlightStatus();
130 c.fill = GridBagConstraints.HORIZONTAL;
133 bag.add(flightStatus, c);
136 /* The rest of the window uses a tabbed pane to
137 * show one of the alternate data views
139 pane = new JTabbedPane();
141 pad = new AltosPad();
142 pane.add("Launch Pad", pad);
144 flightInfo = new AltosInfoTable();
145 pane.add("Table", new JScrollPane(flightInfo));
147 /* Make the tabbed pane use the rest of the window space */
150 c.fill = GridBagConstraints.BOTH;
156 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
158 AltosUIPreferences.register_font_listener(this);
160 addWindowListener(new WindowAdapter() {
162 public void windowClosing(WindowEvent e) {
166 AltosUIPreferences.unregister_font_listener(AltosIdleMonitorUI.this);
173 thread = new AltosIdleMonitor((AltosIdleMonitorListener) this, (AltosLink) new AltosSerial (device), (boolean) remote);
175 status_update = new AltosFlightStatusUpdate(flightStatus);
177 new javax.swing.Timer(100, status_update).start();