altosui/telegps: Add config option for APRS format
[fw/altos] / telegps / TeleGPSConfigUI.java
1 /*
2  * Copyright © 2010 Keith Packard <keithp@keithp.com>
3  *
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.
7  *
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.
12  *
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.
16  */
17
18 package org.altusmetrum.telegps;
19
20 import java.awt.*;
21 import java.awt.event.*;
22 import javax.swing.*;
23 import javax.swing.event.*;
24 import org.altusmetrum.altoslib_6.*;
25 import org.altusmetrum.altosuilib_6.*;
26
27 public class TeleGPSConfigUI
28         extends AltosUIDialog
29         implements ActionListener, ItemListener, DocumentListener, AltosConfigValues, AltosUnitsListener
30 {
31
32         Container               pane;
33         JLabel                  product_label;
34         JLabel                  version_label;
35         JLabel                  serial_label;
36         JLabel                  frequency_label;
37         JLabel                  radio_calibration_label;
38         JLabel                  radio_frequency_label;
39         JLabel                  radio_enable_label;
40         JLabel                  rate_label;
41         JLabel                  aprs_interval_label;
42         JLabel                  aprs_ssid_label;
43         JLabel                  aprs_format_label;
44         JLabel                  flight_log_max_label;
45         JLabel                  callsign_label;
46         JLabel                  tracker_motion_label;
47         JLabel                  tracker_interval_label;
48
49         public boolean          dirty;
50
51         JFrame                  owner;
52         JLabel                  product_value;
53         JLabel                  version_value;
54         JLabel                  serial_value;
55         AltosUIFreqList         radio_frequency_value;
56         JTextField              radio_calibration_value;
57         JRadioButton            radio_enable_value;
58         AltosUIRateList         rate_value;
59         JComboBox<String>       aprs_interval_value;
60         JComboBox<Integer>      aprs_ssid_value;
61         JComboBox<String>       aprs_format_value;
62         JComboBox<String>       flight_log_max_value;
63         JTextField              callsign_value;
64         JComboBox<String>       tracker_motion_value;
65         JComboBox<String>       tracker_interval_value;
66
67         JButton                 save;
68         JButton                 reset;
69         JButton                 reboot;
70         JButton                 close;
71
72         ActionListener          listener;
73
74         static String[]         aprs_interval_values = {
75                 "Disabled",
76                 "2",
77                 "5",
78                 "10"
79         };
80
81         static Integer[]        aprs_ssid_values = {
82                 0, 1, 2 ,3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
83         };
84
85         static String[]         tracker_motion_values_m = {
86                 "2",
87                 "5",
88                 "10",
89                 "25",
90         };
91
92         static String[]         tracker_motion_values_ft = {
93                 "5",
94                 "20",
95                 "50",
96                 "100"
97         };
98
99         static String[]         tracker_interval_values = {
100                 "1",
101                 "2",
102                 "5",
103                 "10"
104         };
105
106         /* A window listener to catch closing events and tell the config code */
107         class ConfigListener extends WindowAdapter {
108                 TeleGPSConfigUI ui;
109
110                 public ConfigListener(TeleGPSConfigUI this_ui) {
111                         ui = this_ui;
112                 }
113
114                 public void windowClosing(WindowEvent e) {
115                         ui.actionPerformed(new ActionEvent(e.getSource(),
116                                                            ActionEvent.ACTION_PERFORMED,
117                                                            "Close"));
118                 }
119         }
120
121         public void set_pyros(AltosPyro[] new_pyros) {
122         }
123
124         public AltosPyro[] pyros() {
125                 return null;
126         }
127
128         public void set_pyro_firing_time(double new_pyro_firing_time) {
129         }
130
131         public double pyro_firing_time() {
132                 return -1;
133         }
134
135         boolean is_telemetrum() {
136                 String  product = product_value.getText();
137                 return product != null && product.startsWith("TeleGPS");
138         }
139
140         void set_radio_calibration_tool_tip() {
141                 if (radio_calibration_value.isEnabled())
142                         radio_calibration_value.setToolTipText("Tune radio output to match desired frequency");
143                 else
144                         radio_calibration_value.setToolTipText("Cannot tune radio while connected over packet mode");
145         }
146
147         void set_radio_enable_tool_tip() {
148                 if (radio_enable_value.isEnabled())
149                         radio_enable_value.setToolTipText("Enable/Disable telemetry and RDF transmissions");
150                 else
151                         radio_enable_value.setToolTipText("Firmware version does not support disabling radio");
152         }
153
154         void set_rate_tool_tip() {
155                 if (rate_value.isEnabled())
156                         rate_value.setToolTipText("Select telemetry baud rate");
157                 else
158                         rate_value.setToolTipText("Firmware version does not support variable telemetry rates");
159         }
160
161         void set_aprs_interval_tool_tip() {
162                 if (aprs_interval_value.isEnabled())
163                         aprs_interval_value.setToolTipText("Enable APRS and set the interval between APRS reports");
164                 else
165                         aprs_interval_value.setToolTipText("Hardware doesn't support APRS");
166         }
167
168         void set_aprs_ssid_tool_tip() {
169                 if (aprs_ssid_value.isEnabled())
170                         aprs_ssid_value.setToolTipText("Set the APRS SSID (secondary station identifier)");
171                 else if (aprs_ssid_value.isEnabled())
172                         aprs_ssid_value.setToolTipText("Software version doesn't support setting the APRS SSID");
173                 else
174                         aprs_ssid_value.setToolTipText("Hardware doesn't support APRS");
175         }
176
177         void set_aprs_format_tool_tip() {
178                 if (aprs_format_value.isEnabled())
179                         aprs_format_value.setToolTipText("Set the APRS format (compressed/uncompressed)");
180                 else if (aprs_format_value.isEnabled())
181                         aprs_format_value.setToolTipText("Software version doesn't support setting the APRS format");
182                 else
183                         aprs_format_value.setToolTipText("Hardware doesn't support APRS");
184         }
185
186         void set_flight_log_max_tool_tip() {
187                 if (flight_log_max_value.isEnabled())
188                         flight_log_max_value.setToolTipText("Size reserved for each flight log (in kB)");
189                 else
190                         flight_log_max_value.setToolTipText("Cannot set max value with flight logs in memory");
191         }
192
193         /* Build the UI using a grid bag */
194         public TeleGPSConfigUI(JFrame in_owner) {
195                 super (in_owner, "Configure Device", false);
196
197                 owner = in_owner;
198                 GridBagConstraints c;
199                 int row = 0;
200
201                 Insets il = new Insets(4,4,4,4);
202                 Insets ir = new Insets(4,4,4,4);
203
204                 pane = getContentPane();
205                 pane.setLayout(new GridBagLayout());
206
207                 /* Product */
208                 c = new GridBagConstraints();
209                 c.gridx = 0; c.gridy = row;
210                 c.gridwidth = 4;
211                 c.fill = GridBagConstraints.NONE;
212                 c.anchor = GridBagConstraints.LINE_START;
213                 c.insets = il;
214                 product_label = new JLabel("Product:");
215                 pane.add(product_label, c);
216
217                 c = new GridBagConstraints();
218                 c.gridx = 4; c.gridy = row;
219                 c.gridwidth = 4;
220                 c.fill = GridBagConstraints.HORIZONTAL;
221                 c.weightx = 1;
222                 c.anchor = GridBagConstraints.LINE_START;
223                 c.insets = ir;
224                 product_value = new JLabel("");
225                 pane.add(product_value, c);
226                 row++;
227
228                 /* Version */
229                 c = new GridBagConstraints();
230                 c.gridx = 0; c.gridy = row;
231                 c.gridwidth = 4;
232                 c.fill = GridBagConstraints.NONE;
233                 c.anchor = GridBagConstraints.LINE_START;
234                 c.insets = il;
235                 c.ipady = 5;
236                 version_label = new JLabel("Software version:");
237                 pane.add(version_label, c);
238
239                 c = new GridBagConstraints();
240                 c.gridx = 4; c.gridy = row;
241                 c.gridwidth = 4;
242                 c.fill = GridBagConstraints.HORIZONTAL;
243                 c.weightx = 1;
244                 c.anchor = GridBagConstraints.LINE_START;
245                 c.insets = ir;
246                 c.ipady = 5;
247                 version_value = new JLabel("");
248                 pane.add(version_value, c);
249                 row++;
250
251                 /* Serial */
252                 c = new GridBagConstraints();
253                 c.gridx = 0; c.gridy = row;
254                 c.gridwidth = 4;
255                 c.fill = GridBagConstraints.NONE;
256                 c.anchor = GridBagConstraints.LINE_START;
257                 c.insets = il;
258                 c.ipady = 5;
259                 serial_label = new JLabel("Serial:");
260                 pane.add(serial_label, c);
261
262                 c = new GridBagConstraints();
263                 c.gridx = 4; c.gridy = row;
264                 c.gridwidth = 4;
265                 c.fill = GridBagConstraints.HORIZONTAL;
266                 c.weightx = 1;
267                 c.anchor = GridBagConstraints.LINE_START;
268                 c.insets = ir;
269                 c.ipady = 5;
270                 serial_value = new JLabel("");
271                 pane.add(serial_value, c);
272                 row++;
273
274                 /* Frequency */
275                 c = new GridBagConstraints();
276                 c.gridx = 0; c.gridy = row;
277                 c.gridwidth = 4;
278                 c.fill = GridBagConstraints.NONE;
279                 c.anchor = GridBagConstraints.LINE_START;
280                 c.insets = il;
281                 c.ipady = 5;
282                 radio_frequency_label = new JLabel("Frequency:");
283                 pane.add(radio_frequency_label, c);
284
285                 c = new GridBagConstraints();
286                 c.gridx = 4; c.gridy = row;
287                 c.gridwidth = 4;
288                 c.fill = GridBagConstraints.HORIZONTAL;
289                 c.weightx = 1;
290                 c.anchor = GridBagConstraints.LINE_START;
291                 c.insets = ir;
292                 c.ipady = 5;
293                 radio_frequency_value = new AltosUIFreqList();
294                 radio_frequency_value.addItemListener(this);
295                 pane.add(radio_frequency_value, c);
296                 radio_frequency_value.setToolTipText("Telemetry, RDF and packet frequency");
297                 row++;
298
299                 /* Radio Calibration */
300                 c = new GridBagConstraints();
301                 c.gridx = 0; c.gridy = row;
302                 c.gridwidth = 4;
303                 c.fill = GridBagConstraints.NONE;
304                 c.anchor = GridBagConstraints.LINE_START;
305                 c.insets = il;
306                 c.ipady = 5;
307                 radio_calibration_label = new JLabel("RF Calibration:");
308                 pane.add(radio_calibration_label, c);
309
310                 c = new GridBagConstraints();
311                 c.gridx = 4; c.gridy = row;
312                 c.gridwidth = 4;
313                 c.fill = GridBagConstraints.HORIZONTAL;
314                 c.weightx = 1;
315                 c.anchor = GridBagConstraints.LINE_START;
316                 c.insets = ir;
317                 c.ipady = 5;
318                 radio_calibration_value = new JTextField(String.format("%d", 1186611));
319                 radio_calibration_value.getDocument().addDocumentListener(this);
320                 pane.add(radio_calibration_value, c);
321                 set_radio_calibration_tool_tip();
322                 row++;
323
324                 /* Radio Enable */
325                 c = new GridBagConstraints();
326                 c.gridx = 0; c.gridy = row;
327                 c.gridwidth = 4;
328                 c.fill = GridBagConstraints.NONE;
329                 c.anchor = GridBagConstraints.LINE_START;
330                 c.insets = il;
331                 c.ipady = 5;
332                 radio_enable_label = new JLabel("Telemetry/RDF/APRS Enable:");
333                 pane.add(radio_enable_label, c);
334
335                 c = new GridBagConstraints();
336                 c.gridx = 4; c.gridy = row;
337                 c.gridwidth = 4;
338                 c.fill = GridBagConstraints.HORIZONTAL;
339                 c.weightx = 1;
340                 c.anchor = GridBagConstraints.LINE_START;
341                 c.insets = ir;
342                 c.ipady = 5;
343                 radio_enable_value = new JRadioButton("Enabled");
344                 radio_enable_value.addItemListener(this);
345                 pane.add(radio_enable_value, c);
346                 set_radio_enable_tool_tip();
347                 row++;
348
349                 /* Telemetry Rate */
350                 c = new GridBagConstraints();
351                 c.gridx = 0; c.gridy = row;
352                 c.gridwidth = 4;
353                 c.fill = GridBagConstraints.NONE;
354                 c.anchor = GridBagConstraints.LINE_START;
355                 c.insets = il;
356                 c.ipady = 5;
357                 rate_label = new JLabel("Telemetry baud rate:");
358                 pane.add(rate_label, c);
359
360                 c = new GridBagConstraints();
361                 c.gridx = 4; c.gridy = row;
362                 c.gridwidth = 4;
363                 c.fill = GridBagConstraints.HORIZONTAL;
364                 c.weightx = 1;
365                 c.anchor = GridBagConstraints.LINE_START;
366                 c.insets = ir;
367                 c.ipady = 5;
368                 rate_value = new AltosUIRateList();
369                 rate_value.addItemListener(this);
370                 pane.add(rate_value, c);
371                 set_rate_tool_tip();
372                 row++;
373
374                 /* APRS interval */
375                 c = new GridBagConstraints();
376                 c.gridx = 0; c.gridy = row;
377                 c.gridwidth = 4;
378                 c.fill = GridBagConstraints.NONE;
379                 c.anchor = GridBagConstraints.LINE_START;
380                 c.insets = il;
381                 c.ipady = 5;
382                 aprs_interval_label = new JLabel("APRS Interval(s):");
383                 pane.add(aprs_interval_label, c);
384
385                 c = new GridBagConstraints();
386                 c.gridx = 4; c.gridy = row;
387                 c.gridwidth = 4;
388                 c.fill = GridBagConstraints.HORIZONTAL;
389                 c.weightx = 1;
390                 c.anchor = GridBagConstraints.LINE_START;
391                 c.insets = ir;
392                 c.ipady = 5;
393                 aprs_interval_value = new JComboBox<String>(aprs_interval_values);
394                 aprs_interval_value.setEditable(true);
395                 aprs_interval_value.addItemListener(this);
396                 pane.add(aprs_interval_value, c);
397                 set_aprs_interval_tool_tip();
398                 row++;
399
400                 /* APRS SSID */
401                 c = new GridBagConstraints();
402                 c.gridx = 0; c.gridy = row;
403                 c.gridwidth = 4;
404                 c.fill = GridBagConstraints.NONE;
405                 c.anchor = GridBagConstraints.LINE_START;
406                 c.insets = il;
407                 c.ipady = 5;
408                 aprs_ssid_label = new JLabel("APRS SSID:");
409                 pane.add(aprs_ssid_label, c);
410
411                 c = new GridBagConstraints();
412                 c.gridx = 4; c.gridy = row;
413                 c.gridwidth = 4;
414                 c.fill = GridBagConstraints.HORIZONTAL;
415                 c.weightx = 1;
416                 c.anchor = GridBagConstraints.LINE_START;
417                 c.insets = ir;
418                 c.ipady = 5;
419                 aprs_ssid_value = new JComboBox<Integer>(aprs_ssid_values);
420                 aprs_ssid_value.setEditable(false);
421                 aprs_ssid_value.addItemListener(this);
422                 aprs_ssid_value.setMaximumRowCount(aprs_ssid_values.length);
423                 pane.add(aprs_ssid_value, c);
424                 set_aprs_ssid_tool_tip();
425                 row++;
426
427                 /* APRS format */
428                 c = new GridBagConstraints();
429                 c.gridx = 0; c.gridy = row;
430                 c.gridwidth = 4;
431                 c.fill = GridBagConstraints.NONE;
432                 c.anchor = GridBagConstraints.LINE_START;
433                 c.insets = il;
434                 c.ipady = 5;
435                 aprs_format_label = new JLabel("APRS format:");
436                 pane.add(aprs_format_label, c);
437
438                 c = new GridBagConstraints();
439                 c.gridx = 4; c.gridy = row;
440                 c.gridwidth = 4;
441                 c.fill = GridBagConstraints.HORIZONTAL;
442                 c.weightx = 1;
443                 c.anchor = GridBagConstraints.LINE_START;
444                 c.insets = ir;
445                 c.ipady = 5;
446                 aprs_format_value = new JComboBox<String>(AltosLib.ao_aprs_format_name);
447                 aprs_format_value.setEditable(false);
448                 aprs_format_value.addItemListener(this);
449                 aprs_format_value.setMaximumRowCount(AltosLib.ao_aprs_format_name.length);
450                 pane.add(aprs_format_value, c);
451                 set_aprs_format_tool_tip();
452                 row++;
453
454                 /* Callsign */
455                 c = new GridBagConstraints();
456                 c.gridx = 0; c.gridy = row;
457                 c.gridwidth = 4;
458                 c.fill = GridBagConstraints.NONE;
459                 c.anchor = GridBagConstraints.LINE_START;
460                 c.insets = il;
461                 c.ipady = 5;
462                 callsign_label = new JLabel("Callsign:");
463                 pane.add(callsign_label, c);
464
465                 c = new GridBagConstraints();
466                 c.gridx = 4; c.gridy = row;
467                 c.gridwidth = 4;
468                 c.fill = GridBagConstraints.HORIZONTAL;
469                 c.weightx = 1;
470                 c.anchor = GridBagConstraints.LINE_START;
471                 c.insets = ir;
472                 c.ipady = 5;
473                 callsign_value = new JTextField(AltosUIPreferences.callsign());
474                 callsign_value.getDocument().addDocumentListener(this);
475                 pane.add(callsign_value, c);
476                 callsign_value.setToolTipText("Callsign reported in telemetry data");
477                 row++;
478
479                 /* Flight log max */
480                 c = new GridBagConstraints();
481                 c.gridx = 0; c.gridy = row;
482                 c.gridwidth = 4;
483                 c.fill = GridBagConstraints.NONE;
484                 c.anchor = GridBagConstraints.LINE_START;
485                 c.insets = il;
486                 c.ipady = 5;
487                 flight_log_max_label = new JLabel("Maximum Log Size (kB):");
488                 pane.add(flight_log_max_label, c);
489
490                 c = new GridBagConstraints();
491                 c.gridx = 4; c.gridy = row;
492                 c.gridwidth = 4;
493                 c.fill = GridBagConstraints.HORIZONTAL;
494                 c.weightx = 1;
495                 c.anchor = GridBagConstraints.LINE_START;
496                 c.insets = ir;
497                 c.ipady = 5;
498                 flight_log_max_value = new JComboBox<String>();
499                 flight_log_max_value.setEditable(true);
500                 flight_log_max_value.addItemListener(this);
501                 pane.add(flight_log_max_value, c);
502                 set_flight_log_max_tool_tip();
503                 row++;
504
505                 /* Tracker triger horiz distances */
506                 c = new GridBagConstraints();
507                 c.gridx = 0; c.gridy = row;
508                 c.gridwidth = 4;
509                 c.fill = GridBagConstraints.NONE;
510                 c.anchor = GridBagConstraints.LINE_START;
511                 c.insets = il;
512                 c.ipady = 5;
513                 tracker_motion_label = new JLabel(get_tracker_motion_label());
514                 pane.add(tracker_motion_label, c);
515
516                 c = new GridBagConstraints();
517                 c.gridx = 4; c.gridy = row;
518                 c.gridwidth = 4;
519                 c.fill = GridBagConstraints.HORIZONTAL;
520                 c.weightx = 1;
521                 c.anchor = GridBagConstraints.LINE_START;
522                 c.insets = ir;
523                 c.ipady = 5;
524                 tracker_motion_value = new JComboBox<String>(tracker_motion_values());
525                 tracker_motion_value.setEditable(true);
526                 tracker_motion_value.addItemListener(this);
527                 pane.add(tracker_motion_value, c);
528                 row++;
529
530                 /* Tracker triger vert distances */
531                 c = new GridBagConstraints();
532                 c.gridx = 0; c.gridy = row;
533                 c.gridwidth = 4;
534                 c.fill = GridBagConstraints.NONE;
535                 c.anchor = GridBagConstraints.LINE_START;
536                 c.insets = il;
537                 c.ipady = 5;
538                 tracker_interval_label = new JLabel("Position Reporting Interval (s):");
539                 pane.add(tracker_interval_label, c);
540
541                 c = new GridBagConstraints();
542                 c.gridx = 4; c.gridy = row;
543                 c.gridwidth = 4;
544                 c.fill = GridBagConstraints.HORIZONTAL;
545                 c.weightx = 1;
546                 c.anchor = GridBagConstraints.LINE_START;
547                 c.insets = ir;
548                 c.ipady = 5;
549                 tracker_interval_value = new JComboBox<String>(tracker_interval_values);
550                 tracker_interval_value.setEditable(true);
551                 tracker_interval_value.addItemListener(this);
552                 pane.add(tracker_interval_value, c);
553                 set_tracker_tool_tip();
554                 row++;
555
556                 /* Buttons */
557                 c = new GridBagConstraints();
558                 c.gridx = 0; c.gridy = row;
559                 c.gridwidth = 2;
560                 c.fill = GridBagConstraints.NONE;
561                 c.anchor = GridBagConstraints.LINE_START;
562                 c.insets = il;
563                 save = new JButton("Save");
564                 pane.add(save, c);
565                 save.addActionListener(this);
566                 save.setActionCommand("Save");
567
568                 c = new GridBagConstraints();
569                 c.gridx = 2; c.gridy = row;
570                 c.gridwidth = 2;
571                 c.fill = GridBagConstraints.NONE;
572                 c.anchor = GridBagConstraints.CENTER;
573                 c.insets = il;
574                 reset = new JButton("Reset");
575                 pane.add(reset, c);
576                 reset.addActionListener(this);
577                 reset.setActionCommand("Reset");
578
579                 c = new GridBagConstraints();
580                 c.gridx = 4; c.gridy = row;
581                 c.gridwidth = 2;
582                 c.fill = GridBagConstraints.NONE;
583                 c.anchor = GridBagConstraints.CENTER;
584                 c.insets = il;
585                 reboot = new JButton("Reboot");
586                 pane.add(reboot, c);
587                 reboot.addActionListener(this);
588                 reboot.setActionCommand("Reboot");
589
590                 c = new GridBagConstraints();
591                 c.gridx = 6; c.gridy = row;
592                 c.gridwidth = 2;
593                 c.fill = GridBagConstraints.NONE;
594                 c.anchor = GridBagConstraints.LINE_END;
595                 c.insets = il;
596                 close = new JButton("Close");
597                 pane.add(close, c);
598                 close.addActionListener(this);
599                 close.setActionCommand("Close");
600
601                 addWindowListener(new ConfigListener(this));
602                 AltosPreferences.register_units_listener(this);
603         }
604
605         /* Once the initial values are set, the config code will show the dialog */
606         public void make_visible() {
607                 pack();
608                 setLocationRelativeTo(owner);
609                 setVisible(true);
610         }
611
612         /* If any values have been changed, confirm before closing */
613         public boolean check_dirty(String operation) {
614                 if (dirty) {
615                         Object[] options = { String.format("%s anyway", operation), "Keep editing" };
616                         int i;
617                         i = JOptionPane.showOptionDialog(this,
618                                                          String.format("Configuration modified. %s anyway?", operation),
619                                                          "Configuration Modified",
620                                                          JOptionPane.DEFAULT_OPTION,
621                                                          JOptionPane.WARNING_MESSAGE,
622                                                          null, options, options[1]);
623                         if (i != 0)
624                                 return false;
625                 }
626                 return true;
627         }
628
629         void set_dirty() {
630                 dirty = true;
631                 save.setEnabled(true);
632         }
633
634         public void set_clean() {
635                 dirty = false;
636                 save.setEnabled(false);
637         }
638
639         public void dispose() {
640                 AltosPreferences.unregister_units_listener(this);
641                 super.dispose();
642         }
643
644         /* Listen for events from our buttons */
645         public void actionPerformed(ActionEvent e) {
646                 String  cmd = e.getActionCommand();
647
648                 if (cmd.equals("Close") || cmd.equals("Reboot"))
649                         if (!check_dirty(cmd))
650                                 return;
651                 listener.actionPerformed(e);
652                 if (cmd.equals("Close") || cmd.equals("Reboot")) {
653                         setVisible(false);
654                         dispose();
655                 }
656                 set_clean();
657         }
658
659         /* ItemListener interface method */
660         public void itemStateChanged(ItemEvent e) {
661                 set_dirty();
662         }
663
664         /* DocumentListener interface methods */
665         public void changedUpdate(DocumentEvent e) {
666                 set_dirty();
667         }
668
669         public void insertUpdate(DocumentEvent e) {
670                 set_dirty();
671         }
672
673         public void removeUpdate(DocumentEvent e) {
674                 set_dirty();
675         }
676
677         /* Let the config code hook on a listener */
678         public void addActionListener(ActionListener l) {
679                 listener = l;
680         }
681
682         public void units_changed(boolean imperial_units) {
683                 boolean was_dirty = dirty;
684
685                 if (tracker_motion_value.isEnabled()) {
686                         String motion = tracker_motion_value.getSelectedItem().toString();
687                         tracker_motion_label.setText(get_tracker_motion_label());
688                         set_tracker_motion_values();
689                         set_tracker_motion((int) (AltosConvert.height.parse(motion, !imperial_units) + 0.5));
690                 }
691                 if (!was_dirty)
692                         set_clean();
693         }
694
695         /* set and get all of the dialog values */
696         public void set_product(String product) {
697                 radio_frequency_value.set_product(product);
698                 product_value.setText(product);
699                 set_flight_log_max_tool_tip();
700         }
701
702         public void set_version(String version) {
703                 version_value.setText(version);
704         }
705
706         public void set_serial(int serial) {
707                 radio_frequency_value.set_serial(serial);
708                 serial_value.setText(String.format("%d", serial));
709         }
710
711         public void set_altitude_32(int altitude_32) {
712         }
713
714         public void set_main_deploy(int new_main_deploy) {
715         }
716
717         public int main_deploy() {
718                 return -1;
719         }
720
721         public void set_apogee_delay(int new_apogee_delay) { }
722
723         public int apogee_delay() {
724                 return -1;
725         }
726
727         public void set_apogee_lockout(int new_apogee_lockout) { }
728
729         public int apogee_lockout() { return -1; }
730
731         public void set_radio_frequency(double new_radio_frequency) {
732                 radio_frequency_value.set_frequency(new_radio_frequency);
733         }
734
735         public double radio_frequency() {
736                 return radio_frequency_value.frequency();
737         }
738
739         public void set_radio_calibration(int new_radio_calibration) {
740                 radio_calibration_value.setVisible(new_radio_calibration >= 0);
741                 if (new_radio_calibration < 0)
742                         radio_calibration_value.setText("Disabled");
743                 else
744                         radio_calibration_value.setText(String.format("%d", new_radio_calibration));
745         }
746
747         private int parse_int(String name, String s, boolean split) throws AltosConfigDataException {
748                 String v = s;
749                 if (split)
750                         v = s.split("\\s+")[0];
751                 try {
752                         return Integer.parseInt(v);
753                 } catch (NumberFormatException ne) {
754                         throw new AltosConfigDataException("Invalid %s \"%s\"", name, s);
755                 }
756         }
757
758         public int radio_calibration() throws AltosConfigDataException {
759                 return parse_int("radio calibration", radio_calibration_value.getText(), false);
760         }
761
762         public void set_radio_enable(int new_radio_enable) {
763                 if (new_radio_enable >= 0) {
764                         radio_enable_value.setSelected(new_radio_enable > 0);
765                         radio_enable_value.setEnabled(true);
766                 } else {
767                         radio_enable_value.setSelected(true);
768                         radio_enable_value.setVisible(radio_frequency() > 0);
769                         radio_enable_value.setEnabled(false);
770                 }
771                 set_radio_enable_tool_tip();
772         }
773
774         public int radio_enable() {
775                 if (radio_enable_value.isEnabled())
776                         return radio_enable_value.isSelected() ? 1 : 0;
777                 else
778                         return -1;
779         }
780
781         public void set_telemetry_rate(int new_rate) {
782                 rate_value.set_rate(new_rate);
783         }
784
785         public int telemetry_rate() {
786                 return rate_value.rate();
787         }
788
789         public void set_callsign(String new_callsign) {
790                 callsign_value.setVisible(new_callsign != null);
791                 callsign_value.setText(new_callsign);
792         }
793
794         public String callsign() {
795                 return callsign_value.getText();
796         }
797
798         int     flight_log_max_limit;
799         int     flight_log_max;
800
801         public String flight_log_max_label(int flight_log_max) {
802                 if (flight_log_max_limit != 0) {
803                         int     nflight = flight_log_max_limit / flight_log_max;
804                         String  plural = nflight > 1 ? "s" : "";
805
806                         return String.format("%d (%d flight%s)", flight_log_max, nflight, plural);
807                 }
808                 return String.format("%d", flight_log_max);
809         }
810
811         public void set_flight_log_max(int new_flight_log_max) {
812                 flight_log_max_value.setSelectedItem(flight_log_max_label(new_flight_log_max));
813                 flight_log_max = new_flight_log_max;
814                 set_flight_log_max_tool_tip();
815         }
816
817         public void set_flight_log_max_enabled(boolean enable) {
818                 flight_log_max_value.setEnabled(enable);
819                 set_flight_log_max_tool_tip();
820         }
821
822         public int flight_log_max() throws AltosConfigDataException {
823                 return parse_int("flight log max", flight_log_max_value.getSelectedItem().toString(), true);
824         }
825
826         public void set_flight_log_max_limit(int new_flight_log_max_limit) {
827                 flight_log_max_limit = new_flight_log_max_limit;
828                 flight_log_max_value.removeAllItems();
829                 for (int i = 8; i >= 1; i--) {
830                         int     size = flight_log_max_limit / i;
831                         flight_log_max_value.addItem(String.format("%d (%d flights)", size, i));
832                 }
833                 if (flight_log_max != 0)
834                         set_flight_log_max(flight_log_max);
835         }
836
837         public void set_ignite_mode(int new_ignite_mode) { }
838         public int ignite_mode() { return -1; }
839
840
841         public void set_pad_orientation(int new_pad_orientation) { }
842         public int pad_orientation() { return -1; }
843
844         public void set_beep(int new_beep) { }
845
846         public int beep() { return -1; }
847
848         String[] tracker_motion_values() {
849                 if (AltosConvert.imperial_units)
850                         return tracker_motion_values_ft;
851                 else
852                         return tracker_motion_values_m;
853         }
854
855         void set_tracker_motion_values() {
856                 String[]        v = tracker_motion_values();
857                 while (tracker_motion_value.getItemCount() > 0)
858                         tracker_motion_value.removeItemAt(0);
859                 for (int i = 0; i < v.length; i++)
860                         tracker_motion_value.addItem(v[i]);
861                 tracker_motion_value.setMaximumRowCount(v.length);
862         }
863
864         String get_tracker_motion_label() {
865                 return String.format("Logging Trigger Motion (%s):", AltosConvert.height.show_units_name(AltosLib.MISSING));
866         }
867
868         void set_tracker_tool_tip() {
869                 if (tracker_motion_value.isEnabled())
870                         tracker_motion_value.setToolTipText("How far the device must move before logging");
871                 else
872                         tracker_motion_value.setToolTipText("This device doesn't disable logging when stationary");
873                 if (tracker_interval_value.isEnabled())
874                         tracker_interval_value.setToolTipText("How often to report GPS position");
875                 else
876                         tracker_interval_value.setToolTipText("This device can't configure interval");
877         }
878
879         public void set_tracker_motion(int tracker_motion) {
880                 if (tracker_motion < 0) {
881                         tracker_motion_value.setEnabled(false);
882                 } else {
883                         tracker_motion_value.setEnabled(true);
884                         tracker_motion_value.setSelectedItem(AltosConvert.height.say(tracker_motion));
885                 }
886         }
887
888         public int tracker_motion() throws AltosConfigDataException {
889                 return (int) AltosConvert.height.parse(tracker_motion_value.getSelectedItem().toString());
890         }
891
892         public void set_tracker_interval(int tracker_interval) {
893                 if (tracker_interval< 0) {
894                         tracker_interval_value.setEnabled(false);
895                 } else {
896                         tracker_interval_value.setEnabled(true);
897                         tracker_interval_value.setSelectedItem(String.format("%d", tracker_interval));
898                 }
899         }
900
901         public int tracker_interval() throws AltosConfigDataException {
902                 return parse_int ("tracker interval", tracker_interval_value.getSelectedItem().toString(), false);
903         }
904
905         public void set_aprs_interval(int new_aprs_interval) {
906                 String  s;
907
908                 if (new_aprs_interval <= 0)
909                         s = "Disabled";
910                 else
911                         s = Integer.toString(new_aprs_interval);
912                 aprs_interval_value.setSelectedItem(s);
913                 aprs_interval_value.setVisible(new_aprs_interval >= 0);
914                 set_aprs_interval_tool_tip();
915         }
916
917         public int aprs_interval() throws AltosConfigDataException {
918                 String  s = aprs_interval_value.getSelectedItem().toString();
919
920                 if (s.equals("Disabled"))
921                         return 0;
922                 return parse_int("aprs interval", s, false);
923         }
924
925         public void set_aprs_ssid(int new_aprs_ssid) {
926                 aprs_ssid_value.setSelectedItem(Math.max(0,new_aprs_ssid));
927                 aprs_ssid_value.setVisible(new_aprs_ssid >= 0);
928                 set_aprs_ssid_tool_tip();
929         }
930
931         public int aprs_ssid() throws AltosConfigDataException {
932                 Integer i = (Integer) aprs_ssid_value.getSelectedItem();
933                 return i;
934         }
935
936         public void set_aprs_format(int new_aprs_format) {
937                 aprs_format_value.setVisible(new_aprs_format >= 0);
938                 aprs_format_label.setVisible(new_aprs_format >= 0);
939
940                 aprs_format_value.setSelectedIndex(Math.max(0,new_aprs_format));
941                 set_aprs_format_tool_tip();
942         }
943
944         public int aprs_format() throws AltosConfigDataException {
945                 return aprs_format_value.getSelectedIndex();
946         }
947 }