2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.bin.Cache;
24 import jalview.util.MessageManager;
25 import jalview.util.Platform;
27 import java.awt.Desktop;
28 import java.awt.desktop.AboutEvent;
29 import java.awt.desktop.AboutHandler;
30 import java.awt.desktop.PreferencesEvent;
31 import java.awt.desktop.PreferencesHandler;
32 import java.awt.desktop.QuitEvent;
33 import java.awt.desktop.QuitHandler;
34 import java.awt.desktop.QuitResponse;
35 import java.awt.desktop.QuitStrategy;
37 import javax.swing.JOptionPane;
39 public class APQHandlers
41 private static boolean setAPQHandlers = false;
43 public APQHandlers() {
46 protected static boolean setAPQHandlers(jalview.gui.Desktop jalviewDesktop)
48 // flagging this test to avoid unnecessary reflection
51 // see if the Quit, About and Preferences handlers are available
52 Class desktopClass = Desktop.class;
53 Desktop hdesktop = Desktop.getDesktop();
57 Float specversion = Float.parseFloat(
58 System.getProperty("java.specification.version"));
62 if (Platform.isAMacAndNotJS())
64 if (desktopClass.getDeclaredMethod("setAboutHandler",
66 { AboutHandler.class }) != null)
69 hdesktop.setAboutHandler(new AboutHandler()
72 public void handleAbout(AboutEvent e)
74 jalviewDesktop.aboutMenuItem_actionPerformed(null);
80 if (desktopClass.getDeclaredMethod("setPreferencesHandler",
82 { PreferencesHandler.class }) != null)
85 hdesktop.setPreferencesHandler(
86 new PreferencesHandler()
89 public void handlePreferences(
92 jalviewDesktop.preferences_actionPerformed(null);
98 if (desktopClass.getDeclaredMethod("setQuitHandler",
100 { QuitHandler.class }) != null)
103 hdesktop.setQuitHandler(new QuitHandler()
106 public void handleQuitRequestWith(
107 QuitEvent e, QuitResponse r)
109 boolean confirmQuit = Cache
111 jalview.gui.Desktop.CONFIRM_KEYBOARD_QUIT,
116 n = JOptionPane.showConfirmDialog(null,
117 MessageManager.getString("label.quit_jalview"),
118 MessageManager.getString("action.quit"),
119 JOptionPane.OK_CANCEL_OPTION,
120 JOptionPane.PLAIN_MESSAGE, null);
124 n = JOptionPane.OK_OPTION;
126 if (n == JOptionPane.OK_OPTION)
128 System.out.println("Shortcut Quit confirmed by user");
129 jalviewDesktop.quit();
130 r.performQuit(); // probably won't reach this line, but just
137 System.out.println("Shortcut Quit cancelled by user");
141 hdesktop.setQuitStrategy(
142 QuitStrategy.CLOSE_ALL_WINDOWS);
146 setAPQHandlers = true;
151 "Not going to try setting APQ Handlers as java.spec.version is "
155 } catch (Exception e)
158 "Exception when looking for About, Preferences, Quit Handlers");
159 // e.printStackTrace();
160 } catch (Throwable t)
163 "Throwable when looking for About, Preferences, Quit Handlers");
164 // t.printStackTrace();
169 return setAPQHandlers;