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