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

WindowsPopupMenuUI

public class WindowsPopupMenuUI extends BasicPopupMenuUI
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.

version
1.24 12/15/06
author
Igor Kushnirskiy

Fields Summary
static MnemonicListener
mnemonicListener
static final Object
GUTTER_OFFSET_KEY
Constructors Summary
Methods Summary
public static javax.swing.plaf.ComponentUIcreateUI(javax.swing.JComponent c)

 

         
	return new WindowsPopupMenuUI();
    
static intgetGutterWidth()
Returns gutter width. used only on Vista.

return
width of the gutter

        int rv = 2;
        XPStyle xp = XPStyle.getXP();
        if (xp != null) {
            Skin skin = xp.getSkin(null, Part.MP_POPUPGUTTER);
            rv = skin.getWidth();
        }
        return rv;
    
public javax.swing.PopupgetPopup(javax.swing.JPopupMenu popupMenu, int x, int y)
Returns the Popup that will be responsible for displaying the JPopupMenu.

param
popupMenu JPopupMenu requesting Popup
param
x Screen x location Popup is to be shown at
param
y Screen y location Popup is to be shown at.
return
Popup that will show the JPopupMenu
since
1.4

        PopupFactory popupFactory = PopupFactory.getSharedInstance();
        return popupFactory.getPopup(popupMenu.getInvoker(), popupMenu, x, y);
    
static intgetSpanAfterGutter()
Returns span after gutter. used only on Vista.

return
span after gutter

        return 3;
    
static intgetSpanBeforeGutter()
Returns span before gutter. used only on Vista.

return
span before gutter

        return 3;
    
static intgetTextOffset(javax.swing.JComponent c)
Returns offset for the text. BasicMenuItemUI sets max text offset on the JPopupMenuUI.

param
c PopupMenu to return text offset for.
return
text offset for the component

        int rv = -1;
        Object maxTextOffset = 
            c.getClientProperty(BASICMENUITEMUI_MAX_TEXT_OFFSET);
        if (maxTextOffset instanceof Integer) {
            /* 
             * this is in JMenuItem coordinates. 
             * Let's assume all the JMenuItem have the same offset along X.
             */
            rv = (Integer) maxTextOffset;
            int menuItemOffset = 0;
            Component component = c.getComponent(0);
            if (component != null) {
                menuItemOffset = component.getX();
            }
            rv += menuItemOffset;
        }
        return rv;
    
public voidinstallListeners()

        super.installListeners();
	if (! UIManager.getBoolean("Button.showMnemonics") &&
            mnemonicListener == null) {

            mnemonicListener = new MnemonicListener();
            MenuSelectionManager.defaultManager().
                addChangeListener(mnemonicListener);
        }
    
private static booleanisLeftToRight(javax.swing.JComponent c)
Checks if PopupMenu is leftToRight The orientation is derived from the children of the component. It is leftToRight if all the children are leftToRight

param
c component to return orientation for
return
true if all the children are leftToRight

        boolean leftToRight = true;
        for (int i = c.getComponentCount() - 1; i >=0 && leftToRight; i-- ) {
            leftToRight = 
                c.getComponent(i).getComponentOrientation().isLeftToRight();
        }
        return leftToRight;
    
public voidpaint(java.awt.Graphics g, javax.swing.JComponent c)

        if (WindowsMenuItemUI.isVistaPainting()) {
            XPStyle xp = XPStyle.getXP();
            Skin skin = xp.getSkin(c, Part.MP_POPUPBACKGROUND);
            skin.paintSkin(g, 0, 0, c.getWidth(),c.getHeight(), State.NORMAL);
            int textOffset = getTextOffset(c);
            if (textOffset >= 0
                    /* paint gutter only for leftToRight case */
                    && isLeftToRight(c)) {
                skin = xp.getSkin(c, Part.MP_POPUPGUTTER);
                int gutterWidth = getGutterWidth();
                int gutterOffset = 
                    textOffset - getSpanAfterGutter() - gutterWidth;
                c.putClientProperty(GUTTER_OFFSET_KEY, 
                    Integer.valueOf(gutterOffset));
                Insets insets = c.getInsets();
                skin.paintSkin(g, gutterOffset, insets.top, 
                    gutterWidth, c.getHeight() - insets.bottom - insets.top, 
                    State.NORMAL);
            } else {
                if (c.getClientProperty(GUTTER_OFFSET_KEY) != null) {
                    c.putClientProperty(GUTTER_OFFSET_KEY, null);  
                }
            }
        } else {
            super.paint(g, c);
        }