X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=altosui%2FAltosScanUI.java;h=44eeda6dcc83ff228c21efe0415a1bf4f7de5bfa;hb=75d6aa6f798606f1a6c5a46542065dda81e63b2a;hp=b47405c8bf5f4fb61eed5207013d2cb74d259513;hpb=364102d29ff4de0c252774f26417587fa88b7467;p=fw%2Faltos diff --git a/altosui/AltosScanUI.java b/altosui/AltosScanUI.java index b47405c8..44eeda6d 100644 --- a/altosui/AltosScanUI.java +++ b/altosui/AltosScanUI.java @@ -28,6 +28,7 @@ import java.util.*; import java.text.*; import java.util.prefs.*; import java.util.concurrent.*; +import org.altusmetrum.AltosLib.*; class AltosScanResult { String callsign; @@ -102,7 +103,7 @@ class AltosScanResults extends LinkedList implements ListModel } public class AltosScanUI - extends JDialog + extends AltosDialog implements ActionListener { AltosUI owner; @@ -115,6 +116,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(); @@ -129,8 +131,7 @@ public class AltosScanUI void scan_exception(Exception e) { if (e instanceof FileNotFoundException) { JOptionPane.showMessageDialog(owner, - String.format("Cannot open device \"%s\"", - device.toShortString()), + ((FileNotFoundException) e).getMessage(), "Cannot open target device", JOptionPane.ERROR_MESSAGE); } else if (e instanceof AltosSerialInUseException) { @@ -207,19 +208,23 @@ public class AltosScanUI } void next() throws InterruptedException, TimeoutException { - reader.serial.set_monitor(false); + reader.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(); set_label(); - reader.serial.set_monitor(true); + reader.set_monitor(true); } @@ -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); + } + AltosUIPreferences.set_scanning_telemetry(scanning_telemetry); + } + if (cmd.equals("monitor")) { close(); AltosScanResult r = (AltosScanResult) (list.getSelectedValue()); @@ -292,7 +312,7 @@ public class AltosScanUI if (device == null) return false; try { - reader = new AltosTelemetryReader(device); + reader = new AltosTelemetryReader(new AltosSerial(device)); set_frequency(); set_telemetry(); try { @@ -306,8 +326,7 @@ public class AltosScanUI return true; } catch (FileNotFoundException ee) { JOptionPane.showMessageDialog(owner, - String.format("Cannot open device \"%s\"", - device.toShortString()), + ee.getMessage(), "Cannot open target device", JOptionPane.ERROR_MESSAGE); } catch (AltosSerialInUseException si) { @@ -341,7 +360,7 @@ public class AltosScanUI owner = in_owner; - frequencies = AltosPreferences.common_frequencies(); + frequencies = AltosUIPreferences.common_frequencies(); frequency_index = 0; telemetry = Altos.ao_telemetry_min; @@ -366,7 +385,7 @@ public class AltosScanUI set_label(); - c.fill = GridBagConstraints.NONE; + c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.WEST; c.insets = i; c.weightx = 1; @@ -382,6 +401,20 @@ public class AltosScanUI c.gridy = 2; pane.add(telemetry_label, c); + int scanning_telemetry = AltosUIPreferences.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 +481,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 +498,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 +515,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;