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 org.altusmetrum.altoslib_9.*;
26 import org.altusmetrum.altosuilib_9.*;
28 public class AltosConfigUI
30 implements ActionListener, ItemListener, DocumentListener, AltosConfigValues, AltosUnitsListener
37 JLabel main_deploy_label;
38 JLabel apogee_delay_label;
39 JLabel apogee_lockout_label;
40 JLabel frequency_label;
41 JLabel radio_calibration_label;
42 JLabel radio_frequency_label;
43 JLabel radio_enable_label;
45 JLabel aprs_interval_label;
46 JLabel aprs_ssid_label;
47 JLabel aprs_format_label;
48 JLabel flight_log_max_label;
49 JLabel ignite_mode_label;
50 JLabel pad_orientation_label;
51 JLabel callsign_label;
53 JLabel tracker_motion_label;
54 JLabel tracker_interval_label;
62 JComboBox<String> main_deploy_value;
63 JComboBox<String> apogee_delay_value;
64 JComboBox<String> apogee_lockout_value;
65 AltosUIFreqList radio_frequency_value;
66 JLabel radio_calibration_value;
67 JRadioButton radio_enable_value;
68 AltosUIRateList rate_value;
69 JComboBox<String> aprs_interval_value;
70 JComboBox<Integer> aprs_ssid_value;
71 JComboBox<String> aprs_format_value;
72 JComboBox<String> flight_log_max_value;
73 JComboBox<String> ignite_mode_value;
74 JComboBox<String> pad_orientation_value;
75 JTextField callsign_value;
76 JComboBox<String> beep_value;
77 JComboBox<String> tracker_motion_value;
78 JComboBox<String> tracker_interval_value;
88 double pyro_firing_time;
90 ActionListener listener;
92 static String[] main_deploy_values_m = {
93 "100", "150", "200", "250", "300", "350",
97 static String[] main_deploy_values_ft = {
98 "250", "500", "750", "1000", "1250", "1500",
102 static String[] apogee_delay_values = {
103 "0", "1", "2", "3", "4", "5"
106 static String[] apogee_lockout_values = {
107 "0", "5", "10", "15", "20"
110 static String[] ignite_mode_values = {
116 static String[] aprs_interval_values = {
123 static Integer[] aprs_ssid_values = {
124 0, 1, 2 ,3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
127 static String[] beep_values = {
133 static String[] pad_orientation_values = {
138 static String[] tracker_motion_values_m = {
145 static String[] tracker_motion_values_ft = {
152 static String[] tracker_interval_values = {
159 /* A window listener to catch closing events and tell the config code */
160 class ConfigListener extends WindowAdapter {
163 public ConfigListener(AltosConfigUI this_ui) {
167 public void windowClosing(WindowEvent e) {
168 ui.actionPerformed(new ActionEvent(e.getSource(),
169 ActionEvent.ACTION_PERFORMED,
174 boolean is_telemini_v1() {
175 String product = product_value.getText();
176 return product != null && product.startsWith("TeleMini-v1");
179 boolean is_telemini() {
180 String product = product_value.getText();
181 return product != null && product.startsWith("TeleMini");
184 boolean is_easymini() {
185 String product = product_value.getText();
186 return product != null && product.startsWith("EasyMini");
189 boolean is_telemetrum() {
190 String product = product_value.getText();
191 return product != null && product.startsWith("TeleMetrum");
194 void set_radio_enable_tool_tip() {
195 if (radio_enable_value.isEnabled())
196 radio_enable_value.setToolTipText("Enable/Disable telemetry and RDF transmissions");
198 radio_enable_value.setToolTipText("Firmware version does not support disabling radio");
201 void set_rate_tool_tip() {
202 if (rate_value.isEnabled())
203 rate_value.setToolTipText("Select telemetry baud rate");
205 rate_value.setToolTipText("Firmware version does not support variable telemetry rates");
208 void set_aprs_interval_tool_tip() {
209 if (aprs_interval_value.isEnabled())
210 aprs_interval_value.setToolTipText("Enable APRS and set the interval between APRS reports");
212 aprs_interval_value.setToolTipText("Hardware doesn't support APRS");
215 void set_aprs_ssid_tool_tip() {
216 if (aprs_ssid_value.isEnabled())
217 aprs_ssid_value.setToolTipText("Set the APRS SSID (secondary station identifier)");
218 else if (aprs_ssid_value.isEnabled())
219 aprs_ssid_value.setToolTipText("Software version doesn't support setting the APRS SSID");
221 aprs_ssid_value.setToolTipText("Hardware doesn't support APRS");
224 void set_aprs_format_tool_tip() {
225 if (aprs_format_value.isEnabled())
226 aprs_format_value.setToolTipText("Set the APRS format (compressed/uncompressed)");
227 else if (aprs_format_value.isEnabled())
228 aprs_format_value.setToolTipText("Software version doesn't support setting the APRS format");
230 aprs_format_value.setToolTipText("Hardware doesn't support APRS");
233 void set_flight_log_max_tool_tip() {
234 if (flight_log_max_value.isEnabled())
235 flight_log_max_value.setToolTipText("Size reserved for each flight log (in kB)");
237 if (is_telemini_v1())
238 flight_log_max_value.setToolTipText("TeleMini-v1 stores only one flight");
240 flight_log_max_value.setToolTipText("Cannot set max value with flight logs in memory");
244 void set_ignite_mode_tool_tip() {
245 if (ignite_mode_value.isEnabled())
246 ignite_mode_value.setToolTipText("Select when igniters will be fired");
248 ignite_mode_value.setToolTipText("Older firmware could not select ignite mode");
251 void set_pad_orientation_tool_tip() {
252 if (pad_orientation_value.isEnabled())
253 pad_orientation_value.setToolTipText("How will the computer be mounted in the airframe");
256 pad_orientation_value.setToolTipText("Older TeleMetrum firmware must fly antenna forward");
257 else if (is_telemini() || is_easymini())
258 pad_orientation_value.setToolTipText("TeleMini and EasyMini don't care how they are mounted");
260 pad_orientation_value.setToolTipText("Can't select orientation");
264 void set_beep_tool_tip() {
265 if (beep_value.isEnabled())
266 beep_value.setToolTipText("What frequency the beeper will sound at");
268 beep_value.setToolTipText("Older firmware could not select beeper frequency");
271 /* Build the UI using a grid bag */
272 public AltosConfigUI(JFrame in_owner, boolean remote) {
273 super (in_owner, "Configure Flight Computer", false);
276 GridBagConstraints c;
279 Insets il = new Insets(4,4,4,4);
280 Insets ir = new Insets(4,4,4,4);
282 pane = getContentPane();
283 pane.setLayout(new GridBagLayout());
286 c = new GridBagConstraints();
287 c.gridx = 0; c.gridy = row;
289 c.fill = GridBagConstraints.NONE;
290 c.anchor = GridBagConstraints.LINE_START;
292 product_label = new JLabel("Product:");
293 pane.add(product_label, c);
295 c = new GridBagConstraints();
296 c.gridx = 4; c.gridy = row;
298 c.fill = GridBagConstraints.HORIZONTAL;
300 c.anchor = GridBagConstraints.LINE_START;
302 product_value = new JLabel("");
303 pane.add(product_value, c);
307 c = new GridBagConstraints();
308 c.gridx = 0; c.gridy = row;
310 c.fill = GridBagConstraints.NONE;
311 c.anchor = GridBagConstraints.LINE_START;
314 version_label = new JLabel("Software version:");
315 pane.add(version_label, c);
317 c = new GridBagConstraints();
318 c.gridx = 4; c.gridy = row;
320 c.fill = GridBagConstraints.HORIZONTAL;
322 c.anchor = GridBagConstraints.LINE_START;
325 version_value = new JLabel("");
326 pane.add(version_value, c);
330 c = new GridBagConstraints();
331 c.gridx = 0; c.gridy = row;
333 c.fill = GridBagConstraints.NONE;
334 c.anchor = GridBagConstraints.LINE_START;
337 serial_label = new JLabel("Serial:");
338 pane.add(serial_label, c);
340 c = new GridBagConstraints();
341 c.gridx = 4; c.gridy = row;
343 c.fill = GridBagConstraints.HORIZONTAL;
345 c.anchor = GridBagConstraints.LINE_START;
348 serial_value = new JLabel("");
349 pane.add(serial_value, c);
353 c = new GridBagConstraints();
354 c.gridx = 0; c.gridy = row;
356 c.fill = GridBagConstraints.NONE;
357 c.anchor = GridBagConstraints.LINE_START;
360 main_deploy_label = new JLabel(get_main_deploy_label());
361 pane.add(main_deploy_label, c);
363 c = new GridBagConstraints();
364 c.gridx = 4; c.gridy = row;
366 c.fill = GridBagConstraints.HORIZONTAL;
368 c.anchor = GridBagConstraints.LINE_START;
371 main_deploy_value = new JComboBox<String>(main_deploy_values());
372 main_deploy_value.setEditable(true);
373 main_deploy_value.addItemListener(this);
374 pane.add(main_deploy_value, c);
375 main_deploy_value.setToolTipText("Height above pad altitude to fire main charge");
379 c = new GridBagConstraints();
380 c.gridx = 0; c.gridy = row;
382 c.fill = GridBagConstraints.NONE;
383 c.anchor = GridBagConstraints.LINE_START;
386 apogee_delay_label = new JLabel("Apogee Delay(s):");
387 pane.add(apogee_delay_label, c);
389 c = new GridBagConstraints();
390 c.gridx = 4; c.gridy = row;
392 c.fill = GridBagConstraints.HORIZONTAL;
394 c.anchor = GridBagConstraints.LINE_START;
397 apogee_delay_value = new JComboBox<String>(apogee_delay_values);
398 apogee_delay_value.setEditable(true);
399 apogee_delay_value.addItemListener(this);
400 pane.add(apogee_delay_value, c);
401 apogee_delay_value.setToolTipText("Delay after apogee before charge fires");
405 c = new GridBagConstraints();
406 c.gridx = 0; c.gridy = row;
408 c.fill = GridBagConstraints.NONE;
409 c.anchor = GridBagConstraints.LINE_START;
412 apogee_lockout_label = new JLabel("Apogee Lockout(s):");
413 pane.add(apogee_lockout_label, c);
415 c = new GridBagConstraints();
416 c.gridx = 4; c.gridy = row;
418 c.fill = GridBagConstraints.HORIZONTAL;
420 c.anchor = GridBagConstraints.LINE_START;
423 apogee_lockout_value = new JComboBox<String>(apogee_lockout_values);
424 apogee_lockout_value.setEditable(true);
425 apogee_lockout_value.addItemListener(this);
426 pane.add(apogee_lockout_value, c);
427 apogee_lockout_value.setToolTipText("Time after boost while apogee detection is locked out");
431 c = new GridBagConstraints();
432 c.gridx = 0; c.gridy = row;
434 c.fill = GridBagConstraints.NONE;
435 c.anchor = GridBagConstraints.LINE_START;
438 radio_frequency_label = new JLabel("Frequency:");
439 pane.add(radio_frequency_label, c);
441 c = new GridBagConstraints();
442 c.gridx = 4; c.gridy = row;
444 c.fill = GridBagConstraints.HORIZONTAL;
446 c.anchor = GridBagConstraints.LINE_START;
449 radio_frequency_value = new AltosUIFreqList();
450 radio_frequency_value.addItemListener(this);
451 pane.add(radio_frequency_value, c);
452 radio_frequency_value.setToolTipText("Telemetry, RDF and packet frequency");
455 /* Radio Calibration */
456 c = new GridBagConstraints();
457 c.gridx = 0; c.gridy = row;
459 c.fill = GridBagConstraints.NONE;
460 c.anchor = GridBagConstraints.LINE_START;
463 radio_calibration_label = new JLabel("RF Calibration:");
464 pane.add(radio_calibration_label, c);
466 c = new GridBagConstraints();
467 c.gridx = 4; c.gridy = row;
469 c.fill = GridBagConstraints.HORIZONTAL;
471 c.anchor = GridBagConstraints.LINE_START;
474 radio_calibration_value = new JLabel(String.format("%d", 1186611));
475 pane.add(radio_calibration_value, c);
479 c = new GridBagConstraints();
480 c.gridx = 0; c.gridy = row;
482 c.fill = GridBagConstraints.NONE;
483 c.anchor = GridBagConstraints.LINE_START;
486 radio_enable_label = new JLabel("Telemetry/RDF/APRS Enable:");
487 pane.add(radio_enable_label, c);
489 c = new GridBagConstraints();
490 c.gridx = 4; c.gridy = row;
492 c.fill = GridBagConstraints.HORIZONTAL;
494 c.anchor = GridBagConstraints.LINE_START;
497 radio_enable_value = new JRadioButton("Enabled");
498 radio_enable_value.addItemListener(this);
499 pane.add(radio_enable_value, c);
500 set_radio_enable_tool_tip();
504 c = new GridBagConstraints();
505 c.gridx = 0; c.gridy = row;
507 c.fill = GridBagConstraints.NONE;
508 c.anchor = GridBagConstraints.LINE_START;
511 rate_label = new JLabel("Telemetry baud rate:");
512 pane.add(rate_label, c);
514 c = new GridBagConstraints();
515 c.gridx = 4; c.gridy = row;
517 c.fill = GridBagConstraints.HORIZONTAL;
519 c.anchor = GridBagConstraints.LINE_START;
522 rate_value = new AltosUIRateList();
523 rate_value.addItemListener(this);
524 pane.add(rate_value, c);
529 c = new GridBagConstraints();
530 c.gridx = 0; c.gridy = row;
532 c.fill = GridBagConstraints.NONE;
533 c.anchor = GridBagConstraints.LINE_START;
536 aprs_interval_label = new JLabel("APRS Interval(s):");
537 pane.add(aprs_interval_label, c);
539 c = new GridBagConstraints();
540 c.gridx = 4; c.gridy = row;
542 c.fill = GridBagConstraints.HORIZONTAL;
544 c.anchor = GridBagConstraints.LINE_START;
547 aprs_interval_value = new JComboBox<String>(aprs_interval_values);
548 aprs_interval_value.setEditable(true);
549 aprs_interval_value.addItemListener(this);
550 pane.add(aprs_interval_value, c);
551 set_aprs_interval_tool_tip();
555 c = new GridBagConstraints();
556 c.gridx = 0; c.gridy = row;
558 c.fill = GridBagConstraints.NONE;
559 c.anchor = GridBagConstraints.LINE_START;
562 aprs_ssid_label = new JLabel("APRS SSID:");
563 pane.add(aprs_ssid_label, c);
565 c = new GridBagConstraints();
566 c.gridx = 4; c.gridy = row;
568 c.fill = GridBagConstraints.HORIZONTAL;
570 c.anchor = GridBagConstraints.LINE_START;
573 aprs_ssid_value = new JComboBox<Integer>(aprs_ssid_values);
574 aprs_ssid_value.setEditable(false);
575 aprs_ssid_value.addItemListener(this);
576 aprs_ssid_value.setMaximumRowCount(aprs_ssid_values.length);
577 pane.add(aprs_ssid_value, c);
578 set_aprs_ssid_tool_tip();
582 c = new GridBagConstraints();
583 c.gridx = 0; c.gridy = row;
585 c.fill = GridBagConstraints.NONE;
586 c.anchor = GridBagConstraints.LINE_START;
589 aprs_format_label = new JLabel("APRS format:");
590 pane.add(aprs_format_label, c);
592 c = new GridBagConstraints();
593 c.gridx = 4; c.gridy = row;
595 c.fill = GridBagConstraints.HORIZONTAL;
597 c.anchor = GridBagConstraints.LINE_START;
600 aprs_format_value = new JComboBox<String>(AltosLib.ao_aprs_format_name);
601 aprs_format_value.setEditable(false);
602 aprs_format_value.addItemListener(this);
603 aprs_format_value.setMaximumRowCount(AltosLib.ao_aprs_format_name.length);
604 pane.add(aprs_format_value, c);
605 set_aprs_format_tool_tip();
609 c = new GridBagConstraints();
610 c.gridx = 0; c.gridy = row;
612 c.fill = GridBagConstraints.NONE;
613 c.anchor = GridBagConstraints.LINE_START;
616 callsign_label = new JLabel("Callsign:");
617 pane.add(callsign_label, c);
619 c = new GridBagConstraints();
620 c.gridx = 4; c.gridy = row;
622 c.fill = GridBagConstraints.HORIZONTAL;
624 c.anchor = GridBagConstraints.LINE_START;
627 callsign_value = new JTextField(AltosUIPreferences.callsign());
628 callsign_value.getDocument().addDocumentListener(this);
629 pane.add(callsign_value, c);
630 callsign_value.setToolTipText("Callsign reported in telemetry data");
634 c = new GridBagConstraints();
635 c.gridx = 0; c.gridy = row;
637 c.fill = GridBagConstraints.NONE;
638 c.anchor = GridBagConstraints.LINE_START;
641 flight_log_max_label = new JLabel("Maximum Flight Log Size (kB):");
642 pane.add(flight_log_max_label, c);
644 c = new GridBagConstraints();
645 c.gridx = 4; c.gridy = row;
647 c.fill = GridBagConstraints.HORIZONTAL;
649 c.anchor = GridBagConstraints.LINE_START;
652 flight_log_max_value = new JComboBox<String>();
653 flight_log_max_value.setEditable(true);
654 flight_log_max_value.addItemListener(this);
655 pane.add(flight_log_max_value, c);
656 set_flight_log_max_tool_tip();
660 c = new GridBagConstraints();
661 c.gridx = 0; c.gridy = row;
663 c.fill = GridBagConstraints.NONE;
664 c.anchor = GridBagConstraints.LINE_START;
667 ignite_mode_label = new JLabel("Igniter Firing Mode:");
668 pane.add(ignite_mode_label, c);
670 c = new GridBagConstraints();
671 c.gridx = 4; c.gridy = row;
673 c.fill = GridBagConstraints.HORIZONTAL;
675 c.anchor = GridBagConstraints.LINE_START;
678 ignite_mode_value = new JComboBox<String>(ignite_mode_values);
679 ignite_mode_value.setEditable(false);
680 ignite_mode_value.addItemListener(this);
681 pane.add(ignite_mode_value, c);
682 set_ignite_mode_tool_tip();
685 /* Pad orientation */
686 c = new GridBagConstraints();
687 c.gridx = 0; c.gridy = row;
689 c.fill = GridBagConstraints.NONE;
690 c.anchor = GridBagConstraints.LINE_START;
693 pad_orientation_label = new JLabel("Pad Orientation:");
694 pane.add(pad_orientation_label, c);
696 c = new GridBagConstraints();
697 c.gridx = 4; c.gridy = row;
699 c.fill = GridBagConstraints.HORIZONTAL;
701 c.anchor = GridBagConstraints.LINE_START;
704 pad_orientation_value = new JComboBox<String>(pad_orientation_values);
705 pad_orientation_value.setEditable(false);
706 pad_orientation_value.addItemListener(this);
707 pane.add(pad_orientation_value, c);
708 set_pad_orientation_tool_tip();
712 c = new GridBagConstraints();
713 c.gridx = 0; c.gridy = row;
715 c.fill = GridBagConstraints.NONE;
716 c.anchor = GridBagConstraints.LINE_START;
719 beep_label = new JLabel("Beeper Frequency:");
720 pane.add(beep_label, c);
722 c = new GridBagConstraints();
723 c.gridx = 4; c.gridy = row;
725 c.fill = GridBagConstraints.HORIZONTAL;
727 c.anchor = GridBagConstraints.LINE_START;
730 beep_value = new JComboBox<String>(beep_values);
731 beep_value.setEditable(true);
732 beep_value.addItemListener(this);
733 pane.add(beep_value, c);
737 /* Tracker triger horiz distances */
738 c = new GridBagConstraints();
739 c.gridx = 0; c.gridy = row;
741 c.fill = GridBagConstraints.NONE;
742 c.anchor = GridBagConstraints.LINE_START;
745 tracker_motion_label = new JLabel(get_tracker_motion_label());
746 pane.add(tracker_motion_label, c);
748 c = new GridBagConstraints();
749 c.gridx = 4; c.gridy = row;
751 c.fill = GridBagConstraints.HORIZONTAL;
753 c.anchor = GridBagConstraints.LINE_START;
756 tracker_motion_value = new JComboBox<String>(tracker_motion_values());
757 tracker_motion_value.setEditable(true);
758 tracker_motion_value.addItemListener(this);
759 pane.add(tracker_motion_value, c);
762 /* Tracker triger vert distances */
763 c = new GridBagConstraints();
764 c.gridx = 0; c.gridy = row;
766 c.fill = GridBagConstraints.NONE;
767 c.anchor = GridBagConstraints.LINE_START;
770 tracker_interval_label = new JLabel("Position Reporting Interval(s):");
771 pane.add(tracker_interval_label, c);
773 c = new GridBagConstraints();
774 c.gridx = 4; c.gridy = row;
776 c.fill = GridBagConstraints.HORIZONTAL;
778 c.anchor = GridBagConstraints.LINE_START;
781 tracker_interval_value = new JComboBox<String>(tracker_interval_values);
782 tracker_interval_value.setEditable(true);
783 tracker_interval_value.addItemListener(this);
784 pane.add(tracker_interval_value, c);
785 set_tracker_tool_tip();
789 c = new GridBagConstraints();
790 c.gridx = 4; c.gridy = row;
792 c.fill = GridBagConstraints.HORIZONTAL;
793 c.anchor = GridBagConstraints.LINE_START;
796 pyro = new JButton("Configure Pyro Channels");
798 pyro.addActionListener(this);
799 pyro.setActionCommand("Pyro");
803 c = new GridBagConstraints();
804 c.gridx = 0; c.gridy = row;
806 c.fill = GridBagConstraints.NONE;
807 c.anchor = GridBagConstraints.LINE_START;
809 save = new JButton("Save");
811 save.addActionListener(this);
812 save.setActionCommand("Save");
814 c = new GridBagConstraints();
815 c.gridx = 2; c.gridy = row;
817 c.fill = GridBagConstraints.NONE;
818 c.anchor = GridBagConstraints.CENTER;
820 reset = new JButton("Reset");
822 reset.addActionListener(this);
823 reset.setActionCommand("Reset");
825 c = new GridBagConstraints();
826 c.gridx = 4; c.gridy = row;
828 c.fill = GridBagConstraints.NONE;
829 c.anchor = GridBagConstraints.CENTER;
831 reboot = new JButton("Reboot");
833 reboot.addActionListener(this);
834 reboot.setActionCommand("Reboot");
836 c = new GridBagConstraints();
837 c.gridx = 6; c.gridy = row;
839 c.fill = GridBagConstraints.NONE;
840 c.anchor = GridBagConstraints.LINE_END;
842 close = new JButton("Close");
844 close.addActionListener(this);
845 close.setActionCommand("Close");
847 addWindowListener(new ConfigListener(this));
848 AltosPreferences.register_units_listener(this);
851 /* Once the initial values are set, the config code will show the dialog */
852 public void make_visible() {
854 setLocationRelativeTo(owner);
858 /* If any values have been changed, confirm before closing */
859 public boolean check_dirty(String operation) {
861 Object[] options = { String.format("%s anyway", operation), "Keep editing" };
863 i = JOptionPane.showOptionDialog(this,
864 String.format("Configuration modified. %s anyway?", operation),
865 "Configuration Modified",
866 JOptionPane.DEFAULT_OPTION,
867 JOptionPane.WARNING_MESSAGE,
868 null, options, options[1]);
877 save.setEnabled(true);
880 public void set_clean() {
882 save.setEnabled(false);
885 AltosConfigPyroUI pyro_ui;
887 public void dispose() {
890 AltosPreferences.unregister_units_listener(this);
894 /* Listen for events from our buttons */
895 public void actionPerformed(ActionEvent e) {
896 String cmd = e.getActionCommand();
898 if (cmd.equals("Pyro")) {
899 if (pyro_ui == null && pyros != null)
900 pyro_ui = new AltosConfigPyroUI(this, pyros, pyro_firing_time);
902 pyro_ui.make_visible();
906 if (cmd.equals("Close") || cmd.equals("Reboot"))
907 if (!check_dirty(cmd))
909 listener.actionPerformed(e);
910 if (cmd.equals("Close") || cmd.equals("Reboot")) {
917 /* ItemListener interface method */
918 public void itemStateChanged(ItemEvent e) {
922 /* DocumentListener interface methods */
923 public void changedUpdate(DocumentEvent e) {
927 public void insertUpdate(DocumentEvent e) {
931 public void removeUpdate(DocumentEvent e) {
935 /* Let the config code hook on a listener */
936 public void addActionListener(ActionListener l) {
940 /* set and get all of the dialog values */
941 public void set_product(String product) {
942 radio_frequency_value.set_product(product);
943 product_value.setText(product);
944 set_pad_orientation_tool_tip();
945 set_flight_log_max_tool_tip();
948 public void set_version(String version) {
949 version_value.setText(version);
952 public void set_serial(int serial) {
953 radio_frequency_value.set_serial(serial);
954 serial_value.setText(String.format("%d", serial));
957 public void set_altitude_32(int altitude_32) {
960 public void set_main_deploy(int new_main_deploy) {
961 main_deploy_value.setSelectedItem(AltosConvert.height.say(new_main_deploy));
962 main_deploy_value.setEnabled(new_main_deploy >= 0);
964 main_deploy_value.setVisible(new_main_deploy >= 0);
965 main_deploy_label.setVisible(new_main_deploy >= 0);
969 public int main_deploy() throws AltosConfigDataException {
970 String str = main_deploy_value.getSelectedItem().toString();
972 return (int) (AltosConvert.height.parse_locale(str) + 0.5);
973 } catch (ParseException pe) {
974 throw new AltosConfigDataException("invalid main deploy height %s", str);
978 String get_main_deploy_label() {
979 return String.format("Main Deploy Altitude(%s):", AltosConvert.height.show_units());
982 String[] main_deploy_values() {
983 if (AltosConvert.imperial_units)
984 return main_deploy_values_ft;
986 return main_deploy_values_m;
989 void set_main_deploy_values() {
990 String[] v = main_deploy_values();
991 while (main_deploy_value.getItemCount() > 0)
992 main_deploy_value.removeItemAt(0);
993 for (int i = 0; i < v.length; i++)
994 main_deploy_value.addItem(v[i]);
995 main_deploy_value.setMaximumRowCount(v.length);
998 public void units_changed(boolean imperial_units) {
999 boolean was_dirty = dirty;
1001 String v = main_deploy_value.getSelectedItem().toString();
1002 main_deploy_label.setText(get_main_deploy_label());
1003 set_main_deploy_values();
1005 int m = (int) (AltosConvert.height.parse_locale(v, !imperial_units) + 0.5);
1007 } catch (ParseException pe) {
1010 if (tracker_motion_value.isEnabled()) {
1011 String motion = tracker_motion_value.getSelectedItem().toString();
1012 tracker_motion_label.setText(get_tracker_motion_label());
1013 set_tracker_motion_values();
1015 int m = (int) (AltosConvert.height.parse_locale(motion, !imperial_units) + 0.5);
1016 set_tracker_motion(m);
1017 } catch (ParseException pe) {
1025 public void set_apogee_delay(int new_apogee_delay) {
1026 apogee_delay_value.setVisible(new_apogee_delay >= 0);
1027 apogee_delay_label.setVisible(new_apogee_delay >= 0);
1029 apogee_delay_value.setSelectedItem(Integer.toString(new_apogee_delay));
1030 apogee_delay_value.setEnabled(new_apogee_delay >= 0);
1033 private int parse_int(String name, String s, boolean split) throws AltosConfigDataException {
1036 v = s.split("\\s+")[0];
1038 return Integer.parseInt(v);
1039 } catch (NumberFormatException ne) {
1040 throw new AltosConfigDataException("Invalid %s \"%s\"", name, s);
1044 public int apogee_delay() throws AltosConfigDataException {
1045 return parse_int("apogee delay", apogee_delay_value.getSelectedItem().toString(), false);
1048 public void set_apogee_lockout(int new_apogee_lockout) {
1049 apogee_lockout_value.setSelectedItem(Integer.toString(new_apogee_lockout));
1050 apogee_lockout_value.setEnabled(new_apogee_lockout >= 0);
1052 apogee_lockout_value.setVisible(new_apogee_lockout >= 0);
1053 apogee_lockout_label.setVisible(new_apogee_lockout >= 0);
1056 public int apogee_lockout() throws AltosConfigDataException {
1057 return parse_int("apogee lockout", apogee_lockout_value.getSelectedItem().toString(), false);
1060 public void set_radio_frequency(double new_radio_frequency) {
1061 radio_frequency_label.setVisible(new_radio_frequency >= 0);
1062 radio_frequency_value.set_frequency(new_radio_frequency);
1065 public double radio_frequency() {
1066 return radio_frequency_value.frequency();
1069 public void set_radio_calibration(int new_radio_calibration) {
1070 radio_calibration_value.setVisible(new_radio_calibration >= 0);
1071 radio_calibration_label.setVisible(new_radio_calibration >= 0);
1073 if (new_radio_calibration < 0)
1074 radio_calibration_value.setText("Disabled");
1076 radio_calibration_value.setText(String.format("%d", new_radio_calibration));
1079 public void set_radio_enable(int new_radio_enable) {
1080 radio_enable_label.setVisible(new_radio_enable >= 0);
1081 radio_enable_value.setVisible(new_radio_enable >= 0);
1083 if (new_radio_enable >= 0) {
1084 radio_enable_value.setSelected(new_radio_enable > 0);
1085 radio_enable_value.setEnabled(true);
1087 radio_enable_value.setSelected(true);
1088 radio_enable_value.setEnabled(false);
1090 set_radio_enable_tool_tip();
1093 public int radio_enable() {
1094 if (radio_enable_value.isEnabled())
1095 return radio_enable_value.isSelected() ? 1 : 0;
1100 public void set_telemetry_rate(int new_rate) {
1101 rate_label.setVisible(new_rate >= 0);
1103 rate_value.set_rate(new_rate);
1106 public int telemetry_rate() {
1107 return rate_value.rate();
1110 public void set_callsign(String new_callsign) {
1111 callsign_value.setVisible(new_callsign != null);
1112 callsign_label.setVisible(new_callsign != null);
1114 callsign_value.setText(new_callsign);
1117 public String callsign() {
1118 return callsign_value.getText();
1121 int flight_log_max_limit;
1124 public String flight_log_max_label(int flight_log_max) {
1125 if (flight_log_max_limit != 0) {
1126 int nflight = flight_log_max_limit / flight_log_max;
1127 String plural = nflight > 1 ? "s" : "";
1129 return String.format("%d (%d flight%s)", flight_log_max, nflight, plural);
1131 return String.format("%d", flight_log_max);
1134 public void set_flight_log_max(int new_flight_log_max) {
1135 flight_log_max_value.setVisible(new_flight_log_max >= 0);
1136 flight_log_max_label.setVisible(new_flight_log_max >= 0);
1138 flight_log_max_value.setSelectedItem(flight_log_max_label(new_flight_log_max));
1139 flight_log_max = new_flight_log_max;
1140 set_flight_log_max_tool_tip();
1143 public void set_flight_log_max_enabled(boolean enable) {
1144 flight_log_max_value.setEnabled(enable);
1145 set_flight_log_max_tool_tip();
1148 public int flight_log_max() throws AltosConfigDataException {
1149 return parse_int("flight log max", flight_log_max_value.getSelectedItem().toString(), true);
1152 public void set_flight_log_max_limit(int new_flight_log_max_limit) {
1153 flight_log_max_limit = new_flight_log_max_limit;
1154 flight_log_max_value.removeAllItems();
1155 for (int i = 8; i >= 1; i--) {
1156 int size = flight_log_max_limit / i;
1157 flight_log_max_value.addItem(String.format("%d (%d flights)", size, i));
1159 if (flight_log_max != 0)
1160 set_flight_log_max(flight_log_max);
1163 public void set_ignite_mode(int new_ignite_mode) {
1164 ignite_mode_value.setVisible(new_ignite_mode >= 0);
1165 ignite_mode_label.setVisible(new_ignite_mode >= 0);
1167 if (new_ignite_mode >= ignite_mode_values.length)
1168 new_ignite_mode = 0;
1169 if (new_ignite_mode < 0) {
1170 ignite_mode_value.setEnabled(false);
1171 new_ignite_mode = 0;
1173 ignite_mode_value.setEnabled(true);
1175 ignite_mode_value.setSelectedIndex(new_ignite_mode);
1176 set_ignite_mode_tool_tip();
1179 public int ignite_mode() {
1180 if (ignite_mode_value.isEnabled())
1181 return ignite_mode_value.getSelectedIndex();
1187 public void set_pad_orientation(int new_pad_orientation) {
1188 pad_orientation_value.setVisible(new_pad_orientation >= 0);
1189 pad_orientation_label.setVisible(new_pad_orientation >= 0);
1191 if (new_pad_orientation >= pad_orientation_values.length)
1192 new_pad_orientation = 0;
1193 if (new_pad_orientation < 0)
1194 new_pad_orientation = 0;
1195 pad_orientation_value.setSelectedIndex(new_pad_orientation);
1196 set_pad_orientation_tool_tip();
1199 public int pad_orientation() {
1200 if (pad_orientation_value.isEnabled())
1201 return pad_orientation_value.getSelectedIndex();
1206 public void set_beep(int new_beep) {
1207 beep_value.setVisible(new_beep >= 0);
1208 beep_label.setVisible(new_beep >= 0);
1210 int new_freq = (int) Math.floor (AltosConvert.beep_value_to_freq(new_beep) + 0.5);
1211 for (int i = 0; i < beep_values.length; i++)
1212 if (new_beep == AltosConvert.beep_freq_to_value(Integer.parseInt(beep_values[i]))) {
1213 beep_value.setSelectedIndex(i);
1214 set_beep_tool_tip();
1217 beep_value.setSelectedItem(String.format("%d", new_freq));
1218 beep_value.setEnabled(new_beep >= 0);
1219 set_beep_tool_tip();
1223 if (beep_value.isEnabled())
1224 return AltosConvert.beep_freq_to_value(Integer.parseInt(beep_value.getSelectedItem().toString()));
1229 String[] tracker_motion_values() {
1230 if (AltosConvert.imperial_units)
1231 return tracker_motion_values_ft;
1233 return tracker_motion_values_m;
1236 void set_tracker_motion_values() {
1237 String[] v = tracker_motion_values();
1238 while (tracker_motion_value.getItemCount() > 0)
1239 tracker_motion_value.removeItemAt(0);
1240 for (int i = 0; i < v.length; i++)
1241 tracker_motion_value.addItem(v[i]);
1242 tracker_motion_value.setMaximumRowCount(v.length);
1245 String get_tracker_motion_label() {
1246 return String.format("Logging Trigger Motion (%s):", AltosConvert.height.show_units());
1249 void set_tracker_tool_tip() {
1250 if (tracker_motion_value.isEnabled())
1251 tracker_motion_value.setToolTipText("How far the device must move before logging");
1253 tracker_motion_value.setToolTipText("This device doesn't disable logging when stationary");
1254 if (tracker_interval_value.isEnabled())
1255 tracker_interval_value.setToolTipText("How often to report GPS position");
1257 tracker_interval_value.setToolTipText("This device can't configure interval");
1260 public void set_tracker_motion(int tracker_motion) {
1261 tracker_motion_label.setVisible(tracker_motion >= 0);
1262 tracker_motion_value.setVisible(tracker_motion >= 0);
1264 if (tracker_motion < 0) {
1265 tracker_motion_value.setEnabled(false);
1267 tracker_motion_value.setEnabled(true);
1268 tracker_motion_value.setSelectedItem(AltosConvert.height.say(tracker_motion));
1272 public int tracker_motion() throws AltosConfigDataException {
1273 String str = tracker_motion_value.getSelectedItem().toString();
1275 return (int) (AltosConvert.height.parse_locale(str) + 0.5);
1276 } catch (ParseException pe) {
1277 throw new AltosConfigDataException("invalid tracker motion %s", str);
1281 public void set_tracker_interval(int tracker_interval) {
1282 tracker_interval_label.setVisible(tracker_interval >= 0);
1283 tracker_interval_value.setVisible(tracker_interval >= 0);
1285 if (tracker_interval< 0) {
1286 tracker_interval_value.setEnabled(false);
1288 tracker_interval_value.setEnabled(true);
1289 tracker_interval_value.setSelectedItem(String.format("%d", tracker_interval));
1293 public int tracker_interval() throws AltosConfigDataException {
1294 return parse_int ("tracker interval", tracker_interval_value.getSelectedItem().toString(), false);
1297 public void set_pyros(AltosPyro[] new_pyros) {
1299 pyro.setVisible(pyros != null);
1300 if (pyros != null && pyro_ui != null)
1301 pyro_ui.set_pyros(pyros);
1304 public AltosPyro[] pyros() throws AltosConfigDataException {
1305 if (pyro_ui != null)
1306 pyros = pyro_ui.get_pyros();
1310 public void set_pyro_firing_time(double new_pyro_firing_time) {
1311 pyro_firing_time = new_pyro_firing_time;
1312 pyro.setVisible(pyro_firing_time >= 0);
1313 if (pyro_firing_time >= 0 && pyro_ui != null)
1314 pyro_ui.set_pyro_firing_time(pyro_firing_time);
1317 public double pyro_firing_time() throws AltosConfigDataException {
1318 if (pyro_ui != null)
1319 pyro_firing_time = pyro_ui.get_pyro_firing_time();
1320 return pyro_firing_time;
1323 public void set_aprs_interval(int new_aprs_interval) {
1324 aprs_interval_value.setVisible(new_aprs_interval >= 0);
1325 aprs_interval_label.setVisible(new_aprs_interval >= 0);
1329 if (new_aprs_interval <= 0)
1332 s = Integer.toString(new_aprs_interval);
1333 aprs_interval_value.setSelectedItem(s);
1334 set_aprs_interval_tool_tip();
1337 public int aprs_interval() throws AltosConfigDataException {
1338 String s = aprs_interval_value.getSelectedItem().toString();
1340 if (s.equals("Disabled"))
1342 return parse_int("aprs interval", s, false);
1345 public void set_aprs_ssid(int new_aprs_ssid) {
1346 aprs_ssid_value.setVisible(new_aprs_ssid >= 0);
1347 aprs_ssid_label.setVisible(new_aprs_ssid >= 0);
1349 aprs_ssid_value.setSelectedItem(Math.max(0,new_aprs_ssid));
1350 set_aprs_ssid_tool_tip();
1353 public int aprs_ssid() throws AltosConfigDataException {
1354 Integer i = (Integer) aprs_ssid_value.getSelectedItem();
1358 public void set_aprs_format(int new_aprs_format) {
1359 aprs_format_value.setVisible(new_aprs_format >= 0);
1360 aprs_format_label.setVisible(new_aprs_format >= 0);
1362 aprs_format_value.setSelectedIndex(Math.max(0,new_aprs_format));
1363 set_aprs_format_tool_tip();
1366 public int aprs_format() throws AltosConfigDataException {
1367 return aprs_format_value.getSelectedIndex();