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