private Map<Object, Runnable> callbacks = new HashMap<>();
+ private int timeout = -1;
+
+ public void setTimeout(int i)
+ {
+ timeout = i;
+ }
+
/*
* JalviewJS reports user choice in the dialog as the selected option (text);
* this list allows conversion to index (int)
"Supplied buttons array not the same length as supplied options array.");
break NOTNULL;
}
+
+ // run through buttons for initialValue first so can set a final
+ // timeoutThreadF
+ Thread timeoutThread = null;
+ for (int i = 0; i < options.length; i++)
+ {
+ Object o = options[i];
+ JButton jb = buttons[i];
+ if (o.equals(initialValue))
+ {
+ initialValueButton = jb;
+ if (timeout > 0 && initialValueButton != null
+ && initialValueButton instanceof JButton)
+ {
+ Runnable timeoutClose = () -> {
+ try
+ {
+ Thread.sleep(timeout);
+ } catch (InterruptedException e)
+ {
+ Console.debug(
+ "Dialog timeout interrupted. Probably a button pressed.");
+ }
+ jb.doClick();
+ };
+ timeoutThread = new Thread(timeoutClose);
+ }
+ }
+ }
+ final Thread timeoutThreadF = timeoutThread;
+ timeoutThreadF.start();
+
int[] buttonActions = { JOptionPane.YES_OPTION,
JOptionPane.NO_OPTION, JOptionPane.CANCEL_OPTION };
for (int i = 0; i < options.length; i++)
"Setting button " + i + " to '" + o.toString() + "'");
JButton jb = buttons[i];
- if (o.equals(initialValue))
- initialValueButton = jb;
-
int buttonAction = buttonActions[i];
Runnable action = callbacks.get(buttonAction);
jb.setText((String) o);
@Override
public void actionPerformed(ActionEvent e)
{
+ if (timeoutThreadF != null)
+ {
+ timeoutThreadF.interrupt();
+ }
Object obj = e.getSource();
if (obj == null || !(obj instanceof Component))