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

BasicMenuUI

public class BasicMenuUI extends BasicMenuItemUI
A default L&F implementation of MenuUI. This implementation is a "combined" view/controller.
version
1.158 02/26/04
author
Georges Saab
author
David Karlton
author
Arnaud Weber

Fields Summary
protected ChangeListener
changeListener
protected PropertyChangeListener
propertyChangeListener
protected MenuListener
menuListener
private int
lastMnemonic
private InputMap
selectedWindowInputMap
Uses as the parent of the windowInputMap when selected.
private static final boolean
TRACE
private static final boolean
VERBOSE
private static final boolean
DEBUG
private static boolean
crossMenuMnemonic
Constructors Summary
Methods Summary
private static voidappendPath(javax.swing.MenuElement[] path, javax.swing.MenuElement elem)

        MenuElement newPath[] = new MenuElement[path.length+1];
        System.arraycopy(path, 0, newPath, 0, path.length);
        newPath[path.length] = elem;
        MenuSelectionManager.defaultManager().setSelectedPath(newPath);
    
protected javax.swing.event.ChangeListenercreateChangeListener(javax.swing.JComponent c)

	return null;
    
protected javax.swing.event.MenuDragMouseListenercreateMenuDragMouseListener(javax.swing.JComponent c)

	return getHandler();
    
protected javax.swing.event.MenuKeyListenercreateMenuKeyListener(javax.swing.JComponent c)

	return (MenuKeyListener)getHandler();
    
protected javax.swing.event.MenuListenercreateMenuListener(javax.swing.JComponent c)

	return null;
    
protected javax.swing.event.MouseInputListenercreateMouseInputListener(javax.swing.JComponent c)

	return getHandler();
    
protected java.beans.PropertyChangeListenercreatePropertyChangeListener(javax.swing.JComponent c)

        return getHandler();
    
public static javax.swing.plaf.ComponentUIcreateUI(javax.swing.JComponent x)


         
	return new BasicMenuUI();
    
javax.swing.plaf.basic.BasicMenuItemUI$HandlergetHandler()

        if (handler == null) {
            handler = new Handler();
        }
        return handler;
    
public java.awt.DimensiongetMaximumSize(javax.swing.JComponent c)

	if (((JMenu)menuItem).isTopLevelMenu() == true) {
	    Dimension d = c.getPreferredSize();
	    return new Dimension(d.width, Short.MAX_VALUE);
	}
        return null;
    
protected java.lang.StringgetPropertyPrefix()

	return "Menu";
    
protected voidinstallDefaults()

	super.installDefaults();
	updateDefaultBackgroundColor();
	((JMenu)menuItem).setDelay(200);
        crossMenuMnemonic = UIManager.getBoolean("Menu.crossMenuMnemonic");
    
protected voidinstallKeyboardActions()

	super.installKeyboardActions();
	updateMnemonicBinding();
    
voidinstallLazyActionMap()

        LazyActionMap.installLazyActionMap(menuItem, BasicMenuUI.class,
                                           getPropertyPrefix() + ".actionMap");
    
protected voidinstallListeners()

	super.installListeners();

	if (changeListener == null)
	    changeListener = createChangeListener(menuItem);

	if (changeListener != null)
	    menuItem.addChangeListener(changeListener);

	if (propertyChangeListener == null)
	    propertyChangeListener = createPropertyChangeListener(menuItem);

	if (propertyChangeListener != null)
	    menuItem.addPropertyChangeListener(propertyChangeListener);
	    
	if (menuListener == null)
	    menuListener = createMenuListener(menuItem);

	if (menuListener != null)
	    ((JMenu)menuItem).addMenuListener(menuListener);
    
static voidloadActionMap(javax.swing.plaf.basic.LazyActionMap map)

        BasicMenuItemUI.loadActionMap(map);
        map.put(new Actions(Actions.SELECT, null, true));
    
protected voidsetupPostTimer(javax.swing.JMenu menu)

        Timer timer = new Timer(menu.getDelay(), new Actions(
                                    Actions.SELECT, menu,false));
        timer.setRepeats(false);
        timer.start();
    
protected voiduninstallDefaults()

	menuItem.setArmed(false);
	menuItem.setSelected(false);
	menuItem.resetKeyboardActions();
	super.uninstallDefaults();
    
protected voiduninstallKeyboardActions()

	super.uninstallKeyboardActions();
        lastMnemonic = 0;
    
protected voiduninstallListeners()

	super.uninstallListeners();

	if (changeListener != null)
	    menuItem.removeChangeListener(changeListener);

	if (propertyChangeListener != null)
	    menuItem.removePropertyChangeListener(propertyChangeListener);

	if (menuListener != null)
	    ((JMenu)menuItem).removeMenuListener(menuListener);

	changeListener = null;
	propertyChangeListener = null;
	menuListener = null;
        handler = null;
    
private voidupdateDefaultBackgroundColor()

	if (!UIManager.getBoolean("Menu.useMenuBarBackgroundForTopLevel")) {
	   return;
	}
	JMenu menu = (JMenu)menuItem;
	if (menu.getBackground() instanceof UIResource) {
	    if (menu.isTopLevelMenu()) {
		menu.setBackground(UIManager.getColor("MenuBar.background"));
	    } else {
		menu.setBackground(UIManager.getColor(getPropertyPrefix() + ".background"));
	    }
	}		    
    
voidupdateMnemonicBinding()

	int mnemonic = menuItem.getModel().getMnemonic();
        int[] shortcutKeys = (int[])DefaultLookup.get(menuItem, this,
                                                   "Menu.shortcutKeys");
        if (shortcutKeys == null) {
            shortcutKeys = new int[] {KeyEvent.ALT_MASK};
        }
	if (mnemonic == lastMnemonic) {
	    return;
	}
        InputMap windowInputMap = SwingUtilities.getUIInputMap(
                       menuItem, JComponent.WHEN_IN_FOCUSED_WINDOW);
	if (lastMnemonic != 0 && windowInputMap != null) {
            for (int i=0; i<shortcutKeys.length; i++) {
                windowInputMap.remove(KeyStroke.getKeyStroke
                                      (lastMnemonic, shortcutKeys[i], false));
            }
	}
	if (mnemonic != 0) {
	    if (windowInputMap == null) {
		windowInputMap = createInputMap(JComponent.
					      WHEN_IN_FOCUSED_WINDOW);
		SwingUtilities.replaceUIInputMap(menuItem, JComponent.
				       WHEN_IN_FOCUSED_WINDOW, windowInputMap);
	    }
            for (int i=0; i<shortcutKeys.length; i++) {
                windowInputMap.put(KeyStroke.getKeyStroke(mnemonic,
                                         shortcutKeys[i], false),
                                   "selectMenu");
            }
        }
	lastMnemonic = mnemonic;