Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/macosx/classes/com/apple/eawt/_AppDockIconHandler.java
38831 views
1
/*
2
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
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
31
import sun.lwawt.macosx.*;
32
import sun.lwawt.macosx.CImage.Creator;
33
34
class _AppDockIconHandler {
35
private static native void nativeSetDockMenu(final long cmenu);
36
private static native void nativeSetDockIconImage(final long image);
37
private static native long nativeGetDockIconImage();
38
private static native void nativeSetDockIconBadge(final String badge);
39
40
PopupMenu fDockMenu = null;
41
42
_AppDockIconHandler() { }
43
44
@SuppressWarnings("deprecation")
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();
58
newParent.add(menu);
59
newParent.addNotify();
60
}
61
62
// instantiate the menu peer and set the native fDockMenu ivar
63
menu.addNotify();
64
final long nsMenuPtr = ((CMenu)fDockMenu.getPeer()).getNativeMenu();
65
nativeSetDockMenu(nsMenuPtr);
66
}
67
68
public PopupMenu getDockMenu() {
69
return fDockMenu;
70
}
71
72
public void setDockIconImage(final Image image) {
73
try {
74
final CImage cImage = getCImageCreator().createFromImage(image);
75
cImage.execute(_AppDockIconHandler::nativeSetDockIconImage);
76
} catch (final Throwable e) {
77
throw new RuntimeException(e);
78
}
79
}
80
81
Image getDockIconImage() {
82
try {
83
final long dockNSImage = nativeGetDockIconImage();
84
if (dockNSImage == 0) return null;
85
return getCImageCreator().createImageUsingNativeSize(dockNSImage);
86
} catch (final Throwable e) {
87
throw new RuntimeException(e);
88
}
89
}
90
91
void setDockIconBadge(final String badge) {
92
nativeSetDockIconBadge(badge);
93
}
94
95
static Creator getCImageCreator() {
96
try {
97
final Method getCreatorMethod = CImage.class.getDeclaredMethod("getCreator", new Class[] {});
98
getCreatorMethod.setAccessible(true);
99
return (Creator)getCreatorMethod.invoke(null, new Object[] {});
100
} catch (final Throwable e) {
101
throw new RuntimeException(e);
102
}
103
}
104
}
105
106