JAL-3027 Avoid FlatLAF Desktop class is JalviewJS
[jalview.git] / src / jalview / jbgui / APQHandlers.java
index 27c53b9..5e04b14 100644 (file)
  */
 package jalview.jbgui;
 
+import javax.swing.JFrame;
 import javax.swing.JOptionPane;
 
 import com.formdev.flatlaf.extras.FlatDesktop;
 
-import jalview.gui.Desktop;
 import jalview.util.MessageManager;
+import jalview.util.Platform;
 
 public class APQHandlers
 {
-  protected static boolean setAPQHandlers = false;
-
   public static boolean setAPQHandlers(GDesktop desktop)
   {
+    if (Platform.isJS())
+    {
+      return false;
+    }
     FlatDesktop.setAboutHandler(() -> {
       desktop.aboutMenuItem_actionPerformed(null);
     });
@@ -46,11 +49,26 @@ public class APQHandlers
       int n;
       if (confirmQuit)
       {
-        n = JOptionPane.showConfirmDialog(null,
+        // ensure Jalview window is brought to front for Quit confirmation
+        // window to be
+        // visible
+
+        // this method of raising the Jalview window is broken in java
+        // jalviewDesktop.setVisible(true);
+        // jalviewDesktop.toFront();
+
+        // a better hack which works instead
+        JFrame dialogParent = new JFrame();
+        dialogParent.setAlwaysOnTop(true);
+
+        n = JOptionPane.showConfirmDialog(dialogParent,
                 MessageManager.getString("label.quit_jalview"),
                 MessageManager.getString("action.quit"),
                 JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE,
                 null);
+
+        dialogParent.setAlwaysOnTop(false);
+        dialogParent.dispose();
       }
       else
       {
@@ -66,10 +84,8 @@ public class APQHandlers
         response.cancelQuit();
       }
     });
-
-    setAPQHandlers = true;
-
-    return setAPQHandlers;
+    // if we got to here, no exceptions occurred when we set the handlers.
+    return true;
   }
 
 }