Clover icon

Coverage Report

  1. Project Clover database Thu Aug 13 2020 12:04:21 BST
  2. Package jalview.gui

File APQHandlers.java

 

Coverage histogram

../../img/srcFileCovDistChart3.png
47% of files have more coverage

Code metrics

16
32
5
1
171
125
15
0.47
6.4
5
3

Classes

Class Line # Actions
APQHandlers 38 32 15
0.2641509526.4%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.gui;
22   
23    import jalview.util.MessageManager;
24    import jalview.util.Platform;
25   
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;
35   
36    import javax.swing.JOptionPane;
37   
 
38    public class APQHandlers
39    {
40    private static boolean setAPQHandlers = false;
41   
 
42  0 toggle public APQHandlers() {
43    }
44   
 
45  18 toggle protected static boolean setAPQHandlers(jalview.gui.Desktop jalviewDesktop)
46    {
47    // flagging this test to avoid unnecessary reflection
48  18 if (!setAPQHandlers)
49    {
50    // see if the Quit, About and Preferences handlers are available
51  2 Class desktopClass = Desktop.class;
52  2 Desktop hdesktop = Desktop.getDesktop();
53   
54  2 try
55    {
56  2 Float specversion = Float.parseFloat(
57    System.getProperty("java.specification.version"));
58   
59  2 if (specversion >= 9)
60    {
61  2 if (Platform.isAMacAndNotJS())
62    {
63  0 if (desktopClass.getDeclaredMethod("setAboutHandler",
64    new Class[]
65    { AboutHandler.class }) != null)
66    {
67   
68  0 hdesktop.setAboutHandler(new AboutHandler()
69    {
 
70  0 toggle @Override
71    public void handleAbout(AboutEvent e)
72    {
73  0 jalviewDesktop.aboutMenuItem_actionPerformed(null);
74    }
75    });
76   
77    }
78   
79  0 if (desktopClass.getDeclaredMethod("setPreferencesHandler",
80    new Class[]
81    { PreferencesHandler.class }) != null)
82    {
83   
84  0 hdesktop.setPreferencesHandler(
85    new PreferencesHandler()
86    {
 
87  0 toggle @Override
88    public void handlePreferences(
89    PreferencesEvent e)
90    {
91  0 jalviewDesktop.preferences_actionPerformed(null);
92    }
93    });
94   
95    }
96   
97  0 if (desktopClass.getDeclaredMethod("setQuitHandler",
98    new Class[]
99    { QuitHandler.class }) != null)
100    {
101   
102  0 hdesktop.setQuitHandler(new QuitHandler()
103    {
 
104  0 toggle @Override
105    public void handleQuitRequestWith(
106    QuitEvent e, QuitResponse r)
107    {
108  0 boolean confirmQuit = jalview.bin.Cache
109    .getDefault(
110    jalview.gui.Desktop.CONFIRM_KEYBOARD_QUIT,
111    true);
112  0 int n;
113  0 if (confirmQuit)
114    {
115  0 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);
120    }
121    else
122    {
123  0 n = JOptionPane.OK_OPTION;
124    }
125  0 if (n == JOptionPane.OK_OPTION)
126    {
127  0 System.out.println("Shortcut Quit confirmed by user");
128  0 jalviewDesktop.quit();
129  0 r.performQuit(); // probably won't reach this line, but just
130    // in
131    // case
132    }
133    else
134    {
135  0 r.cancelQuit();
136  0 System.out.println("Shortcut Quit cancelled by user");
137    }
138    }
139    });
140  0 hdesktop.setQuitStrategy(
141    QuitStrategy.CLOSE_ALL_WINDOWS);
142   
143    }
144    }
145  2 setAPQHandlers = true;
146    }
147    else
148    {
149  0 System.out.println(
150    "Not going to try setting APQ Handlers as java.spec.version is "
151    + specversion);
152    }
153   
154    } catch (Exception e)
155    {
156  0 System.out.println(
157    "Exception when looking for About, Preferences, Quit Handlers");
158    // e.printStackTrace();
159    } catch (Throwable t)
160    {
161  0 System.out.println(
162    "Throwable when looking for About, Preferences, Quit Handlers");
163    // t.printStackTrace();
164    }
165   
166    }
167   
168  18 return setAPQHandlers;
169    }
170   
171    }