j.getArgParser().getMixedExamples());
String quit = MessageManager.getString("action.quit");
- Desktop.instance.nonBlockingDialog(title, warning, quit,
- JvOptionPane.WARNING_MESSAGE, false, true);
+ Desktop.instance.nonBlockingDialog(title, warning, null, quit,
+ JvOptionPane.WARNING_MESSAGE, false, false, true, 30000);
Jalview.exit(
"Exiting due to mixed old and new command line arguments.",
{
String cont = MessageManager.getString("label.continue");
- Desktop.instance.nonBlockingDialog(32, 2, title, warning, url, cont,
- JvOptionPane.WARNING_MESSAGE, false, true, true);
+ Desktop.instance.nonBlockingDialog(title, warning, url, cont,
+ JvOptionPane.WARNING_MESSAGE, false, true, true, 2000);
}
}
if (j.getCommands() != null && j.getCommands().getErrors().size() > 0)
Math.max(message.length(), Math.min(60, shortest)),
Math.min(errors.size(), 20), title, message,
j.getCommands().errorsToString(), ok,
- JvOptionPane.WARNING_MESSAGE, true, false, true);
+ JvOptionPane.WARNING_MESSAGE, true, false, true, -1);
}
}
}
public void nonBlockingDialog(String title, String message, String button,
int type, boolean scrollable, boolean modal)
{
- nonBlockingDialog(32, 2, title, message, null, button, type, scrollable,
- false, modal);
+ nonBlockingDialog(title, message, null, button, type, scrollable, false,
+ modal, -1);
+ }
+
+ public void nonBlockingDialog(String title, String message,
+ String boxtext, String button, int type, boolean scrollable,
+ boolean html, boolean modal, int timeout)
+ {
+ nonBlockingDialog(32, 2, title, message, boxtext, button, type,
+ scrollable, false, modal, timeout);
}
public void nonBlockingDialog(int width, int height, String title,
String message, String boxtext, String button, int type,
- boolean scrollable, boolean html, boolean modal)
+ boolean scrollable, boolean html, boolean modal, int timeout)
{
if (type < 0)
{
jvp.setResponseHandler(JOptionPane.YES_OPTION, () -> {
});
+ jvp.setTimeout(timeout);
+ JButton jb = new JButton(button);
jvp.showDialogOnTopAsync(this, jp, title, JOptionPane.YES_OPTION, type,
null, new Object[]
- { button }, button, modal, null, false);
+ { button }, button, modal, new JButton[] { jb }, false);
}
}
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))