Lets the user plug/unplug devices and have the dialog box show the
current set of available devices. Particularly useful on Windows where
it takes a long time after connecting a device for the OS to actually
make it usable.
Signed-off-by: Keith Packard <keithp@keithp.com>
public Frame frame;
public int product;
public JPanel buttonPane;
public Frame frame;
public int product;
public JPanel buttonPane;
+ private Timer timer;
+ AltosDevice[] devices;
public AltosDevice getValue() {
return value;
public AltosDevice getValue() {
return value;
public abstract AltosDevice[] devices();
public void update_devices() {
public abstract AltosDevice[] devices();
public void update_devices() {
- AltosDevice[] devices = devices();
+ AltosDevice selected = list.getSelectedValue();
+
+ devices = devices();
list.setListData(devices);
list.setListData(devices);
+ for (AltosDevice d : devices) {
+ if (d.equals(selected)) {
+ list.setSelectedValue(d, true);
+ break;
+ }
+ }
select_button.setEnabled(devices.length > 0);
}
select_button.setEnabled(devices.length > 0);
}
frame = in_frame;
value = null;
frame = in_frame;
value = null;
- AltosDevice[] devices = devices();
-
cancel_button = new JButton("Cancel");
cancel_button.setActionCommand("cancel");
cancel_button.addActionListener(this);
cancel_button = new JButton("Cancel");
cancel_button.setActionCommand("cancel");
cancel_button.addActionListener(this);
select_button = new JButton("Select");
select_button.setActionCommand("select");
select_button.addActionListener(this);
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) {
getRootPane().setDefaultButton(select_button);
list = new JList<AltosDevice>(devices) {
contentPane.add(buttonPane, BorderLayout.PAGE_END);
//Initialize values.
contentPane.add(buttonPane, BorderLayout.PAGE_END);
//Initialize values.
if (devices != null && devices.length != 0)
list.setSelectedValue(devices[0], true);
pack();
setLocationRelativeTo(location);
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.
}
//Handle clicks on the Set and Cancel buttons.