X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FAPQHandlers.java;h=00ec2176bb678f1b8c223dcb56e7d34821c9ac60;hb=469dc5a0e6d06a2c8a27f27b712ccfdbe3314ee4;hp=4d3a3f314646f14782729abeeb4a449fbfed8584;hpb=a1984b1c8c273ed33c7ce9283039f4027dcae2de;p=jalview.git diff --git a/src/jalview/gui/APQHandlers.java b/src/jalview/gui/APQHandlers.java index 4d3a3f3..00ec217 100644 --- a/src/jalview/gui/APQHandlers.java +++ b/src/jalview/gui/APQHandlers.java @@ -20,153 +20,46 @@ */ package jalview.gui; -import jalview.bin.Cache; -import jalview.util.MessageManager; -import jalview.util.Platform; - -import java.awt.Desktop; -import java.awt.desktop.AboutEvent; -import java.awt.desktop.AboutHandler; -import java.awt.desktop.PreferencesEvent; -import java.awt.desktop.PreferencesHandler; -import java.awt.desktop.QuitEvent; -import java.awt.desktop.QuitHandler; -import java.awt.desktop.QuitResponse; -import java.awt.desktop.QuitStrategy; +import com.formdev.flatlaf.extras.FlatDesktop; +import com.formdev.flatlaf.extras.FlatDesktop.Action; -import javax.swing.JOptionPane; +import jalview.util.Platform; public class APQHandlers { - private static boolean setAPQHandlers = false; + public static boolean setAbout = false; - public APQHandlers() { - } + public static boolean setPreferences = false; + + public static boolean setQuit = false; - protected static boolean setAPQHandlers(jalview.gui.Desktop jalviewDesktop) + public static boolean setAPQHandlers(Desktop desktop) { - // flagging this test to avoid unnecessary reflection - if (!setAPQHandlers) + if (Platform.isJS()) { - // see if the Quit, About and Preferences handlers are available - Class desktopClass = Desktop.class; - Desktop hdesktop = Desktop.getDesktop(); - - try - { - Float specversion = Float.parseFloat( - System.getProperty("java.specification.version")); - - if (specversion >= 9) - { - if (Platform.isAMacAndNotJS()) - { - if (desktopClass.getDeclaredMethod("setAboutHandler", - new Class[] - { AboutHandler.class }) != null) - { - - hdesktop.setAboutHandler(new AboutHandler() - { - @Override - public void handleAbout(AboutEvent e) - { - jalviewDesktop.aboutMenuItem_actionPerformed(null); - } - }); - - } - - if (desktopClass.getDeclaredMethod("setPreferencesHandler", - new Class[] - { PreferencesHandler.class }) != null) - { - - hdesktop.setPreferencesHandler( - new PreferencesHandler() - { - @Override - public void handlePreferences( - PreferencesEvent e) - { - jalviewDesktop.preferences_actionPerformed(null); - } - }); - - } - - if (desktopClass.getDeclaredMethod("setQuitHandler", - new Class[] - { QuitHandler.class }) != null) - { - - hdesktop.setQuitHandler(new QuitHandler() - { - @Override - public void handleQuitRequestWith( - QuitEvent e, QuitResponse r) - { - boolean confirmQuit = Cache - .getDefault( - jalview.gui.Desktop.CONFIRM_KEYBOARD_QUIT, - true); - int n; - if (confirmQuit) - { - n = JOptionPane.showConfirmDialog(null, - MessageManager.getString("label.quit_jalview"), - MessageManager.getString("action.quit"), - JOptionPane.OK_CANCEL_OPTION, - JOptionPane.PLAIN_MESSAGE, null); - } - else - { - n = JOptionPane.OK_OPTION; - } - if (n == JOptionPane.OK_OPTION) - { - System.out.println("Shortcut Quit confirmed by user"); - jalviewDesktop.quit(); - r.performQuit(); // probably won't reach this line, but just - // in - // case - } - else - { - r.cancelQuit(); - System.out.println("Shortcut Quit cancelled by user"); - } - } - }); - hdesktop.setQuitStrategy( - QuitStrategy.CLOSE_ALL_WINDOWS); - - } - } - setAPQHandlers = true; - } - else - { - System.out.println( - "Not going to try setting APQ Handlers as java.spec.version is " - + specversion); - } - - } catch (Exception e) - { - System.out.println( - "Exception when looking for About, Preferences, Quit Handlers"); - // e.printStackTrace(); - } catch (Throwable t) - { - System.out.println( - "Throwable when looking for About, Preferences, Quit Handlers"); - // t.printStackTrace(); - } - + return false; + } + 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)) + { + QuitHandler.setQuitHandler(); + setQuit = true; } - - return setAPQHandlers; + // if we got to here, no exceptions occurred when we set the handlers. + return setAbout || setPreferences || setQuit; } }