4632N/A/*
4632N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
4632N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4632N/A *
4632N/A * This code is free software; you can redistribute it and/or modify it
4632N/A * under the terms of the GNU General Public License version 2 only, as
4632N/A * published by the Free Software Foundation. Oracle designates this
4632N/A * particular file as subject to the "Classpath" exception as provided
4632N/A * by Oracle in the LICENSE file that accompanied this code.
4632N/A *
4632N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4632N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4632N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4632N/A * version 2 for more details (a copy is included in the LICENSE file that
4632N/A * accompanied this code).
4632N/A *
4632N/A * You should have received a copy of the GNU General Public License version
4632N/A * 2 along with this work; if not, write to the Free Software Foundation,
4632N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4632N/A *
4632N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4632N/A * or visit www.oracle.com if you need additional information or have any
4632N/A * questions.
4632N/A */
4632N/A
4632N/Apackage com.apple.laf;
4632N/A
4632N/Aimport java.awt.*;
4632N/Aimport java.security.PrivilegedAction;
4632N/A
4632N/Aimport javax.swing.*;
4632N/A
4632N/Aimport sun.lwawt.macosx.CPlatformWindow;
4632N/A
4632N/Aclass ScreenPopupFactory extends PopupFactory {
4632N/A static {
4632N/A java.security.AccessController.doPrivileged((PrivilegedAction<?>)new sun.security.action.LoadLibraryAction("osxui"));
4632N/A }
4632N/A
4632N/A static final Float TRANSLUCENT = new Float(248f/255f);
4632N/A static final Float OPAQUE = new Float(1.0f);
4632N/A
4632N/A boolean fIsActive = true;
4632N/A
4632N/A // Only popups generated with the Aqua LaF turned on will be translucent with shadows
4632N/A void setActive(final boolean b) {
4632N/A fIsActive = b;
4632N/A }
4632N/A
4632N/A private static Window getWindow(final Component c) {
4632N/A Component w = c;
4632N/A while(!(w instanceof Window) && (w!=null)) {
4632N/A w = w.getParent();
4632N/A }
4632N/A return (Window)w;
4632N/A }
4632N/A
4632N/A /*
4632N/A * Since we can't change the signature of PopupFactory, we have to call the
4632N/A * private method getPopup(Component, Component, int, int, int) through JNI
4632N/A * (see AquaLookAndFeel.m)
4632N/A */
4632N/A native Popup _getHeavyWeightPopup(Component comp, Component invoker, int x, int y);
4632N/A
4632N/A public Popup getPopup(final Component comp, final Component invoker, final int x, final int y) {
4632N/A if (invoker == null) throw new IllegalArgumentException("Popup.getPopup must be passed non-null contents");
4632N/A
4632N/A final Popup popup;
4632N/A if (fIsActive) {
4632N/A popup = _getHeavyWeightPopup(comp, invoker, x, y);
4632N/A } else {
4632N/A popup = super.getPopup(comp, invoker, x, y);
4632N/A }
4632N/A
4632N/A // Make the popup semi-translucent if it is a heavy weight
4632N/A // see <rdar://problem/3547670> JPopupMenus have incorrect background
4632N/A final Window w = getWindow(invoker);
4632N/A if (w == null) return popup;
4632N/A
4632N/A if (!(w instanceof RootPaneContainer)) return popup;
4632N/A final JRootPane popupRootPane = ((RootPaneContainer)w).getRootPane();
4632N/A
4632N/A // we need to set every time, because PopupFactory caches the heavy weight
4632N/A // TODO: CPlatformWindow constants?
4632N/A if (fIsActive) {
4632N/A popupRootPane.putClientProperty(CPlatformWindow.WINDOW_ALPHA, TRANSLUCENT);
4632N/A popupRootPane.putClientProperty(CPlatformWindow.WINDOW_SHADOW, Boolean.TRUE);
4632N/A popupRootPane.putClientProperty(CPlatformWindow.WINDOW_FADE_DELEGATE, invoker);
4632N/A
4632N/A w.setBackground(UIManager.getColor("PopupMenu.translucentBackground"));
4632N/A popupRootPane.putClientProperty(CPlatformWindow.WINDOW_DRAGGABLE_BACKGROUND, Boolean.FALSE);
4632N/A SwingUtilities.invokeLater(new Runnable() {
4632N/A public void run() {
4632N/A popupRootPane.putClientProperty(CPlatformWindow.WINDOW_SHADOW_REVALIDATE_NOW, Double.valueOf(Math.random()));
4632N/A }
4632N/A });
4632N/A } else {
4632N/A popupRootPane.putClientProperty(CPlatformWindow.WINDOW_ALPHA, OPAQUE);
4632N/A popupRootPane.putClientProperty(CPlatformWindow.WINDOW_SHADOW, Boolean.FALSE);
4632N/A }
4632N/A
4632N/A return popup;
4632N/A }
4632N/A}