mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-11 14:37:13 -06:00
Menus:
- added 1px to menu item top and bottom margin - changed gap between menu item icon and text from 4 to 6 - improved colors of checked menu items that have a icon (issue #96)
This commit is contained in:
@@ -16,12 +16,11 @@
|
||||
|
||||
package com.formdev.flatlaf.ui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.LookAndFeel;
|
||||
import javax.swing.plaf.ComponentUI;
|
||||
import javax.swing.plaf.basic.BasicCheckBoxMenuItemUI;
|
||||
|
||||
@@ -49,21 +48,13 @@ import javax.swing.plaf.basic.BasicCheckBoxMenuItemUI;
|
||||
*
|
||||
* <!-- FlatCheckBoxMenuItemUI -->
|
||||
*
|
||||
* @uiDefault CheckBoxMenuItem.checkBackground Color
|
||||
*
|
||||
* <!-- FlatMenuItemRenderer -->
|
||||
*
|
||||
* @uiDefault MenuItem.minimumIconSize Dimension
|
||||
* @uiDefault MenuItem.textAcceleratorGap int
|
||||
* @uiDefault MenuItem.textNoAcceleratorGap int
|
||||
* @uiDefault MenuItem.acceleratorArrowGap int
|
||||
* @uiDefault MenuItem.iconTextGap int
|
||||
*
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
public class FlatCheckBoxMenuItemUI
|
||||
extends BasicCheckBoxMenuItemUI
|
||||
{
|
||||
private Color checkBackground;
|
||||
private FlatMenuItemRenderer renderer;
|
||||
|
||||
public static ComponentUI createUI( JComponent c ) {
|
||||
@@ -74,7 +65,8 @@ public class FlatCheckBoxMenuItemUI
|
||||
protected void installDefaults() {
|
||||
super.installDefaults();
|
||||
|
||||
checkBackground = UIManager.getColor( "CheckBoxMenuItem.checkBackground" );
|
||||
LookAndFeel.installProperty( menuItem, "iconTextGap", FlatUIUtils.getUIInt( "MenuItem.iconTextGap", 4 ) );
|
||||
|
||||
renderer = createRenderer();
|
||||
}
|
||||
|
||||
@@ -82,7 +74,6 @@ public class FlatCheckBoxMenuItemUI
|
||||
protected void uninstallDefaults() {
|
||||
super.uninstallDefaults();
|
||||
|
||||
checkBackground = null;
|
||||
renderer = null;
|
||||
}
|
||||
|
||||
@@ -98,6 +89,6 @@ public class FlatCheckBoxMenuItemUI
|
||||
@Override
|
||||
public void paint( Graphics g, JComponent c ) {
|
||||
renderer.paintMenuItem( g, selectionBackground, selectionForeground, disabledForeground,
|
||||
checkBackground, acceleratorForeground, acceleratorSelectionForeground );
|
||||
acceleratorForeground, acceleratorSelectionForeground );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,17 @@ import com.formdev.flatlaf.util.Graphics2DProxy;
|
||||
/**
|
||||
* Renderer for menu items.
|
||||
*
|
||||
* @uiDefault MenuItem.minimumWidth int
|
||||
* @uiDefault MenuItem.minimumIconSize Dimension
|
||||
* @uiDefault MenuItem.textAcceleratorGap int
|
||||
* @uiDefault MenuItem.textNoAcceleratorGap int
|
||||
* @uiDefault MenuItem.acceleratorArrowGap int
|
||||
* @uiDefault MenuItem.checkBackground Color
|
||||
* @uiDefault MenuItem.underlineSelectionBackground Color
|
||||
* @uiDefault MenuItem.underlineSelectionCheckBackground Color
|
||||
* @uiDefault MenuItem.underlineSelectionColor Color
|
||||
* @uiDefault MenuItem.underlineSelectionHeight Color
|
||||
*
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
public class FlatMenuItemRenderer
|
||||
@@ -60,7 +71,11 @@ public class FlatMenuItemRenderer
|
||||
protected final int textNoAcceleratorGap = FlatUIUtils.getUIInt( "MenuItem.textNoAcceleratorGap", 6 );
|
||||
protected final int acceleratorArrowGap = FlatUIUtils.getUIInt( "MenuItem.acceleratorArrowGap", 2 );
|
||||
|
||||
protected final Color checkBackground = UIManager.getColor( "MenuItem.checkBackground" );
|
||||
protected final Insets checkMargins = UIManager.getInsets( "MenuItem.checkMargins" );
|
||||
|
||||
protected final Color underlineSelectionBackground = UIManager.getColor( "MenuItem.underlineSelectionBackground" );
|
||||
protected final Color underlineSelectionCheckBackground = UIManager.getColor( "MenuItem.underlineSelectionCheckBackground" );
|
||||
protected final Color underlineSelectionColor = UIManager.getColor( "MenuItem.underlineSelectionColor" );
|
||||
protected final int underlineSelectionHeight = UIManager.getInt( "MenuItem.underlineSelectionHeight" );
|
||||
|
||||
@@ -201,8 +216,7 @@ public class FlatMenuItemRenderer
|
||||
}
|
||||
|
||||
protected void paintMenuItem( Graphics g, Color selectionBackground, Color selectionForeground,
|
||||
Color disabledForeground, Color checkBackground,
|
||||
Color acceleratorForeground, Color acceleratorSelectionForeground )
|
||||
Color disabledForeground, Color acceleratorForeground, Color acceleratorSelectionForeground )
|
||||
{
|
||||
Rectangle viewRect = new Rectangle( menuItem.getWidth(), menuItem.getHeight() );
|
||||
|
||||
@@ -231,7 +245,7 @@ public class FlatMenuItemRenderer
|
||||
debug*/
|
||||
|
||||
paintBackground( g, selectionBackground );
|
||||
paintIcon( g, iconRect, getIconForPainting(), checkBackground );
|
||||
paintIcon( g, iconRect, getIconForPainting() );
|
||||
paintText( g, textRect, menuItem.getText(), selectionForeground, disabledForeground );
|
||||
paintAccelerator( g, accelRect, getAcceleratorText(), acceleratorForeground, acceleratorSelectionForeground, disabledForeground );
|
||||
if( !isTopLevelMenu( menuItem ) )
|
||||
@@ -268,14 +282,13 @@ debug*/
|
||||
}
|
||||
}
|
||||
|
||||
protected void paintIcon( Graphics g, Rectangle iconRect, Icon icon, Color checkBackground ) {
|
||||
protected void paintIcon( Graphics g, Rectangle iconRect, Icon icon ) {
|
||||
// if checkbox/radiobutton menu item is selected and also has a custom icon,
|
||||
// then use filled icon background to indicate selection (instead of using checkIcon)
|
||||
if( menuItem.isSelected() && checkIcon != null && icon != checkIcon ) {
|
||||
int outset = scale( Math.max( menuItem.getIconTextGap() / 2, 2 ) );
|
||||
g.setColor( checkBackground );
|
||||
g.fillRect( iconRect.x - outset, iconRect.y - outset,
|
||||
iconRect.width + (outset * 2), iconRect.height + (outset * 2) );
|
||||
Rectangle r = FlatUIUtils.addInsets( iconRect, scale( checkMargins ) );
|
||||
g.setColor( isUnderlineSelection() ? underlineSelectionCheckBackground : checkBackground );
|
||||
g.fillRect( r.x, r.y, r.width, r.height );
|
||||
}
|
||||
|
||||
paintIcon( g, menuItem, icon, iconRect );
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.LookAndFeel;
|
||||
import javax.swing.plaf.ComponentUI;
|
||||
import javax.swing.plaf.basic.BasicMenuItemUI;
|
||||
|
||||
@@ -45,12 +46,9 @@ import javax.swing.plaf.basic.BasicMenuItemUI;
|
||||
* @uiDefault MenuItem.checkIcon Icon
|
||||
* @uiDefault MenuItem.opaque boolean
|
||||
*
|
||||
* <!-- FlatMenuItemRenderer -->
|
||||
* <!-- FlatMenuItemUI -->
|
||||
*
|
||||
* @uiDefault MenuItem.minimumIconSize Dimension
|
||||
* @uiDefault MenuItem.textAcceleratorGap int
|
||||
* @uiDefault MenuItem.textNoAcceleratorGap int
|
||||
* @uiDefault MenuItem.acceleratorArrowGap int
|
||||
* @uiDefault MenuItem.iconTextGap int
|
||||
*
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
@@ -67,6 +65,8 @@ public class FlatMenuItemUI
|
||||
protected void installDefaults() {
|
||||
super.installDefaults();
|
||||
|
||||
LookAndFeel.installProperty( menuItem, "iconTextGap", FlatUIUtils.getUIInt( "MenuItem.iconTextGap", 4 ) );
|
||||
|
||||
renderer = createRenderer();
|
||||
}
|
||||
|
||||
@@ -89,6 +89,6 @@ public class FlatMenuItemUI
|
||||
@Override
|
||||
public void paint( Graphics g, JComponent c ) {
|
||||
renderer.paintMenuItem( g, selectionBackground, selectionForeground, disabledForeground,
|
||||
null, acceleratorForeground, acceleratorSelectionForeground );
|
||||
acceleratorForeground, acceleratorSelectionForeground );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import javax.swing.Icon;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.LookAndFeel;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.event.MouseInputListener;
|
||||
import javax.swing.plaf.ComponentUI;
|
||||
@@ -58,15 +59,9 @@ import javax.swing.plaf.basic.BasicMenuUI;
|
||||
*
|
||||
* <!-- FlatMenuUI -->
|
||||
*
|
||||
* @uiDefault MenuItem.iconTextGap int
|
||||
* @uiDefault MenuBar.hoverBackground Color
|
||||
*
|
||||
* <!-- FlatMenuItemRenderer -->
|
||||
*
|
||||
* @uiDefault MenuItem.minimumIconSize Dimension
|
||||
* @uiDefault MenuItem.textAcceleratorGap int
|
||||
* @uiDefault MenuItem.textNoAcceleratorGap int
|
||||
* @uiDefault MenuItem.acceleratorArrowGap int
|
||||
*
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
public class FlatMenuUI
|
||||
@@ -83,6 +78,8 @@ public class FlatMenuUI
|
||||
protected void installDefaults() {
|
||||
super.installDefaults();
|
||||
|
||||
LookAndFeel.installProperty( menuItem, "iconTextGap", FlatUIUtils.getUIInt( "MenuItem.iconTextGap", 4 ) );
|
||||
|
||||
menuItem.setRolloverEnabled( true );
|
||||
|
||||
hoverBackground = UIManager.getColor( "MenuBar.hoverBackground" );
|
||||
@@ -134,7 +131,7 @@ public class FlatMenuUI
|
||||
@Override
|
||||
public void paint( Graphics g, JComponent c ) {
|
||||
renderer.paintMenuItem( g, selectionBackground, selectionForeground, disabledForeground,
|
||||
null, acceleratorForeground, acceleratorSelectionForeground );
|
||||
acceleratorForeground, acceleratorSelectionForeground );
|
||||
}
|
||||
|
||||
//---- class FlatMenuRenderer ---------------------------------------------
|
||||
|
||||
@@ -16,12 +16,11 @@
|
||||
|
||||
package com.formdev.flatlaf.ui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.LookAndFeel;
|
||||
import javax.swing.plaf.ComponentUI;
|
||||
import javax.swing.plaf.basic.BasicRadioButtonMenuItemUI;
|
||||
|
||||
@@ -49,21 +48,13 @@ import javax.swing.plaf.basic.BasicRadioButtonMenuItemUI;
|
||||
*
|
||||
* <!-- FlatRadioButtonMenuItemUI -->
|
||||
*
|
||||
* @uiDefault RadioButtonMenuItem.checkBackground Color
|
||||
*
|
||||
* <!-- FlatMenuItemRenderer -->
|
||||
*
|
||||
* @uiDefault MenuItem.minimumIconSize Dimension
|
||||
* @uiDefault MenuItem.textAcceleratorGap int
|
||||
* @uiDefault MenuItem.textNoAcceleratorGap int
|
||||
* @uiDefault MenuItem.acceleratorArrowGap int
|
||||
* @uiDefault MenuItem.iconTextGap int
|
||||
*
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
public class FlatRadioButtonMenuItemUI
|
||||
extends BasicRadioButtonMenuItemUI
|
||||
{
|
||||
private Color checkBackground;
|
||||
private FlatMenuItemRenderer renderer;
|
||||
|
||||
public static ComponentUI createUI( JComponent c ) {
|
||||
@@ -74,7 +65,8 @@ public class FlatRadioButtonMenuItemUI
|
||||
protected void installDefaults() {
|
||||
super.installDefaults();
|
||||
|
||||
checkBackground = UIManager.getColor( "RadioButtonMenuItem.checkBackground" );
|
||||
LookAndFeel.installProperty( menuItem, "iconTextGap", FlatUIUtils.getUIInt( "MenuItem.iconTextGap", 4 ) );
|
||||
|
||||
renderer = createRenderer();
|
||||
}
|
||||
|
||||
@@ -82,7 +74,6 @@ public class FlatRadioButtonMenuItemUI
|
||||
protected void uninstallDefaults() {
|
||||
super.uninstallDefaults();
|
||||
|
||||
checkBackground = null;
|
||||
renderer = null;
|
||||
}
|
||||
|
||||
@@ -98,6 +89,6 @@ public class FlatRadioButtonMenuItemUI
|
||||
@Override
|
||||
public void paint( Graphics g, JComponent c ) {
|
||||
renderer.paintMenuItem( g, selectionBackground, selectionForeground, disabledForeground,
|
||||
checkBackground, acceleratorForeground, acceleratorSelectionForeground );
|
||||
acceleratorForeground, acceleratorSelectionForeground );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,8 @@
|
||||
@textComponentBackground=#45494A
|
||||
@menuBackground=darken(@background,5%)
|
||||
@menuHoverBackground=lighten(@menuBackground,10%)
|
||||
@menuCheckBackground=lighten(@menuBackground,15%)
|
||||
@menuCheckBackground=lighten(@menuBackground,10%)
|
||||
@menuCheckHoverBackground=lighten(@menuBackground,20%)
|
||||
@cellFocusColor=#000000
|
||||
@icon=#adadad
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ ViewportUI=com.formdev.flatlaf.ui.FlatViewportUI
|
||||
#---- variables ----
|
||||
|
||||
@textComponentMargin=2,6,2,6
|
||||
@menuItemMargin=2,6,2,6
|
||||
@menuItemMargin=3,6,3,6
|
||||
|
||||
|
||||
#---- system colors ----
|
||||
@@ -165,7 +165,6 @@ CheckBoxMenuItem.margin=@menuItemMargin
|
||||
CheckBoxMenuItem.opaque=false
|
||||
CheckBoxMenuItem.borderPainted=true
|
||||
CheckBoxMenuItem.background=@menuBackground
|
||||
CheckBoxMenuItem.checkBackground=@menuCheckBackground
|
||||
|
||||
|
||||
#---- ColorChooser ----
|
||||
@@ -312,8 +311,11 @@ MenuItem.margin=@menuItemMargin
|
||||
MenuItem.opaque=false
|
||||
MenuItem.borderPainted=true
|
||||
MenuItem.background=@menuBackground
|
||||
MenuItem.checkBackground=@menuCheckBackground
|
||||
MenuItem.checkMargins=3,3,3,3
|
||||
MenuItem.minimumWidth=72
|
||||
MenuItem.minimumIconSize=16,16
|
||||
MenuItem.iconTextGap=6
|
||||
MenuItem.textAcceleratorGap=24
|
||||
MenuItem.textNoAcceleratorGap=6
|
||||
MenuItem.acceleratorArrowGap=2
|
||||
@@ -322,6 +324,7 @@ MenuItem.acceleratorDelimiter=-
|
||||
|
||||
# for MenuItem.selectionType=underline
|
||||
MenuItem.underlineSelectionBackground=@menuHoverBackground
|
||||
MenuItem.underlineSelectionCheckBackground=@menuCheckHoverBackground
|
||||
MenuItem.underlineSelectionColor=$TabbedPane.underlineColor
|
||||
MenuItem.underlineSelectionHeight=3
|
||||
|
||||
@@ -402,7 +405,6 @@ RadioButtonMenuItem.margin=@menuItemMargin
|
||||
RadioButtonMenuItem.opaque=false
|
||||
RadioButtonMenuItem.borderPainted=true
|
||||
RadioButtonMenuItem.background=@menuBackground
|
||||
RadioButtonMenuItem.checkBackground=@menuCheckBackground
|
||||
|
||||
|
||||
#---- ScrollBar ----
|
||||
|
||||
@@ -30,7 +30,8 @@
|
||||
@textComponentBackground=#ffffff
|
||||
@menuBackground=#fff
|
||||
@menuHoverBackground=darken(@menuBackground,10%)
|
||||
@menuCheckBackground=darken(@menuBackground,15%)
|
||||
@menuCheckBackground=darken(@menuBackground,10%)
|
||||
@menuCheckHoverBackground=darken(@menuBackground,20%)
|
||||
@cellFocusColor=#000000
|
||||
@icon=#afafaf
|
||||
|
||||
|
||||
Reference in New Issue
Block a user