altos/telefireone-v2.0: Remove build of ao_product.h from Makefile
[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; 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_13;
20
21 import javax.swing.*;
22 import java.awt.*;
23 import java.awt.event.*;
24
25 public class AltosDeviceUIDialog extends AltosDeviceDialog {
26
27         boolean include_bluetooth;
28
29         public AltosDevice[] devices() {
30                 java.util.List<AltosDevice>     usb_devices = AltosUSBDevice.list(product);
31                 int                             num_devices = usb_devices.size();
32
33                 java.util.List<AltosDevice>     bt_devices = null;
34
35                 if (include_bluetooth) {
36                         bt_devices = AltosBTKnown.bt_known().list(product);
37                         num_devices += bt_devices.size();
38                 }
39
40                 AltosDevice[]                   devices = new AltosDevice[num_devices];
41
42                 for (int i = 0; i < usb_devices.size(); i++)
43                         devices[i] = usb_devices.get(i);
44                 if (include_bluetooth) {
45                         int off = usb_devices.size();
46                         for (int j = 0; j < bt_devices.size(); j++)
47                                 devices[off + j] = bt_devices.get(j);
48                 }
49                 return devices;
50         }
51
52         public void add_bluetooth() {
53                 if (include_bluetooth) {
54                         JButton manage_bluetooth_button = new JButton("Manage Bluetooth");
55                         manage_bluetooth_button.setActionCommand("manage");
56                         manage_bluetooth_button.addActionListener(this);
57                         buttonPane.add(manage_bluetooth_button);
58                         buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
59                 }
60         }
61
62         public void actionPerformed(ActionEvent e) {
63                 super.actionPerformed(e);
64                 if ("manage".equals(e.getActionCommand())) {
65                         AltosBTManage.show(frame, AltosBTKnown.bt_known());
66                         update_devices();
67                 }
68         }
69
70         public AltosDeviceUIDialog (Frame in_frame, Component location, int in_product, boolean include_bluetooth) {
71                 super(in_frame, location, in_product);
72                 this.include_bluetooth = include_bluetooth;
73         }
74
75         public AltosDeviceUIDialog (Frame in_frame, Component location, int in_product) {
76                 this(in_frame, location, in_product, true);
77         }
78
79         public static AltosDevice show (Component frameComp, int product, boolean include_bluetooth) {
80                 Frame                   frame = JOptionPane.getFrameForComponent(frameComp);
81                 AltosDeviceUIDialog     dialog;
82
83                 dialog = new AltosDeviceUIDialog(frame, frameComp, product, include_bluetooth);
84                 dialog.setVisible(true);
85                 return dialog.getValue();
86         }
87
88         public static AltosDevice show (Component frameComp, int product) {
89                 return show(frameComp, product, true);
90         }
91
92         public static AltosUSBDevice show_usb (Component frameComp, int product) {
93                 return (AltosUSBDevice) show(frameComp, product, false);
94         }
95 }