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