altosuilib: Wrap radio frequency menu in JMenuBar when used in config
[fw/altos] / telegps / TeleGPSConfigUI.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 org.altusmetrum.telegps;
19
20 import java.awt.*;
21 import java.awt.event.*;
22 import javax.swing.*;
23 import javax.swing.event.*;
24 import org.altusmetrum.altoslib_5.*;
25 import org.altusmetrum.altosuilib_3.*;
26
27 public class TeleGPSConfigUI
28         extends AltosUIDialog
29         implements ActionListener, ItemListener, DocumentListener, AltosConfigValues, AltosUnitsListener
30 {
31
32         Container               pane;
33         JLabel                  product_label;
34         JLabel                  version_label;
35         JLabel                  serial_label;
36         JLabel                  frequency_label;
37         JLabel                  radio_calibration_label;
38         JLabel                  radio_frequency_label;
39         JLabel                  radio_enable_label;
40         JLabel                  aprs_interval_label;
41         JLabel                  flight_log_max_label;
42         JLabel                  callsign_label;
43         JLabel                  tracker_motion_label;
44         JLabel                  tracker_interval_label;
45
46         public boolean          dirty;
47
48         JFrame                  owner;
49         JLabel                  product_value;
50         JLabel                  version_value;
51         JLabel                  serial_value;
52         AltosFreqList           radio_frequency_value;
53         JTextField              radio_calibration_value;
54         JRadioButton            radio_enable_value;
55         JComboBox<String>       aprs_interval_value;
56         JComboBox<String>       flight_log_max_value;
57         JTextField              callsign_value;
58         JComboBox<String>       tracker_motion_value;
59         JComboBox<String>       tracker_interval_value;
60
61         JButton                 save;
62         JButton                 reset;
63         JButton                 reboot;
64         JButton                 close;
65
66         ActionListener          listener;
67
68         static String[]         aprs_interval_values = {
69                 "Disabled",
70                 "2",
71                 "5",
72                 "10"
73         };
74
75         static String[]         tracker_motion_values_m = {
76                 "2",
77                 "5",
78                 "10",
79                 "25",
80         };
81
82         static String[]         tracker_motion_values_ft = {
83                 "5",
84                 "20",
85                 "50",
86                 "100"
87         };
88
89         static String[]         tracker_interval_values = {
90                 "1",
91                 "2",
92                 "5",
93                 "10"
94         };
95
96         /* A window listener to catch closing events and tell the config code */
97         class ConfigListener extends WindowAdapter {
98                 TeleGPSConfigUI ui;
99
100                 public ConfigListener(TeleGPSConfigUI this_ui) {
101                         ui = this_ui;
102                 }
103
104                 public void windowClosing(WindowEvent e) {
105                         ui.actionPerformed(new ActionEvent(e.getSource(),
106                                                            ActionEvent.ACTION_PERFORMED,
107                                                            "Close"));
108                 }
109         }
110
111         public void set_pyros(AltosPyro[] new_pyros) {
112         }
113
114         public AltosPyro[] pyros() {
115                 return null;
116         }
117
118         public void set_pyro_firing_time(double new_pyro_firing_time) {
119         }
120
121         public double pyro_firing_time() {
122                 return -1;
123         }
124
125         boolean is_telemetrum() {
126                 String  product = product_value.getText();
127                 return product != null && product.startsWith("TeleGPS");
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_aprs_interval_tool_tip() {
145                 if (aprs_interval_value.isEnabled())
146                         aprs_interval_value.setToolTipText("Enable APRS and set the interval between APRS reports");
147                 else
148                         aprs_interval_value.setToolTipText("Hardware doesn't support APRS");
149         }
150
151         void set_flight_log_max_tool_tip() {
152                 if (flight_log_max_value.isEnabled())
153                         flight_log_max_value.setToolTipText("Size reserved for each flight log (in kB)");
154                 else
155                         flight_log_max_value.setToolTipText("Cannot set max value with flight logs in memory");
156         }
157
158         /* Build the UI using a grid bag */
159         public TeleGPSConfigUI(JFrame in_owner) {
160                 super (in_owner, "Configure Device", false);
161
162                 owner = in_owner;
163                 GridBagConstraints c;
164                 int row = 0;
165
166                 Insets il = new Insets(4,4,4,4);
167                 Insets ir = new Insets(4,4,4,4);
168
169                 pane = getContentPane();
170                 pane.setLayout(new GridBagLayout());
171
172                 /* Product */
173                 c = new GridBagConstraints();
174                 c.gridx = 0; c.gridy = row;
175                 c.gridwidth = 4;
176                 c.fill = GridBagConstraints.NONE;
177                 c.anchor = GridBagConstraints.LINE_START;
178                 c.insets = il;
179                 product_label = new JLabel("Product:");
180                 pane.add(product_label, c);
181
182                 c = new GridBagConstraints();
183                 c.gridx = 4; c.gridy = row;
184                 c.gridwidth = 4;
185                 c.fill = GridBagConstraints.HORIZONTAL;
186                 c.weightx = 1;
187                 c.anchor = GridBagConstraints.LINE_START;
188                 c.insets = ir;
189                 product_value = new JLabel("");
190                 pane.add(product_value, c);
191                 row++;
192
193                 /* Version */
194                 c = new GridBagConstraints();
195                 c.gridx = 0; c.gridy = row;
196                 c.gridwidth = 4;
197                 c.fill = GridBagConstraints.NONE;
198                 c.anchor = GridBagConstraints.LINE_START;
199                 c.insets = il;
200                 c.ipady = 5;
201                 version_label = new JLabel("Software version:");
202                 pane.add(version_label, c);
203
204                 c = new GridBagConstraints();
205                 c.gridx = 4; c.gridy = row;
206                 c.gridwidth = 4;
207                 c.fill = GridBagConstraints.HORIZONTAL;
208                 c.weightx = 1;
209                 c.anchor = GridBagConstraints.LINE_START;
210                 c.insets = ir;
211                 c.ipady = 5;
212                 version_value = new JLabel("");
213                 pane.add(version_value, c);
214                 row++;
215
216                 /* Serial */
217                 c = new GridBagConstraints();
218                 c.gridx = 0; c.gridy = row;
219                 c.gridwidth = 4;
220                 c.fill = GridBagConstraints.NONE;
221                 c.anchor = GridBagConstraints.LINE_START;
222                 c.insets = il;
223                 c.ipady = 5;
224                 serial_label = new JLabel("Serial:");
225                 pane.add(serial_label, c);
226
227                 c = new GridBagConstraints();
228                 c.gridx = 4; c.gridy = row;
229                 c.gridwidth = 4;
230                 c.fill = GridBagConstraints.HORIZONTAL;
231                 c.weightx = 1;
232                 c.anchor = GridBagConstraints.LINE_START;
233                 c.insets = ir;
234                 c.ipady = 5;
235                 serial_value = new JLabel("");
236                 pane.add(serial_value, c);
237                 row++;
238
239                 /* Frequency */
240                 c = new GridBagConstraints();
241                 c.gridx = 0; c.gridy = row;
242                 c.gridwidth = 4;
243                 c.fill = GridBagConstraints.NONE;
244                 c.anchor = GridBagConstraints.LINE_START;
245                 c.insets = il;
246                 c.ipady = 5;
247                 radio_frequency_label = new JLabel("Frequency:");
248                 pane.add(radio_frequency_label, c);
249
250                 c = new GridBagConstraints();
251                 c.gridx = 4; c.gridy = row;
252                 c.gridwidth = 4;
253                 c.fill = GridBagConstraints.HORIZONTAL;
254                 c.weightx = 1;
255                 c.anchor = GridBagConstraints.LINE_START;
256                 c.insets = ir;
257                 c.ipady = 5;
258                 radio_frequency_value = new AltosFreqList();
259                 radio_frequency_value.addItemListener(this);
260
261                 JMenuBar menu_bar = new JMenuBar();
262                 menu_bar.add(radio_frequency_value);
263
264                 pane.add(menu_bar, c);
265                 radio_frequency_value.setToolTipText("Telemetry, RDF and packet frequency");
266                 row++;
267
268                 /* Radio Calibration */
269                 c = new GridBagConstraints();
270                 c.gridx = 0; c.gridy = row;
271                 c.gridwidth = 4;
272                 c.fill = GridBagConstraints.NONE;
273                 c.anchor = GridBagConstraints.LINE_START;
274                 c.insets = il;
275                 c.ipady = 5;
276                 radio_calibration_label = new JLabel("RF Calibration:");
277                 pane.add(radio_calibration_label, c);
278
279                 c = new GridBagConstraints();
280                 c.gridx = 4; c.gridy = row;
281                 c.gridwidth = 4;
282                 c.fill = GridBagConstraints.HORIZONTAL;
283                 c.weightx = 1;
284                 c.anchor = GridBagConstraints.LINE_START;
285                 c.insets = ir;
286                 c.ipady = 5;
287                 radio_calibration_value = new JTextField(String.format("%d", 1186611));
288                 radio_calibration_value.getDocument().addDocumentListener(this);
289                 pane.add(radio_calibration_value, c);
290                 set_radio_calibration_tool_tip();
291                 row++;
292
293                 /* Radio Enable */
294                 c = new GridBagConstraints();
295                 c.gridx = 0; c.gridy = row;
296                 c.gridwidth = 4;
297                 c.fill = GridBagConstraints.NONE;
298                 c.anchor = GridBagConstraints.LINE_START;
299                 c.insets = il;
300                 c.ipady = 5;
301                 radio_enable_label = new JLabel("Telemetry/RDF/APRS Enable:");
302                 pane.add(radio_enable_label, c);
303
304                 c = new GridBagConstraints();
305                 c.gridx = 4; c.gridy = row;
306                 c.gridwidth = 4;
307                 c.fill = GridBagConstraints.HORIZONTAL;
308                 c.weightx = 1;
309                 c.anchor = GridBagConstraints.LINE_START;
310                 c.insets = ir;
311                 c.ipady = 5;
312                 radio_enable_value = new JRadioButton("Enabled");
313                 radio_enable_value.addItemListener(this);
314                 pane.add(radio_enable_value, c);
315                 set_radio_enable_tool_tip();
316                 row++;
317
318                 /* APRS interval */
319                 c = new GridBagConstraints();
320                 c.gridx = 0; c.gridy = row;
321                 c.gridwidth = 4;
322                 c.fill = GridBagConstraints.NONE;
323                 c.anchor = GridBagConstraints.LINE_START;
324                 c.insets = il;
325                 c.ipady = 5;
326                 aprs_interval_label = new JLabel("APRS Interval(s):");
327                 pane.add(aprs_interval_label, c);
328
329                 c = new GridBagConstraints();
330                 c.gridx = 4; c.gridy = row;
331                 c.gridwidth = 4;
332                 c.fill = GridBagConstraints.HORIZONTAL;
333                 c.weightx = 1;
334                 c.anchor = GridBagConstraints.LINE_START;
335                 c.insets = ir;
336                 c.ipady = 5;
337                 aprs_interval_value = new JComboBox<String>(aprs_interval_values);
338                 aprs_interval_value.setEditable(true);
339                 aprs_interval_value.addItemListener(this);
340                 pane.add(aprs_interval_value, c);
341                 set_aprs_interval_tool_tip();
342                 row++;
343
344                 /* Callsign */
345                 c = new GridBagConstraints();
346                 c.gridx = 0; c.gridy = row;
347                 c.gridwidth = 4;
348                 c.fill = GridBagConstraints.NONE;
349                 c.anchor = GridBagConstraints.LINE_START;
350                 c.insets = il;
351                 c.ipady = 5;
352                 callsign_label = new JLabel("Callsign:");
353                 pane.add(callsign_label, c);
354
355                 c = new GridBagConstraints();
356                 c.gridx = 4; c.gridy = row;
357                 c.gridwidth = 4;
358                 c.fill = GridBagConstraints.HORIZONTAL;
359                 c.weightx = 1;
360                 c.anchor = GridBagConstraints.LINE_START;
361                 c.insets = ir;
362                 c.ipady = 5;
363                 callsign_value = new JTextField(AltosUIPreferences.callsign());
364                 callsign_value.getDocument().addDocumentListener(this);
365                 pane.add(callsign_value, c);
366                 callsign_value.setToolTipText("Callsign reported in telemetry data");
367                 row++;
368
369                 /* Flight log max */
370                 c = new GridBagConstraints();
371                 c.gridx = 0; c.gridy = row;
372                 c.gridwidth = 4;
373                 c.fill = GridBagConstraints.NONE;
374                 c.anchor = GridBagConstraints.LINE_START;
375                 c.insets = il;
376                 c.ipady = 5;
377                 flight_log_max_label = new JLabel("Maximum Log Size (kB):");
378                 pane.add(flight_log_max_label, c);
379
380                 c = new GridBagConstraints();
381                 c.gridx = 4; c.gridy = row;
382                 c.gridwidth = 4;
383                 c.fill = GridBagConstraints.HORIZONTAL;
384                 c.weightx = 1;
385                 c.anchor = GridBagConstraints.LINE_START;
386                 c.insets = ir;
387                 c.ipady = 5;
388                 flight_log_max_value = new JComboBox<String>();
389                 flight_log_max_value.setEditable(true);
390                 flight_log_max_value.addItemListener(this);
391                 pane.add(flight_log_max_value, c);
392                 set_flight_log_max_tool_tip();
393                 row++;
394
395                 /* Tracker triger horiz distances */
396                 c = new GridBagConstraints();
397                 c.gridx = 0; c.gridy = row;
398                 c.gridwidth = 4;
399                 c.fill = GridBagConstraints.NONE;
400                 c.anchor = GridBagConstraints.LINE_START;
401                 c.insets = il;
402                 c.ipady = 5;
403                 tracker_motion_label = new JLabel(get_tracker_motion_label());
404                 pane.add(tracker_motion_label, c);
405
406                 c = new GridBagConstraints();
407                 c.gridx = 4; c.gridy = row;
408                 c.gridwidth = 4;
409                 c.fill = GridBagConstraints.HORIZONTAL;
410                 c.weightx = 1;
411                 c.anchor = GridBagConstraints.LINE_START;
412                 c.insets = ir;
413                 c.ipady = 5;
414                 tracker_motion_value = new JComboBox<String>(tracker_motion_values());
415                 tracker_motion_value.setEditable(true);
416                 tracker_motion_value.addItemListener(this);
417                 pane.add(tracker_motion_value, c);
418                 row++;
419
420                 /* Tracker triger vert distances */
421                 c = new GridBagConstraints();
422                 c.gridx = 0; c.gridy = row;
423                 c.gridwidth = 4;
424                 c.fill = GridBagConstraints.NONE;
425                 c.anchor = GridBagConstraints.LINE_START;
426                 c.insets = il;
427                 c.ipady = 5;
428                 tracker_interval_label = new JLabel("Position Reporting Interval (s):");
429                 pane.add(tracker_interval_label, c);
430
431                 c = new GridBagConstraints();
432                 c.gridx = 4; c.gridy = row;
433                 c.gridwidth = 4;
434                 c.fill = GridBagConstraints.HORIZONTAL;
435                 c.weightx = 1;
436                 c.anchor = GridBagConstraints.LINE_START;
437                 c.insets = ir;
438                 c.ipady = 5;
439                 tracker_interval_value = new JComboBox<String>(tracker_interval_values);
440                 tracker_interval_value.setEditable(true);
441                 tracker_interval_value.addItemListener(this);
442                 pane.add(tracker_interval_value, c);
443                 set_tracker_tool_tip();
444                 row++;
445
446                 /* Buttons */
447                 c = new GridBagConstraints();
448                 c.gridx = 0; c.gridy = row;
449                 c.gridwidth = 2;
450                 c.fill = GridBagConstraints.NONE;
451                 c.anchor = GridBagConstraints.LINE_START;
452                 c.insets = il;
453                 save = new JButton("Save");
454                 pane.add(save, c);
455                 save.addActionListener(this);
456                 save.setActionCommand("Save");
457
458                 c = new GridBagConstraints();
459                 c.gridx = 2; c.gridy = row;
460                 c.gridwidth = 2;
461                 c.fill = GridBagConstraints.NONE;
462                 c.anchor = GridBagConstraints.CENTER;
463                 c.insets = il;
464                 reset = new JButton("Reset");
465                 pane.add(reset, c);
466                 reset.addActionListener(this);
467                 reset.setActionCommand("Reset");
468
469                 c = new GridBagConstraints();
470                 c.gridx = 4; c.gridy = row;
471                 c.gridwidth = 2;
472                 c.fill = GridBagConstraints.NONE;
473                 c.anchor = GridBagConstraints.CENTER;
474                 c.insets = il;
475                 reboot = new JButton("Reboot");
476                 pane.add(reboot, c);
477                 reboot.addActionListener(this);
478                 reboot.setActionCommand("Reboot");
479
480                 c = new GridBagConstraints();
481                 c.gridx = 6; c.gridy = row;
482                 c.gridwidth = 2;
483                 c.fill = GridBagConstraints.NONE;
484                 c.anchor = GridBagConstraints.LINE_END;
485                 c.insets = il;
486                 close = new JButton("Close");
487                 pane.add(close, c);
488                 close.addActionListener(this);
489                 close.setActionCommand("Close");
490
491                 addWindowListener(new ConfigListener(this));
492                 AltosPreferences.register_units_listener(this);
493         }
494
495         /* Once the initial values are set, the config code will show the dialog */
496         public void make_visible() {
497                 pack();
498                 setLocationRelativeTo(owner);
499                 setVisible(true);
500         }
501
502         /* If any values have been changed, confirm before closing */
503         public boolean check_dirty(String operation) {
504                 if (dirty) {
505                         Object[] options = { String.format("%s anyway", operation), "Keep editing" };
506                         int i;
507                         i = JOptionPane.showOptionDialog(this,
508                                                          String.format("Configuration modified. %s anyway?", operation),
509                                                          "Configuration Modified",
510                                                          JOptionPane.DEFAULT_OPTION,
511                                                          JOptionPane.WARNING_MESSAGE,
512                                                          null, options, options[1]);
513                         if (i != 0)
514                                 return false;
515                 }
516                 return true;
517         }
518
519         void set_dirty() {
520                 dirty = true;
521                 save.setEnabled(true);
522         }
523
524         public void set_clean() {
525                 dirty = false;
526                 save.setEnabled(false);
527         }
528
529         public void dispose() {
530                 AltosPreferences.unregister_units_listener(this);
531                 super.dispose();
532         }
533
534         /* Listen for events from our buttons */
535         public void actionPerformed(ActionEvent e) {
536                 String  cmd = e.getActionCommand();
537
538                 if (cmd.equals("Close") || cmd.equals("Reboot"))
539                         if (!check_dirty(cmd))
540                                 return;
541                 listener.actionPerformed(e);
542                 if (cmd.equals("Close") || cmd.equals("Reboot")) {
543                         setVisible(false);
544                         dispose();
545                 }
546                 set_clean();
547         }
548
549         /* ItemListener interface method */
550         public void itemStateChanged(ItemEvent e) {
551                 set_dirty();
552         }
553
554         /* DocumentListener interface methods */
555         public void changedUpdate(DocumentEvent e) {
556                 set_dirty();
557         }
558
559         public void insertUpdate(DocumentEvent e) {
560                 set_dirty();
561         }
562
563         public void removeUpdate(DocumentEvent e) {
564                 set_dirty();
565         }
566
567         /* Let the config code hook on a listener */
568         public void addActionListener(ActionListener l) {
569                 listener = l;
570         }
571
572         public void units_changed(boolean imperial_units) {
573                 if (tracker_motion_value.isEnabled()) {
574                         String motion = tracker_motion_value.getSelectedItem().toString();
575                         tracker_motion_label.setText(get_tracker_motion_label());
576                         set_tracker_motion_values();
577                         set_tracker_motion((int) (AltosConvert.height.parse(motion, !imperial_units) + 0.5));
578                 }
579         }
580
581         /* set and get all of the dialog values */
582         public void set_product(String product) {
583                 radio_frequency_value.set_product(product);
584                 product_value.setText(product);
585                 set_flight_log_max_tool_tip();
586         }
587
588         public void set_version(String version) {
589                 version_value.setText(version);
590         }
591
592         public void set_serial(int serial) {
593                 radio_frequency_value.set_serial(serial);
594                 serial_value.setText(String.format("%d", serial));
595         }
596
597         public void set_main_deploy(int new_main_deploy) {
598         }
599
600         public int main_deploy() {
601                 return -1;
602         }
603
604         public void set_apogee_delay(int new_apogee_delay) { }
605
606         public int apogee_delay() {
607                 return -1;
608         }
609
610         public void set_apogee_lockout(int new_apogee_lockout) { }
611
612         public int apogee_lockout() { return -1; }
613
614         public void set_radio_frequency(double new_radio_frequency) {
615                 radio_frequency_value.set_frequency(new_radio_frequency);
616         }
617
618         public double radio_frequency() {
619                 return radio_frequency_value.frequency();
620         }
621
622         public void set_radio_calibration(int new_radio_calibration) {
623                 radio_calibration_value.setVisible(new_radio_calibration >= 0);
624                 if (new_radio_calibration < 0)
625                         radio_calibration_value.setText("Disabled");
626                 else
627                         radio_calibration_value.setText(String.format("%d", new_radio_calibration));
628         }
629
630         private int parse_int(String name, String s, boolean split) throws AltosConfigDataException {
631                 String v = s;
632                 if (split)
633                         v = s.split("\\s+")[0];
634                 try {
635                         return Integer.parseInt(v);
636                 } catch (NumberFormatException ne) {
637                         throw new AltosConfigDataException("Invalid %s \"%s\"", name, s);
638                 }
639         }
640
641         public int radio_calibration() throws AltosConfigDataException {
642                 return parse_int("radio calibration", radio_calibration_value.getText(), false);
643         }
644
645         public void set_radio_enable(int new_radio_enable) {
646                 if (new_radio_enable >= 0) {
647                         radio_enable_value.setSelected(new_radio_enable > 0);
648                         radio_enable_value.setEnabled(true);
649                 } else {
650                         radio_enable_value.setSelected(true);
651                         radio_enable_value.setVisible(radio_frequency() > 0);
652                         radio_enable_value.setEnabled(false);
653                 }
654                 set_radio_enable_tool_tip();
655         }
656
657         public int radio_enable() {
658                 if (radio_enable_value.isEnabled())
659                         return radio_enable_value.isSelected() ? 1 : 0;
660                 else
661                         return -1;
662         }
663
664         public void set_callsign(String new_callsign) {
665                 callsign_value.setVisible(new_callsign != null);
666                 callsign_value.setText(new_callsign);
667         }
668
669         public String callsign() {
670                 return callsign_value.getText();
671         }
672
673         int     flight_log_max_limit;
674         int     flight_log_max;
675
676         public String flight_log_max_label(int flight_log_max) {
677                 if (flight_log_max_limit != 0) {
678                         int     nflight = flight_log_max_limit / flight_log_max;
679                         String  plural = nflight > 1 ? "s" : "";
680
681                         return String.format("%d (%d flight%s)", flight_log_max, nflight, plural);
682                 }
683                 return String.format("%d", flight_log_max);
684         }
685
686         public void set_flight_log_max(int new_flight_log_max) {
687                 flight_log_max_value.setSelectedItem(flight_log_max_label(new_flight_log_max));
688                 flight_log_max = new_flight_log_max;
689                 set_flight_log_max_tool_tip();
690         }
691
692         public void set_flight_log_max_enabled(boolean enable) {
693                 flight_log_max_value.setEnabled(enable);
694                 set_flight_log_max_tool_tip();
695         }
696
697         public int flight_log_max() throws AltosConfigDataException {
698                 return parse_int("flight log max", flight_log_max_value.getSelectedItem().toString(), true);
699         }
700
701         public void set_flight_log_max_limit(int new_flight_log_max_limit) {
702                 flight_log_max_limit = new_flight_log_max_limit;
703                 flight_log_max_value.removeAllItems();
704                 for (int i = 8; i >= 1; i--) {
705                         int     size = flight_log_max_limit / i;
706                         flight_log_max_value.addItem(String.format("%d (%d flights)", size, i));
707                 }
708                 if (flight_log_max != 0)
709                         set_flight_log_max(flight_log_max);
710         }
711
712         public void set_ignite_mode(int new_ignite_mode) { }
713         public int ignite_mode() { return -1; }
714
715
716         public void set_pad_orientation(int new_pad_orientation) { }
717         public int pad_orientation() { return -1; }
718
719         public void set_beep(int new_beep) { }
720
721         public int beep() { return -1; }
722
723         String[] tracker_motion_values() {
724                 if (AltosConvert.imperial_units)
725                         return tracker_motion_values_ft;
726                 else
727                         return tracker_motion_values_m;
728         }
729
730         void set_tracker_motion_values() {
731                 String[]        v = tracker_motion_values();
732                 while (tracker_motion_value.getItemCount() > 0)
733                         tracker_motion_value.removeItemAt(0);
734                 for (int i = 0; i < v.length; i++)
735                         tracker_motion_value.addItem(v[i]);
736                 tracker_motion_value.setMaximumRowCount(v.length);
737         }
738
739         String get_tracker_motion_label() {
740                 return String.format("Logging Trigger Motion (%s):", AltosConvert.height.show_units());
741         }
742
743         void set_tracker_tool_tip() {
744                 if (tracker_motion_value.isEnabled())
745                         tracker_motion_value.setToolTipText("How far the device must move before logging");
746                 else
747                         tracker_motion_value.setToolTipText("This device doesn't disable logging when stationary");
748                 if (tracker_interval_value.isEnabled())
749                         tracker_interval_value.setToolTipText("How often to report GPS position");
750                 else
751                         tracker_interval_value.setToolTipText("This device can't configure interval");
752         }
753
754         public void set_tracker_motion(int tracker_motion) {
755                 tracker_motion_value.setSelectedItem(AltosConvert.height.say(tracker_motion));
756         }
757
758         public int tracker_motion() throws AltosConfigDataException {
759                 return (int) AltosConvert.height.parse(tracker_motion_value.getSelectedItem().toString());
760         }
761
762         public void set_tracker_interval(int tracker_interval) {
763                 tracker_interval_value.setSelectedItem(String.format("%d", tracker_interval));
764         }
765
766         public int tracker_interval() throws AltosConfigDataException {
767                 return parse_int ("tracker interval", tracker_interval_value.getSelectedItem().toString(), false);
768         }
769
770         public void set_aprs_interval(int new_aprs_interval) {
771                 String  s;
772
773                 if (new_aprs_interval <= 0)
774                         s = "Disabled";
775                 else
776                         s = Integer.toString(new_aprs_interval);
777                 aprs_interval_value.setSelectedItem(s);
778                 aprs_interval_value.setVisible(new_aprs_interval >= 0);
779                 set_aprs_interval_tool_tip();
780         }
781
782         public int aprs_interval() throws AltosConfigDataException {
783                 String  s = aprs_interval_value.getSelectedItem().toString();
784
785                 if (s.equals("Disabled"))
786                         return 0;
787                 return parse_int("aprs interval", s, false);
788         }
789 }