Menus: use disabled and pressed icons (issue #3)

This commit is contained in:
Karl Tauber
2020-04-26 11:24:49 +02:00
parent 115a2df2b0
commit 41dd0acfa3

View File

@@ -214,7 +214,7 @@ debug*/
paintBackground( g, selectionBackground ); paintBackground( g, selectionBackground );
if( !isTopLevelMenu ) if( !isTopLevelMenu )
paintIcon( g, iconRect, getIcon() ); paintIcon( g, iconRect, getIconForPainting() );
paintText( g, textRect, menuItem.getText(), selectionForeground, disabledForeground ); paintText( g, textRect, menuItem.getText(), selectionForeground, disabledForeground );
paintAccelerator( g, accelRect, getAcceleratorText(), acceleratorForeground, acceleratorSelectionForeground, disabledForeground ); paintAccelerator( g, accelRect, getAcceleratorText(), acceleratorForeground, acceleratorSelectionForeground, disabledForeground );
if( !isTopLevelMenu ) if( !isTopLevelMenu )
@@ -304,6 +304,26 @@ debug*/
return (checkIcon != null) ? checkIcon : menuItem.getIcon(); return (checkIcon != null) ? checkIcon : menuItem.getIcon();
} }
private Icon getIconForPainting() {
if( checkIcon != null )
return checkIcon;
Icon icon = menuItem.getIcon();
if( icon == null )
return null;
if( !menuItem.isEnabled() )
return menuItem.getDisabledIcon();
if( menuItem.getModel().isPressed() && menuItem.isArmed() ) {
Icon pressedIcon = menuItem.getPressedIcon();
if( pressedIcon != null )
return pressedIcon;
}
return icon;
}
private Dimension getIconSize() { private Dimension getIconSize() {
Icon icon = getIcon(); Icon icon = getIcon();
int iconWidth = (icon != null) ? icon.getIconWidth() : 0; int iconWidth = (icon != null) ? icon.getIconWidth() : 0;