X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altosui%2FAltosDeviceDialog.java;h=fa9d0013722ee88e5e48aa3df49e8bbe10bf16bd;hp=fa20f867524758cf51506067b536a4fb80dc2e54;hb=95268d681c9a6652d84db383f55a4fe8a4ac5173;hpb=f249e5926f5fd9f86c41e7f0a414193533d4d8b0 diff --git a/altosui/AltosDeviceDialog.java b/altosui/AltosDeviceDialog.java index fa20f867..fa9d0013 100644 --- a/altosui/AltosDeviceDialog.java +++ b/altosui/AltosDeviceDialog.java @@ -24,20 +24,7 @@ import java.awt.*; import java.awt.event.*; import libaltosJNI.*; -public class AltosDeviceDialog extends JDialog implements ActionListener { - - public static AltosDevice show (Component frameComp, int product) { - - Frame frame = JOptionPane.getFrameForComponent(frameComp); - AltosDevice[] devices; - devices = AltosUSBDevice.list(product); - AltosDeviceDialog dialog; - - dialog = new AltosDeviceDialog(frame, frameComp, - devices); - dialog.setVisible(true); - return dialog.getValue(); - } +public class AltosDeviceDialog extends AltosDialog implements ActionListener { private AltosDevice value; private JList list; @@ -45,18 +32,42 @@ public class AltosDeviceDialog extends JDialog implements ActionListener { private JButton select_button; private JButton manage_bluetooth_button; private Frame frame; + private int product; private AltosDevice getValue() { return value; } - private AltosDeviceDialog (Frame in_frame, Component location, - AltosDevice[] devices) { + private AltosDevice[] devices() { + java.util.List usb_devices = AltosUSBDevice.list(product); + int num_devices = usb_devices.size(); + java.util.List bt_devices = AltosBTKnown.bt_known().list(product); + num_devices += bt_devices.size(); + AltosDevice[] devices = new AltosDevice[num_devices]; + + for (int i = 0; i < usb_devices.size(); i++) + devices[i] = usb_devices.get(i); + int off = usb_devices.size(); + for (int j = 0; j < bt_devices.size(); j++) + devices[off + j] = bt_devices.get(j); + return devices; + } + + private void update_devices() { + AltosDevice[] devices = devices(); + list.setListData(devices); + select_button.setEnabled(devices.length > 0); + } + + private AltosDeviceDialog (Frame in_frame, Component location, int in_product) { super(in_frame, "Device Selection", true); + product = in_product; frame = in_frame; value = null; + AltosDevice[] devices = devices(); + cancel_button = new JButton("Cancel"); cancel_button.setActionCommand("cancel"); cancel_button.addActionListener(this); @@ -147,7 +158,7 @@ public class AltosDeviceDialog extends JDialog implements ActionListener { contentPane.add(buttonPane, BorderLayout.PAGE_END); //Initialize values. - if (devices != null && devices.length > 0) + if (devices != null && devices.length != 0) list.setSelectedValue(devices[0], true); pack(); setLocationRelativeTo(location); @@ -158,10 +169,20 @@ public class AltosDeviceDialog extends JDialog implements ActionListener { if ("select".equals(e.getActionCommand())) value = (AltosDevice)(list.getSelectedValue()); if ("manage".equals(e.getActionCommand())) { - AltosBTManage.show(frame); + AltosBTManage.show(frame, AltosBTKnown.bt_known()); + update_devices(); return; } setVisible(false); } + public static AltosDevice show (Component frameComp, int product) { + + Frame frame = JOptionPane.getFrameForComponent(frameComp); + AltosDeviceDialog dialog; + + dialog = new AltosDeviceDialog(frame, frameComp, product); + dialog.setVisible(true); + return dialog.getValue(); + } }