FileDocCategorySizeDatePackage
BasicPopupMenuUI.javaAPI DocJava SE 5 API40844Fri Aug 26 14:58:04 BST 2005javax.swing.plaf.basic

BasicPopupMenuUI

public class BasicPopupMenuUI extends PopupMenuUI
A Windows L&F implementation of PopupMenuUI. This implementation is a "combined" view/controller.
version
1.122 06/06/05
author
Georges Saab
author
David Karlton
author
Arnaud Weber

Fields Summary
protected JPopupMenu
popupMenu
private transient PopupMenuListener
popupMenuListener
private MenuKeyListener
menuKeyListener
static boolean
menuKeyboardHelperInstalled
static MenuKeyboardHelper
menuKeyboardHelper
private static boolean
checkedUnpostPopup
private static boolean
unpostPopup
private static transient MouseGrabber
mouseGrabber
Constructors Summary
public BasicPopupMenuUI()

        BasicLookAndFeel.hasPopups = true;
        LookAndFeel laf = UIManager.getLookAndFeel();
        if (laf instanceof BasicLookAndFeel) {
            ((BasicLookAndFeel)laf).createdPopup();
        }
    
Methods Summary
private static booleancheckInvokerEqual(javax.swing.MenuElement present, javax.swing.MenuElement last)

        Component invokerPresent = present.getComponent();
        Component invokerLast = last.getComponent();

        if (invokerPresent instanceof JPopupMenu) {
            invokerPresent = ((JPopupMenu)invokerPresent).getInvoker();
    }
        if (invokerLast instanceof JPopupMenu) {
            invokerLast = ((JPopupMenu)invokerLast).getInvoker();
        }
        return (invokerPresent == invokerLast);
    
public static javax.swing.plaf.ComponentUIcreateUI(javax.swing.JComponent x)


         
	return new BasicPopupMenuUI();
    
private static booleandoUnpostPopupOnDeactivation()

        if (!checkedUnpostPopup) {
            Boolean b = java.security.AccessController.doPrivileged(
                new java.security.PrivilegedAction <Boolean> () {
                    public Boolean run() {
                        String pKey =
                            "sun.swing.unpostPopupsOnWindowDeactivation";
                        String value = System.getProperty(pKey, "true");
                        return Boolean.valueOf(value);
                    }
                }
            );
            unpostPopup = b.booleanValue();
            checkedUnpostPopup = true;
        }
        return unpostPopup;
    
static javax.swing.MenuElementfindEnabledChild(javax.swing.MenuElement[] e, int fromIndex, boolean forward)

        MenuElement result = null;
        if (forward) {
            result = nextEnabledChild(e, fromIndex+1, e.length-1);
            if (result == null) result = nextEnabledChild(e, 0, fromIndex-1);
        } else {
            result = previousEnabledChild(e, fromIndex-1, 0);
            if (result == null) result = previousEnabledChild(e, e.length-1,
                                                              fromIndex+1);
        }
	return result;
    
static javax.swing.MenuElementfindEnabledChild(javax.swing.MenuElement[] e, javax.swing.MenuElement elem, boolean forward)

        for (int i=0; i<e.length; i++) {
            if (e[i] == elem) {
                return findEnabledChild(e, i, forward);
            }
        }
        return null;
    
static javax.swing.ActionMapgetActionMap()

        return LazyActionMap.getActionMap(BasicPopupMenuUI.class,
                                          "PopupMenu.actionMap");
    
static javax.swing.MenuElementgetFirstPopup()

	MenuSelectionManager msm = MenuSelectionManager.defaultManager();
	MenuElement[] p = msm.getSelectedPath();
	MenuElement me = null;	    
	
	for(int i = 0 ; me == null && i < p.length ; i++) {
	    if (p[i] instanceof JPopupMenu)
		me = p[i];
	}
	
	return me;
    
static javax.swing.InputMapgetInputMap(javax.swing.JPopupMenu popup, javax.swing.JComponent c)

        InputMap windowInputMap = null;
	Object[] bindings = (Object[])UIManager.get("PopupMenu.selectedWindowInputMapBindings");
	if (bindings != null) {
	    windowInputMap = LookAndFeel.makeComponentInputMap(c, bindings);
	    if (!popup.getComponentOrientation().isLeftToRight()) {
		Object[] km = (Object[])UIManager.get("PopupMenu.selectedWindowInputMapBindings.RightToLeft");
		if (km != null) {
		    InputMap rightToLeftInputMap = LookAndFeel.makeComponentInputMap(c, km);
		    rightToLeftInputMap.setParent(windowInputMap);
		    windowInputMap = rightToLeftInputMap;
		}
	    }
        }
        return windowInputMap;
    
