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