src/java.desktop/windows/classes/sun/awt/windows/WTrayIconPeer.java

Print this page


   1 /*
   2  * Copyright (c) 2005, 2014, 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 sun.awt.windows;
  27 
  28 import java.awt.Graphics2D;
  29 import java.awt.AWTEvent;
  30 import java.awt.Frame;
  31 import java.awt.PopupMenu;
  32 import java.awt.Point;
  33 import java.awt.TrayIcon;
  34 import java.awt.Image;
  35 import java.awt.peer.TrayIconPeer;
  36 import java.awt.image.*;


  37 import sun.awt.SunToolkit;
  38 import sun.awt.image.IntegerComponentRaster;
  39 
  40 final class WTrayIconPeer extends WObjectPeer implements TrayIconPeer {
  41     final static int TRAY_ICON_WIDTH = 16;
  42     final static int TRAY_ICON_HEIGHT = 16;
  43     final static int TRAY_ICON_MASK_SIZE = (TRAY_ICON_WIDTH * TRAY_ICON_HEIGHT) / 8;
  44 
  45     IconObserver observer = new IconObserver();
  46     boolean firstUpdate = true;
  47     Frame popupParent = new Frame("PopupMessageWindow");
  48     PopupMenu popup;
  49 
  50     @Override
  51     protected void disposeImpl() {
  52         if (popupParent != null) {
  53             popupParent.dispose();
  54         }
  55         popupParent.dispose();
  56         _dispose();


  63         create();
  64         updateImage();
  65     }
  66 
  67     @Override
  68     public void updateImage() {
  69         Image image = ((TrayIcon)target).getImage();
  70         if (image != null) {
  71             updateNativeImage(image);
  72         }
  73     }
  74 
  75     @Override
  76     public native void setToolTip(String tooltip);
  77 
  78     @Override
  79     public synchronized void showPopupMenu(final int x, final int y) {
  80         if (isDisposed())
  81             return;
  82 
  83         SunToolkit.executeOnEventHandlerThread(target, new Runnable() {
  84                 @Override
  85                 @SuppressWarnings("deprecation")
  86                 public void run() {
  87                     PopupMenu newPopup = ((TrayIcon)target).getPopupMenu();
  88                     if (popup != newPopup) {
  89                         if (popup != null) {
  90                             popupParent.remove(popup);
  91                         }
  92                         if (newPopup != null) {
  93                             popupParent.add(newPopup);
  94                         }
  95                         popup = newPopup;
  96                     }
  97                     if (popup != null) {
  98                         ((WPopupMenuPeer)popup.getPeer()).show(popupParent, new Point(x, y));
  99                     }

 100                 }
 101             });
 102     }
 103 
 104     @Override
 105     public void displayMessage(String caption, String text, String messageType) {
 106         // The situation when both caption and text are null is processed in the shared code.
 107         if (caption == null) {
 108             caption = "";
 109         }
 110         if (text == null) {
 111             text = "";
 112         }
 113         _displayMessage(caption, text, messageType);
 114     }
 115 
 116 
 117     // ***********************************************
 118     // ***********************************************
 119 


   1 /*
   2  * Copyright (c) 2005, 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 sun.awt.windows;
  27 
  28 import java.awt.Graphics2D;
  29 import java.awt.AWTEvent;
  30 import java.awt.Frame;
  31 import java.awt.PopupMenu;
  32 import java.awt.Point;
  33 import java.awt.TrayIcon;
  34 import java.awt.Image;
  35 import java.awt.peer.TrayIconPeer;
  36 import java.awt.image.*;
  37 
  38 import sun.awt.AWTAccessor;
  39 import sun.awt.SunToolkit;
  40 import sun.awt.image.IntegerComponentRaster;
  41 
  42 final class WTrayIconPeer extends WObjectPeer implements TrayIconPeer {
  43     final static int TRAY_ICON_WIDTH = 16;
  44     final static int TRAY_ICON_HEIGHT = 16;
  45     final static int TRAY_ICON_MASK_SIZE = (TRAY_ICON_WIDTH * TRAY_ICON_HEIGHT) / 8;
  46 
  47     IconObserver observer = new IconObserver();
  48     boolean firstUpdate = true;
  49     Frame popupParent = new Frame("PopupMessageWindow");
  50     PopupMenu popup;
  51 
  52     @Override
  53     protected void disposeImpl() {
  54         if (popupParent != null) {
  55             popupParent.dispose();
  56         }
  57         popupParent.dispose();
  58         _dispose();


  65         create();
  66         updateImage();
  67     }
  68 
  69     @Override
  70     public void updateImage() {
  71         Image image = ((TrayIcon)target).getImage();
  72         if (image != null) {
  73             updateNativeImage(image);
  74         }
  75     }
  76 
  77     @Override
  78     public native void setToolTip(String tooltip);
  79 
  80     @Override
  81     public synchronized void showPopupMenu(final int x, final int y) {
  82         if (isDisposed())
  83             return;
  84 
  85         SunToolkit.executeOnEventHandlerThread(target, () -> {



  86             PopupMenu newPopup = ((TrayIcon)target).getPopupMenu();
  87             if (popup != newPopup) {
  88                 if (popup != null) {
  89                     popupParent.remove(popup);
  90                 }
  91                 if (newPopup != null) {
  92                     popupParent.add(newPopup);
  93                 }
  94                 popup = newPopup;
  95             }
  96             if (popup != null) {
  97                 WPopupMenuPeer peer = AWTAccessor.getMenuComponentAccessor()
  98                                                  .getPeer(popup);
  99                 peer.show(popupParent, new Point(x, y));
 100             }
 101         });
 102     }
 103 
 104     @Override
 105     public void displayMessage(String caption, String text, String messageType) {
 106         // The situation when both caption and text are null is processed in the shared code.
 107         if (caption == null) {
 108             caption = "";
 109         }
 110         if (text == null) {
 111             text = "";
 112         }
 113         _displayMessage(caption, text, messageType);
 114     }
 115 
 116 
 117     // ***********************************************
 118     // ***********************************************
 119