altosui: Make set of telemetries to use while scanning configurable
authorKeith Packard <keithp@keithp.com>
Tue, 9 Aug 2011 03:38:44 +0000 (20:38 -0700)
committerKeith Packard <keithp@keithp.com>
Tue, 9 Aug 2011 03:38:44 +0000 (20:38 -0700)
with a preference to remember across application runs.

Signed-off-by: Keith Packard <keithp@keithp.com>
altosui/AltosPreferences.java
altosui/AltosScanUI.java

index 8609f94..de926b3 100644 (file)
@@ -52,6 +52,9 @@ class AltosPreferences {
        /* serial debug preference name */
        final static String serialDebugPreference = "SERIAL-DEBUG";
 
+       /* scanning telemetry preferences name */
+       final static String scanningTelemetryPreference = "SCANNING-TELEMETRY";
+
        /* Default logdir is ~/TeleMetrum */
        final static String logdirName = "TeleMetrum";
 
@@ -82,6 +85,9 @@ class AltosPreferences {
        /* Serial debug */
        static boolean serial_debug;
 
+       /* Scanning telemetry */
+       static int scanning_telemetry;
+
        /* List of frequencies */
        final static String common_frequencies_node_name = "COMMON-FREQUENCIES";
        static AltosFrequency[] common_frequencies;
@@ -156,6 +162,8 @@ class AltosPreferences {
 
                callsign = preferences.get(callsignPreference,"N0CALL");
 
+               scanning_telemetry = preferences.getInt(scanningTelemetryPreference,(1 << Altos.ao_telemetry_standard));
+
                String firmwaredir_string = preferences.get(firmwaredirPreference, null);
                if (firmwaredir_string != null)
                        firmwaredir = new File(firmwaredir_string);
@@ -279,6 +287,18 @@ class AltosPreferences {
                return telemetry;
        }
 
+       public static void set_scanning_telemetry(int new_scanning_telemetry) {
+               scanning_telemetry = new_scanning_telemetry;
+               synchronized (preferences) {
+                       preferences.putInt(scanningTelemetryPreference, scanning_telemetry);
+                       flush_preferences();
+               }
+       }
+
+       public static int scanning_telemetry() {
+               return scanning_telemetry;
+       }
+
        public static void set_voice(boolean new_voice) {
                voice = new_voice;
                synchronized (preferences) {
index b47405c..dd6672a 100644 (file)
@@ -115,6 +115,7 @@ public class AltosScanUI
        private JLabel                  telemetry_label;
        private JButton                 cancel_button;
        private JButton                 monitor_button;
+       private JCheckBox[]             telemetry_boxes;
        javax.swing.Timer               timer;
        AltosScanResults                results = new AltosScanResults();
 
@@ -210,11 +211,15 @@ public class AltosScanUI
                reader.serial.set_monitor(false);
                Thread.sleep(100);
                ++frequency_index;
-               if (frequency_index >= frequencies.length) {
+               if (frequency_index >= frequencies.length ||
+                   !telemetry_boxes[telemetry - Altos.ao_telemetry_min].isSelected())
+               {
                        frequency_index = 0;
-                       ++telemetry;
-                       if (telemetry > Altos.ao_telemetry_max)
-                               telemetry = Altos.ao_telemetry_min;
+                       do {
+                               ++telemetry;
+                               if (telemetry > Altos.ao_telemetry_max)
+                                       telemetry = Altos.ao_telemetry_min;
+                       } while (!telemetry_boxes[telemetry - Altos.ao_telemetry_min].isSelected());
                        set_telemetry();
                }
                set_frequency();
@@ -251,6 +256,21 @@ public class AltosScanUI
                        if (cmd.equals("tick"))
                                tick_timer();
 
+                       if (cmd.equals("telemetry")) {
+                               int k;
+                               int scanning_telemetry = 0;
+                               for (k = Altos.ao_telemetry_min; k <= Altos.ao_telemetry_max; k++) {
+                                       int j = k - Altos.ao_telemetry_min;
+                                       if (telemetry_boxes[j].isSelected())
+                                               scanning_telemetry |= (1 << k);
+                               }
+                               if (scanning_telemetry == 0) {
+                                       scanning_telemetry |= (1 << Altos.ao_telemetry_standard);
+                                       telemetry_boxes[Altos.ao_telemetry_standard - Altos.ao_telemetry_min].setSelected(true);
+                               }
+                               AltosPreferences.set_scanning_telemetry(scanning_telemetry);
+                       }
+
                        if (cmd.equals("monitor")) {
                                close();
                                AltosScanResult r = (AltosScanResult) (list.getSelectedValue());
@@ -382,6 +402,20 @@ public class AltosScanUI
                c.gridy = 2;
                pane.add(telemetry_label, c);
 
+               int     scanning_telemetry = AltosPreferences.scanning_telemetry();
+               telemetry_boxes = new JCheckBox[Altos.ao_telemetry_max - Altos.ao_telemetry_min + 1];
+               for (int k = Altos.ao_telemetry_min; k <= Altos.ao_telemetry_max; k++) {
+                       int j = k - Altos.ao_telemetry_min;
+                       telemetry_boxes[j] = new JCheckBox(Altos.ao_telemetry_name[k]);
+                       c.gridy = 3 + j;
+                       pane.add(telemetry_boxes[j], c);
+                       telemetry_boxes[j].setActionCommand("telemetry");
+                       telemetry_boxes[j].addActionListener(this);
+                       telemetry_boxes[j].setSelected((scanning_telemetry & (1 << k)) != 0);
+               }
+
+               int     y_offset = 3 + (Altos.ao_telemetry_max - Altos.ao_telemetry_min + 1);
+                               
                list = new JList(results) {
                                //Subclass JList to workaround bug 4832765, which can cause the
                                //scroll pane to not let the user easily scroll up to the beginning
@@ -448,7 +482,7 @@ public class AltosScanUI
                c.weighty = 1;
 
                c.gridx = 0;
-               c.gridy = 3;
+               c.gridy = y_offset;
                c.gridwidth = 2;
                c.anchor = GridBagConstraints.CENTER;
 
@@ -465,7 +499,7 @@ public class AltosScanUI
                c.weighty = 1;
 
                c.gridx = 0;
-               c.gridy = 4;
+               c.gridy = y_offset + 1;
                c.gridwidth = 1;
                c.anchor = GridBagConstraints.CENTER;
 
@@ -482,7 +516,7 @@ public class AltosScanUI
                c.weighty = 1;
 
                c.gridx = 1;
-               c.gridy = 4;
+               c.gridy = y_offset + 1;
                c.gridwidth = 1;
                c.anchor = GridBagConstraints.CENTER;