Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.desktop/macosx/classes/com/apple/eawt/_AppDockIconHandler.java
41153 views
1
/*
2
* Copyright (c) 2011, 2016, 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.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();
59
newParent.add(menu);
60
newParent.addNotify();
61
}
62
63
// instantiate the menu peer and set the native fDockMenu ivar
64
menu.addNotify();
65
CMenu peer = AWTAccessor.getMenuComponentAccessor().getPeer(fDockMenu);
66
nativeSetDockMenu(peer.getNativeMenu());
67
}
68
69
public PopupMenu getDockMenu() {
70
return fDockMenu;
71
}
72
73
public void setDockIconImage(final Image image) {
74
try {
75
final CImage cImage = CImage.createFromImage(image);
76
cImage.execute(_AppDockIconHandler::nativeSetDockIconImage);
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
final Method getCreatorMethod = CImage.class.getDeclaredMethod(
87
"getCreator", new Class<?>[]{});
88
getCreatorMethod.setAccessible(true);
89
Creator imageCreator = (Creator) getCreatorMethod.invoke(null, new Object[]{});
90
return imageCreator.createImageUsingNativeSize(dockNSImage);
91
} catch (final Throwable e) {
92
throw new RuntimeException(e);
93
}
94
}
95
96
void setDockIconBadge(final String badge) {
97
nativeSetDockIconBadge(badge);
98
}
99
100
void setDockIconProgress(int value) {
101
nativeSetDockIconProgress(value);
102
}
103
}
104
105