+
+ public void cancel() {
+ t.interrupt();
+ }
+
+ public open_task(AltosDevice device, open_dialog dialog) {
+ this.device = device;
+ this.dialog = dialog;
+ t = new Thread(this);
+ t.start();
+ }
+ }
+
+ class open_dialog
+ extends AltosUIDialog
+ implements ActionListener
+ {
+ AltosUIFrame owner;
+
+ private JLabel opening_label;
+ private JButton cancel_button;
+
+ boolean done = false;
+
+ AltosLink link = null;
+
+ open_task open = null;
+
+ public void open_exception(Exception e) {
+ System.out.printf("open_exception\n");
+ setVisible(false);
+ exception(e);
+ done = true;
+ }
+
+ public void open_success(AltosLink link) {
+ System.out.printf("open_success\n");
+ setVisible(false);
+ this.link = link;
+ done = true;
+ }
+
+ public void open_failure() {
+ System.out.printf("open_failure\n");
+ setVisible(false);
+ done = true;
+ }
+
+ public void open_cancel() {
+ System.out.printf("open_cancel\n");
+ setVisible(false);
+ done = true;
+ }
+
+ public AltosLink do_open(open_task open) throws InterruptedException {
+ this.open = open;
+ setVisible(true);
+ return link;
+ }
+
+ public void actionPerformed(ActionEvent e) {
+ String cmd = e.getActionCommand();
+
+ if (cmd.equals("cancel"))
+ if (open != null)
+ open.cancel();
+ done = true;
+ setVisible(false);
+ }
+
+ public open_dialog(AltosUIFrame in_owner) {
+ super(in_owner, "Open Flash Target Device", true);
+ owner = in_owner;
+
+ Container pane = getScrollablePane();
+ GridBagConstraints c = new GridBagConstraints();
+ Insets i = new Insets(4,4,4,4);
+
+
+ pane.setLayout(new GridBagLayout());
+
+ opening_label = new JLabel("Opening Device");
+ c.fill = GridBagConstraints.HORIZONTAL;
+ c.anchor = GridBagConstraints.LINE_START;
+ c.insets = i;
+ c.weightx = 0;
+ c.weighty = 0;
+
+ c.gridx = 0;
+ c.gridy = 0;
+
+ pane.add(opening_label, c);
+
+ cancel_button = new JButton("Cancel");
+ cancel_button.addActionListener(this);
+ cancel_button.setActionCommand("cancel");
+
+ c.gridy = 1;
+ pane.add(cancel_button, c);
+ pack();
+ setLocationRelativeTo(owner);
+ }
+ }
+
+ private boolean open_device() throws InterruptedException {
+
+ open_dialog dialog = new open_dialog(frame);
+
+ open_task open = new open_task(device, dialog);
+
+ link = dialog.do_open(open);
+
+ return link != null;