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.event.*;
25 import java.util.concurrent.*;
26 import org.altusmetrum.altoslib_1.*;
27 import org.altusmetrum.altosuilib_1.*;
29 public class AltosIdleMonitorUI extends AltosUIFrame implements AltosFlightDisplay, AltosFontListener, AltosIdleMonitorListener, DocumentListener {
33 AltosInfoTable flightInfo;
34 AltosFlightStatus flightStatus;
35 AltosIdleMonitor thread;
55 public void set_font() {
57 flightInfo.set_font();
60 public void font_size_changed(int font_size) {
64 AltosFlightStatusUpdate status_update;
66 public void show(AltosState state, AltosListenerState listener_state) {
67 status_update.saved_state = state;
69 pad.show(state, listener_state);
70 flightStatus.show(state, listener_state);
71 flightInfo.show(state, listener_state);
72 } catch (Exception e) {
73 System.out.print("Show exception" + e);
77 public void update(final AltosState state, final AltosListenerState listener_state) {
78 Runnable r = new Runnable() {
80 show(state, listener_state);
83 SwingUtilities.invokeLater(r);
87 AltosFreqList frequencies;
88 JTextField callsign_value;
90 /* DocumentListener interface methods */
91 public void changedUpdate(DocumentEvent e) {
92 if (callsign_value != null) {
93 String callsign = callsign_value.getText();
94 thread.set_callsign(callsign);
95 AltosUIPreferences.set_callsign(callsign);
99 public void insertUpdate(DocumentEvent e) {
103 public void removeUpdate(DocumentEvent e) {
109 public GridBagConstraints constraints (int x, int width, int fill) {
110 GridBagConstraints c = new GridBagConstraints();
111 Insets insets = new Insets(4, 4, 4, 4);
116 c.anchor = GridBagConstraints.CENTER;
118 c.anchor = GridBagConstraints.EAST;
120 c.anchor = GridBagConstraints.WEST;
127 public GridBagConstraints constraints(int x, int width) {
128 return constraints(x, width, GridBagConstraints.NONE);
131 public AltosIdleMonitorUI(JFrame in_owner)
132 throws FileNotFoundException, AltosSerialInUseException, TimeoutException, InterruptedException {
134 device = AltosDeviceUIDialog.show(in_owner, Altos.product_any);
136 if (!device.matchProduct(Altos.product_altimeter))
139 serial = device.getSerial();
140 bag = getContentPane();
141 bag.setLayout(new GridBagLayout());
143 setTitle(String.format("AltOS %s", device.toShortString()));
145 /* Stick frequency selector at top of table for telemetry monitoring */
146 if (remote && serial >= 0) {
148 frequencies = new AltosFreqList(AltosUIPreferences.frequency(serial));
149 frequencies.addActionListener(new ActionListener() {
150 public void actionPerformed(ActionEvent e) {
151 double frequency = frequencies.frequency();
152 thread.set_frequency(frequency);
153 AltosUIPreferences.set_frequency(device.getSerial(),
157 bag.add (frequencies, constraints(0, 1));
158 bag.add (new JLabel("Callsign:"), constraints(1, 1));
159 /* Add callsign configuration */
160 callsign_value = new JTextField(AltosUIPreferences.callsign());
161 callsign_value.getDocument().addDocumentListener(this);
162 callsign_value.setToolTipText("Callsign sent in packet mode");
163 bag.add(callsign_value, constraints(2, 1, GridBagConstraints.BOTH));
168 /* Flight status is always visible */
169 flightStatus = new AltosFlightStatus();
170 bag.add(flightStatus, constraints(0, 3, GridBagConstraints.HORIZONTAL));
173 /* The rest of the window uses a tabbed pane to
174 * show one of the alternate data views
176 pane = new JTabbedPane();
178 pad = new AltosPad();
179 pane.add("Launch Pad", pad);
181 flightInfo = new AltosInfoTable();
182 pane.add("Table", new JScrollPane(flightInfo));
184 /* Make the tabbed pane use the rest of the window space */
185 bag.add(pane, constraints(0, 3, GridBagConstraints.BOTH));
187 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
189 AltosUIPreferences.register_font_listener(this);
191 addWindowListener(new WindowAdapter() {
193 public void windowClosing(WindowEvent e) {
197 AltosUIPreferences.unregister_font_listener(AltosIdleMonitorUI.this);
204 thread = new AltosIdleMonitor((AltosIdleMonitorListener) this, (AltosLink) new AltosSerial (device), (boolean) remote);
206 status_update = new AltosFlightStatusUpdate(flightStatus);
208 new javax.swing.Timer(100, status_update).start();