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.util.MessageManager;
24 import jalview.util.Platform;
26 import java.awt.Desktop;
27 import java.awt.desktop.AboutEvent;
28 import java.awt.desktop.AboutHandler;
29 import java.awt.desktop.PreferencesEvent;
30 import java.awt.desktop.PreferencesHandler;
31 import java.awt.desktop.QuitEvent;
32 import java.awt.desktop.QuitHandler;
33 import java.awt.desktop.QuitResponse;
34 import java.awt.desktop.QuitStrategy;
36 import javax.swing.JOptionPane;
38 public class APQHandlers
40 private static boolean setAPQHandlers = false;
42 public APQHandlers() {
45 protected static boolean setAPQHandlers(jalview.gui.Desktop jalviewDesktop)
47 // flagging this test to avoid unnecessary reflection
50 // see if the Quit, About and Preferences handlers are available
51 Class desktopClass = Desktop.class;
52 Desktop hdesktop = Desktop.getDesktop();
56 Float specversion = Float.parseFloat(
57 System.getProperty("java.specification.version"));
61 if (Platform.isAMacAndNotJS())
63 if (desktopClass.getDeclaredMethod("setAboutHandler",
65 { AboutHandler.class }) != null)
68 hdesktop.setAboutHandler(new AboutHandler()
71 public void handleAbout(AboutEvent e)
73 jalviewDesktop.aboutMenuItem_actionPerformed(null);
79 if (desktopClass.getDeclaredMethod("setPreferencesHandler",
81 { PreferencesHandler.class }) != null)
84 hdesktop.setPreferencesHandler(
85 new PreferencesHandler()
88 public void handlePreferences(
91 jalviewDesktop.preferences_actionPerformed(null);
97 if (desktopClass.getDeclaredMethod("setQuitHandler",
99 { QuitHandler.class }) != null)
102 hdesktop.setQuitHandler(new QuitHandler()
105 public void handleQuitRequestWith(
106 QuitEvent e, QuitResponse r)
108 boolean confirmQuit = jalview.bin.Cache
110 jalview.gui.Desktop.CONFIRM_KEYBOARD_QUIT,
115 n = JOptionPane.showConfirmDialog(null,
116 MessageManager.getString("label.quit_jalview"),
117 MessageManager.getString("action.quit"),
118 JOptionPane.OK_CANCEL_OPTION,
119 JOptionPane.PLAIN_MESSAGE, null);
123 n = JOptionPane.OK_OPTION;
125 if (n == JOptionPane.OK_OPTION)
127 System.out.println("Shortcut Quit confirmed by user");
128 jalviewDesktop.quit();
129 r.performQuit(); // probably won't reach this line, but just
136 System.out.println("Shortcut Quit cancelled by user");
140 hdesktop.setQuitStrategy(
141 QuitStrategy.CLOSE_ALL_WINDOWS);
145 setAPQHandlers = true;
150 "Not going to try setting APQ Handlers as java.spec.version is "
154 } catch (Exception e)
157 "Exception when looking for About, Preferences, Quit Handlers");
158 // e.printStackTrace();
159 } catch (Throwable t)
162 "Throwable when looking for About, Preferences, Quit Handlers");
163 // t.printStackTrace();
168 return setAPQHandlers;