FileDocCategorySizeDatePackage
BasicPopupMenuUI.javaAPI DocJava SE 6 API42810Tue Jun 10 00:26:48 BST 2008javax.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.139 06/25/07
author
Georges Saab
author
David Karlton
author
Arnaud Weber

Fields Summary
static final StringBuilder
MOUSE_GRABBER_KEY
static final StringBuilder
MENU_KEYBOARD_HELPER_KEY
protected JPopupMenu
popupMenu
private transient PopupMenuListener
popupMenuListener
private MenuKeyListener
menuKeyListener
private static boolean
checkedUnpostPopup
private static boolean
unpostPopup
Constructors Summary
public BasicPopupMenuUI()

        BasicLookAndFeel.needsEventHelper = true;
        LookAndFeel laf = UIManager.getLookAndFeel();
        if (laf instanceof BasicLookAndFeel) {
            ((BasicLookAndFeel)laf).installAWTEventListener();
        }
    
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();
    
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);

        AppContext context = AppContext.getAppContext();
        synchronized (MOUSE_GRABBER_KEY) {
            MouseGrabber mouseGrabber = (MouseGrabber)context.get(
                                                     MOUSE_GRABBER_KEY);   
            if (mouseGrabber == null) {    
                mouseGrabber = new MouseGrabber();   
                context.put(MOUSE_GRABBER_KEY, mouseGrabber);   
            } 
        }
        synchronized (MENU_KEYBOARD_HELPER_KEY) {
            MenuKeyboardHelper helper =
                    (MenuKeyboardHelper)context.get(MENU_KEYBOARD_HELPER_KEY);
            if (helper == null) {
                helper = new MenuKeyboardHelper();
                context.put(MENU_KEYBOARD_HELPER_KEY, helper);
                MenuSelectionManager msm = MenuSelectionManager.defaultManager();
                msm.addChangeListener(helper);
            }
        }
    
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() || UIManager.getBoolean("MenuItem.disabledAreNavigable"))
                        && 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() || UIManager.getBoolean("MenuItem.disabledAreNavigable"))
                        && 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);
        }
    
public voiduninstallUI(javax.swing.JComponent c)

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