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; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
22 import java.awt.event.*;
24 import javax.swing.event.*;
26 import org.altusmetrum.altoslib_11.*;
27 import org.altusmetrum.altosuilib_11.*;
29 public class AltosConfigUI
31 implements ActionListener, ItemListener, DocumentListener, AltosConfigValues, AltosUnitsListener
38 JLabel main_deploy_label;
39 JLabel apogee_delay_label;
40 JLabel apogee_lockout_label;
41 JLabel frequency_label;
42 JLabel radio_calibration_label;
43 JLabel radio_frequency_label;
44 JLabel radio_enable_label;
46 JLabel aprs_interval_label;
47 JLabel aprs_ssid_label;
48 JLabel aprs_format_label;
49 JLabel flight_log_max_label;
50 JLabel ignite_mode_label;
51 JLabel pad_orientation_label;
52 JLabel callsign_label;
54 JLabel tracker_motion_label;
55 JLabel tracker_interval_label;
63 JComboBox<String> main_deploy_value;
64 JComboBox<String> apogee_delay_value;
65 JComboBox<String> apogee_lockout_value;
66 AltosUIFreqList radio_frequency_value;
67 JLabel radio_calibration_value;
68 JRadioButton radio_enable_value;
69 AltosUIRateList rate_value;
70 JComboBox<String> aprs_interval_value;
71 JComboBox<Integer> aprs_ssid_value;
72 JComboBox<String> aprs_format_value;
73 JComboBox<String> flight_log_max_value;
74 JComboBox<String> ignite_mode_value;
75 JComboBox<String> pad_orientation_value;
76 JTextField callsign_value;
77 JComboBox<String> beep_value;
78 JComboBox<String> tracker_motion_value;
79 JComboBox<String> tracker_interval_value;
89 double pyro_firing_time;
91 ActionListener listener;
93 static String[] main_deploy_values_m = {
94 "100", "150", "200", "250", "300", "350",
98 static String[] main_deploy_values_ft = {
99 "250", "500", "750", "1000", "1250", "1500",
103 static String[] apogee_delay_values = {
104 "0", "1", "2", "3", "4", "5"
107 static String[] apogee_lockout_values = {
108 "0", "5", "10", "15", "20"
111 static String[] ignite_mode_values = {
117 static String[] aprs_interval_values = {
124 static Integer[] aprs_ssid_values = {
125 0, 1, 2 ,3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
128 static String[] beep_values = {
134 static String[] pad_orientation_values = {
139 static String[] tracker_motion_values_m = {
146 static String[] tracker_motion_values_ft = {
153 static String[] tracker_interval_values = {
160 /* A window listener to catch closing events and tell the config code */
161 class ConfigListener extends WindowAdapter {
164 public ConfigListener(AltosConfigUI this_ui) {
168 public void windowClosing(WindowEvent e) {
169 ui.actionPerformed(new ActionEvent(e.getSource(),
170 ActionEvent.ACTION_PERFORMED,
175 boolean is_telemini_v1() {
176 String product = product_value.getText();
177 return product != null && product.startsWith("TeleMini-v1");
180 boolean is_telemini() {
181 String product = product_value.getText();
182 return product != null && product.startsWith("TeleMini");
185 boolean is_easymini() {
186 String product = product_value.getText();
187 return product != null && product.startsWith("EasyMini");
190 boolean is_telemetrum() {
191 String product = product_value.getText();
192 return product != null && product.startsWith("TeleMetrum");
195 void set_radio_enable_tool_tip() {
196 if (radio_enable_value.isEnabled())
197 radio_enable_value.setToolTipText("Enable/Disable telemetry and RDF transmissions");
199 radio_enable_value.setToolTipText("Firmware version does not support disabling radio");
202 void set_rate_tool_tip() {
203 if (rate_value.isEnabled())
204 rate_value.setToolTipText("Select telemetry baud rate");
206 rate_value.setToolTipText("Firmware version does not support variable telemetry rates");
209 void set_aprs_interval_tool_tip() {
210 if (aprs_interval_value.isEnabled())
211 aprs_interval_value.setToolTipText("Enable APRS and set the interval between APRS reports");
213 aprs_interval_value.setToolTipText("Hardware doesn't support APRS");
216 void set_aprs_ssid_tool_tip() {
217 if (aprs_ssid_value.isEnabled())
218 aprs_ssid_value.setToolTipText("Set the APRS SSID (secondary station identifier)");
219 else if (aprs_ssid_value.isEnabled())
220 aprs_ssid_value.setToolTipText("Software version doesn't support setting the APRS SSID");
222 aprs_ssid_value.setToolTipText("Hardware doesn't support APRS");
225 void set_aprs_format_tool_tip() {
226 if (aprs_format_value.isEnabled())
227 aprs_format_value.setToolTipText("Set the APRS format (compressed/uncompressed)");
228 else if (aprs_format_value.isEnabled())
229 aprs_format_value.setToolTipText("Software version doesn't support setting the APRS format");
231 aprs_format_value.setToolTipText("Hardware doesn't support APRS");
234 void set_flight_log_max_tool_tip() {
235 if (flight_log_max_value.isEnabled())
236 flight_log_max_value.setToolTipText("Size reserved for each flight log (in kB)");
238 if (is_telemini_v1())
239 flight_log_max_value.setToolTipText("TeleMini-v1 stores only one flight");
241 flight_log_max_value.setToolTipText("Cannot set max value with flight logs in memory");
245 void set_ignite_mode_tool_tip() {
246 if (ignite_mode_value.isEnabled())
247 ignite_mode_value.setToolTipText("Select when igniters will be fired");
249 ignite_mode_value.setToolTipText("Older firmware could not select ignite mode");
252 void set_pad_orientation_tool_tip() {
253 if (pad_orientation_value.isEnabled())
254 pad_orientation_value.setToolTipText("How will the computer be mounted in the airframe");
257 pad_orientation_value.setToolTipText("Older TeleMetrum firmware must fly antenna forward");
258 else if (is_telemini() || is_easymini())
259 pad_orientation_value.setToolTipText("TeleMini and EasyMini don't care how they are mounted");
261 pad_orientation_value.setToolTipText("Can't select orientation");
265 void set_beep_tool_tip() {
266 if (beep_value.isEnabled())
267 beep_value.setToolTipText("What frequency the beeper will sound at");
269 beep_value.setToolTipText("Older firmware could not select beeper frequency");
272 /* Build the UI using a grid bag */
273 public AltosConfigUI(JFrame in_owner, boolean remote) {
274 super (in_owner, "Configure Flight Computer", false);
277 GridBagConstraints c;
280 Insets il = new Insets(4,4,4,4);
281 Insets ir = new Insets(4,4,4,4);
283 pane = getContentPane();
284 pane.setLayout(new GridBagLayout());
287 c = new GridBagConstraints();
288 c.gridx = 0; c.gridy = row;
290 c.fill = GridBagConstraints.NONE;
291 c.anchor = GridBagConstraints.LINE_START;
293 product_label = new JLabel("Product:");
294 pane.add(product_label, c);
296 c = new GridBagConstraints();
297 c.gridx = 4; c.gridy = row;
299 c.fill = GridBagConstraints.HORIZONTAL;
301 c.anchor = GridBagConstraints.LINE_START;
303 product_value = new JLabel("");
304 pane.add(product_value, c);
308 c = new GridBagConstraints();
309 c.gridx = 0; c.gridy = row;
311 c.fill = GridBagConstraints.NONE;
312 c.anchor = GridBagConstraints.LINE_START;
315 version_label = new JLabel("Software version:");
316 pane.add(version_label, c);
318 c = new GridBagConstraints();
319 c.gridx = 4; c.gridy = row;
321 c.fill = GridBagConstraints.HORIZONTAL;
323 c.anchor = GridBagConstraints.LINE_START;
326 version_value = new JLabel("");
327 pane.add(version_value, c);
331 c = new GridBagConstraints();
332 c.gridx = 0; c.gridy = row;
334 c.fill = GridBagConstraints.NONE;
335 c.anchor = GridBagConstraints.LINE_START;
338 serial_label = new JLabel("Serial:");
339 pane.add(serial_label, c);
341 c = new GridBagConstraints();
342 c.gridx = 4; c.gridy = row;
344 c.fill = GridBagConstraints.HORIZONTAL;
346 c.anchor = GridBagConstraints.LINE_START;
349 serial_value = new JLabel("");
350 pane.add(serial_value, c);
354 c = new GridBagConstraints();
355 c.gridx = 0; c.gridy = row;
357 c.fill = GridBagConstraints.NONE;
358 c.anchor = GridBagConstraints.LINE_START;
361 main_deploy_label = new JLabel(get_main_deploy_label());
362 pane.add(main_deploy_label, c);
364 c = new GridBagConstraints();
365 c.gridx = 4; c.gridy = row;
367 c.fill = GridBagConstraints.HORIZONTAL;
369 c.anchor = GridBagConstraints.LINE_START;
372 main_deploy_value = new JComboBox<String>(main_deploy_values());
373 main_deploy_value.setEditable(true);
374 main_deploy_value.addItemListener(this);
375 pane.add(main_deploy_value, c);
376 main_deploy_value.setToolTipText("Height above pad altitude to fire main charge");
380 c = new GridBagConstraints();
381 c.gridx = 0; c.gridy = row;
383 c.fill = GridBagConstraints.NONE;
384 c.anchor = GridBagConstraints.LINE_START;
387 apogee_delay_label = new JLabel("Apogee Delay(s):");
388 pane.add(apogee_delay_label, c);
390 c = new GridBagConstraints();
391 c.gridx = 4; c.gridy = row;
393 c.fill = GridBagConstraints.HORIZONTAL;
395 c.anchor = GridBagConstraints.LINE_START;
398 apogee_delay_value = new JComboBox<String>(apogee_delay_values);
399 apogee_delay_value.setEditable(true);
400 apogee_delay_value.addItemListener(this);
401 pane.add(apogee_delay_value, c);
402 apogee_delay_value.setToolTipText("Delay after apogee before charge fires");
406 c = new GridBagConstraints();
407 c.gridx = 0; c.gridy = row;
409 c.fill = GridBagConstraints.NONE;
410 c.anchor = GridBagConstraints.LINE_START;
413 apogee_lockout_label = new JLabel("Apogee Lockout(s):");
414 pane.add(apogee_lockout_label, c);
416 c = new GridBagConstraints();
417 c.gridx = 4; c.gridy = row;
419 c.fill = GridBagConstraints.HORIZONTAL;
421 c.anchor = GridBagConstraints.LINE_START;
424 apogee_lockout_value = new JComboBox<String>(apogee_lockout_values);
425 apogee_lockout_value.setEditable(true);
426 apogee_lockout_value.addItemListener(this);
427 pane.add(apogee_lockout_value, c);
428 apogee_lockout_value.setToolTipText("Time after boost while apogee detection is locked out");
432 c = new GridBagConstraints();
433 c.gridx = 0; c.gridy = row;
435 c.fill = GridBagConstraints.NONE;
436 c.anchor = GridBagConstraints.LINE_START;
439 radio_frequency_label = new JLabel("Frequency:");
440 pane.add(radio_frequency_label, c);
442 c = new GridBagConstraints();
443 c.gridx = 4; c.gridy = row;
445 c.fill = GridBagConstraints.HORIZONTAL;
447 c.anchor = GridBagConstraints.LINE_START;
450 radio_frequency_value = new AltosUIFreqList();
451 radio_frequency_value.addItemListener(this);
452 pane.add(radio_frequency_value, c);
453 radio_frequency_value.setToolTipText("Telemetry, RDF and packet frequency");
456 /* Radio Calibration */
457 c = new GridBagConstraints();
458 c.gridx = 0; c.gridy = row;
460 c.fill = GridBagConstraints.NONE;
461 c.anchor = GridBagConstraints.LINE_START;
464 radio_calibration_label = new JLabel("RF Calibration:");
465 pane.add(radio_calibration_label, c);
467 c = new GridBagConstraints();
468 c.gridx = 4; c.gridy = row;
470 c.fill = GridBagConstraints.HORIZONTAL;
472 c.anchor = GridBagConstraints.LINE_START;
475 radio_calibration_value = new JLabel(String.format("%d", 1186611));
476 pane.add(radio_calibration_value, c);
480 c = new GridBagConstraints();
481 c.gridx = 0; c.gridy = row;
483 c.fill = GridBagConstraints.NONE;
484 c.anchor = GridBagConstraints.LINE_START;
487 radio_enable_label = new JLabel("Telemetry/RDF/APRS Enable:");
488 pane.add(radio_enable_label, c);
490 c = new GridBagConstraints();
491 c.gridx = 4; c.gridy = row;
493 c.fill = GridBagConstraints.HORIZONTAL;
495 c.anchor = GridBagConstraints.LINE_START;
498 radio_enable_value = new JRadioButton("Enabled");
499 radio_enable_value.addItemListener(this);
500 pane.add(radio_enable_value, c);
501 set_radio_enable_tool_tip();
505 c = new GridBagConstraints();
506 c.gridx = 0; c.gridy = row;
508 c.fill = GridBagConstraints.NONE;
509 c.anchor = GridBagConstraints.LINE_START;
512 rate_label = new JLabel("Telemetry baud rate:");
513 pane.add(rate_label, c);
515 c = new GridBagConstraints();
516 c.gridx = 4; c.gridy = row;
518 c.fill = GridBagConstraints.HORIZONTAL;
520 c.anchor = GridBagConstraints.LINE_START;
523 rate_value = new AltosUIRateList();
524 rate_value.addItemListener(this);
525 pane.add(rate_value, c);
530 c = new GridBagConstraints();
531 c.gridx = 0; c.gridy = row;
533 c.fill = GridBagConstraints.NONE;
534 c.anchor = GridBagConstraints.LINE_START;
537 aprs_interval_label = new JLabel("APRS Interval(s):");
538 pane.add(aprs_interval_label, c);
540 c = new GridBagConstraints();
541 c.gridx = 4; c.gridy = row;
543 c.fill = GridBagConstraints.HORIZONTAL;
545 c.anchor = GridBagConstraints.LINE_START;
548 aprs_interval_value = new JComboBox<String>(aprs_interval_values);
549 aprs_interval_value.setEditable(true);
550 aprs_interval_value.addItemListener(this);
551 pane.add(aprs_interval_value, c);
552 set_aprs_interval_tool_tip();
556 c = new GridBagConstraints();
557 c.gridx = 0; c.gridy = row;
559 c.fill = GridBagConstraints.NONE;
560 c.anchor = GridBagConstraints.LINE_START;
563 aprs_ssid_label = new JLabel("APRS SSID:");
564 pane.add(aprs_ssid_label, c);
566 c = new GridBagConstraints();
567 c.gridx = 4; c.gridy = row;
569 c.fill = GridBagConstraints.HORIZONTAL;
571 c.anchor = GridBagConstraints.LINE_START;
574 aprs_ssid_value = new JComboBox<Integer>(aprs_ssid_values);
575 aprs_ssid_value.setEditable(false);
576 aprs_ssid_value.addItemListener(this);
577 aprs_ssid_value.setMaximumRowCount(aprs_ssid_values.length);
578 pane.add(aprs_ssid_value, c);
579 set_aprs_ssid_tool_tip();
583 c = new GridBagConstraints();
584 c.gridx = 0; c.gridy = row;
586 c.fill = GridBagConstraints.NONE;
587 c.anchor = GridBagConstraints.LINE_START;
590 aprs_format_label = new JLabel("APRS format:");
591 pane.add(aprs_format_label, c);
593 c = new GridBagConstraints();
594 c.gridx = 4; c.gridy = row;
596 c.fill = GridBagConstraints.HORIZONTAL;
598 c.anchor = GridBagConstraints.LINE_START;
601 aprs_format_value = new JComboBox<String>(AltosLib.ao_aprs_format_name);
602 aprs_format_value.setEditable(false);
603 aprs_format_value.addItemListener(this);
604 aprs_format_value.setMaximumRowCount(AltosLib.ao_aprs_format_name.length);
605 pane.add(aprs_format_value, c);
606 set_aprs_format_tool_tip();
610 c = new GridBagConstraints();
611 c.gridx = 0; c.gridy = row;
613 c.fill = GridBagConstraints.NONE;
614 c.anchor = GridBagConstraints.LINE_START;
617 callsign_label = new JLabel("Callsign:");
618 pane.add(callsign_label, c);
620 c = new GridBagConstraints();
621 c.gridx = 4; c.gridy = row;
623 c.fill = GridBagConstraints.HORIZONTAL;
625 c.anchor = GridBagConstraints.LINE_START;
628 callsign_value = new JTextField(AltosUIPreferences.callsign());
629 callsign_value.getDocument().addDocumentListener(this);
630 pane.add(callsign_value, c);
631 callsign_value.setToolTipText("Callsign reported in telemetry data");
635 c = new GridBagConstraints();
636 c.gridx = 0; c.gridy = row;
638 c.fill = GridBagConstraints.NONE;
639 c.anchor = GridBagConstraints.LINE_START;
642 flight_log_max_label = new JLabel("Maximum Flight Log Size (kB):");
643 pane.add(flight_log_max_label, c);
645 c = new GridBagConstraints();
646 c.gridx = 4; c.gridy = row;
648 c.fill = GridBagConstraints.HORIZONTAL;
650 c.anchor = GridBagConstraints.LINE_START;
653 flight_log_max_value = new JComboBox<String>();
654 flight_log_max_value.setEditable(true);
655 flight_log_max_value.addItemListener(this);
656 pane.add(flight_log_max_value, c);
657 set_flight_log_max_tool_tip();
661 c = new GridBagConstraints();
662 c.gridx = 0; c.gridy = row;
664 c.fill = GridBagConstraints.NONE;
665 c.anchor = GridBagConstraints.LINE_START;
668 ignite_mode_label = new JLabel("Igniter Firing Mode:");
669 pane.add(ignite_mode_label, c);
671 c = new GridBagConstraints();
672 c.gridx = 4; c.gridy = row;
674 c.fill = GridBagConstraints.HORIZONTAL;
676 c.anchor = GridBagConstraints.LINE_START;
679 ignite_mode_value = new JComboBox<String>(ignite_mode_values);
680 ignite_mode_value.setEditable(false);
681 ignite_mode_value.addItemListener(this);
682 pane.add(ignite_mode_value, c);
683 set_ignite_mode_tool_tip();
686 /* Pad orientation */
687 c = new GridBagConstraints();
688 c.gridx = 0; c.gridy = row;
690 c.fill = GridBagConstraints.NONE;
691 c.anchor = GridBagConstraints.LINE_START;
694 pad_orientation_label = new JLabel("Pad Orientation:");
695 pane.add(pad_orientation_label, c);
697 c = new GridBagConstraints();
698 c.gridx = 4; c.gridy = row;
700 c.fill = GridBagConstraints.HORIZONTAL;
702 c.anchor = GridBagConstraints.LINE_START;
705 pad_orientation_value = new JComboBox<String>(pad_orientation_values);
706 pad_orientation_value.setEditable(false);
707 pad_orientation_value.addItemListener(this);
708 pane.add(pad_orientation_value, c);
709 set_pad_orientation_tool_tip();
713 c = new GridBagConstraints();
714 c.gridx = 0; c.gridy = row;
716 c.fill = GridBagConstraints.NONE;
717 c.anchor = GridBagConstraints.LINE_START;
720 beep_label = new JLabel("Beeper Frequency:");
721 pane.add(beep_label, c);
723 c = new GridBagConstraints();
724 c.gridx = 4; c.gridy = row;
726 c.fill = GridBagConstraints.HORIZONTAL;
728 c.anchor = GridBagConstraints.LINE_START;
731 beep_value = new JComboBox<String>(beep_values);
732 beep_value.setEditable(true);
733 beep_value.addItemListener(this);
734 pane.add(beep_value, c);
738 /* Tracker triger horiz distances */
739 c = new GridBagConstraints();
740 c.gridx = 0; c.gridy = row;
742 c.fill = GridBagConstraints.NONE;
743 c.anchor = GridBagConstraints.LINE_START;
746 tracker_motion_label = new JLabel(get_tracker_motion_label());
747 pane.add(tracker_motion_label, c);
749 c = new GridBagConstraints();
750 c.gridx = 4; c.gridy = row;
752 c.fill = GridBagConstraints.HORIZONTAL;
754 c.anchor = GridBagConstraints.LINE_START;
757 tracker_motion_value = new JComboBox<String>(tracker_motion_values());
758 tracker_motion_value.setEditable(true);
759 tracker_motion_value.addItemListener(this);
760 pane.add(tracker_motion_value, c);
763 /* Tracker triger vert distances */
764 c = new GridBagConstraints();
765 c.gridx = 0; c.gridy = row;
767 c.fill = GridBagConstraints.NONE;
768 c.anchor = GridBagConstraints.LINE_START;
771 tracker_interval_label = new JLabel("Position Reporting Interval(s):");
772 pane.add(tracker_interval_label, c);
774 c = new GridBagConstraints();
775 c.gridx = 4; c.gridy = row;
777 c.fill = GridBagConstraints.HORIZONTAL;
779 c.anchor = GridBagConstraints.LINE_START;
782 tracker_interval_value = new JComboBox<String>(tracker_interval_values);
783 tracker_interval_value.setEditable(true);
784 tracker_interval_value.addItemListener(this);
785 pane.add(tracker_interval_value, c);
786 set_tracker_tool_tip();
790 c = new GridBagConstraints();
791 c.gridx = 4; c.gridy = row;
793 c.fill = GridBagConstraints.HORIZONTAL;
794 c.anchor = GridBagConstraints.LINE_START;
797 pyro = new JButton("Configure Pyro Channels");
799 pyro.addActionListener(this);
800 pyro.setActionCommand("Pyro");
804 c = new GridBagConstraints();
805 c.gridx = 0; c.gridy = row;
807 c.fill = GridBagConstraints.NONE;
808 c.anchor = GridBagConstraints.LINE_START;
810 save = new JButton("Save");
812 save.addActionListener(this);
813 save.setActionCommand("Save");
815 c = new GridBagConstraints();
816 c.gridx = 2; c.gridy = row;
818 c.fill = GridBagConstraints.NONE;
819 c.anchor = GridBagConstraints.CENTER;
821 reset = new JButton("Reset");
823 reset.addActionListener(this);
824 reset.setActionCommand("Reset");
826 c = new GridBagConstraints();
827 c.gridx = 4; c.gridy = row;
829 c.fill = GridBagConstraints.NONE;
830 c.anchor = GridBagConstraints.CENTER;
832 reboot = new JButton("Reboot");
834 reboot.addActionListener(this);
835 reboot.setActionCommand("Reboot");
837 c = new GridBagConstraints();
838 c.gridx = 6; c.gridy = row;
840 c.fill = GridBagConstraints.NONE;
841 c.anchor = GridBagConstraints.LINE_END;
843 close = new JButton("Close");
845 close.addActionListener(this);
846 close.setActionCommand("Close");
848 addWindowListener(new ConfigListener(this));
849 AltosPreferences.register_units_listener(this);
852 /* Once the initial values are set, the config code will show the dialog */
853 public void make_visible() {
855 setLocationRelativeTo(owner);
859 /* If any values have been changed, confirm before closing */
860 public boolean check_dirty(String operation) {
862 Object[] options = { String.format("%s anyway", operation), "Keep editing" };
864 i = JOptionPane.showOptionDialog(this,
865 String.format("Configuration modified. %s anyway?", operation),
866 "Configuration Modified",
867 JOptionPane.DEFAULT_OPTION,
868 JOptionPane.WARNING_MESSAGE,
869 null, options, options[1]);
878 save.setEnabled(true);
881 public void set_clean() {
883 save.setEnabled(false);
886 AltosConfigPyroUI pyro_ui;
888 public void dispose() {
891 AltosPreferences.unregister_units_listener(this);
895 /* Listen for events from our buttons */
896 public void actionPerformed(ActionEvent e) {
897 String cmd = e.getActionCommand();
899 if (cmd.equals("Pyro")) {
900 if (pyro_ui == null && pyros != null)
901 pyro_ui = new AltosConfigPyroUI(this, pyros, pyro_firing_time);
903 pyro_ui.make_visible();
907 if (cmd.equals("Close") || cmd.equals("Reboot"))
908 if (!check_dirty(cmd))
910 listener.actionPerformed(e);
911 if (cmd.equals("Close") || cmd.equals("Reboot")) {
918 /* ItemListener interface method */
919 public void itemStateChanged(ItemEvent e) {
923 /* DocumentListener interface methods */
924 public void changedUpdate(DocumentEvent e) {
928 public void insertUpdate(DocumentEvent e) {
932 public void removeUpdate(DocumentEvent e) {
936 /* Let the config code hook on a listener */
937 public void addActionListener(ActionListener l) {
941 /* set and get all of the dialog values */
942 public void set_product(String product) {
943 radio_frequency_value.set_product(product);
944 product_value.setText(product);
945 set_pad_orientation_tool_tip();
946 set_flight_log_max_tool_tip();
949 public void set_version(String version) {
950 version_value.setText(version);
953 public void set_serial(int serial) {
954 radio_frequency_value.set_serial(serial);
955 serial_value.setText(String.format("%d", serial));
958 public void set_altitude_32(int altitude_32) {
961 public void set_main_deploy(int new_main_deploy) {
962 main_deploy_value.setSelectedItem(AltosConvert.height.say(new_main_deploy));
963 main_deploy_value.setEnabled(new_main_deploy >= 0);
965 main_deploy_value.setVisible(new_main_deploy >= 0);
966 main_deploy_label.setVisible(new_main_deploy >= 0);
970 public int main_deploy() throws AltosConfigDataException {
971 String str = main_deploy_value.getSelectedItem().toString();
973 return (int) (AltosConvert.height.parse_locale(str) + 0.5);
974 } catch (ParseException pe) {
975 throw new AltosConfigDataException("invalid main deploy height %s", str);
979 String get_main_deploy_label() {
980 return String.format("Main Deploy Altitude(%s):", AltosConvert.height.parse_units());
983 String[] main_deploy_values() {
984 if (AltosConvert.imperial_units)
985 return main_deploy_values_ft;
987 return main_deploy_values_m;
990 void set_main_deploy_values() {
991 String[] v = main_deploy_values();
992 while (main_deploy_value.getItemCount() > 0)
993 main_deploy_value.removeItemAt(0);
994 for (int i = 0; i < v.length; i++)
995 main_deploy_value.addItem(v[i]);
996 main_deploy_value.setMaximumRowCount(v.length);
999 public void units_changed(boolean imperial_units) {
1000 boolean was_dirty = dirty;
1002 String v = main_deploy_value.getSelectedItem().toString();
1003 main_deploy_label.setText(get_main_deploy_label());
1004 set_main_deploy_values();
1006 int m = (int) (AltosConvert.height.parse_locale(v, !imperial_units) + 0.5);
1008 } catch (ParseException pe) {
1011 if (tracker_motion_value.isEnabled()) {
1012 String motion = tracker_motion_value.getSelectedItem().toString();
1013 tracker_motion_label.setText(get_tracker_motion_label());
1014 set_tracker_motion_values();
1016 int m = (int) (AltosConvert.height.parse_locale(motion, !imperial_units) + 0.5);
1017 set_tracker_motion(m);
1018 } catch (ParseException pe) {
1026 public void set_apogee_delay(int new_apogee_delay) {
1027 apogee_delay_value.setVisible(new_apogee_delay >= 0);
1028 apogee_delay_label.setVisible(new_apogee_delay >= 0);
1030 apogee_delay_value.setSelectedItem(Integer.toString(new_apogee_delay));
1031 apogee_delay_value.setEnabled(new_apogee_delay >= 0);
1034 private int parse_int(String name, String s, boolean split) throws AltosConfigDataException {
1037 v = s.split("\\s+")[0];
1039 return Integer.parseInt(v);
1040 } catch (NumberFormatException ne) {
1041 throw new AltosConfigDataException("Invalid %s \"%s\"", name, s);
1045 public int apogee_delay() throws AltosConfigDataException {
1046 return parse_int("apogee delay", apogee_delay_value.getSelectedItem().toString(), false);
1049 public void set_apogee_lockout(int new_apogee_lockout) {
1050 apogee_lockout_value.setSelectedItem(Integer.toString(new_apogee_lockout));
1051 apogee_lockout_value.setEnabled(new_apogee_lockout >= 0);
1053 apogee_lockout_value.setVisible(new_apogee_lockout >= 0);
1054 apogee_lockout_label.setVisible(new_apogee_lockout >= 0);
1057 public int apogee_lockout() throws AltosConfigDataException {
1058 return parse_int("apogee lockout", apogee_lockout_value.getSelectedItem().toString(), false);
1061 public void set_radio_frequency(double new_radio_frequency) {
1062 radio_frequency_label.setVisible(new_radio_frequency >= 0);
1063 radio_frequency_value.set_frequency(new_radio_frequency);
1066 public double radio_frequency() {
1067 return radio_frequency_value.frequency();
1070 public void set_radio_calibration(int new_radio_calibration) {
1071 radio_calibration_value.setVisible(new_radio_calibration >= 0);
1072 radio_calibration_label.setVisible(new_radio_calibration >= 0);
1074 if (new_radio_calibration < 0)
1075 radio_calibration_value.setText("Disabled");
1077 radio_calibration_value.setText(String.format("%d", new_radio_calibration));
1080 public void set_radio_enable(int new_radio_enable) {
1081 radio_enable_label.setVisible(new_radio_enable >= 0);
1082 radio_enable_value.setVisible(new_radio_enable >= 0);
1084 if (new_radio_enable >= 0) {
1085 radio_enable_value.setSelected(new_radio_enable > 0);
1086 radio_enable_value.setEnabled(true);
1088 radio_enable_value.setSelected(true);
1089 radio_enable_value.setEnabled(false);
1091 set_radio_enable_tool_tip();
1094 public int radio_enable() {
1095 if (radio_enable_value.isEnabled())
1096 return radio_enable_value.isSelected() ? 1 : 0;
1101 public void set_telemetry_rate(int new_rate) {
1102 rate_label.setVisible(new_rate >= 0);
1104 rate_value.set_rate(new_rate);
1107 public int telemetry_rate() {
1108 return rate_value.rate();
1111 public void set_callsign(String new_callsign) {
1112 callsign_value.setVisible(new_callsign != null);
1113 callsign_label.setVisible(new_callsign != null);
1115 callsign_value.setText(new_callsign);
1118 public String callsign() {
1119 return callsign_value.getText();
1122 int flight_log_max_limit;
1125 public String flight_log_max_label(int flight_log_max) {
1126 if (flight_log_max_limit != 0) {
1127 int nflight = flight_log_max_limit / flight_log_max;
1128 String plural = nflight > 1 ? "s" : "";
1130 return String.format("%d (%d flight%s)", flight_log_max, nflight, plural);
1132 return String.format("%d", flight_log_max);
1135 public void set_flight_log_max(int new_flight_log_max) {
1136 flight_log_max_value.setVisible(new_flight_log_max >= 0);
1137 flight_log_max_label.setVisible(new_flight_log_max >= 0);
1139 flight_log_max_value.setSelectedItem(flight_log_max_label(new_flight_log_max));
1140 flight_log_max = new_flight_log_max;
1141 set_flight_log_max_tool_tip();
1144 public void set_flight_log_max_enabled(boolean enable) {
1145 flight_log_max_value.setEnabled(enable);
1146 set_flight_log_max_tool_tip();
1149 public int flight_log_max() throws AltosConfigDataException {
1150 return parse_int("flight log max", flight_log_max_value.getSelectedItem().toString(), true);
1153 public void set_flight_log_max_limit(int new_flight_log_max_limit) {
1154 flight_log_max_limit = new_flight_log_max_limit;
1155 flight_log_max_value.removeAllItems();
1156 for (int i = 8; i >= 1; i--) {
1157 int size = flight_log_max_limit / i;
1158 flight_log_max_value.addItem(String.format("%d (%d flights)", size, i));
1160 if (flight_log_max != 0)
1161 set_flight_log_max(flight_log_max);
1164 public void set_ignite_mode(int new_ignite_mode) {
1165 ignite_mode_value.setVisible(new_ignite_mode >= 0);
1166 ignite_mode_label.setVisible(new_ignite_mode >= 0);
1168 if (new_ignite_mode >= ignite_mode_values.length)
1169 new_ignite_mode = 0;
1170 if (new_ignite_mode < 0) {
1171 ignite_mode_value.setEnabled(false);
1172 new_ignite_mode = 0;
1174 ignite_mode_value.setEnabled(true);
1176 ignite_mode_value.setSelectedIndex(new_ignite_mode);
1177 set_ignite_mode_tool_tip();
1180 public int ignite_mode() {
1181 if (ignite_mode_value.isEnabled())
1182 return ignite_mode_value.getSelectedIndex();
1188 public void set_pad_orientation(int new_pad_orientation) {
1189 pad_orientation_value.setVisible(new_pad_orientation >= 0);
1190 pad_orientation_label.setVisible(new_pad_orientation >= 0);
1192 if (new_pad_orientation >= pad_orientation_values.length)
1193 new_pad_orientation = 0;
1194 if (new_pad_orientation < 0)
1195 new_pad_orientation = 0;
1196 pad_orientation_value.setSelectedIndex(new_pad_orientation);
1197 set_pad_orientation_tool_tip();
1200 public int pad_orientation() {
1201 if (pad_orientation_value.isEnabled())
1202 return pad_orientation_value.getSelectedIndex();
1207 public void set_beep(int new_beep) {
1208 beep_value.setVisible(new_beep >= 0);
1209 beep_label.setVisible(new_beep >= 0);
1211 int new_freq = (int) Math.floor (AltosConvert.beep_value_to_freq(new_beep) + 0.5);
1212 for (int i = 0; i < beep_values.length; i++)
1213 if (new_beep == AltosConvert.beep_freq_to_value(Integer.parseInt(beep_values[i]))) {
1214 beep_value.setSelectedIndex(i);
1215 set_beep_tool_tip();
1218 beep_value.setSelectedItem(String.format("%d", new_freq));
1219 beep_value.setEnabled(new_beep >= 0);
1220 set_beep_tool_tip();
1224 if (beep_value.isEnabled())
1225 return AltosConvert.beep_freq_to_value(Integer.parseInt(beep_value.getSelectedItem().toString()));
1230 String[] tracker_motion_values() {
1231 if (AltosConvert.imperial_units)
1232 return tracker_motion_values_ft;
1234 return tracker_motion_values_m;
1237 void set_tracker_motion_values() {
1238 String[] v = tracker_motion_values();
1239 while (tracker_motion_value.getItemCount() > 0)
1240 tracker_motion_value.removeItemAt(0);
1241 for (int i = 0; i < v.length; i++)
1242 tracker_motion_value.addItem(v[i]);
1243 tracker_motion_value.setMaximumRowCount(v.length);
1246 String get_tracker_motion_label() {
1247 return String.format("Logging Trigger Motion (%s):", AltosConvert.height.parse_units());
1250 void set_tracker_tool_tip() {
1251 if (tracker_motion_value.isEnabled())
1252 tracker_motion_value.setToolTipText("How far the device must move before logging");
1254 tracker_motion_value.setToolTipText("This device doesn't disable logging when stationary");
1255 if (tracker_interval_value.isEnabled())
1256 tracker_interval_value.setToolTipText("How often to report GPS position");
1258 tracker_interval_value.setToolTipText("This device can't configure interval");
1261 public void set_tracker_motion(int tracker_motion) {
1262 tracker_motion_label.setVisible(tracker_motion >= 0);
1263 tracker_motion_value.setVisible(tracker_motion >= 0);
1265 if (tracker_motion < 0) {
1266 tracker_motion_value.setEnabled(false);
1268 tracker_motion_value.setEnabled(true);
1269 tracker_motion_value.setSelectedItem(AltosConvert.height.say(tracker_motion));
1273 public int tracker_motion() throws AltosConfigDataException {
1274 String str = tracker_motion_value.getSelectedItem().toString();
1276 return (int) (AltosConvert.height.parse_locale(str) + 0.5);
1277 } catch (ParseException pe) {
1278 throw new AltosConfigDataException("invalid tracker motion %s", str);
1282 public void set_tracker_interval(int tracker_interval) {
1283 tracker_interval_label.setVisible(tracker_interval >= 0);
1284 tracker_interval_value.setVisible(tracker_interval >= 0);
1286 if (tracker_interval< 0) {
1287 tracker_interval_value.setEnabled(false);
1289 tracker_interval_value.setEnabled(true);
1290 tracker_interval_value.setSelectedItem(String.format("%d", tracker_interval));
1294 public int tracker_interval() throws AltosConfigDataException {
1295 return parse_int ("tracker interval", tracker_interval_value.getSelectedItem().toString(), false);
1298 public void set_pyros(AltosPyro[] new_pyros) {
1300 pyro.setVisible(pyros != null);
1301 if (pyros != null && pyro_ui != null)
1302 pyro_ui.set_pyros(pyros);
1305 public AltosPyro[] pyros() throws AltosConfigDataException {
1306 if (pyro_ui != null)
1307 pyros = pyro_ui.get_pyros();
1311 public void set_pyro_firing_time(double new_pyro_firing_time) {
1312 pyro_firing_time = new_pyro_firing_time;
1313 pyro.setVisible(pyro_firing_time >= 0);
1314 if (pyro_firing_time >= 0 && pyro_ui != null)
1315 pyro_ui.set_pyro_firing_time(pyro_firing_time);
1318 public double pyro_firing_time() throws AltosConfigDataException {
1319 if (pyro_ui != null)
1320 pyro_firing_time = pyro_ui.get_pyro_firing_time();
1321 return pyro_firing_time;
1324 public void set_aprs_interval(int new_aprs_interval) {
1325 aprs_interval_value.setVisible(new_aprs_interval >= 0);
1326 aprs_interval_label.setVisible(new_aprs_interval >= 0);
1330 if (new_aprs_interval <= 0)
1333 s = Integer.toString(new_aprs_interval);
1334 aprs_interval_value.setSelectedItem(s);
1335 set_aprs_interval_tool_tip();
1338 public int aprs_interval() throws AltosConfigDataException {
1339 String s = aprs_interval_value.getSelectedItem().toString();
1341 if (s.equals("Disabled"))
1343 return parse_int("aprs interval", s, false);
1346 public void set_aprs_ssid(int new_aprs_ssid) {
1347 aprs_ssid_value.setVisible(new_aprs_ssid >= 0);
1348 aprs_ssid_label.setVisible(new_aprs_ssid >= 0);
1350 aprs_ssid_value.setSelectedItem(Math.max(0,new_aprs_ssid));
1351 set_aprs_ssid_tool_tip();
1354 public int aprs_ssid() throws AltosConfigDataException {
1355 Integer i = (Integer) aprs_ssid_value.getSelectedItem();
1359 public void set_aprs_format(int new_aprs_format) {
1360 aprs_format_value.setVisible(new_aprs_format >= 0);
1361 aprs_format_label.setVisible(new_aprs_format >= 0);
1363 aprs_format_value.setSelectedIndex(Math.max(0,new_aprs_format));
1364 set_aprs_format_tool_tip();
1367 public int aprs_format() throws AltosConfigDataException {
1368 return aprs_format_value.getSelectedIndex();