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.*;
25 import javax.swing.event.*;
29 import java.util.prefs.*;
30 import java.util.concurrent.LinkedBlockingQueue;
33 import altosui.AltosSerial;
34 import altosui.AltosSerialMonitor;
35 import altosui.AltosRecord;
36 import altosui.AltosTelemetry;
37 import altosui.AltosState;
38 import altosui.AltosDeviceDialog;
39 import altosui.AltosPreferences;
40 import altosui.AltosLog;
41 import altosui.AltosVoice;
42 import altosui.AltosFlightStatusTableModel;
43 import altosui.AltosFlightInfoTableModel;
47 public class AltosConfigUI
49 implements ActionListener, ItemListener, DocumentListener
57 JLabel main_deploy_label;
58 JLabel apogee_delay_label;
59 JLabel radio_channel_label;
60 JLabel callsign_label;
68 JComboBox main_deploy_value;
69 JComboBox apogee_delay_value;
70 JComboBox radio_channel_value;
71 JTextField callsign_value;
77 ActionListener listener;
79 static String[] main_deploy_values = {
80 "100", "150", "200", "250", "300", "350",
84 static String[] apogee_delay_values = {
85 "0", "1", "2", "3", "4", "5"
88 static String[] radio_channel_values = new String[10];
90 for (int i = 0; i <= 9; i++)
91 radio_channel_values[i] = String.format("Channel %1d (%7.3fMHz)",
92 i, 434.550 + i * 0.1);
95 /* A window listener to catch closing events and tell the config code */
96 class ConfigListener extends WindowAdapter {
99 public ConfigListener(AltosConfigUI this_ui) {
103 public void windowClosing(WindowEvent e) {
104 ui.actionPerformed(new ActionEvent(e.getSource(),
105 ActionEvent.ACTION_PERFORMED,
110 /* Build the UI using a grid bag */
111 public AltosConfigUI(JFrame in_owner) {
112 super (in_owner, "Configure TeleMetrum", false);
115 GridBagConstraints c;
117 Insets il = new Insets(4,4,4,4);
118 Insets ir = new Insets(4,4,4,4);
120 pane = getContentPane();
121 pane.setLayout(new GridBagLayout());
124 c = new GridBagConstraints();
125 c.gridx = 0; c.gridy = 0;
127 c.fill = GridBagConstraints.NONE;
128 c.anchor = GridBagConstraints.LINE_START;
130 product_label = new JLabel("Product:");
131 pane.add(product_label, c);
133 c = new GridBagConstraints();
134 c.gridx = 3; c.gridy = 0;
136 c.fill = GridBagConstraints.HORIZONTAL;
138 c.anchor = GridBagConstraints.LINE_START;
140 product_value = new JLabel("");
141 pane.add(product_value, c);
144 c = new GridBagConstraints();
145 c.gridx = 0; c.gridy = 1;
147 c.fill = GridBagConstraints.NONE;
148 c.anchor = GridBagConstraints.LINE_START;
151 version_label = new JLabel("Software version:");
152 pane.add(version_label, c);
154 c = new GridBagConstraints();
155 c.gridx = 3; c.gridy = 1;
157 c.fill = GridBagConstraints.HORIZONTAL;
159 c.anchor = GridBagConstraints.LINE_START;
162 version_value = new JLabel("");
163 pane.add(version_value, c);
166 c = new GridBagConstraints();
167 c.gridx = 0; c.gridy = 2;
169 c.fill = GridBagConstraints.NONE;
170 c.anchor = GridBagConstraints.LINE_START;
173 serial_label = new JLabel("Serial:");
174 pane.add(serial_label, c);
176 c = new GridBagConstraints();
177 c.gridx = 3; c.gridy = 2;
179 c.fill = GridBagConstraints.HORIZONTAL;
181 c.anchor = GridBagConstraints.LINE_START;
184 serial_value = new JLabel("");
185 pane.add(serial_value, c);
188 c = new GridBagConstraints();
189 c.gridx = 0; c.gridy = 3;
191 c.fill = GridBagConstraints.NONE;
192 c.anchor = GridBagConstraints.LINE_START;
195 main_deploy_label = new JLabel("Main Deploy Altitude(m):");
196 pane.add(main_deploy_label, c);
198 c = new GridBagConstraints();
199 c.gridx = 3; c.gridy = 3;
201 c.fill = GridBagConstraints.HORIZONTAL;
203 c.anchor = GridBagConstraints.LINE_START;
206 main_deploy_value = new JComboBox(main_deploy_values);
207 main_deploy_value.setEditable(true);
208 main_deploy_value.addItemListener(this);
209 pane.add(main_deploy_value, c);
212 c = new GridBagConstraints();
213 c.gridx = 0; c.gridy = 4;
215 c.fill = GridBagConstraints.NONE;
216 c.anchor = GridBagConstraints.LINE_START;
219 apogee_delay_label = new JLabel("Apogee Delay(s):");
220 pane.add(apogee_delay_label, c);
222 c = new GridBagConstraints();
223 c.gridx = 3; c.gridy = 4;
225 c.fill = GridBagConstraints.HORIZONTAL;
227 c.anchor = GridBagConstraints.LINE_START;
230 apogee_delay_value = new JComboBox(apogee_delay_values);
231 apogee_delay_value.setEditable(true);
232 apogee_delay_value.addItemListener(this);
233 pane.add(apogee_delay_value, c);
236 c = new GridBagConstraints();
237 c.gridx = 0; c.gridy = 5;
239 c.fill = GridBagConstraints.NONE;
240 c.anchor = GridBagConstraints.LINE_START;
243 radio_channel_label = new JLabel("Radio Channel:");
244 pane.add(radio_channel_label, c);
246 c = new GridBagConstraints();
247 c.gridx = 3; c.gridy = 5;
249 c.fill = GridBagConstraints.HORIZONTAL;
251 c.anchor = GridBagConstraints.LINE_START;
254 radio_channel_value = new JComboBox(radio_channel_values);
255 radio_channel_value.setEditable(false);
256 radio_channel_value.addItemListener(this);
257 pane.add(radio_channel_value, c);
260 c = new GridBagConstraints();
261 c.gridx = 0; c.gridy = 6;
263 c.fill = GridBagConstraints.NONE;
264 c.anchor = GridBagConstraints.LINE_START;
267 callsign_label = new JLabel("Callsign:");
268 pane.add(callsign_label, c);
270 c = new GridBagConstraints();
271 c.gridx = 3; c.gridy = 6;
273 c.fill = GridBagConstraints.HORIZONTAL;
275 c.anchor = GridBagConstraints.LINE_START;
278 callsign_value = new JTextField("N0CALL");
279 callsign_value.getDocument().addDocumentListener(this);
280 pane.add(callsign_value, c);
283 c = new GridBagConstraints();
284 c.gridx = 0; c.gridy = 7;
286 c.fill = GridBagConstraints.NONE;
287 c.anchor = GridBagConstraints.LINE_START;
289 save = new JButton("Save");
291 save.addActionListener(this);
292 save.setActionCommand("save");
294 c = new GridBagConstraints();
295 c.gridx = 0; c.gridy = 7;
297 c.fill = GridBagConstraints.NONE;
298 c.anchor = GridBagConstraints.CENTER;
300 reset = new JButton("Reset");
302 reset.addActionListener(this);
303 reset.setActionCommand("reset");
305 c = new GridBagConstraints();
306 c.gridx = 0; c.gridy = 7;
308 c.fill = GridBagConstraints.NONE;
309 c.anchor = GridBagConstraints.LINE_END;
311 close = new JButton("Close");
313 close.addActionListener(this);
314 close.setActionCommand("close");
316 addWindowListener(new ConfigListener(this));
319 /* Once the initial values are set, the config code will show the dialog */
320 public void make_visible() {
322 setLocationRelativeTo(owner);
326 /* If any values have been changed, confirm before closing */
327 public boolean check_dirty() {
329 Object[] options = { "Close anyway", "Keep editing" };
331 i = JOptionPane.showOptionDialog(this,
332 "Configuration modified, close anyway?",
333 "Configuration Modified",
334 JOptionPane.DEFAULT_OPTION,
335 JOptionPane.WARNING_MESSAGE,
336 null, options, options[1]);
343 /* Listen for events from our buttons */
344 public void actionPerformed(ActionEvent e) {
345 String cmd = e.getActionCommand();
347 if (cmd.equals("close"))
350 listener.actionPerformed(e);
351 if (cmd.equals("close")) {
358 /* ItemListener interface method */
359 public void itemStateChanged(ItemEvent e) {
363 /* DocumentListener interface methods */
364 public void changedUpdate(DocumentEvent e) {
368 public void insertUpdate(DocumentEvent e) {
372 public void removeUpdate(DocumentEvent e) {
376 /* Let the config code hook on a listener */
377 public void addActionListener(ActionListener l) {
381 /* set and get all of the dialog values */
382 public void set_product(String product) {
383 product_value.setText(product);
386 public void set_version(String version) {
387 version_value.setText(version);
390 public void set_serial(int serial) {
391 serial_value.setText(String.format("%d", serial));
394 public void set_main_deploy(int new_main_deploy) {
395 main_deploy_value.setSelectedItem(Integer.toString(new_main_deploy));
398 public int main_deploy() {
399 return Integer.parseInt(main_deploy_value.getSelectedItem().toString());
402 public void set_apogee_delay(int new_apogee_delay) {
403 apogee_delay_value.setSelectedItem(Integer.toString(new_apogee_delay));
406 public int apogee_delay() {
407 return Integer.parseInt(apogee_delay_value.getSelectedItem().toString());
410 public void set_radio_channel(int new_radio_channel) {
411 radio_channel_value.setSelectedIndex(new_radio_channel);
414 public int radio_channel() {
415 return radio_channel_value.getSelectedIndex();
418 public void set_callsign(String new_callsign) {
419 callsign_value.setText(new_callsign);
422 public String callsign() {
423 return callsign_value.getText();
426 public void set_clean() {