Add shipping products to fat_altos target, note that in Releasing
[fw/altos] / altosuilib / AltosDeviceDialog.java
index 5fb1331ee210a5cf40618e5b58a7e91c69a0974f..d8a24b1841d0e0c58c3606907055c8622e96863e 100644 (file)
@@ -3,7 +3,8 @@
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -15,7 +16,7 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altosuilib_6;
+package org.altusmetrum.altosuilib_13;
 
 import javax.swing.*;
 import java.awt.*;
@@ -30,6 +31,8 @@ public abstract class AltosDeviceDialog extends AltosUIDialog implements ActionL
        public Frame                    frame;
        public int                      product;
        public JPanel                   buttonPane;
+       private Timer                   timer;
+       AltosDevice[]                   devices;
 
        public AltosDevice getValue() {
                return value;
@@ -38,8 +41,16 @@ public abstract class AltosDeviceDialog extends AltosUIDialog implements ActionL
        public abstract AltosDevice[] devices();
 
        public void update_devices() {
-               AltosDevice[] devices = devices();
+               AltosDevice selected = list.getSelectedValue();
+
+               devices = devices();
                list.setListData(devices);
+               for (AltosDevice d : devices) {
+                       if (d.equals(selected)) {
+                               list.setSelectedValue(d, true);
+                               break;
+                       }
+               }
                select_button.setEnabled(devices.length > 0);
        }
 
@@ -52,8 +63,6 @@ public abstract class AltosDeviceDialog extends AltosUIDialog implements ActionL
                frame = in_frame;
                value = null;
 
-               AltosDevice[]   devices = devices();
-
                cancel_button = new JButton("Cancel");
                cancel_button.setActionCommand("cancel");
                cancel_button.addActionListener(this);
@@ -61,8 +70,7 @@ public abstract class AltosDeviceDialog extends AltosUIDialog implements ActionL
                select_button = new JButton("Select");
                select_button.setActionCommand("select");
                select_button.addActionListener(this);
-               if (devices.length == 0)
-                       select_button.setEnabled(false);
+               select_button.setEnabled(false);
                getRootPane().setDefaultButton(select_button);
 
                list = new JList<AltosDevice>(devices) {
@@ -142,10 +150,31 @@ public abstract class AltosDeviceDialog extends AltosUIDialog implements ActionL
                contentPane.add(buttonPane, BorderLayout.PAGE_END);
 
                //Initialize values.
+               update_devices();
                if (devices != null && devices.length != 0)
                        list.setSelectedValue(devices[0], true);
                pack();
                setLocationRelativeTo(location);
+
+               timer = new Timer(1000, new ActionListener () {
+                               public void actionPerformed(ActionEvent evt) {
+                                       update_devices();
+                               }
+                       });
+
+               addComponentListener(new ComponentListener() {
+                               public void componentShown(ComponentEvent e) {
+                                       timer.start();
+                               }
+                               public void componentMoved(ComponentEvent e) {
+                               }
+                               public void componentResized(ComponentEvent e) {
+                               }
+                               public void componentHidden(ComponentEvent e) {
+                                       timer.stop();
+                               }
+                       });
+
        }
 
        //Handle clicks on the Set and Cancel buttons.