src/macosx/classes/com/apple/laf/ScreenPopupFactory.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.laf;
  27 
  28 import java.awt.*;
  29 import javax.swing.*;
  30 

  31 import sun.lwawt.macosx.CPlatformWindow;

  32 
  33 class ScreenPopupFactory extends PopupFactory {
  34     static {
  35         java.security.AccessController.doPrivileged(
  36             new java.security.PrivilegedAction<Void>() {
  37                 public Void run() {
  38                     System.loadLibrary("osxui");
  39                     return null;
  40                 }
  41             });
  42     }
  43 
  44     static final Float TRANSLUCENT = new Float(248f/255f);
  45     static final Float OPAQUE = new Float(1.0f);
  46 
  47     boolean fIsActive = true;
  48 
  49     // Only popups generated with the Aqua LaF turned on will be translucent with shadows
  50     void setActive(final boolean b) {
  51         fIsActive = b;


  59         return (Window)w;
  60     }
  61 
  62     /*
  63      * Since we can't change the signature of PopupFactory, we have to call the
  64      * private method getPopup(Component, Component, int, int, int) through JNI
  65      * (see AquaLookAndFeel.m)
  66      */
  67     native Popup _getHeavyWeightPopup(Component comp, Component invoker, int x, int y);
  68 
  69     public Popup getPopup(final Component comp, final Component invoker, final int x, final int y) {
  70         if (invoker == null) throw new IllegalArgumentException("Popup.getPopup must be passed non-null contents");
  71 
  72         final Popup popup;
  73         if (fIsActive) {
  74             popup = _getHeavyWeightPopup(comp, invoker, x, y);
  75         } else {
  76             popup = super.getPopup(comp, invoker, x, y);
  77         }
  78 




  79         // Make the popup semi-translucent if it is a heavy weight
  80         // see <rdar://problem/3547670> JPopupMenus have incorrect background
  81         final Window w = getWindow(invoker);
  82         if (w == null) return popup;
  83 
  84         if (!(w instanceof RootPaneContainer)) return popup;
  85         final JRootPane popupRootPane = ((RootPaneContainer)w).getRootPane();
  86 
  87         // we need to set every time, because PopupFactory caches the heavy weight
  88         // TODO: CPlatformWindow constants?
  89         if (fIsActive) {
  90             popupRootPane.putClientProperty(CPlatformWindow.WINDOW_ALPHA, TRANSLUCENT);
  91             popupRootPane.putClientProperty(CPlatformWindow.WINDOW_SHADOW, Boolean.TRUE);
  92             popupRootPane.putClientProperty(CPlatformWindow.WINDOW_FADE_DELEGATE, invoker);
  93 
  94             w.setBackground(UIManager.getColor("PopupMenu.translucentBackground"));
  95             popupRootPane.putClientProperty(CPlatformWindow.WINDOW_DRAGGABLE_BACKGROUND, Boolean.FALSE);
  96             SwingUtilities.invokeLater(new Runnable() {
  97                 public void run() {
  98                     popupRootPane.putClientProperty(CPlatformWindow.WINDOW_SHADOW_REVALIDATE_NOW, Double.valueOf(Math.random()));
   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 com.apple.laf;
  27 
  28 import java.awt.*;
  29 import javax.swing.*;
  30 
  31 import sun.awt.EmbeddedFrame;
  32 import sun.lwawt.macosx.CPlatformWindow;
  33 import sun.swing.SwingAccessor;
  34 
  35 class ScreenPopupFactory extends PopupFactory {
  36     static {
  37         java.security.AccessController.doPrivileged(
  38             new java.security.PrivilegedAction<Void>() {
  39                 public Void run() {
  40                     System.loadLibrary("osxui");
  41                     return null;
  42                 }
  43             });
  44     }
  45 
  46     static final Float TRANSLUCENT = new Float(248f/255f);
  47     static final Float OPAQUE = new Float(1.0f);
  48 
  49     boolean fIsActive = true;
  50 
  51     // Only popups generated with the Aqua LaF turned on will be translucent with shadows
  52     void setActive(final boolean b) {
  53         fIsActive = b;


  61         return (Window)w;
  62     }
  63 
  64     /*
  65      * Since we can't change the signature of PopupFactory, we have to call the
  66      * private method getPopup(Component, Component, int, int, int) through JNI
  67      * (see AquaLookAndFeel.m)
  68      */
  69     native Popup _getHeavyWeightPopup(Component comp, Component invoker, int x, int y);
  70 
  71     public Popup getPopup(final Component comp, final Component invoker, final int x, final int y) {
  72         if (invoker == null) throw new IllegalArgumentException("Popup.getPopup must be passed non-null contents");
  73 
  74         final Popup popup;
  75         if (fIsActive) {
  76             popup = _getHeavyWeightPopup(comp, invoker, x, y);
  77         } else {
  78             popup = super.getPopup(comp, invoker, x, y);
  79         }
  80 
  81         if (EmbeddedFrame.getAppletIfAncestorOf(comp) != null) {
  82             SwingAccessor.getPopupFactoryAccessor().setHeavyWeightPopupCacheEnabled(popup, false);
  83         }
  84 
  85         // Make the popup semi-translucent if it is a heavy weight
  86         // see <rdar://problem/3547670> JPopupMenus have incorrect background
  87         final Window w = getWindow(invoker);
  88         if (w == null) return popup;
  89 
  90         if (!(w instanceof RootPaneContainer)) return popup;
  91         final JRootPane popupRootPane = ((RootPaneContainer)w).getRootPane();
  92 
  93         // we need to set every time, because PopupFactory caches the heavy weight
  94         // TODO: CPlatformWindow constants?
  95         if (fIsActive) {
  96             popupRootPane.putClientProperty(CPlatformWindow.WINDOW_ALPHA, TRANSLUCENT);
  97             popupRootPane.putClientProperty(CPlatformWindow.WINDOW_SHADOW, Boolean.TRUE);
  98             popupRootPane.putClientProperty(CPlatformWindow.WINDOW_FADE_DELEGATE, invoker);
  99 
 100             w.setBackground(UIManager.getColor("PopupMenu.translucentBackground"));
 101             popupRootPane.putClientProperty(CPlatformWindow.WINDOW_DRAGGABLE_BACKGROUND, Boolean.FALSE);
 102             SwingUtilities.invokeLater(new Runnable() {
 103                 public void run() {
 104                     popupRootPane.putClientProperty(CPlatformWindow.WINDOW_SHADOW_REVALIDATE_NOW, Double.valueOf(Math.random()));