static javax.swing.JPopupMenugetLastPopup()

	MenuSelectionManager msm = MenuSelectionManager.defaultManager();
	MenuElement[] p = msm.getSelectedPath();
	JPopupMenu popup = null;	    
	
	for(int i = p.length - 1; popup == null && i >= 0; i--) {
	    if (p[i] instanceof JPopupMenu)
		popup = (JPopupMenu)p[i];
	}
	return popup;
    
static java.util.ListgetPopups()

	MenuSelectionManager msm = MenuSelectionManager.defaultManager();
	MenuElement[] p = msm.getSelectedPath();
	
	List list = new ArrayList(p.length); 
	for(int i = 0; i < p.length; i++) {
	    if (p[i] instanceof JPopupMenu) {
		list.add((JPopupMenu)p[i]);
	    }
	}
	return list;
    
public voidinstallDefaults()

	if (popupMenu.getLayout() == null ||
	    popupMenu.getLayout() instanceof UIResource)
	    popupMenu.setLayout(new DefaultMenuLayout(popupMenu, BoxLayout.Y_AXIS));

	LookAndFeel.installProperty(popupMenu, "opaque", Boolean.TRUE);
	LookAndFeel.installBorder(popupMenu, "PopupMenu.border");
	LookAndFeel.installColorsAndFont(popupMenu,
					 "PopupMenu.background",
					 "PopupMenu.foreground",
					 "PopupMenu.font");
    
protected voidinstallKeyboardActions()

    
protected voidinstallListeners()

        if (popupMenuListener == null) {
	    popupMenuListener = new BasicPopupMenuListener();
	}
 	popupMenu.addPopupMenuListener(popupMenuListener);

        if (menuKeyListener == null) {
            menuKeyListener = new BasicMenuKeyListener();
        }
        popupMenu.addMenuKeyListener(menuKeyListener);

	if (mouseGrabber == null) {
	    mouseGrabber = new MouseGrabber();
	}

        if (!menuKeyboardHelperInstalled) {
            if (menuKeyboardHelper == null) {
                menuKeyboardHelper = new MenuKeyboardHelper();
            }
            MenuSelectionManager msm = MenuSelectionManager.defaultManager();
            msm.addChangeListener(menuKeyboardHelper);
            menuKeyboardHelperInstalled = true;
        }
    
public voidinstallUI(javax.swing.JComponent c)

	popupMenu = (JPopupMenu) c;

	installDefaults();
        installListeners();
        installKeyboardActions();
    
public booleanisPopupTrigger(java.awt.event.MouseEvent e)

	return ((e.getID()==MouseEvent.MOUSE_RELEASED) 
		&& ((e.getModifiers() & MouseEvent.BUTTON3_MASK)!=0));
    
static voidloadActionMap(javax.swing.plaf.basic.LazyActionMap map)

	map.put(new Actions(Actions.CANCEL));
        map.put(new Actions(Actions.SELECT_NEXT));
        map.put(new Actions(Actions.SELECT_PREVIOUS));
	map.put(new Actions(Actions.SELECT_PARENT));
	map.put(new Actions(Actions.SELECT_CHILD));
	map.put(new Actions(Actions.RETURN));
        BasicLookAndFeel.installAudioActionMap(map);
    
private static javax.swing.MenuElementnextEnabledChild(javax.swing.MenuElement[] e, int fromIndex, int toIndex)

	for (int i=fromIndex; i<=toIndex; i++) {
	    if (e[i] != null) {
		Component comp = e[i].getComponent();
		if (comp != null && comp.isEnabled() && comp.isVisible()) {
                    return e[i];
                }
	    }
	}
	return null;
    
private static javax.swing.MenuElementpreviousEnabledChild(javax.swing.MenuElement[] e, int fromIndex, int toIndex)

	for (int i=fromIndex; i>=toIndex; i--) {
	    if (e[i] != null) {
		Component comp = e[i].getComponent();
		if (comp != null && comp.isEnabled() && comp.isVisible()) {
                    return e[i];
                }
	    }
	}
	return null;
    
protected voiduninstallDefaults()

	LookAndFeel.uninstallBorder(popupMenu);
    
protected voiduninstallKeyboardActions()

	SwingUtilities.replaceUIActionMap(popupMenu, null);
	SwingUtilities.replaceUIInputMap(popupMenu, 
				  JComponent.WHEN_IN_FOCUSED_WINDOW, null);
    
protected voiduninstallListeners()

        if (popupMenuListener != null) {
            popupMenu.removePopupMenuListener(popupMenuListener);
	}
        if (menuKeyListener != null) {
            popupMenu.removeMenuKeyListener(menuKeyListener);
        }
        if(mouseGrabber != null) {
            MenuSelectionManager msm = MenuSelectionManager.defaultManager();
            msm.removeChangeListener(mouseGrabber);
            mouseGrabber.ungrabWindow();
            mouseGrabber = null;
        }
    
public voiduninstallUI(javax.swing.JComponent c)

        uninstallDefaults();
        uninstallListeners();
        uninstallKeyboardActions();
	
	popupMenu = null;