src/java.desktop/macosx/classes/com/apple/eawt/_AppDockIconHandler.java

Print this page


   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             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;


   1 /*
   2  * Copyright (c) 2011, 2015, 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 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();
  58             newParent.add(menu);
  59             newParent.addNotify();
  60         }
  61 
  62         // instantiate the menu peer and set the native fDockMenu ivar
  63         menu.addNotify();
  64         CMenu peer = AWTAccessor.getMenuComponentAccessor().getPeer(fDockMenu);
  65         nativeSetDockMenu(peer.getNativeMenu());
  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             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;