int JOPTIONPANE_OPTION, int JOPTIONPANE_MESSAGETYPE, Icon icon,
Object[] options, Object initialValue, boolean modal)
{
+ showDialogOnTopAsync(new JFrame(), label, actionString,
+ JOPTIONPANE_OPTION, JOPTIONPANE_MESSAGETYPE, icon, options,
+ initialValue, modal);
+ }
+
+ public void showDialogOnTopAsync(JFrame dialogParent, String label,
+ String actionString, int JOPTIONPANE_OPTION,
+ int JOPTIONPANE_MESSAGETYPE, Icon icon, Object[] options,
+ Object initialValue, boolean modal)
+ {
// Ensure Jalview window is brought to front (primarily for Quit
// confirmation window to be visible)
// A better hack which works is to create a new JFrame parent with
// setAlwaysOnTop(true)
- JFrame dialogParent = new JFrame();
dialogParent.setAlwaysOnTop(true);
parentComponent = dialogParent;
waitTime = Math.max(waitTime, size / 2);
Console.debug("Set waitForSave to " + waitTime);
}
+ final int waitTimeFinal = waitTime;
+ QResponse waitResponse = QResponse.NULL;
// future that returns a Boolean when all files are saved
CompletableFuture<Boolean> filesAllSaved = new CompletableFuture<>();
});
}
- final int waitTimeFinal = waitTime;
// timeout the wait -- will result in another wait button when looped
CompletableFuture<Boolean> waitTimeout = CompletableFuture
.supplyAsync(() -> {
- executor.submit(() -> {
- try
- {
- Thread.sleep(waitTimeFinal);
- } catch (InterruptedException e)
- {
- // probably interrupted by all files saving
- }
- });
+ Console.debug("################# STARTING WAIT SLEEP");
+ try
+ {
+ Thread.sleep(waitTimeFinal);
+ } catch (InterruptedException e)
+ {
+ // probably interrupted by all files saving
+ }
return true;
});
CompletableFuture<Object> waitForSave = CompletableFuture
.anyOf(waitTimeout, filesAllSaved);
- Console.debug("##### WAITFORSAVE RUNNING");
-
- QResponse waitResponse = QResponse.NULL;
int iteration = 0;
boolean doIterations = true;
{
try
{
- waitForSave.get();
+ waitForSave.copy().get();
} catch (InterruptedException | ExecutionException e1)
{
Console.debug(
- "Exception whilst waiting for files to save before quitting",
+ "Exception whilst waiting for files to save before quit",
e1);
}
- if (interactive)
+ if (interactive && BackupFiles.hasSavesInProgress())
{
Console.debug("********************About to make waitDialog");
+ JFrame parent = new JFrame();
JvOptionPane waitDialog = JvOptionPane.newOptionDialog()
.setResponseHandler(JOptionPane.YES_OPTION, defaultOkQuit)
.setResponseHandler(JOptionPane.NO_OPTION, forceQuit)
for (CompletableFuture<Boolean> cf : BackupFiles
.savesInProgressCompletableFutures())
{
- // update the list of saving files as they save too
- cf.thenRun(() -> {
- waitDialog.setMessage(waitingForSaveMessage());
- });
- // if this is the last one then close the dialog
cf.whenComplete((ret, e) -> {
+ Console.debug("############# A FILE SAVED!");
+ // update the list of saving files as they save too
+ waitDialog.setMessage(waitingForSaveMessage());
+ waitDialog.setName("AAARGH!");
+ // if this is the last one then close the dialog
if (!BackupFiles.hasSavesInProgress())
{
- // like a click on Wait button
+ // like a click on Wait button ???
Console.debug(
"***** TRYING TO MAKE THE WAIT FOR SAVE DIALOG DISAPPEAR!");
waitDialog.setValue(JOptionPane.YES_OPTION);
+ parent.dispose();
}
});
}
- waitDialog.showDialogOnTopAsync(waitingForSaveMessage(),
+ waitDialog.showDialogOnTopAsync(parent, waitingForSaveMessage(),
MessageManager.getString("action.wait"),
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.WARNING_MESSAGE, null, new Object[]
MessageManager.getString("action.wait"), true);
Console.debug("********************Finished waitDialog");
- waitResponse = gotQuitResponse();
- Console.debug("####### WAITFORSAVE SET: " + waitResponse);
- switch (waitResponse)
+ final QResponse thisWaitResponse = gotQuitResponse();
+ Console.debug("####### WAITFORSAVE SET: " + thisWaitResponse);
+ switch (thisWaitResponse)
{
case QUIT: // wait -- do another iteration
break;
}
} // end if interactive
- }
+ } // end while wait iteration loop
waitResponse = gotQuitResponse();
Console.debug("####### WAITFORSAVE RETURNING: " + waitResponse);