Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/macosx/classes/com/apple/eawt/_AppDockIconHandler.java
38831 views
/*1* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.apple.eawt;2627import java.awt.*;28import java.lang.reflect.*;2930import sun.lwawt.macosx.*;31import sun.lwawt.macosx.CImage.Creator;3233class _AppDockIconHandler {34private static native void nativeSetDockMenu(final long cmenu);35private static native void nativeSetDockIconImage(final long image);36private static native long nativeGetDockIconImage();37private static native void nativeSetDockIconBadge(final String badge);3839PopupMenu fDockMenu = null;4041_AppDockIconHandler() { }4243@SuppressWarnings("deprecation")44public void setDockMenu(final PopupMenu menu) {45fDockMenu = menu;4647// clear the menu if explicitly passed null48if (menu == null) {49nativeSetDockMenu(0);50return;51}5253// check if the menu needs a parent (8343136)54final MenuContainer container = menu.getParent();55if (container == null) {56final MenuBar newParent = new MenuBar();57newParent.add(menu);58newParent.addNotify();59}6061// instantiate the menu peer and set the native fDockMenu ivar62menu.addNotify();63final long nsMenuPtr = ((CMenu)fDockMenu.getPeer()).getNativeMenu();64nativeSetDockMenu(nsMenuPtr);65}6667public PopupMenu getDockMenu() {68return fDockMenu;69}7071public void setDockIconImage(final Image image) {72try {73final CImage cImage = getCImageCreator().createFromImage(image);74cImage.execute(_AppDockIconHandler::nativeSetDockIconImage);75} catch (final Throwable e) {76throw new RuntimeException(e);77}78}7980Image getDockIconImage() {81try {82final long dockNSImage = nativeGetDockIconImage();83if (dockNSImage == 0) return null;84return getCImageCreator().createImageUsingNativeSize(dockNSImage);85} catch (final Throwable e) {86throw new RuntimeException(e);87}88}8990void setDockIconBadge(final String badge) {91nativeSetDockIconBadge(badge);92}9394static Creator getCImageCreator() {95try {96final Method getCreatorMethod = CImage.class.getDeclaredMethod("getCreator", new Class[] {});97getCreatorMethod.setAccessible(true);98return (Creator)getCreatorMethod.invoke(null, new Object[] {});99} catch (final Throwable e) {100throw new RuntimeException(e);101}102}103}104105106