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;
47 protected static boolean setAPQHandlers(
48 jalview.gui.Desktop jalviewDesktop)
50 // flagging this test to avoid unnecessary reflection
53 // see if the Quit, About and Preferences handlers are available
54 Class desktopClass = Desktop.class;
55 Desktop hdesktop = Desktop.getDesktop();
59 Float specversion = Float.parseFloat(
60 System.getProperty("java.specification.version"));
64 if (Platform.isAMacAndNotJS())
66 if (desktopClass.getDeclaredMethod("setAboutHandler",
68 { AboutHandler.class }) != null)
71 hdesktop.setAboutHandler(new AboutHandler()
74 public void handleAbout(AboutEvent e)
76 jalviewDesktop.aboutMenuItem_actionPerformed(null);
82 if (desktopClass.getDeclaredMethod("setPreferencesHandler",
84 { PreferencesHandler.class }) != null)
87 hdesktop.setPreferencesHandler(new PreferencesHandler()
90 public void handlePreferences(PreferencesEvent e)
92 jalviewDesktop.preferences_actionPerformed(null);
98 if (desktopClass.getDeclaredMethod("setQuitHandler",
100 { QuitHandler.class }) != null)
103 hdesktop.setQuitHandler(new QuitHandler()
106 public void handleQuitRequestWith(QuitEvent e,
109 boolean confirmQuit = Cache.getDefault(
110 jalview.gui.Desktop.CONFIRM_KEYBOARD_QUIT, true);
114 n = JOptionPane.showConfirmDialog(null,
115 MessageManager.getString("label.quit_jalview"),
116 MessageManager.getString("action.quit"),
117 JOptionPane.OK_CANCEL_OPTION,
118 JOptionPane.PLAIN_MESSAGE, null);
122 n = JOptionPane.OK_OPTION;
124 if (n == JOptionPane.OK_OPTION)
126 System.out.println("Shortcut Quit confirmed by user");
127 jalviewDesktop.quit();
128 r.performQuit(); // probably won't reach this line, but just
135 System.out.println("Shortcut Quit cancelled by user");
139 hdesktop.setQuitStrategy(QuitStrategy.CLOSE_ALL_WINDOWS);
143 setAPQHandlers = true;
148 "Not going to try setting APQ Handlers as java.spec.version is "
152 } catch (Exception e)
155 "Exception when looking for About, Preferences, Quit Handlers");
156 // e.printStackTrace();
157 } catch (Throwable t)
160 "Throwable when looking for About, Preferences, Quit Handlers");
161 // t.printStackTrace();
166 return setAPQHandlers;