if (!isInteractiveMode())
{
handleResponse(getMockResponse());
+ return;
}
// two uses:
//
public static int showDialogOnTop(String label, String actionString,
int JOPTIONPANE_OPTION, int JOPTIONPANE_MESSAGETYPE)
{
+ if (!isInteractiveMode())
+ {
+ return (int) getMockResponse();
+ }
// Ensure Jalview window is brought to front (primarily for Quit
// confirmation window to be visible)
int JOPTIONPANE_MESSAGETYPE, Icon icon, Object[] options,
Object initialValue, boolean modal, JButton[] buttons)
{
+ if (!isInteractiveMode())
+ {
+ handleResponse(getMockResponse());
+ return;
+ }
// Ensure Jalview window is brought to front (primarily for Quit
// confirmation window to be visible)
Object[] options, Object initialValue, boolean modal,
JButton[] buttons)
{
+ if (!isInteractiveMode())
+ {
+ handleResponse(getMockResponse());
+ return null;
+ }
JButton[] optionsButtons = null;
Object initialValueButton = null;
JOptionPane joptionpane = new JOptionPane();
public class QuitHandler
{
- private static final int MIN_WAIT_FOR_SAVE = 3000;
+ private static final int MIN_WAIT_FOR_SAVE = 1000;
private static final int MAX_WAIT_FOR_SAVE = 20000;
+ private static boolean interactive = true;
+
public static enum QResponse
{
NULL, QUIT, CANCEL_QUIT, FORCE_QUIT
private static QResponse gotQuitResponse = QResponse.NULL;
- private static QResponse setResponse(QResponse qresponse)
+ protected static QResponse setResponse(QResponse qresponse)
{
gotQuitResponse = qresponse;
return qresponse;
public static final Callable<Void> defaultCancelQuit = () -> {
Console.debug("QuitHandler: (default) Quit action CANCELLED by user");
// reset
- setResponse(QResponse.NULL);
+ setResponse(QResponse.CANCEL_QUIT);
return null;
};
defaultCancelQuit);
}
- private static boolean interactive = true;
-
public static QResponse getQuitResponse(boolean ui, Callable<Void> okQuit,
Callable<Void> forceQuit, Callable<Void> cancelQuit)
{
{
JvOptionPane.newOptionDialog()
.setResponseHandler(JOptionPane.YES_OPTION, defaultOkQuit)
- .setResponseHandler(JOptionPane.NO_OPTION, defaultCancelQuit)
+ .setResponseHandler(JOptionPane.NO_OPTION, cancelQuit)
.showDialogOnTopAsync(
new StringBuilder(MessageManager
.getString("label.quit_jalview"))
- .append("\n")
- .append(MessageManager.getString(
- "label.unsaved_changes"))
- .toString(),
+ .append("\n")
+ .append(MessageManager
+ .getString("label.unsaved_changes"))
+ .toString(),
MessageManager.getString("action.quit"),
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE, null, new Object[]
if (got == QResponse.CANCEL_QUIT)
{
// reset
+ Console.debug("Cancelling quit. Resetting response to NULL");
setResponse(QResponse.NULL);
// but return cancel
return QResponse.CANCEL_QUIT;
if (Cache.getDefault("DEBUG_DELAY_SAVE", false))
{
- int n = 20;
+ int n = debugDelaySave;
int i = 0;
while (i < n)
{
if (Cache.getDefault("DEBUG_DELAY_SAVE", false))
{
- int n = 20;
+ int n = debugDelaySave;
int i = 0;
while (i < n)
{
}
return true;
}
+
+ // used for debugging and tests
+ private static int debugDelaySave = 20;
+
+ public static void setDebugDelaySave(int n)
+ {
+ debugDelaySave = n;
+ }
}