altos/test: Adjust CRC error rate after FEC fix
[fw/altos] / altosuilib / AltosUIFreqList.java
1 /*
2  * Copyright © 2011 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; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
17  */
18
19 package org.altusmetrum.altosuilib_14;
20
21 import javax.swing.*;
22 import org.altusmetrum.altoslib_14.*;
23
24 public class AltosUIFreqList extends JComboBox<AltosFrequency> {
25
26         String  product;
27         int     serial;
28         int     calibrate;
29
30         public void set_frequency(double new_frequency) {
31                 int i;
32
33                 if (new_frequency < 0) {
34                         setVisible(false);
35                         return;
36                 }
37
38                 for (i = 0; i < getItemCount(); i++) {
39                         AltosFrequency  f = (AltosFrequency) getItemAt(i);
40
41                         if (f.close(new_frequency)) {
42                                 setSelectedIndex(i);
43                                 return;
44                         }
45                 }
46                 for (i = 0; i < getItemCount(); i++) {
47                         AltosFrequency  f = (AltosFrequency) getItemAt(i);
48
49                         if (new_frequency < f.frequency)
50                                 break;
51                 }
52                 String  description = String.format("%s serial %d", product, serial);
53                 AltosFrequency  frequency = new AltosFrequency(new_frequency, description);
54                 AltosUIPreferences.add_common_frequency(frequency);
55                 insertItemAt(frequency, i);
56                 setMaximumRowCount(getItemCount());
57                 setVisible(true);
58         }
59
60         public void set_product(String new_product) {
61                 product = new_product;
62         }
63
64         public void set_serial(int new_serial) {
65                 serial = new_serial;
66         }
67
68         public double frequency() {
69                 AltosFrequency  f = (AltosFrequency) getSelectedItem();
70                 if (f != null)
71                         return f.frequency;
72                 return 434.550;
73         }
74
75         public AltosUIFreqList () {
76                 super(AltosUIPreferences.common_frequencies());
77                 setMaximumRowCount(getItemCount());
78                 setEditable(false);
79                 product = "Unknown";
80                 serial = 0;
81         }
82
83         public AltosUIFreqList(double in_frequency) {
84                 this();
85                 set_frequency(in_frequency);
86         }
87 }