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
31 import sun.awt.AWTAccessor;
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);
38 private static native long nativeGetDockIconImage();
39 private static native void nativeSetDockIconBadge(final String badge);
40
41 PopupMenu fDockMenu = null;
42
43 _AppDockIconHandler() { }
44
45 public void setDockMenu(final PopupMenu menu) {
46 fDockMenu = menu;
47
48 // clear the menu if explicitly passed null
49 if (menu == null) {
50 nativeSetDockMenu(0);
51 return;
52 }
53
54 // check if the menu needs a parent (8343136)
55 final MenuContainer container = menu.getParent();
56 if (container == null) {
57 final MenuBar newParent = new MenuBar();
74 final CImage cImage = getCImageCreator().createFromImage(image);
75 final long nsImagePtr = getNSImagePtrFrom(cImage);
76 nativeSetDockIconImage(nsImagePtr);
77 } catch (final Throwable e) {
78 throw new RuntimeException(e);
79 }
80 }
81
82 Image getDockIconImage() {
83 try {
84 final long dockNSImage = nativeGetDockIconImage();
85 if (dockNSImage == 0) return null;
86 return getCImageCreator().createImageUsingNativeSize(dockNSImage);
87 } catch (final Throwable e) {
88 throw new RuntimeException(e);
89 }
90 }
91
92 void setDockIconBadge(final String badge) {
93 nativeSetDockIconBadge(badge);
94 }
95
96 static Creator getCImageCreator() {
97 try {
98 final Method getCreatorMethod = CImage.class.getDeclaredMethod("getCreator", new Class<?>[] {});
99 getCreatorMethod.setAccessible(true);
100 return (Creator)getCreatorMethod.invoke(null, new Object[] {});
101 } catch (final Throwable e) {
102 throw new RuntimeException(e);
103 }
104 }
105
106 static long getNSImagePtrFrom(final CImage cImage) {
107 if (cImage == null) return 0;
108
109 try {
110 final Field cImagePtrField = CFRetainedResource.class.getDeclaredField("ptr");
111 cImagePtrField.setAccessible(true);
112 return cImagePtrField.getLong(cImage);
113 } catch (final Throwable e) {
|
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
31 import sun.awt.AWTAccessor;
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);
38 private static native void nativeSetDockIconProgress(final int value);
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();
75 final CImage cImage = getCImageCreator().createFromImage(image);
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;
87 return getCImageCreator().createImageUsingNativeSize(dockNSImage);
88 } catch (final Throwable e) {
89 throw new RuntimeException(e);
90 }
91 }
92
93 void setDockIconBadge(final String badge) {
94 nativeSetDockIconBadge(badge);
95 }
96
97 void setDockIconProgress(int value) {
98 nativeSetDockIconProgress(value);
99 }
100
101 static Creator getCImageCreator() {
102 try {
103 final Method getCreatorMethod = CImage.class.getDeclaredMethod("getCreator", new Class<?>[] {});
104 getCreatorMethod.setAccessible(true);
105 return (Creator)getCreatorMethod.invoke(null, new Object[] {});
106 } catch (final Throwable e) {
107 throw new RuntimeException(e);
108 }
109 }
110
111 static long getNSImagePtrFrom(final CImage cImage) {
112 if (cImage == null) return 0;
113
114 try {
115 final Field cImagePtrField = CFRetainedResource.class.getDeclaredField("ptr");
116 cImagePtrField.setAccessible(true);
117 return cImagePtrField.getLong(cImage);
118 } catch (final Throwable e) {
|