altosui: Move AltosEepromChunk.java to lib
[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 import org.altusmetrum.AltosLib.*;
32
33 import libaltosJNI.*;
34
35 public class AltosConfigUI
36         extends AltosDialog
37         implements ActionListener, ItemListener, DocumentListener
38 {
39
40         Container       pane;
41         Box             box;
42         JLabel          product_label;
43         JLabel          version_label;
44         JLabel          serial_label;
45         JLabel          main_deploy_label;
46         JLabel          apogee_delay_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         AltosFreqList   radio_frequency_value;
65         JTextField      radio_calibration_value;
66         JRadioButton    radio_enable_value;
67         JComboBox       flight_log_max_value;
68         JComboBox       ignite_mode_value;
69         JComboBox       pad_orientation_value;
70         JTextField      callsign_value;
71
72         JButton         save;
73         JButton         reset;
74         JButton         reboot;
75         JButton         close;
76
77         ActionListener  listener;
78
79         static String[] main_deploy_values = {
80                 "100", "150", "200", "250", "300", "350",
81                 "400", "450", "500"
82         };
83
84         static String[] apogee_delay_values = {
85                 "0", "1", "2", "3", "4", "5"
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
184                 Insets il = new Insets(4,4,4,4);
185                 Insets ir = new Insets(4,4,4,4);
186
187                 pane = getContentPane();
188                 pane.setLayout(new GridBagLayout());
189
190                 /* Product */
191                 c = new GridBagConstraints();
192                 c.gridx = 0; c.gridy = 0;
193                 c.gridwidth = 4;
194                 c.fill = GridBagConstraints.NONE;
195                 c.anchor = GridBagConstraints.LINE_START;
196                 c.insets = il;
197                 product_label = new JLabel("Product:");
198                 pane.add(product_label, c);
199
200                 c = new GridBagConstraints();
201                 c.gridx = 4; c.gridy = 0;
202                 c.gridwidth = 4;
203                 c.fill = GridBagConstraints.HORIZONTAL;
204                 c.weightx = 1;
205                 c.anchor = GridBagConstraints.LINE_START;
206                 c.insets = ir;
207                 product_value = new JLabel("");
208                 pane.add(product_value, c);
209
210                 /* Version */
211                 c = new GridBagConstraints();
212                 c.gridx = 0; c.gridy = 1;
213                 c.gridwidth = 4;
214                 c.fill = GridBagConstraints.NONE;
215                 c.anchor = GridBagConstraints.LINE_START;
216                 c.insets = il;
217                 c.ipady = 5;
218                 version_label = new JLabel("Software version:");
219                 pane.add(version_label, c);
220
221                 c = new GridBagConstraints();
222                 c.gridx = 4; c.gridy = 1;
223                 c.gridwidth = 4;
224                 c.fill = GridBagConstraints.HORIZONTAL;
225                 c.weightx = 1;
226                 c.anchor = GridBagConstraints.LINE_START;
227                 c.insets = ir;
228                 c.ipady = 5;
229                 version_value = new JLabel("");
230                 pane.add(version_value, c);
231
232                 /* Serial */
233                 c = new GridBagConstraints();
234                 c.gridx = 0; c.gridy = 2;
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 = 2;
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
254                 /* Main deploy */
255                 c = new GridBagConstraints();
256                 c.gridx = 0; c.gridy = 3;
257                 c.gridwidth = 4;
258                 c.fill = GridBagConstraints.NONE;
259                 c.anchor = GridBagConstraints.LINE_START;
260                 c.insets = il;
261                 c.ipady = 5;
262                 main_deploy_label = new JLabel("Main Deploy Altitude(m):");
263                 pane.add(main_deploy_label, c);
264
265                 c = new GridBagConstraints();
266                 c.gridx = 4; c.gridy = 3;
267                 c.gridwidth = 4;
268                 c.fill = GridBagConstraints.HORIZONTAL;
269                 c.weightx = 1;
270                 c.anchor = GridBagConstraints.LINE_START;
271                 c.insets = ir;
272                 c.ipady = 5;
273                 main_deploy_value = new JComboBox(main_deploy_values);
274                 main_deploy_value.setEditable(true);
275                 main_deploy_value.addItemListener(this);
276                 pane.add(main_deploy_value, c);
277                 main_deploy_value.setToolTipText("Height above pad altitude to fire main charge");
278
279                 /* Apogee delay */
280                 c = new GridBagConstraints();
281                 c.gridx = 0; c.gridy = 4;
282                 c.gridwidth = 4;
283                 c.fill = GridBagConstraints.NONE;
284                 c.anchor = GridBagConstraints.LINE_START;
285                 c.insets = il;
286                 c.ipady = 5;
287                 apogee_delay_label = new JLabel("Apogee Delay(s):");
288                 pane.add(apogee_delay_label, c);
289
290                 c = new GridBagConstraints();
291                 c.gridx = 4; c.gridy = 4;
292                 c.gridwidth = 4;
293                 c.fill = GridBagConstraints.HORIZONTAL;
294                 c.weightx = 1;
295                 c.anchor = GridBagConstraints.LINE_START;
296                 c.insets = ir;
297                 c.ipady = 5;
298                 apogee_delay_value = new JComboBox(apogee_delay_values);
299                 apogee_delay_value.setEditable(true);
300                 apogee_delay_value.addItemListener(this);
301                 pane.add(apogee_delay_value, c);
302                 apogee_delay_value.setToolTipText("Delay after apogee before charge fires");
303
304                 /* Frequency */
305                 c = new GridBagConstraints();
306                 c.gridx = 0; c.gridy = 5;
307                 c.gridwidth = 4;
308                 c.fill = GridBagConstraints.NONE;
309                 c.anchor = GridBagConstraints.LINE_START;
310                 c.insets = il;
311                 c.ipady = 5;
312                 radio_frequency_label = new JLabel("Frequency:");
313                 pane.add(radio_frequency_label, c);
314
315                 c = new GridBagConstraints();
316                 c.gridx = 4; c.gridy = 5;
317                 c.gridwidth = 4;
318                 c.fill = GridBagConstraints.HORIZONTAL;
319                 c.weightx = 1;
320                 c.anchor = GridBagConstraints.LINE_START;
321                 c.insets = ir;
322                 c.ipady = 5;
323                 radio_frequency_value = new AltosFreqList();
324                 radio_frequency_value.addItemListener(this);
325                 pane.add(radio_frequency_value, c);
326                 radio_frequency_value.setToolTipText("Telemetry, RDF and packet frequency");
327
328                 /* Radio Calibration */
329                 c = new GridBagConstraints();
330                 c.gridx = 0; c.gridy = 6;
331                 c.gridwidth = 4;
332                 c.fill = GridBagConstraints.NONE;
333                 c.anchor = GridBagConstraints.LINE_START;
334                 c.insets = il;
335                 c.ipady = 5;
336                 radio_calibration_label = new JLabel("RF Calibration:");
337                 pane.add(radio_calibration_label, c);
338
339                 c = new GridBagConstraints();
340                 c.gridx = 4; c.gridy = 6;
341                 c.gridwidth = 4;
342                 c.fill = GridBagConstraints.HORIZONTAL;
343                 c.weightx = 1;
344                 c.anchor = GridBagConstraints.LINE_START;
345                 c.insets = ir;
346                 c.ipady = 5;
347                 radio_calibration_value = new JTextField(String.format("%d", 1186611));
348                 radio_calibration_value.getDocument().addDocumentListener(this);
349                 if (remote)
350                         radio_calibration_value.setEnabled(false);
351                 pane.add(radio_calibration_value, c);
352                 set_radio_calibration_tool_tip();
353
354                 /* Radio Enable */
355                 c = new GridBagConstraints();
356                 c.gridx = 0; c.gridy = 7;
357                 c.gridwidth = 4;
358                 c.fill = GridBagConstraints.NONE;
359                 c.anchor = GridBagConstraints.LINE_START;
360                 c.insets = il;
361                 c.ipady = 5;
362                 radio_enable_label = new JLabel("Telemetry/RDF Enable:");
363                 pane.add(radio_enable_label, c);
364
365                 c = new GridBagConstraints();
366                 c.gridx = 4; c.gridy = 7;
367                 c.gridwidth = 4;
368                 c.fill = GridBagConstraints.HORIZONTAL;
369                 c.weightx = 1;
370                 c.anchor = GridBagConstraints.LINE_START;
371                 c.insets = ir;
372                 c.ipady = 5;
373                 radio_enable_value = new JRadioButton("Enabled");
374                 radio_enable_value.addItemListener(this);
375                 pane.add(radio_enable_value, c);
376                 set_radio_enable_tool_tip();
377
378                 /* Callsign */
379                 c = new GridBagConstraints();
380                 c.gridx = 0; c.gridy = 8;
381                 c.gridwidth = 4;
382                 c.fill = GridBagConstraints.NONE;
383                 c.anchor = GridBagConstraints.LINE_START;
384                 c.insets = il;
385                 c.ipady = 5;
386                 callsign_label = new JLabel("Callsign:");
387                 pane.add(callsign_label, c);
388
389                 c = new GridBagConstraints();
390                 c.gridx = 4; c.gridy = 8;
391                 c.gridwidth = 4;
392                 c.fill = GridBagConstraints.HORIZONTAL;
393                 c.weightx = 1;
394                 c.anchor = GridBagConstraints.LINE_START;
395                 c.insets = ir;
396                 c.ipady = 5;
397                 callsign_value = new JTextField(AltosUIPreferences.callsign());
398                 callsign_value.getDocument().addDocumentListener(this);
399                 pane.add(callsign_value, c);
400                 callsign_value.setToolTipText("Callsign reported in telemetry data");
401
402                 /* Flight log max */
403                 c = new GridBagConstraints();
404                 c.gridx = 0; c.gridy = 9;
405                 c.gridwidth = 4;
406                 c.fill = GridBagConstraints.NONE;
407                 c.anchor = GridBagConstraints.LINE_START;
408                 c.insets = il;
409                 c.ipady = 5;
410                 flight_log_max_label = new JLabel("Maximum Flight Log Size:");
411                 pane.add(flight_log_max_label, c);
412
413                 c = new GridBagConstraints();
414                 c.gridx = 4; c.gridy = 9;
415                 c.gridwidth = 4;
416                 c.fill = GridBagConstraints.HORIZONTAL;
417                 c.weightx = 1;
418                 c.anchor = GridBagConstraints.LINE_START;
419                 c.insets = ir;
420                 c.ipady = 5;
421                 flight_log_max_value = new JComboBox(flight_log_max_values);
422                 flight_log_max_value.setEditable(true);
423                 flight_log_max_value.addItemListener(this);
424                 pane.add(flight_log_max_value, c);
425                 set_flight_log_max_tool_tip();
426
427                 /* Ignite mode */
428                 c = new GridBagConstraints();
429                 c.gridx = 0; c.gridy = 10;
430                 c.gridwidth = 4;
431                 c.fill = GridBagConstraints.NONE;
432                 c.anchor = GridBagConstraints.LINE_START;
433                 c.insets = il;
434                 c.ipady = 5;
435                 ignite_mode_label = new JLabel("Igniter Firing Mode:");
436                 pane.add(ignite_mode_label, c);
437
438                 c = new GridBagConstraints();
439                 c.gridx = 4; c.gridy = 10;
440                 c.gridwidth = 4;
441                 c.fill = GridBagConstraints.HORIZONTAL;
442                 c.weightx = 1;
443                 c.anchor = GridBagConstraints.LINE_START;
444                 c.insets = ir;
445                 c.ipady = 5;
446                 ignite_mode_value = new JComboBox(ignite_mode_values);
447                 ignite_mode_value.setEditable(false);
448                 ignite_mode_value.addItemListener(this);
449                 pane.add(ignite_mode_value, c);
450                 set_ignite_mode_tool_tip();
451
452                 /* Pad orientation */
453                 c = new GridBagConstraints();
454                 c.gridx = 0; c.gridy = 11;
455                 c.gridwidth = 4;
456                 c.fill = GridBagConstraints.NONE;
457                 c.anchor = GridBagConstraints.LINE_START;
458                 c.insets = il;
459                 c.ipady = 5;
460                 pad_orientation_label = new JLabel("Pad Orientation:");
461                 pane.add(pad_orientation_label, c);
462
463                 c = new GridBagConstraints();
464                 c.gridx = 4; c.gridy = 11;
465                 c.gridwidth = 4;
466                 c.fill = GridBagConstraints.HORIZONTAL;
467                 c.weightx = 1;
468                 c.anchor = GridBagConstraints.LINE_START;
469                 c.insets = ir;
470                 c.ipady = 5;
471                 pad_orientation_value = new JComboBox(pad_orientation_values);
472                 pad_orientation_value.setEditable(false);
473                 pad_orientation_value.addItemListener(this);
474                 pane.add(pad_orientation_value, c);
475                 set_pad_orientation_tool_tip();
476
477                 /* Buttons */
478                 c = new GridBagConstraints();
479                 c.gridx = 0; c.gridy = 12;
480                 c.gridwidth = 2;
481                 c.fill = GridBagConstraints.NONE;
482                 c.anchor = GridBagConstraints.LINE_START;
483                 c.insets = il;
484                 save = new JButton("Save");
485                 pane.add(save, c);
486                 save.addActionListener(this);
487                 save.setActionCommand("Save");
488
489                 c = new GridBagConstraints();
490                 c.gridx = 2; c.gridy = 12;
491                 c.gridwidth = 2;
492                 c.fill = GridBagConstraints.NONE;
493                 c.anchor = GridBagConstraints.CENTER;
494                 c.insets = il;
495                 reset = new JButton("Reset");
496                 pane.add(reset, c);
497                 reset.addActionListener(this);
498                 reset.setActionCommand("Reset");
499
500                 c = new GridBagConstraints();
501                 c.gridx = 4; c.gridy = 12;
502                 c.gridwidth = 2;
503                 c.fill = GridBagConstraints.NONE;
504                 c.anchor = GridBagConstraints.CENTER;
505                 c.insets = il;
506                 reboot = new JButton("Reboot");
507                 pane.add(reboot, c);
508                 reboot.addActionListener(this);
509                 reboot.setActionCommand("Reboot");
510
511                 c = new GridBagConstraints();
512                 c.gridx = 6; c.gridy = 12;
513                 c.gridwidth = 2;
514                 c.fill = GridBagConstraints.NONE;
515                 c.anchor = GridBagConstraints.LINE_END;
516                 c.insets = il;
517                 close = new JButton("Close");
518                 pane.add(close, c);
519                 close.addActionListener(this);
520                 close.setActionCommand("Close");
521
522                 addWindowListener(new ConfigListener(this));
523         }
524
525         /* Once the initial values are set, the config code will show the dialog */
526         public void make_visible() {
527                 pack();
528                 setLocationRelativeTo(owner);
529                 setVisible(true);
530         }
531
532         /* If any values have been changed, confirm before closing */
533         public boolean check_dirty(String operation) {
534                 if (dirty) {
535                         Object[] options = { String.format("%s anyway", operation), "Keep editing" };
536                         int i;
537                         i = JOptionPane.showOptionDialog(this,
538                                                          String.format("Configuration modified. %s anyway?", operation),
539                                                          "Configuration Modified",
540                                                          JOptionPane.DEFAULT_OPTION,
541                                                          JOptionPane.WARNING_MESSAGE,
542                                                          null, options, options[1]);
543                         if (i != 0)
544                                 return false;
545                 }
546                 return true;
547         }
548
549         /* Listen for events from our buttons */
550         public void actionPerformed(ActionEvent e) {
551                 String  cmd = e.getActionCommand();
552
553                 if (cmd.equals("Close") || cmd.equals("Reboot"))
554                         if (!check_dirty(cmd))
555                                 return;
556                 listener.actionPerformed(e);
557                 if (cmd.equals("Close") || cmd.equals("Reboot")) {
558                         setVisible(false);
559                         dispose();
560                 }
561                 dirty = false;
562         }
563
564         /* ItemListener interface method */
565         public void itemStateChanged(ItemEvent e) {
566                 dirty = true;
567         }
568
569         /* DocumentListener interface methods */
570         public void changedUpdate(DocumentEvent e) {
571                 dirty = true;
572         }
573
574         public void insertUpdate(DocumentEvent e) {
575                 dirty = true;
576         }
577
578         public void removeUpdate(DocumentEvent e) {
579                 dirty = true;
580         }
581
582         /* Let the config code hook on a listener */
583         public void addActionListener(ActionListener l) {
584                 listener = l;
585         }
586
587         /* set and get all of the dialog values */
588         public void set_product(String product) {
589                 radio_frequency_value.set_product(product);
590                 product_value.setText(product);
591                 set_pad_orientation_tool_tip();
592                 set_flight_log_max_tool_tip();
593         }
594
595         public void set_version(String version) {
596                 version_value.setText(version);
597         }
598
599         public void set_serial(int serial) {
600                 radio_frequency_value.set_serial(serial);
601                 serial_value.setText(String.format("%d", serial));
602         }
603
604         public void set_main_deploy(int new_main_deploy) {
605                 main_deploy_value.setSelectedItem(Integer.toString(new_main_deploy));
606         }
607
608         public int main_deploy() {
609                 return Integer.parseInt(main_deploy_value.getSelectedItem().toString());
610         }
611
612         public void set_apogee_delay(int new_apogee_delay) {
613                 apogee_delay_value.setSelectedItem(Integer.toString(new_apogee_delay));
614         }
615
616         public int apogee_delay() {
617                 return Integer.parseInt(apogee_delay_value.getSelectedItem().toString());
618         }
619
620         public void set_radio_frequency(double new_radio_frequency) {
621                 int i;
622                 for (i = 0; i < radio_frequency_value.getItemCount(); i++) {
623                         AltosFrequency  f = (AltosFrequency) radio_frequency_value.getItemAt(i);
624                         
625                         if (f.close(new_radio_frequency)) {
626                                 radio_frequency_value.setSelectedIndex(i);
627                                 return;
628                         }
629                 }
630                 for (i = 0; i < radio_frequency_value.getItemCount(); i++) {
631                         AltosFrequency  f = (AltosFrequency) radio_frequency_value.getItemAt(i);
632                         
633                         if (new_radio_frequency < f.frequency)
634                                 break;
635                 }
636                 String  description = String.format("%s serial %s",
637                                                     product_value.getText(),
638                                                     serial_value.getText());
639                 AltosFrequency  new_frequency = new AltosFrequency(new_radio_frequency, description);
640                 AltosUIPreferences.add_common_frequency(new_frequency);
641                 radio_frequency_value.insertItemAt(new_frequency, i);
642         }
643
644         public double radio_frequency() {
645                 return radio_frequency_value.frequency();
646         }
647
648         public void set_radio_calibration(int new_radio_calibration) {
649                 radio_calibration_value.setText(String.format("%d", new_radio_calibration));
650         }
651
652         public int radio_calibration() {
653                 return Integer.parseInt(radio_calibration_value.getText());
654         }
655
656         public void set_radio_enable(int new_radio_enable) {
657                 if (new_radio_enable >= 0) {
658                         radio_enable_value.setSelected(new_radio_enable > 0);
659                         radio_enable_value.setEnabled(true);
660                 } else {
661                         radio_enable_value.setSelected(true);
662                         radio_enable_value.setEnabled(false);
663                 }
664                 set_radio_enable_tool_tip();
665         }
666
667         public int radio_enable() {
668                 if (radio_enable_value.isEnabled())
669                         return radio_enable_value.isSelected() ? 1 : 0;
670                 else
671                         return -1;
672         }
673
674         public void set_callsign(String new_callsign) {
675                 callsign_value.setText(new_callsign);
676         }
677
678         public String callsign() {
679                 return callsign_value.getText();
680         }
681
682         public void set_flight_log_max(int new_flight_log_max) {
683                 if (new_flight_log_max == 0)
684                         flight_log_max_value.setEnabled(false);
685                 flight_log_max_value.setSelectedItem(Integer.toString(new_flight_log_max));
686                 set_flight_log_max_tool_tip();
687         }
688
689         public void set_flight_log_max_enabled(boolean enable) {
690                 flight_log_max_value.setEnabled(enable);
691                 set_flight_log_max_tool_tip();
692         }
693
694         public int flight_log_max() {
695                 return Integer.parseInt(flight_log_max_value.getSelectedItem().toString());
696         }
697
698         public void set_flight_log_max_limit(int flight_log_max_limit) {
699                 boolean any_added = false;
700                 flight_log_max_value.removeAllItems();
701                 for (int i = 0; i < flight_log_max_values.length; i++) {
702                         if (Integer.parseInt(flight_log_max_values[i]) < flight_log_max_limit){
703                                 flight_log_max_value.addItem(flight_log_max_values[i]);
704                                 any_added = true;
705                         }
706                 }
707                 flight_log_max_value.addItem(String.format("%d", flight_log_max_limit));
708         }
709
710         public void set_ignite_mode(int new_ignite_mode) {
711                 if (new_ignite_mode < 0) {
712                         ignite_mode_value.setEnabled(false);
713                         new_ignite_mode = 0;
714                 } else {
715                         ignite_mode_value.setEnabled(true);
716                 }
717                 ignite_mode_value.setSelectedIndex(new_ignite_mode);
718                 set_ignite_mode_tool_tip();
719         }
720
721         public int ignite_mode() {
722                 if (ignite_mode_value.isEnabled())
723                         return ignite_mode_value.getSelectedIndex();
724                 else
725                         return -1;
726         }
727
728
729         public void set_pad_orientation(int new_pad_orientation) {
730                 if (new_pad_orientation < 0) {
731                         pad_orientation_value.setEnabled(false);
732                         new_pad_orientation = 0;
733                 } else {
734                         pad_orientation_value.setEnabled(true);
735                 }
736                 pad_orientation_value.setSelectedIndex(new_pad_orientation);
737                 set_pad_orientation_tool_tip();
738         }
739
740         public int pad_orientation() {
741                 if (pad_orientation_value.isEnabled())
742                         return pad_orientation_value.getSelectedIndex();
743                 else
744                         return -1;
745         }
746
747         public void set_clean() {
748                 dirty = false;
749         }
750 }