3 import jalview.util.MessageManager;
4 import jalview.util.Platform;
6 import java.awt.Desktop;
7 import java.awt.desktop.AboutEvent;
8 import java.awt.desktop.AboutHandler;
9 import java.awt.desktop.PreferencesEvent;
10 import java.awt.desktop.PreferencesHandler;
11 import java.awt.desktop.QuitEvent;
12 import java.awt.desktop.QuitHandler;
13 import java.awt.desktop.QuitResponse;
14 import java.awt.desktop.QuitStrategy;
16 import javax.swing.JOptionPane;
18 public class APQHandlers
20 private static boolean setAPQHandlers = false;
22 public APQHandlers() {
25 protected static boolean setAPQHandlers(jalview.gui.Desktop jalviewDesktop)
27 // flagging this test to avoid unnecessary reflection
30 // see if the Quit, About and Preferences handlers are available
31 Class desktopClass = Desktop.class;
32 Desktop hdesktop = Desktop.getDesktop();
36 Float specversion = Float.parseFloat(
37 System.getProperty("java.specification.version"));
41 if (Platform.isAMac())
43 if (desktopClass.getDeclaredMethod("setAboutHandler",
45 { AboutHandler.class }) != null)
48 hdesktop.setAboutHandler(new AboutHandler()
51 public void handleAbout(AboutEvent e)
53 jalviewDesktop.aboutMenuItem_actionPerformed(null);
59 if (desktopClass.getDeclaredMethod("setPreferencesHandler",
61 { PreferencesHandler.class }) != null)
64 hdesktop.setPreferencesHandler(
65 new PreferencesHandler()
68 public void handlePreferences(
71 jalviewDesktop.preferences_actionPerformed(null);
77 if (desktopClass.getDeclaredMethod("setQuitHandler",
79 { QuitHandler.class }) != null)
82 hdesktop.setQuitHandler(new QuitHandler()
85 public void handleQuitRequestWith(
86 QuitEvent e, QuitResponse r)
88 boolean confirmQuit = jalview.bin.Cache
89 .getDefault(jalviewDesktop.CONFIRM_KEYBOARD_QUIT,
94 n = JOptionPane.showConfirmDialog(null,
95 MessageManager.getString("label.quit_jalview"),
96 MessageManager.getString("action.quit"),
97 JOptionPane.OK_CANCEL_OPTION,
98 JOptionPane.PLAIN_MESSAGE, null);
102 n = JOptionPane.OK_OPTION;
104 if (n == JOptionPane.OK_OPTION)
106 System.out.println("Shortcut Quit confirmed by user");
107 jalviewDesktop.quit();
108 r.performQuit(); // probably won't reach this line, but just
115 System.out.println("Shortcut Quit cancelled by user");
119 hdesktop.setQuitStrategy(
120 QuitStrategy.CLOSE_ALL_WINDOWS);
124 setAPQHandlers = true;
129 "Not going to try setting APQ Handlers as java.spec.version is "
133 } catch (Exception e)
136 "Exception when looking for About, Preferences, Quit Handlers");
138 } catch (Throwable t)
141 "Throwable when looking for About, Preferences, Quit Handlers");
147 return setAPQHandlers;