FileDocCategorySizeDatePackage
WindowsMenuBarUI.javaAPI DocJava SE 6 API5774Tue Jun 10 00:21:58 BST 2008com.sun.java.swing.plaf.windows

WindowsMenuBarUI

public class WindowsMenuBarUI extends BasicMenuBarUI
Windows rendition of the component.

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. A future release of Swing will provide support for long term persistence.

Fields Summary
private WindowListener
windowListener
private HierarchyListener
hierarchyListener
private Window
window
Constructors Summary
Methods Summary
public static javax.swing.plaf.ComponentUIcreateUI(javax.swing.JComponent x)

    
         
	return new WindowsMenuBarUI();
    
protected voidinstallKeyboardActions()

        super.installKeyboardActions();
	ActionMap map = SwingUtilities.getUIActionMap(menuBar);
        if (map == null) {
            map = new ActionMapUIResource();
            SwingUtilities.replaceUIActionMap(menuBar, map);
        }
        map.put("takeFocus", new TakeFocus());
    
protected voidinstallListeners()

        if (WindowsLookAndFeel.isOnVista()) {
            installWindowListener();
            hierarchyListener = 
                new HierarchyListener() {
                    public void hierarchyChanged(HierarchyEvent e) {
                        if ((e.getChangeFlags() 
                                & HierarchyEvent.DISPLAYABILITY_CHANGED) != 0) {
                            if (menuBar.isDisplayable()) {
                                installWindowListener();
                            } else {
                                uninstallWindowListener();
                            }
                        }
                    }
            };
            menuBar.addHierarchyListener(hierarchyListener);
        }
        super.installListeners();
    
private voidinstallWindowListener()

        if (windowListener == null) {
            Component component = menuBar.getTopLevelAncestor();
            if (component instanceof Window) {
                window = (Window) component;
                windowListener = new WindowAdapter() {
                    @Override
                    public void windowActivated(WindowEvent e) {
                        menuBar.repaint();
                    }
                    @Override
                    public void windowDeactivated(WindowEvent e) {
                        menuBar.repaint();
                    }
                };
                ((Window) component).addWindowListener(windowListener);
            }
        }
    
static booleanisActive(javax.swing.JComponent c)
Checks if component belongs to an active window.

param
c component to check
return
true if component belongs to an active window

        JRootPane rootPane = c.getRootPane();
        if (rootPane != null) {
            Component component = rootPane.getParent();
            if (component instanceof Window) {
                return ((Window) component).isActive();
            }
        }
        return true;
    
public voidpaint(java.awt.Graphics g, javax.swing.JComponent c)

        if (WindowsMenuItemUI.isVistaPainting()) {
            XPStyle xp = XPStyle.getXP();
            Skin skin;
            skin = xp.getSkin(c, Part.MP_BARBACKGROUND);
            int width = c.getWidth();
            int height = c.getHeight();
            State state =  isActive(c) ? State.ACTIVE : State.INACTIVE;
            skin.paintSkin(g, 0, 0, width, height, state);
        } else {
            super.paint(g, c);
        }
    
protected voiduninstallListeners()

        uninstallWindowListener();
        if (hierarchyListener != null) {
            menuBar.removeHierarchyListener(hierarchyListener);
            hierarchyListener = null;   
        }
        super.uninstallListeners();
    
private voiduninstallWindowListener()

        if (windowListener != null && window != null) {
            window.removeWindowListener(windowListener);
        }
        window = null;
        windowListener = null;