]> git.gag.com Git - fw/altos/blob - altosuilib/AltosDeviceUIDialog.java
altoslib: Support multiple telemetry rates
[fw/altos] / altosuilib / AltosDeviceUIDialog.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.altosuilib_3;
19
20 import javax.swing.*;
21 import java.awt.*;
22 import java.awt.event.*;
23
24 public class AltosDeviceUIDialog extends AltosDeviceDialog {
25
26         public AltosDevice[] devices() {
27                 java.util.List<AltosDevice>     usb_devices = AltosUSBDevice.list(product);
28                 int                             num_devices = usb_devices.size();
29                 java.util.List<AltosDevice>     bt_devices = AltosBTKnown.bt_known().list(product);
30                 num_devices += bt_devices.size();
31                 AltosDevice[]                   devices = new AltosDevice[num_devices];
32
33                 for (int i = 0; i < usb_devices.size(); i++)
34                         devices[i] = usb_devices.get(i);
35                 int off = usb_devices.size();
36                 for (int j = 0; j < bt_devices.size(); j++)
37                         devices[off + j] = bt_devices.get(j);
38                 return devices;
39         }
40
41         public void add_bluetooth() {
42                 JButton manage_bluetooth_button = new JButton("Manage Bluetooth");
43                 manage_bluetooth_button.setActionCommand("manage");
44                 manage_bluetooth_button.addActionListener(this);
45                 buttonPane.add(manage_bluetooth_button);
46                 buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
47         }
48
49         public void actionPerformed(ActionEvent e) {
50                 super.actionPerformed(e);
51                 if ("manage".equals(e.getActionCommand())) {
52                         AltosBTManage.show(frame, AltosBTKnown.bt_known());
53                         update_devices();
54                 }
55         }
56
57         public AltosDeviceUIDialog (Frame in_frame, Component location, int in_product) {
58                 super(in_frame, location, in_product);
59         }
60
61         public static AltosDevice show (Component frameComp, int product) {
62                 Frame                   frame = JOptionPane.getFrameForComponent(frameComp);
63                 AltosDeviceUIDialog     dialog;
64
65                 dialog = new AltosDeviceUIDialog(frame, frameComp, product);
66                 dialog.setVisible(true);
67                 return dialog.getValue();
68         }
69 }