From: Ben Soares Date: Thu, 23 Jun 2022 15:02:46 +0000 (+0100) Subject: Merge branch 'improvement/JAL-1988+JAL-3416_Java8_macOS_APQHandlers_and_FlatLaF_optio... X-Git-Tag: Release_2_11_2_6~44 X-Git-Url: http://source.jalview.org/gitweb/?p=jalview.git;a=commitdiff_plain;h=f9574ab683df8d0c9dfda092c9005ca773c38e55;hp=ec606034401293ba2700c18bdd8b5c62000f7810 Merge branch 'improvement/JAL-1988+JAL-3416_Java8_macOS_APQHandlers_and_FlatLaF_option' into develop --- diff --git a/src/jalview/jbgui/APQHandlers.java b/src/jalview/jbgui/APQHandlers.java index 5e04b14..1a7e971 100644 --- a/src/jalview/jbgui/APQHandlers.java +++ b/src/jalview/jbgui/APQHandlers.java @@ -24,68 +24,86 @@ import javax.swing.JFrame; import javax.swing.JOptionPane; import com.formdev.flatlaf.extras.FlatDesktop; +import com.formdev.flatlaf.extras.FlatDesktop.Action; import jalview.util.MessageManager; import jalview.util.Platform; public class APQHandlers { + public static boolean setAbout = false; + + public static boolean setPreferences = false; + + public static boolean setQuit = false; + public static boolean setAPQHandlers(GDesktop desktop) { if (Platform.isJS()) { return false; } - FlatDesktop.setAboutHandler(() -> { - desktop.aboutMenuItem_actionPerformed(null); - }); - FlatDesktop.setPreferencesHandler(() -> { - desktop.preferences_actionPerformed(null); - }); - FlatDesktop.setQuitHandler(response -> { - boolean confirmQuit = jalview.bin.Cache - .getDefault(jalview.gui.Desktop.CONFIRM_KEYBOARD_QUIT, true); - boolean canQuit = !confirmQuit; - int n; - if (confirmQuit) - { - // ensure Jalview window is brought to front for Quit confirmation - // window to be - // visible + if (FlatDesktop.isSupported(Action.APP_ABOUT)) + { + FlatDesktop.setAboutHandler(() -> { + desktop.aboutMenuItem_actionPerformed(null); + }); + setAbout = true; + } + if (FlatDesktop.isSupported(Action.APP_PREFERENCES)) + { + FlatDesktop.setPreferencesHandler(() -> { + desktop.preferences_actionPerformed(null); + }); + setPreferences = true; + } + if (FlatDesktop.isSupported(Action.APP_QUIT_HANDLER)) + { + FlatDesktop.setQuitHandler(response -> { + boolean confirmQuit = jalview.bin.Cache.getDefault( + jalview.gui.Desktop.CONFIRM_KEYBOARD_QUIT, true); + boolean canQuit = !confirmQuit; + int n; + if (confirmQuit) + { + // 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(); + // 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); + // 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); + 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 - { - n = JOptionPane.OK_OPTION; - } - canQuit = (n == JOptionPane.OK_OPTION); - if (canQuit) - { - response.performQuit(); - } - else - { - response.cancelQuit(); - } - }); + dialogParent.setAlwaysOnTop(false); + dialogParent.dispose(); + } + else + { + n = JOptionPane.OK_OPTION; + } + canQuit = (n == JOptionPane.OK_OPTION); + if (canQuit) + { + response.performQuit(); + } + else + { + response.cancelQuit(); + } + }); + setQuit = true; + } // if we got to here, no exceptions occurred when we set the handlers. - return true; + return setAbout || setPreferences || setQuit; } } diff --git a/src/jalview/jbgui/GDesktop.java b/src/jalview/jbgui/GDesktop.java index 98217b1..459835d 100755 --- a/src/jalview/jbgui/GDesktop.java +++ b/src/jalview/jbgui/GDesktop.java @@ -402,12 +402,12 @@ public class GDesktop extends JFrame FileMenu.add(loadState); FileMenu.addSeparator(); FileMenu.add(quit); - if (!apqHandlersSet) + if (!APQHandlers.setAbout) { HelpMenu.add(aboutMenuItem); } HelpMenu.add(documentationMenuItem); - if (!apqHandlersSet) + if (!APQHandlers.setPreferences) { toolsMenu.add(preferences); }