author | jdv |
Fri, 21 Jun 2019 12:08:37 +0530 | |
branch | metal-prototype-branch |
changeset 57416 | e153174dba06 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
18241 | 1 |
/* |
37700 | 2 |
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. |
18241 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package sun.lwawt.macosx; |
|
27 |
||
28 |
import sun.awt.AWTAccessor; |
|
29 |
import sun.awt.IconInfo; |
|
30 |
import sun.java2d.SunGraphics2D; |
|
31 |
import sun.java2d.SurfaceData; |
|
57416
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
47216
diff
changeset
|
32 |
import sun.java2d.metal.MTLLayer; |
18241 | 33 |
import sun.java2d.opengl.CGLLayer; |
34 |
import sun.lwawt.LWWindowPeer; |
|
35 |
import sun.lwawt.PlatformEventNotifier; |
|
36 |
import sun.lwawt.SecurityWarningWindow; |
|
37 |
||
38 |
import java.awt.*; |
|
39 |
import java.awt.event.MouseEvent; |
|
40 |
import java.awt.geom.Point2D; |
|
41 |
import java.lang.ref.WeakReference; |
|
42 |
||
43 |
public final class CWarningWindow extends CPlatformWindow |
|
44 |
implements SecurityWarningWindow, PlatformEventNotifier { |
|
45 |
||
23681
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
46 |
private static class Lock {} |
18241 | 47 |
private final Lock lock = new Lock(); |
48 |
||
32865
f9cb6e427f9e
8136783: Run blessed-modifier-order script on java.desktop
prr
parents:
32295
diff
changeset
|
49 |
private static final int SHOWING_DELAY = 300; |
f9cb6e427f9e
8136783: Run blessed-modifier-order script on java.desktop
prr
parents:
32295
diff
changeset
|
50 |
private static final int HIDING_DELAY = 2000; |
18241 | 51 |
|
52 |
private Rectangle bounds = new Rectangle(); |
|
53 |
private final WeakReference<LWWindowPeer> ownerPeer; |
|
54 |
private final Window ownerWindow; |
|
55 |
||
56 |
/** |
|
57 |
* Animation stage. |
|
58 |
*/ |
|
59 |
private volatile int currentIcon = 0; |
|
60 |
||
61 |
/* -1 - uninitialized. |
|
62 |
* 0 - 16x16 |
|
63 |
* 1 - 24x24 |
|
64 |
* 2 - 32x32 |
|
65 |
* 3 - 48x48 |
|
66 |
*/ |
|
67 |
private int currentSize = -1; |
|
68 |
private static IconInfo[][] icons; |
|
69 |
private static IconInfo getSecurityIconInfo(int size, int num) { |
|
70 |
synchronized (CWarningWindow.class) { |
|
71 |
if (icons == null) { |
|
72 |
icons = new IconInfo[4][3]; |
|
73 |
icons[0][0] = new IconInfo(sun.awt.AWTIcon32_security_icon_bw16_png.security_icon_bw16_png); |
|
74 |
icons[0][1] = new IconInfo(sun.awt.AWTIcon32_security_icon_interim16_png.security_icon_interim16_png); |
|
75 |
icons[0][2] = new IconInfo(sun.awt.AWTIcon32_security_icon_yellow16_png.security_icon_yellow16_png); |
|
76 |
icons[1][0] = new IconInfo(sun.awt.AWTIcon32_security_icon_bw24_png.security_icon_bw24_png); |
|
77 |
icons[1][1] = new IconInfo(sun.awt.AWTIcon32_security_icon_interim24_png.security_icon_interim24_png); |
|
78 |
icons[1][2] = new IconInfo(sun.awt.AWTIcon32_security_icon_yellow24_png.security_icon_yellow24_png); |
|
79 |
icons[2][0] = new IconInfo(sun.awt.AWTIcon32_security_icon_bw32_png.security_icon_bw32_png); |
|
80 |
icons[2][1] = new IconInfo(sun.awt.AWTIcon32_security_icon_interim32_png.security_icon_interim32_png); |
|
81 |
icons[2][2] = new IconInfo(sun.awt.AWTIcon32_security_icon_yellow32_png.security_icon_yellow32_png); |
|
82 |
icons[3][0] = new IconInfo(sun.awt.AWTIcon32_security_icon_bw48_png.security_icon_bw48_png); |
|
83 |
icons[3][1] = new IconInfo(sun.awt.AWTIcon32_security_icon_interim48_png.security_icon_interim48_png); |
|
84 |
icons[3][2] = new IconInfo(sun.awt.AWTIcon32_security_icon_yellow48_png.security_icon_yellow48_png); |
|
85 |
} |
|
86 |
} |
|
87 |
final int sizeIndex = size % icons.length; |
|
88 |
return icons[sizeIndex][num % icons[sizeIndex].length]; |
|
89 |
} |
|
90 |
||
91 |
public CWarningWindow(final Window _ownerWindow, final LWWindowPeer _ownerPeer) { |
|
92 |
super(); |
|
93 |
||
23681
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
94 |
this.ownerPeer = new WeakReference<>(_ownerPeer); |
18241 | 95 |
this.ownerWindow = _ownerWindow; |
96 |
||
97 |
initialize(null, null, _ownerPeer.getPlatformWindow()); |
|
98 |
||
99 |
setOpaque(false); |
|
100 |
||
101 |
String warningString = ownerWindow.getWarningString(); |
|
102 |
if (warningString != null) { |
|
103 |
contentView.setToolTip(ownerWindow.getWarningString()); |
|
104 |
} |
|
105 |
||
106 |
updateIconSize(); |
|
107 |
} |
|
108 |
||
109 |
/** |
|
110 |
* @param x,y,w,h coordinates of the untrusted window |
|
111 |
*/ |
|
112 |
public void reposition(int x, int y, int w, int h) { |
|
113 |
final Point2D point = AWTAccessor.getWindowAccessor(). |
|
114 |
calculateSecurityWarningPosition(ownerWindow, x, y, w, h); |
|
115 |
setBounds((int)point.getX(), (int)point.getY(), getWidth(), getHeight()); |
|
116 |
} |
|
117 |
||
118 |
public void setVisible(boolean visible, boolean doSchedule) { |
|
23681
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
119 |
synchronized (taskLock) { |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
120 |
cancelTasks(); |
18241 | 121 |
|
122 |
if (visible) { |
|
123 |
if (isVisible()) { |
|
124 |
currentIcon = 0; |
|
125 |
} else { |
|
126 |
currentIcon = 2; |
|
127 |
} |
|
128 |
||
23681
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
129 |
showHideTask = new ShowingTask(); |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
130 |
LWCToolkit.performOnMainThreadAfterDelay(showHideTask, 50); |
18241 | 131 |
} else { |
132 |
if (!isVisible()) { |
|
133 |
return; |
|
134 |
} |
|
135 |
||
23681
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
136 |
showHideTask = new HidingTask(); |
18241 | 137 |
if (doSchedule) { |
23681
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
138 |
LWCToolkit.performOnMainThreadAfterDelay(showHideTask, HIDING_DELAY); |
18241 | 139 |
} else { |
23681
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
140 |
LWCToolkit.performOnMainThreadAfterDelay(showHideTask, 50); |
18241 | 141 |
} |
142 |
} |
|
143 |
} |
|
144 |
} |
|
145 |
||
146 |
@Override |
|
147 |
public void notifyIconify(boolean iconify) { |
|
148 |
} |
|
149 |
||
150 |
@Override |
|
151 |
public void notifyZoom(boolean isZoomed) { |
|
152 |
} |
|
153 |
||
154 |
@Override |
|
155 |
public void notifyExpose(final Rectangle r) { |
|
156 |
repaint(); |
|
157 |
} |
|
158 |
||
159 |
@Override |
|
160 |
public void notifyReshape(int x, int y, int w, int h) { |
|
161 |
} |
|
162 |
||
163 |
@Override |
|
164 |
public void notifyUpdateCursor() { |
|
165 |
} |
|
166 |
||
167 |
@Override |
|
168 |
public void notifyActivation(boolean activation, LWWindowPeer opposite) { |
|
169 |
} |
|
170 |
||
171 |
@Override |
|
172 |
public void notifyNCMouseDown() { |
|
173 |
} |
|
174 |
||
175 |
@Override |
|
176 |
public void notifyMouseEvent(int id, long when, int button, int x, int y, |
|
32295
5ba453554637
6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
25859
diff
changeset
|
177 |
int absX, int absY, int modifiers, |
18241 | 178 |
int clickCount, boolean popupTrigger, |
179 |
byte[] bdata) { |
|
180 |
LWWindowPeer peer = ownerPeer.get(); |
|
181 |
if (id == MouseEvent.MOUSE_EXITED) { |
|
182 |
if (peer != null) { |
|
183 |
peer.updateSecurityWarningVisibility(); |
|
184 |
} |
|
185 |
} else if(id == MouseEvent.MOUSE_ENTERED) { |
|
186 |
if (peer != null) { |
|
187 |
peer.updateSecurityWarningVisibility(); |
|
188 |
} |
|
189 |
} |
|
190 |
} |
|
191 |
||
192 |
public Rectangle getBounds() { |
|
193 |
synchronized (lock) { |
|
194 |
return bounds.getBounds(); |
|
195 |
} |
|
196 |
} |
|
197 |
||
198 |
@Override |
|
199 |
public boolean isVisible() { |
|
200 |
synchronized (lock) { |
|
201 |
return visible; |
|
202 |
} |
|
203 |
} |
|
204 |
||
205 |
@Override |
|
206 |
public void setVisible(boolean visible) { |
|
207 |
synchronized (lock) { |
|
44752 | 208 |
execute(ptr -> { |
209 |
// Actually show or hide the window |
|
210 |
if (visible) { |
|
211 |
CWrapper.NSWindow.orderFront(ptr); |
|
212 |
} else { |
|
213 |
CWrapper.NSWindow.orderOut(ptr); |
|
214 |
} |
|
215 |
}); |
|
18241 | 216 |
|
217 |
this.visible = visible; |
|
218 |
||
219 |
// Manage parent-child relationship when showing |
|
220 |
if (visible) { |
|
38970
aabcf4406038
8080729: [macosx] java 7 and 8 JDialogs on multiscreen jump to parent frame on focus
dmarkov
parents:
37700
diff
changeset
|
221 |
// Order myself above my parent |
18241 | 222 |
if (owner != null && owner.isVisible()) { |
44752 | 223 |
owner.execute(ownerPtr -> { |
224 |
execute(ptr -> { |
|
225 |
CWrapper.NSWindow.orderWindow(ptr, |
|
57416
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
47216
diff
changeset
|
226 |
CWrapper.NSWindow.NSWindowAbove, |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
47216
diff
changeset
|
227 |
ownerPtr); |
44752 | 228 |
}); |
229 |
}); |
|
18241 | 230 |
|
231 |
// do not allow security warning to be obscured by other windows |
|
23253 | 232 |
applyWindowLevel(ownerWindow); |
18241 | 233 |
} |
234 |
} |
|
235 |
} |
|
236 |
} |
|
237 |
||
238 |
@Override |
|
32295
5ba453554637
6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
25859
diff
changeset
|
239 |
public void notifyMouseWheelEvent(long when, int x, int y, int absX, |
5ba453554637
6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
25859
diff
changeset
|
240 |
int absY, int modifiers, int scrollType, |
5ba453554637
6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
25859
diff
changeset
|
241 |
int scrollAmount, int wheelRotation, |
5ba453554637
6778087: getLocationOnScreen() always returns (0, 0) for mouse wheel events
serb
parents:
25859
diff
changeset
|
242 |
double preciseWheelRotation, |
18241 | 243 |
byte[] bdata) { |
244 |
} |
|
245 |
||
246 |
@Override |
|
247 |
public void notifyKeyEvent(int id, long when, int modifiers, int keyCode, |
|
248 |
char keyChar, int keyLocation) { |
|
249 |
} |
|
250 |
||
251 |
protected int getInitialStyleBits() { |
|
252 |
int styleBits = 0; |
|
253 |
CPlatformWindow.SET(styleBits, CPlatformWindow.UTILITY, true); |
|
254 |
return styleBits; |
|
255 |
} |
|
256 |
||
257 |
protected void deliverMoveResizeEvent(int x, int y, int width, int height, |
|
258 |
boolean byUser) { |
|
259 |
||
260 |
boolean isResize; |
|
261 |
synchronized (lock) { |
|
262 |
isResize = (bounds.width != width || bounds.height != height); |
|
263 |
bounds = new Rectangle(x, y, width, height); |
|
264 |
} |
|
265 |
||
266 |
if (isResize) { |
|
267 |
replaceSurface(); |
|
268 |
} |
|
269 |
||
270 |
super.deliverMoveResizeEvent(x, y, width, height, byUser); |
|
271 |
} |
|
272 |
||
273 |
protected CPlatformResponder createPlatformResponder() { |
|
274 |
return new CPlatformResponder(this, false); |
|
275 |
} |
|
276 |
||
277 |
protected CPlatformView createContentView() { |
|
278 |
return new CPlatformView() { |
|
279 |
public GraphicsConfiguration getGraphicsConfiguration() { |
|
280 |
LWWindowPeer peer = ownerPeer.get(); |
|
281 |
return peer.getGraphicsConfiguration(); |
|
282 |
} |
|
283 |
||
284 |
public Rectangle getBounds() { |
|
285 |
return CWarningWindow.this.getBounds(); |
|
286 |
} |
|
287 |
||
288 |
public CGLLayer createCGLayer() { |
|
289 |
return new CGLLayer(null) { |
|
290 |
public Rectangle getBounds() { |
|
291 |
return CWarningWindow.this.getBounds(); |
|
292 |
} |
|
293 |
||
294 |
public GraphicsConfiguration getGraphicsConfiguration() { |
|
295 |
LWWindowPeer peer = ownerPeer.get(); |
|
296 |
return peer.getGraphicsConfiguration(); |
|
297 |
} |
|
298 |
||
299 |
public boolean isOpaque() { |
|
300 |
return false; |
|
301 |
} |
|
302 |
}; |
|
303 |
} |
|
57416
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
47216
diff
changeset
|
304 |
public MTLLayer createMTLLayer() { |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
47216
diff
changeset
|
305 |
return new MTLLayer(null) { |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
47216
diff
changeset
|
306 |
public Rectangle getBounds() { |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
47216
diff
changeset
|
307 |
return CWarningWindow.this.getBounds(); |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
47216
diff
changeset
|
308 |
} |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
47216
diff
changeset
|
309 |
|
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
47216
diff
changeset
|
310 |
public GraphicsConfiguration getGraphicsConfiguration() { |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
47216
diff
changeset
|
311 |
LWWindowPeer peer = ownerPeer.get(); |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
47216
diff
changeset
|
312 |
return peer.getGraphicsConfiguration(); |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
47216
diff
changeset
|
313 |
} |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
47216
diff
changeset
|
314 |
|
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
47216
diff
changeset
|
315 |
public boolean isOpaque() { |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
47216
diff
changeset
|
316 |
return false; |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
47216
diff
changeset
|
317 |
} |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
47216
diff
changeset
|
318 |
}; |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
47216
diff
changeset
|
319 |
} |
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
47216
diff
changeset
|
320 |
|
18241 | 321 |
}; |
322 |
} |
|
323 |
||
23676
f985a8f16d58
8037776: [macosx] Swing app fails to exit after last window is disposed when security manager is enabled
pchelko
parents:
23253
diff
changeset
|
324 |
@Override |
f985a8f16d58
8037776: [macosx] Swing app fails to exit after last window is disposed when security manager is enabled
pchelko
parents:
23253
diff
changeset
|
325 |
public void dispose() { |
23681
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
326 |
cancelTasks(); |
24535
9b1698300d1d
8041490: PIT: [macosx] Crash in system tray functionality check test
pchelko
parents:
23681
diff
changeset
|
327 |
SurfaceData surfaceData = contentView.getSurfaceData(); |
9b1698300d1d
8041490: PIT: [macosx] Crash in system tray functionality check test
pchelko
parents:
23681
diff
changeset
|
328 |
if (surfaceData != null) { |
9b1698300d1d
8041490: PIT: [macosx] Crash in system tray functionality check test
pchelko
parents:
23681
diff
changeset
|
329 |
surfaceData.invalidate(); |
9b1698300d1d
8041490: PIT: [macosx] Crash in system tray functionality check test
pchelko
parents:
23681
diff
changeset
|
330 |
} |
23676
f985a8f16d58
8037776: [macosx] Swing app fails to exit after last window is disposed when security manager is enabled
pchelko
parents:
23253
diff
changeset
|
331 |
super.dispose(); |
f985a8f16d58
8037776: [macosx] Swing app fails to exit after last window is disposed when security manager is enabled
pchelko
parents:
23253
diff
changeset
|
332 |
} |
f985a8f16d58
8037776: [macosx] Swing app fails to exit after last window is disposed when security manager is enabled
pchelko
parents:
23253
diff
changeset
|
333 |
|
23681
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
334 |
private void cancelTasks() { |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
335 |
synchronized (taskLock) { |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
336 |
if (showHideTask != null) { |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
337 |
showHideTask.cancel(); |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
338 |
showHideTask = null; |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
339 |
} |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
340 |
} |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
341 |
} |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
342 |
|
18241 | 343 |
private void updateIconSize() { |
344 |
int newSize = -1; |
|
345 |
||
346 |
if (ownerWindow != null) { |
|
347 |
Insets insets = ownerWindow.getInsets(); |
|
348 |
int max = Math.max(insets.top, Math.max(insets.bottom, |
|
349 |
Math.max(insets.left, insets.right))); |
|
350 |
if (max < 24) { |
|
351 |
newSize = 0; |
|
352 |
} else if (max < 32) { |
|
353 |
newSize = 1; |
|
354 |
} else if (max < 48) { |
|
355 |
newSize = 2; |
|
356 |
} else { |
|
357 |
newSize = 3; |
|
358 |
} |
|
359 |
} |
|
360 |
// Make sure we have a valid size |
|
361 |
if (newSize == -1) { |
|
362 |
newSize = 0; |
|
363 |
} |
|
364 |
||
365 |
synchronized (lock) { |
|
366 |
if (newSize != currentSize) { |
|
367 |
currentSize = newSize; |
|
368 |
IconInfo ico = getSecurityIconInfo(currentSize, 0); |
|
369 |
AWTAccessor.getWindowAccessor().setSecurityWarningSize( |
|
57416
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
47216
diff
changeset
|
370 |
ownerWindow, ico.getWidth(), ico.getHeight()); |
18241 | 371 |
} |
372 |
} |
|
373 |
} |
|
374 |
||
23681
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
375 |
private Graphics getGraphics() { |
18241 | 376 |
SurfaceData sd = contentView.getSurfaceData(); |
377 |
if (ownerWindow == null || sd == null) { |
|
378 |
return null; |
|
379 |
} |
|
380 |
||
37700 | 381 |
return new SunGraphics2D(sd, SystemColor.windowText, SystemColor.window, |
57416
e153174dba06
Merge JDK-8220154 initial metal implementation patch to the jdk sandbox branch
jdv
parents:
47216
diff
changeset
|
382 |
ownerWindow.getFont()); |
18241 | 383 |
} |
384 |
||
385 |
||
386 |
private void repaint() { |
|
387 |
final Graphics g = getGraphics(); |
|
388 |
if (g != null) { |
|
389 |
try { |
|
390 |
((Graphics2D) g).setComposite(AlphaComposite.Src); |
|
391 |
g.drawImage(getSecurityIconInfo().getImage(), 0, 0, null); |
|
392 |
} finally { |
|
393 |
g.dispose(); |
|
394 |
} |
|
395 |
} |
|
396 |
} |
|
397 |
||
398 |
private void replaceSurface() { |
|
399 |
SurfaceData oldData = contentView.getSurfaceData(); |
|
400 |
||
401 |
replaceSurfaceData(); |
|
402 |
||
403 |
if (oldData != null && oldData != contentView.getSurfaceData()) { |
|
404 |
oldData.flush(); |
|
405 |
} |
|
406 |
} |
|
407 |
||
408 |
private int getWidth() { |
|
409 |
return getSecurityIconInfo().getWidth(); |
|
410 |
} |
|
411 |
||
412 |
private int getHeight() { |
|
413 |
return getSecurityIconInfo().getHeight(); |
|
414 |
} |
|
415 |
||
416 |
private IconInfo getSecurityIconInfo() { |
|
417 |
return getSecurityIconInfo(currentSize, currentIcon); |
|
418 |
} |
|
419 |
||
23681
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
420 |
private final Lock taskLock = new Lock(); |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
421 |
private CancelableRunnable showHideTask; |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
422 |
|
32865
f9cb6e427f9e
8136783: Run blessed-modifier-order script on java.desktop
prr
parents:
32295
diff
changeset
|
423 |
private abstract static class CancelableRunnable implements Runnable { |
23681
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
424 |
private volatile boolean perform = true; |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
425 |
|
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
426 |
public final void cancel() { |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
427 |
perform = false; |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
428 |
} |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
429 |
|
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
430 |
@Override |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
431 |
public final void run() { |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
432 |
if (perform) { |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
433 |
perform(); |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
434 |
} |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
435 |
} |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
436 |
|
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
437 |
public abstract void perform(); |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
438 |
} |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
439 |
|
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
440 |
private class HidingTask extends CancelableRunnable { |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
441 |
@Override |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
442 |
public void perform() { |
18241 | 443 |
synchronized (lock) { |
444 |
setVisible(false); |
|
445 |
} |
|
446 |
||
23681
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
447 |
synchronized (taskLock) { |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
448 |
showHideTask = null; |
18241 | 449 |
} |
450 |
} |
|
23681
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
451 |
} |
18241 | 452 |
|
23681
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
453 |
private class ShowingTask extends CancelableRunnable { |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
454 |
@Override |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
455 |
public void perform() { |
18241 | 456 |
synchronized (lock) { |
457 |
if (!isVisible()) { |
|
458 |
setVisible(true); |
|
459 |
} |
|
460 |
repaint(); |
|
461 |
} |
|
462 |
||
23681
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
463 |
synchronized (taskLock) { |
18241 | 464 |
if (currentIcon > 0) { |
465 |
currentIcon--; |
|
23681
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
466 |
showHideTask = new ShowingTask(); |
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
467 |
LWCToolkit.performOnMainThreadAfterDelay(showHideTask, SHOWING_DELAY); |
18241 | 468 |
} else { |
23681
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
469 |
showHideTask = null; |
18241 | 470 |
} |
471 |
} |
|
472 |
} |
|
23681
2044c9d2b681
8037840: [macosx] Rewrite CWarning window to eliminate the ExecutorService
pchelko
parents:
23676
diff
changeset
|
473 |
} |
18241 | 474 |
} |
475 |