2 * Copyright © 2010 Keith Packard <keithp@keithp.com>
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.
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.
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.
19 package org.altusmetrum.altosuilib_13;
23 import java.awt.event.*;
25 public class AltosDeviceUIDialog extends AltosDeviceDialog {
27 boolean include_bluetooth;
29 public AltosDevice[] devices() {
30 java.util.List<AltosDevice> usb_devices = AltosUSBDevice.list(product);
31 int num_devices = usb_devices.size();
33 java.util.List<AltosDevice> bt_devices = null;
35 if (include_bluetooth) {
36 bt_devices = AltosBTKnown.bt_known().list(product);
37 num_devices += bt_devices.size();
40 AltosDevice[] devices = new AltosDevice[num_devices];
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);
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)));
62 public void actionPerformed(ActionEvent e) {
63 super.actionPerformed(e);
64 if ("manage".equals(e.getActionCommand())) {
65 AltosBTManage.show(frame, AltosBTKnown.bt_known());
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;
75 public AltosDeviceUIDialog (Frame in_frame, Component location, int in_product) {
76 this(in_frame, location, in_product, true);
79 public static AltosDevice show (Component frameComp, int product, boolean include_bluetooth) {
80 Frame frame = JOptionPane.getFrameForComponent(frameComp);
81 AltosDeviceUIDialog dialog;
83 dialog = new AltosDeviceUIDialog(frame, frameComp, product, include_bluetooth);
84 dialog.setVisible(true);
85 return dialog.getValue();
88 public static AltosDevice show (Component frameComp, int product) {
89 return show(frameComp, product, true);
92 public static AltosUSBDevice show_usb (Component frameComp, int product) {
93 return (AltosUSBDevice) show(frameComp, product, false);