- // see if the Quit, About and Preferences handlers are available
- Class desktopClass = java.awt.Desktop.class;
- java.awt.Desktop hdesktop = java.awt.Desktop.getDesktop();
-
- try
- {
-
- if (Platform.isAMac())
- {
- if (desktopClass.getDeclaredMethod("setAboutHandler",
- new Class[]
- { AboutHandler.class }) != null)
- {
-
- hdesktop.setAboutHandler(new AboutHandler()
- {
- @Override
- public void handleAbout(AboutEvent e)
- {
- aboutMenuItem_actionPerformed(null);
- }
- });
-
- }
-
- if (desktopClass.getDeclaredMethod("setPreferencesHandler",
- new Class[]
- { PreferencesHandler.class }) != null)
- {
-
- hdesktop.setPreferencesHandler(new PreferencesHandler()
- {
- @Override
- public void handlePreferences(PreferencesEvent e)
- {
- 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 = jalview.bin.Cache
- .getDefault(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");
- 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);
-
- }
- }
-
- } catch (NoSuchMethodException e)
- {
- System.out.println(
- "NoSuchMethodException when looking for About, Preferences, Quit Handlers");
- e.printStackTrace();
- }
-
- setAPQHandlers = true;