JAL-1988 Allow generic Container object in JvOptionPane showDialog. Fix dynamically...
[jalview.git] / src / jalview / jbgui / QuitHandler.java
index db8b500..ac14a2f 100644 (file)
@@ -10,6 +10,7 @@ import java.util.concurrent.Executors;
 
 import javax.swing.JFrame;
 import javax.swing.JOptionPane;
+import javax.swing.JTextPane;
 
 import com.formdev.flatlaf.extras.FlatDesktop;
 
@@ -182,17 +183,6 @@ public class QuitHandler
       if (Cache.getDefault("WAIT_FOR_SAVE", true)
               && BackupFiles.hasSavesInProgress())
       {
-        /*
-        Future<QResponse> waitGot = executor.submit(waitQuitCall);
-        try
-        {
-          got = waitGot.get();
-        } catch (InterruptedException | ExecutionException e)
-        {
-          jalview.bin.Console.debug(
-                  "Exception during quit handling (wait for save)", e);
-        }
-        */
         QResponse waitResponse = waitQuit(interactive, okQuit, forceQuit,
                 cancelQuit);
         wait = waitResponse == QResponse.QUIT;
@@ -268,7 +258,7 @@ public class QuitHandler
 
     // callback as each file finishes saving
     for (CompletableFuture<Boolean> cf : BackupFiles
-            .savesInProgressCompletableFutures())
+            .savesInProgressCompletableFutures(false))
     {
       // if this is the last one then complete filesAllSaved
       cf.whenComplete((ret, e) -> {
@@ -318,28 +308,29 @@ public class QuitHandler
                 .setResponseHandler(JOptionPane.NO_OPTION, forceQuit)
                 .setResponseHandler(JOptionPane.CANCEL_OPTION, cancelQuit);
 
+        JTextPane messagePane = new JTextPane();
+        messagePane.setBackground(waitDialog.getBackground());
+        messagePane.setBorder(null);
+        messagePane.setText(waitingForSaveMessage());
         // callback as each file finishes saving
         for (CompletableFuture<Boolean> cf : BackupFiles
-                .savesInProgressCompletableFutures())
+                .savesInProgressCompletableFutures(false))
         {
           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!");
+            messagePane.setText(waitingForSaveMessage());
             // if this is the last one then close the dialog
             if (!BackupFiles.hasSavesInProgress())
             {
-              // like a click on Wait button ???
-              Console.debug(
-                      "***** TRYING TO MAKE THE WAIT FOR SAVE DIALOG DISAPPEAR!");
+              // like a click on Wait button
               waitDialog.setValue(JOptionPane.YES_OPTION);
               parent.dispose();
             }
           });
         }
 
-        waitDialog.showDialogOnTopAsync(parent, waitingForSaveMessage(),
+        waitDialog.showDialogOnTopAsync(parent, messagePane,
                 MessageManager.getString("action.wait"),
                 JOptionPane.YES_NO_CANCEL_OPTION,
                 JOptionPane.WARNING_MESSAGE, null, new Object[]
@@ -375,56 +366,6 @@ public class QuitHandler
     return waitResponse;
   };
 
-  public static void okk()
-  {
-    /*
-    if (false)
-    {
-      if (false)
-      {
-    
-        waitLonger = JOptionPane.showOptionDialog(dialogParent,
-                waitingForSaveMessage(),
-                MessageManager.getString("action.wait"),
-                JOptionPane.YES_NO_CANCEL_OPTION,
-                JOptionPane.WARNING_MESSAGE, null, options, wait);
-      }
-      else
-      {
-        // non-interactive
-        waitLonger = iteration < NON_INTERACTIVE_WAIT_CYCLES
-                ? JOptionPane.YES_OPTION
-                : JOptionPane.NO_OPTION;
-      }
-    
-      if (waitLonger == JOptionPane.YES_OPTION) // "wait"
-      {
-        saving = !waitForSave(waitIncrement);
-      }
-      else if (waitLonger == JOptionPane.NO_OPTION) // "force
-      // quit"
-      {
-        // do a force quit
-        return setResponse(QResponse.FORCE_QUIT);
-      }
-      else if (waitLonger == JOptionPane.CANCEL_OPTION) // cancel quit
-      {
-        return setResponse(QResponse.CANCEL_QUIT);
-      }
-      else
-      {
-        // Most likely got here by user dismissing the dialog with the
-        // 'x'
-        // -- treat as a "Cancel"
-        return setResponse(QResponse.CANCEL_QUIT);
-      }
-    }
-    
-    // not sure how we got here, best be safe
-    return QResponse.CANCEL_QUIT;
-    */
-  };
-
   private static int waitForceQuitCancelQuitOptionDialog(Object message,
           String title)
   {
@@ -435,34 +376,33 @@ public class QuitHandler
         MessageManager.getString("action.force_quit"),
         MessageManager.getString("action.cancel_quit") };
 
-    // BackupFiles.setWaitForSaveDialog(dialogParent);
-
     int answer = JOptionPane.showOptionDialog(dialogParent, message, title,
             JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE,
             null, options, wait);
 
-    // BackupFiles.clearWaitForSaveDialog();
-
     return answer;
   }
 
   private static String waitingForSaveMessage()
   {
-    StringBuilder messageSB = new StringBuilder(
-            MessageManager.getString("label.save_in_progress"));
-    boolean any = false;
-    for (File file : BackupFiles.savesInProgressFiles())
+    StringBuilder messageSB = new StringBuilder();
+
+    List<File> files = BackupFiles.savesInProgressFiles(false);
+    boolean any = files.size() > 0;
+    if (any)
     {
-      messageSB.append("\n- ");
-      messageSB.append(file.getName());
-      any = true;
+      messageSB.append(MessageManager.getString("label.save_in_progress"));
+      for (File file : files)
+      {
+        messageSB.append("\n- ").append(file.getName());
+      }
     }
-    if (!any)
+    else
     {
-      messageSB.append("\n");
-      messageSB.append(MessageManager.getString("label.unknown"));
+      messageSB.append(MessageManager.getString("label.all_saved"))
+              .append("\n")
+              .append(MessageManager.getString("label.quitting_bye"));
     }
-
     return messageSB.toString();
   }