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"));
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
90 jalview.gui.Desktop.CONFIRM_KEYBOARD_QUIT,
95 n = JOptionPane.showConfirmDialog(null,
96 MessageManager.getString("label.quit_jalview"),
97 MessageManager.getString("action.quit"),
98 JOptionPane.OK_CANCEL_OPTION,
99 JOptionPane.PLAIN_MESSAGE, null);
103 n = JOptionPane.OK_OPTION;
105 if (n == JOptionPane.OK_OPTION)
107 System.out.println("Shortcut Quit confirmed by user");
108 jalviewDesktop.quit();
109 r.performQuit(); // probably won't reach this line, but just
116 System.out.println("Shortcut Quit cancelled by user");
120 hdesktop.setQuitStrategy(
121 QuitStrategy.CLOSE_ALL_WINDOWS);
125 setAPQHandlers = true;
130 "Not going to try setting APQ Handlers as java.spec.version is "
134 } catch (Exception e)
137 "Exception when looking for About, Preferences, Quit Handlers");
138 // e.printStackTrace();
139 } catch (Throwable t)
142 "Throwable when looking for About, Preferences, Quit Handlers");
143 // t.printStackTrace();
148 return setAPQHandlers;