1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
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 |
|
|
|
|
| 26.4% |
Uncovered Elements: 39 (53) |
Complexity: 15 |
Complexity Density: 0.47 |
|
38 |
|
public class APQHandlers |
39 |
|
{ |
40 |
|
private static boolean setAPQHandlers = false; |
41 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
42 |
0 |
public APQHandlers() {... |
43 |
|
} |
44 |
|
|
|
|
| 41.9% |
Uncovered Elements: 18 (31) |
Complexity: 9 |
Complexity Density: 0.47 |
|
45 |
18 |
protected static boolean setAPQHandlers(jalview.gui.Desktop jalviewDesktop)... |
46 |
|
{ |
47 |
|
|
48 |
18 |
if (!setAPQHandlers) |
49 |
|
{ |
50 |
|
|
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 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
70 |
0 |
@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 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
87 |
0 |
@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 |
|
{ |
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 3 |
Complexity Density: 0.27 |
|
104 |
0 |
@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(); |
130 |
|
|
131 |
|
|
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 |
|
|
159 |
|
} catch (Throwable t) |
160 |
|
{ |
161 |
0 |
System.out.println( |
162 |
|
"Throwable when looking for About, Preferences, Quit Handlers"); |
163 |
|
|
164 |
|
} |
165 |
|
|
166 |
|
} |
167 |
|
|
168 |
18 |
return setAPQHandlers; |
169 |
|
} |
170 |
|
|
171 |
|
} |