Path: blob/master/src/java.desktop/macosx/classes/com/apple/eawt/_AppDockIconHandler.java
41153 views
/*1* Copyright (c) 2011, 2016, 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.awt.AWTAccessor;31import sun.lwawt.macosx.*;32import sun.lwawt.macosx.CImage.Creator;3334class _AppDockIconHandler {35private static native void nativeSetDockMenu(final long cmenu);36private static native void nativeSetDockIconImage(final long image);37private static native void nativeSetDockIconProgress(final int value);38private static native long nativeGetDockIconImage();39private static native void nativeSetDockIconBadge(final String badge);4041PopupMenu fDockMenu = null;4243_AppDockIconHandler() { }4445public void setDockMenu(final PopupMenu menu) {46fDockMenu = menu;4748// clear the menu if explicitly passed null49if (menu == null) {50nativeSetDockMenu(0);51return;52}5354// check if the menu needs a parent (8343136)55final MenuContainer container = menu.getParent();56if (container == null) {57final MenuBar newParent = new MenuBar();58newParent.add(menu);59newParent.addNotify();60}6162// instantiate the menu peer and set the native fDockMenu ivar63menu.addNotify();64CMenu peer = AWTAccessor.getMenuComponentAccessor().getPeer(fDockMenu);65nativeSetDockMenu(peer.getNativeMenu());66}6768public PopupMenu getDockMenu() {69return fDockMenu;70}7172public void setDockIconImage(final Image image) {73try {74final CImage cImage = CImage.createFromImage(image);75cImage.execute(_AppDockIconHandler::nativeSetDockIconImage);76} catch (final Throwable e) {77throw new RuntimeException(e);78}79}8081Image getDockIconImage() {82try {83final long dockNSImage = nativeGetDockIconImage();84if (dockNSImage == 0) return null;85final Method getCreatorMethod = CImage.class.getDeclaredMethod(86"getCreator", new Class<?>[]{});87getCreatorMethod.setAccessible(true);88Creator imageCreator = (Creator) getCreatorMethod.invoke(null, new Object[]{});89return imageCreator.createImageUsingNativeSize(dockNSImage);90} catch (final Throwable e) {91throw new RuntimeException(e);92}93}9495void setDockIconBadge(final String badge) {96nativeSetDockIconBadge(badge);97}9899void setDockIconProgress(int value) {100nativeSetDockIconProgress(value);101}102}103104105