author | alexsch |
Wed, 24 Aug 2016 00:23:49 +0400 | |
changeset 40719 | 4ae72a69bd3b |
parent 36903 | addc2e9d4bd4 |
child 44752 | 97a2817b5a9b |
permissions | -rw-r--r-- |
12047 | 1 |
/* |
36903 | 2 |
* Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved. |
12047 | 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 com.apple.eawt; |
|
27 |
||
28 |
import java.awt.*; |
|
29 |
import java.lang.reflect.*; |
|
30 |
||
30469 | 31 |
import sun.awt.AWTAccessor; |
12047 | 32 |
import sun.lwawt.macosx.*; |
33 |
import sun.lwawt.macosx.CImage.Creator; |
|
34 |
||
35 |
class _AppDockIconHandler { |
|
36 |
private static native void nativeSetDockMenu(final long cmenu); |
|
37 |
private static native void nativeSetDockIconImage(final long image); |
|
36903 | 38 |
private static native void nativeSetDockIconProgress(final int value); |
12047 | 39 |
private static native long nativeGetDockIconImage(); |
40 |
private static native void nativeSetDockIconBadge(final String badge); |
|
41 |
||
42 |
PopupMenu fDockMenu = null; |
|
43 |
||
44 |
_AppDockIconHandler() { } |
|
45 |
||
46 |
public void setDockMenu(final PopupMenu menu) { |
|
47 |
fDockMenu = menu; |
|
48 |
||
49 |
// clear the menu if explicitly passed null |
|
50 |
if (menu == null) { |
|
51 |
nativeSetDockMenu(0); |
|
52 |
return; |
|
53 |
} |
|
54 |
||
55 |
// check if the menu needs a parent (8343136) |
|
56 |
final MenuContainer container = menu.getParent(); |
|
57 |
if (container == null) { |
|
58 |
final MenuBar newParent = new MenuBar(); |
|
59 |
newParent.add(menu); |
|
60 |
newParent.addNotify(); |
|
61 |
} |
|
62 |
||
63 |
// instantiate the menu peer and set the native fDockMenu ivar |
|
64 |
menu.addNotify(); |
|
30469 | 65 |
CMenu peer = AWTAccessor.getMenuComponentAccessor().getPeer(fDockMenu); |
66 |
nativeSetDockMenu(peer.getNativeMenu()); |
|
12047 | 67 |
} |
68 |
||
69 |
public PopupMenu getDockMenu() { |
|
70 |
return fDockMenu; |
|
71 |
} |
|
72 |
||
73 |
public void setDockIconImage(final Image image) { |
|
74 |
try { |
|
40719
4ae72a69bd3b
8129854: Remove reflection from AWT/Swing classes
alexsch
parents:
36903
diff
changeset
|
75 |
final CImage cImage = CImage.createFromImage(image); |
12047 | 76 |
final long nsImagePtr = getNSImagePtrFrom(cImage); |
77 |
nativeSetDockIconImage(nsImagePtr); |
|
78 |
} catch (final Throwable e) { |
|
79 |
throw new RuntimeException(e); |
|
80 |
} |
|
81 |
} |
|
82 |
||
83 |
Image getDockIconImage() { |
|
84 |
try { |
|
85 |
final long dockNSImage = nativeGetDockIconImage(); |
|
86 |
if (dockNSImage == 0) return null; |
|
40719
4ae72a69bd3b
8129854: Remove reflection from AWT/Swing classes
alexsch
parents:
36903
diff
changeset
|
87 |
final Method getCreatorMethod = CImage.class.getDeclaredMethod( |
4ae72a69bd3b
8129854: Remove reflection from AWT/Swing classes
alexsch
parents:
36903
diff
changeset
|
88 |
"getCreator", new Class<?>[]{}); |
4ae72a69bd3b
8129854: Remove reflection from AWT/Swing classes
alexsch
parents:
36903
diff
changeset
|
89 |
getCreatorMethod.setAccessible(true); |
4ae72a69bd3b
8129854: Remove reflection from AWT/Swing classes
alexsch
parents:
36903
diff
changeset
|
90 |
Creator imageCreator = (Creator) getCreatorMethod.invoke(null, new Object[]{}); |
4ae72a69bd3b
8129854: Remove reflection from AWT/Swing classes
alexsch
parents:
36903
diff
changeset
|
91 |
return imageCreator.createImageUsingNativeSize(dockNSImage); |
12047 | 92 |
} catch (final Throwable e) { |
93 |
throw new RuntimeException(e); |
|
94 |
} |
|
95 |
} |
|
96 |
||
97 |
void setDockIconBadge(final String badge) { |
|
98 |
nativeSetDockIconBadge(badge); |
|
99 |
} |
|
100 |
||
36903 | 101 |
void setDockIconProgress(int value) { |
102 |
nativeSetDockIconProgress(value); |
|
103 |
} |
|
104 |
||
12047 | 105 |
static long getNSImagePtrFrom(final CImage cImage) { |
106 |
if (cImage == null) return 0; |
|
107 |
||
108 |
try { |
|
109 |
final Field cImagePtrField = CFRetainedResource.class.getDeclaredField("ptr"); |
|
110 |
cImagePtrField.setAccessible(true); |
|
111 |
return cImagePtrField.getLong(cImage); |
|
112 |
} catch (final Throwable e) { |
|
113 |
throw new RuntimeException(e); |
|
114 |
} |
|
115 |
} |
|
116 |
} |