WindowsMenuUIpublic class WindowsMenuUI extends BasicMenuUI 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 |
---|
protected Integer | menuBarHeight | protected boolean | hotTrackingOn | final WindowsMenuItemUIAccessor | accessor |
Methods Summary |
---|
protected javax.swing.event.MouseInputListener | createMouseInputListener(javax.swing.JComponent c)
return new WindowsMouseInputHandler();
| public static javax.swing.plaf.ComponentUI | createUI(javax.swing.JComponent x)
return new WindowsMenuUI();
| protected java.awt.Dimension | getPreferredMenuItemSize(javax.swing.JComponent c, javax.swing.Icon checkIcon, javax.swing.Icon arrowIcon, int defaultTextIconGap)
Dimension d = super.getPreferredMenuItemSize(c, checkIcon, arrowIcon,
defaultTextIconGap);
// Note: When toolbar containers (rebars) are implemented, only do
// this if the JMenuBar is not in a rebar (i.e. ignore the desktop
// property win.menu.height if in a rebar.)
if (c instanceof JMenu && ((JMenu)c).isTopLevelMenu() &&
menuBarHeight != null && d.height < menuBarHeight) {
d.height = menuBarHeight;
}
return d;
| protected void | installDefaults()
super.installDefaults();
if (!WindowsLookAndFeel.isClassicWindows()) {
menuItem.setRolloverEnabled(true);
}
menuBarHeight = (Integer)UIManager.getInt("MenuBar.height");
Object obj = UIManager.get("MenuBar.rolloverEnabled");
hotTrackingOn = (obj instanceof Boolean) ? (Boolean)obj : true;
| protected void | paintBackground(java.awt.Graphics g, javax.swing.JMenuItem menuItem, java.awt.Color bgColor)Draws the background of the menu.
if (WindowsMenuItemUI.isVistaPainting()) {
WindowsMenuItemUI.paintBackground(accessor, g, menuItem, bgColor);
return;
}
JMenu menu = (JMenu)menuItem;
ButtonModel model = menu.getModel();
// Use superclass method for the old Windows LAF,
// for submenus, and for XP toplevel if selected or pressed
if (WindowsLookAndFeel.isClassicWindows() ||
!menu.isTopLevelMenu() ||
(XPStyle.getXP() != null && (model.isArmed() || model.isSelected()))) {
super.paintBackground(g, menu, bgColor);
return;
}
Color oldColor = g.getColor();
int menuWidth = menu.getWidth();
int menuHeight = menu.getHeight();
UIDefaults table = UIManager.getLookAndFeelDefaults();
Color highlight = table.getColor("controlLtHighlight");
Color shadow = table.getColor("controlShadow");
g.setColor(menu.getBackground());
g.fillRect(0,0, menuWidth, menuHeight);
if (menu.isOpaque()) {
if (model.isArmed() || model.isSelected()) {
// Draw a lowered bevel border
g.setColor(shadow);
g.drawLine(0,0, menuWidth - 1,0);
g.drawLine(0,0, 0,menuHeight - 2);
g.setColor(highlight);
g.drawLine(menuWidth - 1,0, menuWidth - 1,menuHeight - 2);
g.drawLine(0,menuHeight - 2, menuWidth - 1,menuHeight - 2);
} else if (model.isRollover() && model.isEnabled()) {
// Only paint rollover if no other menu on menubar is selected
boolean otherMenuSelected = false;
MenuElement[] menus = ((JMenuBar)menu.getParent()).getSubElements();
for (int i = 0; i < menus.length; i++) {
if (((JMenuItem)menus[i]).isSelected()) {
otherMenuSelected = true;
break;
}
}
if (!otherMenuSelected) {
if (XPStyle.getXP() != null) {
g.setColor(selectionBackground); // Uses protected field.
g.fillRect(0, 0, menuWidth, menuHeight);
} else {
// Draw a raised bevel border
g.setColor(highlight);
g.drawLine(0,0, menuWidth - 1,0);
g.drawLine(0,0, 0,menuHeight - 2);
g.setColor(shadow);
g.drawLine(menuWidth - 1,0, menuWidth - 1,menuHeight - 2);
g.drawLine(0,menuHeight - 2, menuWidth - 1,menuHeight - 2);
}
}
}
}
g.setColor(oldColor);
| protected void | paintText(java.awt.Graphics g, javax.swing.JMenuItem menuItem, java.awt.Rectangle textRect, java.lang.String text)Method which renders the text of the current menu item.
if (WindowsMenuItemUI.isVistaPainting()) {
WindowsMenuItemUI.paintText(accessor, g, menuItem, textRect, text);
return;
}
JMenu menu = (JMenu)menuItem;
ButtonModel model = menuItem.getModel();
Color oldColor = g.getColor();
// Only paint rollover if no other menu on menubar is selected
boolean paintRollover = model.isRollover();
if (paintRollover && menu.isTopLevelMenu()) {
MenuElement[] menus = ((JMenuBar)menu.getParent()).getSubElements();
for (int i = 0; i < menus.length; i++) {
if (((JMenuItem)menus[i]).isSelected()) {
paintRollover = false;
break;
}
}
}
if ((model.isSelected() && (WindowsLookAndFeel.isClassicWindows() ||
!menu.isTopLevelMenu())) ||
(XPStyle.getXP() != null && (paintRollover ||
model.isArmed() ||
model.isSelected()))) {
g.setColor(selectionForeground); // Uses protected field.
}
WindowsGraphicsUtils.paintText(g, menuItem, textRect, text, 0);
g.setColor(oldColor);
|
|