1 /* 2 * Copyright (c) 2011, 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.lwawt.macosx; 27 28 import sun.awt.AWTAccessor; 29 import sun.awt.SunToolkit; 30 31 import javax.swing.*; 32 import java.awt.*; 33 import java.awt.event.*; 34 import java.awt.geom.Point2D; 35 import java.awt.image.BufferedImage; 36 import java.awt.peer.TrayIconPeer; 37 import java.beans.PropertyChangeEvent; 38 import java.beans.PropertyChangeListener; 39 40 public class CTrayIcon extends CFRetainedResource implements TrayIconPeer { 41 private TrayIcon target; 42 private PopupMenu popup; 43 private JDialog messageDialog; 44 private DialogEventHandler handler; 45 46 // In order to construct MouseEvent object, we need to specify a 47 // Component target. Because TrayIcon isn't Component's subclass, 48 // we use this dummy frame instead 49 private final Frame dummyFrame; 50 51 // A bitmask that indicates what mouse buttons produce MOUSE_CLICKED events 52 // on MOUSE_RELEASE. Click events are only generated if there were no drag 53 // events between MOUSE_PRESSED and MOUSE_RELEASED for particular button 54 private static int mouseClickButtons = 0; 55 56 CTrayIcon(TrayIcon target) { 57 super(0, true); 58 59 this.messageDialog = null; 60 this.handler = null; 61 this.target = target; 62 this.popup = target.getPopupMenu(); 63 this.dummyFrame = new Frame(); 64 setPtr(createModel()); 65 66 //if no one else is creating the peer. 67 checkAndCreatePopupPeer(); 68 updateImage(); 69 } 70 71 @SuppressWarnings("deprecation") 72 private CPopupMenu checkAndCreatePopupPeer() { 73 CPopupMenu menuPeer = null; 74 if (popup != null) { 75 try { 76 menuPeer = (CPopupMenu)popup.getPeer(); 77 if (menuPeer == null) { 78 popup.addNotify(); 79 menuPeer = (CPopupMenu)popup.getPeer(); 80 } 81 } catch (Exception e) { 82 e.printStackTrace(); 83 } 84 } 85 return menuPeer; 86 } 87 88 private long createModel() { 89 return nativeCreate(); 90 } 91 92 private long getModel() { 93 return ptr; 94 } 95 96 private native long nativeCreate(); 97 98 //invocation from the AWTTrayIcon.m 99 public long getPopupMenuModel(){ | 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 sun.lwawt.macosx; 27 28 import sun.awt.AWTAccessor; 29 import sun.awt.SunToolkit; 30 31 import javax.swing.*; 32 import java.awt.*; 33 import java.awt.event.*; 34 import java.awt.geom.Point2D; 35 import java.awt.image.BufferedImage; 36 import java.awt.peer.TrayIconPeer; 37 import java.beans.PropertyChangeEvent; 38 import java.beans.PropertyChangeListener; 39 40 import static sun.awt.AWTAccessor.*; 41 42 public class CTrayIcon extends CFRetainedResource implements TrayIconPeer { 43 private TrayIcon target; 44 private PopupMenu popup; 45 private JDialog messageDialog; 46 private DialogEventHandler handler; 47 48 // In order to construct MouseEvent object, we need to specify a 49 // Component target. Because TrayIcon isn't Component's subclass, 50 // we use this dummy frame instead 51 private final Frame dummyFrame; 52 53 // A bitmask that indicates what mouse buttons produce MOUSE_CLICKED events 54 // on MOUSE_RELEASE. Click events are only generated if there were no drag 55 // events between MOUSE_PRESSED and MOUSE_RELEASED for particular button 56 private static int mouseClickButtons = 0; 57 58 CTrayIcon(TrayIcon target) { 59 super(0, true); 60 61 this.messageDialog = null; 62 this.handler = null; 63 this.target = target; 64 this.popup = target.getPopupMenu(); 65 this.dummyFrame = new Frame(); 66 setPtr(createModel()); 67 68 //if no one else is creating the peer. 69 checkAndCreatePopupPeer(); 70 updateImage(); 71 } 72 73 private CPopupMenu checkAndCreatePopupPeer() { 74 CPopupMenu menuPeer = null; 75 if (popup != null) { 76 try { 77 final MenuComponentAccessor acc = getMenuComponentAccessor(); 78 menuPeer = acc.getPeer(popup); 79 if (menuPeer == null) { 80 popup.addNotify(); 81 menuPeer = acc.getPeer(popup); 82 } 83 } catch (Exception e) { 84 e.printStackTrace(); 85 } 86 } 87 return menuPeer; 88 } 89 90 private long createModel() { 91 return nativeCreate(); 92 } 93 94 private long getModel() { 95 return ptr; 96 } 97 98 private native long nativeCreate(); 99 100 //invocation from the AWTTrayIcon.m 101 public long getPopupMenuModel(){ |