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