diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatCheckBoxMenuItemIcon.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatCheckBoxMenuItemIcon.java index f49ac08e..c70be48b 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatCheckBoxMenuItemIcon.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatCheckBoxMenuItemIcon.java @@ -30,7 +30,8 @@ import javax.swing.UIManager; * * @uiDefault MenuItemCheckBox.icon.checkmarkColor Color * @uiDefault MenuItemCheckBox.icon.disabledCheckmarkColor Color - * @uiDefault Menu.selectionForeground Color + * @uiDefault MenuItem.selectionForeground Color + * @uiDefault MenuItem.selectionType String * * @author Karl Tauber */ @@ -39,7 +40,7 @@ public class FlatCheckBoxMenuItemIcon { protected final Color checkmarkColor = UIManager.getColor( "MenuItemCheckBox.icon.checkmarkColor" ); protected final Color disabledCheckmarkColor = UIManager.getColor( "MenuItemCheckBox.icon.disabledCheckmarkColor" ); - protected final Color selectionForeground = UIManager.getColor( "Menu.selectionForeground" ); + protected final Color selectionForeground = UIManager.getColor( "MenuItem.selectionForeground" ); public FlatCheckBoxMenuItemIcon() { super( 15, 15, null ); @@ -67,9 +68,14 @@ public class FlatCheckBoxMenuItemIcon } private Color getCheckmarkColor( Component c ) { - if( c instanceof JMenuItem && ((JMenuItem)c).isArmed() ) + if( c instanceof JMenuItem && ((JMenuItem)c).isArmed() && !isUnderlineSelection() ) return selectionForeground; return c.isEnabled() ? checkmarkColor : disabledCheckmarkColor; } + + private boolean isUnderlineSelection() { + // not storing value of "MenuItem.selectionType" in class to allow changing at runtime + return "underline".equals( UIManager.getString( "MenuItem.selectionType" ) ); + } } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatMenuArrowIcon.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatMenuArrowIcon.java index 0e6b41f8..2f4af4de 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatMenuArrowIcon.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/icons/FlatMenuArrowIcon.java @@ -32,6 +32,7 @@ import com.formdev.flatlaf.ui.FlatUIUtils; * @uiDefault Menu.icon.arrowColor Color * @uiDefault Menu.icon.disabledArrowColor Color * @uiDefault Menu.selectionForeground Color + * @uiDefault MenuItem.selectionType String * * @author Karl Tauber */ @@ -65,9 +66,14 @@ public class FlatMenuArrowIcon } private Color getArrowColor( Component c ) { - if( c instanceof JMenu && ((JMenu)c).isSelected() ) + if( c instanceof JMenu && ((JMenu)c).isSelected() && !isUnderlineSelection() ) return selectionForeground; return c.isEnabled() ? arrowColor : disabledArrowColor; } + + private boolean isUnderlineSelection() { + // not storing value of "MenuItem.selectionType" in class to allow changing at runtime + return "underline".equals( UIManager.getString( "MenuItem.selectionType" ) ); + } } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatCheckBoxMenuItemUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatCheckBoxMenuItemUI.java index f1cb3767..6e6c0462 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatCheckBoxMenuItemUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatCheckBoxMenuItemUI.java @@ -16,12 +16,12 @@ package com.formdev.flatlaf.ui; -import static com.formdev.flatlaf.util.UIScale.scale; +import java.awt.Color; +import java.awt.Dimension; import java.awt.Graphics; -import java.awt.Rectangle; -import java.beans.PropertyChangeListener; +import javax.swing.Icon; import javax.swing.JComponent; -import javax.swing.JMenuItem; +import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicCheckBoxMenuItemUI; @@ -30,29 +30,43 @@ import javax.swing.plaf.basic.BasicCheckBoxMenuItemUI; * * * - * @uiDefault CheckBoxMenuItem.font Font - * @uiDefault CheckBoxMenuItem.background Color - * @uiDefault CheckBoxMenuItem.foreground Color - * @uiDefault CheckBoxMenuItem.disabledForeground Color - * @uiDefault CheckBoxMenuItem.selectionBackground Color - * @uiDefault CheckBoxMenuItem.selectionForeground Color - * @uiDefault CheckBoxMenuItem.acceleratorForeground Color - * @uiDefault CheckBoxMenuItem.acceleratorSelectionForeground Color - * @uiDefault MenuItem.acceleratorFont Font defaults to MenuItem.font - * @uiDefault MenuItem.acceleratorDelimiter String - * @uiDefault CheckBoxMenuItem.border Border - * @uiDefault CheckBoxMenuItem.borderPainted boolean - * @uiDefault CheckBoxMenuItem.margin Insets - * @uiDefault CheckBoxMenuItem.arrowIcon Icon - * @uiDefault CheckBoxMenuItem.checkIcon Icon - * @uiDefault CheckBoxMenuItem.opaque boolean - * @uiDefault CheckBoxMenuItem.evenHeight boolean + * @uiDefault CheckBoxMenuItem.font Font + * @uiDefault CheckBoxMenuItem.background Color + * @uiDefault CheckBoxMenuItem.foreground Color + * @uiDefault CheckBoxMenuItem.disabledForeground Color + * @uiDefault CheckBoxMenuItem.selectionBackground Color + * @uiDefault CheckBoxMenuItem.selectionForeground Color + * @uiDefault CheckBoxMenuItem.acceleratorForeground Color + * @uiDefault CheckBoxMenuItem.acceleratorSelectionForeground Color + * @uiDefault MenuItem.acceleratorFont Font defaults to MenuItem.font + * @uiDefault MenuItem.acceleratorDelimiter String + * @uiDefault CheckBoxMenuItem.border Border + * @uiDefault CheckBoxMenuItem.borderPainted boolean + * @uiDefault CheckBoxMenuItem.margin Insets + * @uiDefault CheckBoxMenuItem.arrowIcon Icon + * @uiDefault CheckBoxMenuItem.checkIcon Icon + * @uiDefault CheckBoxMenuItem.opaque boolean + * @uiDefault CheckBoxMenuItem.evenHeight boolean + * + * + * + * @uiDefault CheckBoxMenuItem.checkBackground Color + * + * + * + * @uiDefault MenuItem.minimumIconSize Dimension + * @uiDefault MenuItem.textAcceleratorGap int + * @uiDefault MenuItem.acceleratorArrowGap int + * @uiDefault MenuItem.textArrowGap int * * @author Karl Tauber */ public class FlatCheckBoxMenuItemUI extends BasicCheckBoxMenuItemUI { + private Color checkBackground; + private FlatMenuItemRenderer renderer; + public static ComponentUI createUI( JComponent c ) { return new FlatCheckBoxMenuItemUI(); } @@ -61,25 +75,30 @@ public class FlatCheckBoxMenuItemUI protected void installDefaults() { super.installDefaults(); - // scale - defaultTextIconGap = scale( defaultTextIconGap ); - } - - /** - * Scale defaultTextIconGap again if iconTextGap property has changed. - */ - @Override - protected PropertyChangeListener createPropertyChangeListener( JComponent c ) { - PropertyChangeListener superListener = super.createPropertyChangeListener( c ); - return e -> { - superListener.propertyChange( e ); - if( e.getPropertyName() == "iconTextGap" ) - defaultTextIconGap = scale( defaultTextIconGap ); - }; + checkBackground = UIManager.getColor( "CheckBoxMenuItem.checkBackground" ); + renderer = createRenderer(); } @Override - protected void paintText( Graphics g, JMenuItem menuItem, Rectangle textRect, String text ) { - FlatMenuItemUI.paintText( g, menuItem, textRect, text, disabledForeground, selectionForeground ); + protected void uninstallDefaults() { + super.uninstallDefaults(); + + checkBackground = null; + renderer = null; + } + + protected FlatMenuItemRenderer createRenderer() { + return new FlatMenuItemRenderer( menuItem, checkIcon, arrowIcon, acceleratorFont, acceleratorDelimiter ); + } + + @Override + protected Dimension getPreferredMenuItemSize( JComponent c, Icon checkIcon, Icon arrowIcon, int defaultTextIconGap ) { + return renderer.getPreferredMenuItemSize(); + } + + @Override + public void paint( Graphics g, JComponent c ) { + renderer.paintMenuItem( g, selectionBackground, selectionForeground, disabledForeground, + checkBackground, acceleratorForeground, acceleratorSelectionForeground ); } } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuItemRenderer.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuItemRenderer.java new file mode 100644 index 00000000..325547da --- /dev/null +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuItemRenderer.java @@ -0,0 +1,431 @@ +/* + * Copyright 2020 FormDev Software GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.formdev.flatlaf.ui; + +import static com.formdev.flatlaf.util.UIScale.scale; +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.Graphics; +import java.awt.Insets; +import java.awt.Rectangle; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; +import javax.swing.Icon; +import javax.swing.JMenu; +import javax.swing.JMenuItem; +import javax.swing.KeyStroke; +import javax.swing.SwingUtilities; +import javax.swing.UIManager; +import javax.swing.plaf.basic.BasicHTML; +import javax.swing.text.View; +import com.formdev.flatlaf.FlatLaf; + +/** + * Renderer for menu items. + * + * @author Karl Tauber + */ +public class FlatMenuItemRenderer +{ + protected final JMenuItem menuItem; + protected final Icon checkIcon; + protected final Icon arrowIcon; + protected final Font acceleratorFont; + protected final String acceleratorDelimiter; + + protected final int minimumWidth; + protected final Dimension minimumIconSize; + protected final int textAcceleratorGap; + protected final int textArrowGap; + + protected final String selectionType = UIManager.getString( "MenuItem.selectionType" ); + protected final Color underlineSelectionBackground = UIManager.getColor( "MenuItem.underlineSelectionBackground" ); + protected final Color underlineSelectionColor = UIManager.getColor( "MenuItem.underlineSelectionColor" ); + protected final int underlineSelectionHeight = UIManager.getInt( "MenuItem.underlineSelectionHeight" ); + + protected FlatMenuItemRenderer( JMenuItem menuItem, Icon checkIcon, Icon arrowIcon, + Font acceleratorFont, String acceleratorDelimiter ) + { + this.menuItem = menuItem; + this.checkIcon = checkIcon; + this.arrowIcon = arrowIcon; + this.acceleratorFont = acceleratorFont; + this.acceleratorDelimiter = acceleratorDelimiter; + + minimumWidth = UIManager.getInt( "MenuItem.minimumWidth" ); + Dimension minimumIconSize = UIManager.getDimension( "MenuItem.minimumIconSize" ); + this.minimumIconSize = (minimumIconSize != null) ? minimumIconSize : new Dimension( 16, 16 ); + this.textAcceleratorGap = FlatUIUtils.getUIInt( "MenuItem.textAcceleratorGap", 28 ); + this.textArrowGap = FlatUIUtils.getUIInt( "MenuItem.textArrowGap", 8 ); + } + + protected Dimension getPreferredMenuItemSize() { + int width = 0; + int height = 0; + boolean isTopLevelMenu = isTopLevelMenu( menuItem ); + + Rectangle viewRect = new Rectangle( 0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE ); + Rectangle iconRect = new Rectangle(); + Rectangle textRect = new Rectangle(); + + // layout icon and text + SwingUtilities.layoutCompoundLabel( menuItem, + menuItem.getFontMetrics( menuItem.getFont() ), menuItem.getText(), getIconForLayout(), + menuItem.getVerticalAlignment(), menuItem.getHorizontalAlignment(), + menuItem.getVerticalTextPosition(), menuItem.getHorizontalTextPosition(), + viewRect, iconRect, textRect, scale( menuItem.getIconTextGap() ) ); + + // union icon and text rectangles + Rectangle labelRect = iconRect.union( textRect ); + width += labelRect.width; + height = Math.max( labelRect.height, height ); + + // accelerator size + String accelText = getAcceleratorText(); + if( accelText != null ) { + // gap between text and accelerator + width += scale( textAcceleratorGap ); + + FontMetrics accelFm = menuItem.getFontMetrics( acceleratorFont ); + width += SwingUtilities.computeStringWidth( accelFm, accelText ); + height = Math.max( accelFm.getHeight(), height ); + } + + // arrow size + if( !isTopLevelMenu && arrowIcon != null ) { + // gap between text and arrow + if( accelText == null ) + width += scale( textArrowGap ); + + width += arrowIcon.getIconWidth(); + height = Math.max( arrowIcon.getIconHeight(), height ); + } + + // add insets + Insets insets = menuItem.getInsets(); + width += insets.left + insets.right; + height += insets.top + insets.bottom; + + // minimum width + if( !isTopLevelMenu ) { + int minimumWidth = FlatUIUtils.minimumWidth( menuItem, this.minimumWidth ); + width = Math.max( width, scale( minimumWidth ) ); + } + + return new Dimension( width, height ); + } + + private void layout( Rectangle viewRect, Rectangle iconRect, Rectangle textRect, + Rectangle accelRect, Rectangle arrowRect ) + { + boolean isTopLevelMenu = isTopLevelMenu( menuItem ); + + // layout arrow + if( !isTopLevelMenu && arrowIcon != null ) { + arrowRect.width = arrowIcon.getIconWidth(); + arrowRect.height = arrowIcon.getIconHeight(); + } else + arrowRect.setSize( 0, 0 ); + arrowRect.y = viewRect.y + centerOffset( viewRect.height, arrowRect.height ); + + // layout accelerator + String accelText = getAcceleratorText(); + if( accelText != null ) { + FontMetrics accelFm = menuItem.getFontMetrics( acceleratorFont ); + accelRect.width = SwingUtilities.computeStringWidth( accelFm, accelText ); + accelRect.height = accelFm.getHeight(); + + accelRect.y = viewRect.y + centerOffset( viewRect.height, accelRect.height ); + } else + accelRect.setBounds( 0, 0, 0, 0 ); + + // compute horizontal positions of accelerator and arrow + if( menuItem.getComponentOrientation().isLeftToRight() ) { + // left-to-right + arrowRect.x = viewRect.x + viewRect.width - arrowRect.width; + accelRect.x = arrowRect.x - accelRect.width; + } else { + // right-to-left + arrowRect.x = viewRect.x; + accelRect.x = arrowRect.x + arrowRect.width; + } + + // width of accelerator, arrow and gap + int accelArrowWidth = accelRect.width + arrowRect.width; + if( accelText != null ) + accelArrowWidth += scale( textAcceleratorGap ); + else if( !isTopLevelMenu && arrowIcon != null ) + accelArrowWidth += scale( textArrowGap ); + + // label rectangle is view rectangle subtracted by accelerator, arrow and gap + Rectangle labelRect = new Rectangle( viewRect ); + labelRect.width -= accelArrowWidth; + if( !menuItem.getComponentOrientation().isLeftToRight() ) + labelRect.x += accelArrowWidth; + + // layout icon and text + SwingUtilities.layoutCompoundLabel( menuItem, + menuItem.getFontMetrics( menuItem.getFont() ), menuItem.getText(), getIconForLayout(), + menuItem.getVerticalAlignment(), menuItem.getHorizontalAlignment(), + menuItem.getVerticalTextPosition(), menuItem.getHorizontalTextPosition(), + labelRect, iconRect, textRect, scale( menuItem.getIconTextGap() ) ); + } + + private static int centerOffset( int wh1, int wh2 ) { + return (wh1 / 2) - (wh2 / 2); + } + + protected void paintMenuItem( Graphics g, Color selectionBackground, Color selectionForeground, + Color disabledForeground, Color checkBackground, + Color acceleratorForeground, Color acceleratorSelectionForeground ) + { + Rectangle viewRect = new Rectangle( menuItem.getWidth(), menuItem.getHeight() ); + + // subtract insets + Insets insets = menuItem.getInsets(); + viewRect.x += insets.left; + viewRect.y += insets.top; + viewRect.width -= (insets.left + insets.right); + viewRect.height -= (insets.top + insets.bottom); + + Rectangle iconRect = new Rectangle(); + Rectangle textRect = new Rectangle(); + Rectangle accelRect = new Rectangle(); + Rectangle arrowRect = new Rectangle(); + + layout( viewRect, iconRect, textRect, accelRect, arrowRect ); + +/*debug + g.setColor( Color.red ); g.drawRect( viewRect.x, viewRect.y, viewRect.width - 1, viewRect.height - 1 ); + g.setColor( Color.blue ); g.drawRect( iconRect.x, iconRect.y, iconRect.width - 1, iconRect.height - 1 ); + g.setColor( Color.cyan ); g.drawRect( textRect.x, textRect.y, textRect.width - 1, textRect.height - 1 ); + g.setColor( Color.magenta ); g.drawRect( accelRect.x, accelRect.y, accelRect.width - 1, accelRect.height - 1 ); + g.setColor( Color.orange ); g.drawRect( arrowRect.x, arrowRect.y, arrowRect.width - 1, arrowRect.height - 1 ); +debug*/ + + paintBackground( g, selectionBackground ); + paintIcon( g, iconRect, getIconForPainting(), checkBackground ); + paintText( g, textRect, menuItem.getText(), selectionForeground, disabledForeground ); + paintAccelerator( g, accelRect, getAcceleratorText(), acceleratorForeground, acceleratorSelectionForeground, disabledForeground ); + if( !isTopLevelMenu( menuItem ) ) + paintArrowIcon( g, arrowRect, arrowIcon ); + } + + protected void paintBackground( Graphics g, Color selectionBackground ) { + boolean armedOrSelected = isArmedOrSelected( menuItem ); + if( menuItem.isOpaque() || armedOrSelected ) { + int width = menuItem.getWidth(); + int height = menuItem.getHeight(); + + // paint background + g.setColor( armedOrSelected + ? (isUnderlineSelection() ? underlineSelectionBackground : selectionBackground) + : menuItem.getBackground() ); + g.fillRect( 0, 0, width, height ); + + // paint underline + if( armedOrSelected && isUnderlineSelection() ) { + int underlineHeight = scale( underlineSelectionHeight ); + g.setColor( underlineSelectionColor ); + if( isTopLevelMenu( menuItem ) ) { + // paint underline at bottom + g.fillRect( 0, height - underlineHeight, width, underlineHeight ); + } else if( menuItem.getComponentOrientation().isLeftToRight() ) { + // paint underline at left side + g.fillRect( 0, 0, underlineHeight, height ); + } else { + // paint underline at right side + g.fillRect( width - underlineHeight, 0, underlineHeight, height ); + } + } + } + } + + protected void paintIcon( Graphics g, Rectangle iconRect, Icon icon, Color checkBackground ) { + // 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) ); + } + + paintIcon( g, menuItem, icon, iconRect ); + } + + protected void paintText( Graphics g, Rectangle textRect, String text, Color selectionForeground, Color disabledForeground ) { + View htmlView = (View) menuItem.getClientProperty( BasicHTML.propertyKey ); + if( htmlView != null ) { + htmlView.paint( g, textRect ); + return; + } + + int mnemonicIndex = FlatLaf.isShowMnemonics() ? menuItem.getDisplayedMnemonicIndex() : -1; + Color foreground = menuItem.getForeground(); + + paintText( g, menuItem, textRect, text, mnemonicIndex, menuItem.getFont(), + foreground, isUnderlineSelection() ? foreground : selectionForeground, disabledForeground ); + } + + protected void paintAccelerator( Graphics g, Rectangle accelRect, String accelText, + Color foreground, Color selectionForeground, Color disabledForeground ) + { + paintText( g, menuItem, accelRect, accelText, -1, acceleratorFont, + foreground, isUnderlineSelection() ? foreground : selectionForeground, disabledForeground ); + } + + protected void paintArrowIcon( Graphics g, Rectangle arrowRect, Icon arrowIcon ) { + paintIcon( g, menuItem, arrowIcon, arrowRect ); + } + + protected static void paintIcon( Graphics g, JMenuItem menuItem, Icon icon, Rectangle iconRect ) { + if( icon == null ) + return; + + // center because the real icon may be smaller than dimension in iconRect + int x = iconRect.x + centerOffset( iconRect.width, icon.getIconWidth() ); + int y = iconRect.y + centerOffset( iconRect.height, icon.getIconHeight() ); + + // paint + icon.paintIcon( menuItem, g, x, y ); + } + + protected static void paintText( Graphics g, JMenuItem menuItem, + Rectangle textRect, String text, int mnemonicIndex, Font font, + Color foreground, Color selectionForeground, Color disabledForeground ) + { + if( text == null || text.isEmpty() ) + return; + + FontMetrics fm = menuItem.getFontMetrics( font ); + + Font oldFont = g.getFont(); + g.setFont( font ); + g.setColor( !menuItem.isEnabled() + ? disabledForeground + : (isArmedOrSelected( menuItem ) + ? selectionForeground + : foreground) ); + + FlatUIUtils.drawStringUnderlineCharAt( menuItem, g, text, mnemonicIndex, + textRect.x, textRect.y + fm.getAscent() ); + + g.setFont( oldFont ); + } + + protected static boolean isArmedOrSelected( JMenuItem menuItem ) { + return menuItem.isArmed() || (menuItem instanceof JMenu && menuItem.isSelected()); + } + + protected static boolean isTopLevelMenu( JMenuItem menuItem ) { + return menuItem instanceof JMenu && ((JMenu)menuItem).isTopLevelMenu(); + } + + private boolean isUnderlineSelection() { + return "underline".equals( selectionType ); + } + + private Icon getIconForPainting() { + Icon icon = menuItem.getIcon(); + + if( icon == null && checkIcon != null && !isTopLevelMenu( menuItem ) ) + return checkIcon; + + 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 Icon getIconForLayout() { + Icon icon = menuItem.getIcon(); + + if( isTopLevelMenu( menuItem ) ) + return (icon != null) ? new MinSizeIcon( icon ) : null; + + return new MinSizeIcon( (icon != null) ? icon : checkIcon ); + } + + private KeyStroke cachedAccelerator; + private String cachedAcceleratorText; + + private String getAcceleratorText() { + KeyStroke accelerator = menuItem.getAccelerator(); + if( accelerator == null ) + return null; + + if( accelerator == cachedAccelerator ) + return cachedAcceleratorText; + + StringBuilder buf = new StringBuilder(); + int modifiers = accelerator.getModifiers(); + if( modifiers != 0 ) + buf.append( InputEvent.getModifiersExText( modifiers ) ).append( acceleratorDelimiter ); + + int keyCode = accelerator.getKeyCode(); + if( keyCode != 0 ) + buf.append( KeyEvent.getKeyText( keyCode ) ); + else + buf.append( accelerator.getKeyChar() ); + + cachedAccelerator = accelerator; + cachedAcceleratorText = buf.toString(); + + return cachedAcceleratorText; + } + + //---- class MinSizeIcon -------------------------------------------------- + + private class MinSizeIcon + implements Icon + { + private final Icon delegate; + + MinSizeIcon( Icon delegate ) { + this.delegate = delegate; + } + + @Override + public int getIconWidth() { + int iconWidth = (delegate != null) ? delegate.getIconWidth() : 0; + return Math.max( iconWidth, scale( minimumIconSize.width ) ); + } + + @Override + public int getIconHeight() { + int iconHeight = (delegate != null) ? delegate.getIconHeight() : 0; + return Math.max( iconHeight, scale( minimumIconSize.height ) ); + } + + @Override + public void paintIcon( Component c, Graphics g, int x, int y ) { + } + } +} diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuItemUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuItemUI.java index 28c76999..0c6fbd7f 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuItemUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuItemUI.java @@ -16,48 +16,50 @@ package com.formdev.flatlaf.ui; -import static com.formdev.flatlaf.util.UIScale.scale; -import java.awt.Color; -import java.awt.FontMetrics; +import java.awt.Dimension; import java.awt.Graphics; -import java.awt.Rectangle; -import java.beans.PropertyChangeListener; -import javax.swing.ButtonModel; +import javax.swing.Icon; import javax.swing.JComponent; -import javax.swing.JMenu; -import javax.swing.JMenuItem; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicMenuItemUI; -import com.formdev.flatlaf.FlatLaf; /** * Provides the Flat LaF UI delegate for {@link javax.swing.JMenuItem}. * * * - * @uiDefault MenuItem.font Font - * @uiDefault MenuItem.background Color - * @uiDefault MenuItem.foreground Color - * @uiDefault MenuItem.disabledForeground Color - * @uiDefault MenuItem.selectionBackground Color - * @uiDefault MenuItem.selectionForeground Color - * @uiDefault MenuItem.acceleratorForeground Color - * @uiDefault MenuItem.acceleratorSelectionForeground Color - * @uiDefault MenuItem.acceleratorFont Font defaults to MenuItem.font - * @uiDefault MenuItem.acceleratorDelimiter String - * @uiDefault MenuItem.border Border - * @uiDefault MenuItem.borderPainted boolean - * @uiDefault MenuItem.margin Insets - * @uiDefault MenuItem.arrowIcon Icon - * @uiDefault MenuItem.checkIcon Icon - * @uiDefault MenuItem.opaque boolean - * @uiDefault MenuItem.evenHeight boolean + * @uiDefault MenuItem.font Font + * @uiDefault MenuItem.background Color + * @uiDefault MenuItem.foreground Color + * @uiDefault MenuItem.disabledForeground Color + * @uiDefault MenuItem.selectionBackground Color + * @uiDefault MenuItem.selectionForeground Color + * @uiDefault MenuItem.acceleratorForeground Color + * @uiDefault MenuItem.acceleratorSelectionForeground Color + * @uiDefault MenuItem.acceleratorFont Font defaults to MenuItem.font + * @uiDefault MenuItem.acceleratorDelimiter String + * @uiDefault MenuItem.border Border + * @uiDefault MenuItem.borderPainted boolean + * @uiDefault MenuItem.margin Insets + * @uiDefault MenuItem.arrowIcon Icon + * @uiDefault MenuItem.checkIcon Icon + * @uiDefault MenuItem.opaque boolean + * @uiDefault MenuItem.evenHeight boolean + * + * + * + * @uiDefault MenuItem.minimumIconSize Dimension + * @uiDefault MenuItem.textAcceleratorGap int + * @uiDefault MenuItem.acceleratorArrowGap int + * @uiDefault MenuItem.textArrowGap int * * @author Karl Tauber */ public class FlatMenuItemUI extends BasicMenuItemUI { + private FlatMenuItemRenderer renderer; + public static ComponentUI createUI( JComponent c ) { return new FlatMenuItemUI(); } @@ -66,42 +68,28 @@ public class FlatMenuItemUI protected void installDefaults() { super.installDefaults(); - // scale - defaultTextIconGap = scale( defaultTextIconGap ); - } - - /** - * Scale defaultTextIconGap again if iconTextGap property has changed. - */ - @Override - protected PropertyChangeListener createPropertyChangeListener( JComponent c ) { - PropertyChangeListener superListener = super.createPropertyChangeListener( c ); - return e -> { - superListener.propertyChange( e ); - if( e.getPropertyName() == "iconTextGap" ) - defaultTextIconGap = scale( defaultTextIconGap ); - }; + renderer = createRenderer(); } @Override - protected void paintText( Graphics g, JMenuItem menuItem, Rectangle textRect, String text ) { - paintText( g, menuItem, textRect, text, disabledForeground, selectionForeground ); + protected void uninstallDefaults() { + super.uninstallDefaults(); + + renderer = null; } - public static void paintText( Graphics g, JMenuItem menuItem, Rectangle textRect, - String text, Color disabledForeground, Color selectionForeground ) - { - FontMetrics fm = menuItem.getFontMetrics( menuItem.getFont() ); - int mnemonicIndex = FlatLaf.isShowMnemonics() ? menuItem.getDisplayedMnemonicIndex() : -1; + protected FlatMenuItemRenderer createRenderer() { + return new FlatMenuItemRenderer( menuItem, checkIcon, arrowIcon, acceleratorFont, acceleratorDelimiter ); + } - ButtonModel model = menuItem.getModel(); - g.setColor( !model.isEnabled() - ? disabledForeground - : (model.isArmed() || (menuItem instanceof JMenu && model.isSelected()) - ? selectionForeground - : menuItem.getForeground()) ); + @Override + protected Dimension getPreferredMenuItemSize( JComponent c, Icon checkIcon, Icon arrowIcon, int defaultTextIconGap ) { + return renderer.getPreferredMenuItemSize(); + } - FlatUIUtils.drawStringUnderlineCharAt( menuItem, g, text, mnemonicIndex, - textRect.x, textRect.y + fm.getAscent() ); + @Override + public void paint( Graphics g, JComponent c ) { + renderer.paintMenuItem( g, selectionBackground, selectionForeground, disabledForeground, + null, acceleratorForeground, acceleratorSelectionForeground ); } } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuUI.java index aa282875..38ac6b51 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuUI.java @@ -16,13 +16,13 @@ package com.formdev.flatlaf.ui; -import static com.formdev.flatlaf.util.UIScale.scale; import java.awt.Color; +import java.awt.Dimension; +import java.awt.Font; import java.awt.Graphics; -import java.awt.Rectangle; import java.awt.event.MouseEvent; -import java.beans.PropertyChangeListener; import javax.swing.ButtonModel; +import javax.swing.Icon; import javax.swing.JComponent; import javax.swing.JMenu; import javax.swing.JMenuItem; @@ -36,30 +36,37 @@ import javax.swing.plaf.basic.BasicMenuUI; * * * - * @uiDefault Menu.font Font - * @uiDefault Menu.background Color - * @uiDefault Menu.foreground Color - * @uiDefault Menu.disabledForeground Color - * @uiDefault Menu.selectionBackground Color - * @uiDefault Menu.selectionForeground Color - * @uiDefault Menu.acceleratorForeground Color - * @uiDefault Menu.acceleratorSelectionForeground Color - * @uiDefault MenuItem.acceleratorFont Font defaults to MenuItem.font - * @uiDefault MenuItem.acceleratorDelimiter String - * @uiDefault Menu.border Border - * @uiDefault Menu.borderPainted boolean - * @uiDefault Menu.margin Insets - * @uiDefault Menu.arrowIcon Icon - * @uiDefault Menu.checkIcon Icon - * @uiDefault Menu.opaque boolean - * @uiDefault Menu.evenHeight boolean - * @uiDefault Menu.crossMenuMnemonic boolean default is false - * @uiDefault Menu.useMenuBarBackgroundForTopLevel boolean default is false - * @uiDefault MenuBar.background Color used if Menu.useMenuBarBackgroundForTopLevel is true + * @uiDefault Menu.font Font + * @uiDefault Menu.background Color + * @uiDefault Menu.foreground Color + * @uiDefault Menu.disabledForeground Color + * @uiDefault Menu.selectionBackground Color + * @uiDefault Menu.selectionForeground Color + * @uiDefault Menu.acceleratorForeground Color + * @uiDefault Menu.acceleratorSelectionForeground Color + * @uiDefault MenuItem.acceleratorFont Font defaults to MenuItem.font + * @uiDefault MenuItem.acceleratorDelimiter String + * @uiDefault Menu.border Border + * @uiDefault Menu.borderPainted boolean + * @uiDefault Menu.margin Insets + * @uiDefault Menu.arrowIcon Icon + * @uiDefault Menu.checkIcon Icon + * @uiDefault Menu.opaque boolean + * @uiDefault Menu.evenHeight boolean + * @uiDefault Menu.crossMenuMnemonic boolean default is false + * @uiDefault Menu.useMenuBarBackgroundForTopLevel boolean default is false + * @uiDefault MenuBar.background Color used if Menu.useMenuBarBackgroundForTopLevel is true * * * - * @uiDefault MenuBar.hoverBackground Color + * @uiDefault MenuBar.hoverBackground Color + * + * + * + * @uiDefault MenuItem.minimumIconSize Dimension + * @uiDefault MenuItem.textAcceleratorGap int + * @uiDefault MenuItem.acceleratorArrowGap int + * @uiDefault MenuItem.textArrowGap int * * @author Karl Tauber */ @@ -67,6 +74,7 @@ public class FlatMenuUI extends BasicMenuUI { private Color hoverBackground; + private FlatMenuItemRenderer renderer; public static ComponentUI createUI( JComponent c ) { return new FlatMenuUI(); @@ -79,9 +87,7 @@ public class FlatMenuUI menuItem.setRolloverEnabled( true ); hoverBackground = UIManager.getColor( "MenuBar.hoverBackground" ); - - // scale - defaultTextIconGap = scale( defaultTextIconGap ); + renderer = createRenderer(); } @Override @@ -89,19 +95,11 @@ public class FlatMenuUI super.uninstallDefaults(); hoverBackground = null; + renderer = null; } - /** - * Scale defaultTextIconGap again if iconTextGap property has changed. - */ - @Override - protected PropertyChangeListener createPropertyChangeListener( JComponent c ) { - PropertyChangeListener superListener = super.createPropertyChangeListener( c ); - return e -> { - superListener.propertyChange( e ); - if( e.getPropertyName() == "iconTextGap" ) - defaultTextIconGap = scale( defaultTextIconGap ); - }; + protected FlatMenuItemRenderer createRenderer() { + return new FlatMenuRenderer( menuItem, checkIcon, arrowIcon, acceleratorFont, acceleratorDelimiter ); } @Override @@ -130,19 +128,37 @@ public class FlatMenuUI } @Override - protected void paintBackground( Graphics g, JMenuItem menuItem, Color bgColor ) { - ButtonModel model = menuItem.getModel(); - if( model.isArmed() || model.isSelected() ) { - super.paintBackground( g, menuItem, bgColor ); - } else if( model.isRollover() && model.isEnabled() && ((JMenu)menuItem).isTopLevelMenu() ) { - FlatUIUtils.setColor( g, hoverBackground, menuItem.getBackground() ); - g.fillRect( 0, 0, menuItem.getWidth(), menuItem.getHeight() ); - } else - super.paintBackground( g, menuItem, bgColor ); + protected Dimension getPreferredMenuItemSize( JComponent c, Icon checkIcon, Icon arrowIcon, int defaultTextIconGap ) { + return renderer.getPreferredMenuItemSize(); } @Override - protected void paintText( Graphics g, JMenuItem menuItem, Rectangle textRect, String text ) { - FlatMenuItemUI.paintText( g, menuItem, textRect, text, disabledForeground, selectionForeground ); + public void paint( Graphics g, JComponent c ) { + renderer.paintMenuItem( g, selectionBackground, selectionForeground, disabledForeground, + null, acceleratorForeground, acceleratorSelectionForeground ); + } + + //---- class FlatMenuRenderer --------------------------------------------- + + protected class FlatMenuRenderer + extends FlatMenuItemRenderer + { + protected FlatMenuRenderer( JMenuItem menuItem, Icon checkIcon, Icon arrowIcon, + Font acceleratorFont, String acceleratorDelimiter ) + { + super( menuItem, checkIcon, arrowIcon, acceleratorFont, acceleratorDelimiter ); + } + + @Override + protected void paintBackground( Graphics g, Color selectionBackground ) { + ButtonModel model = menuItem.getModel(); + if( model.isRollover() && !model.isArmed() && !model.isSelected() && + model.isEnabled() && ((JMenu)menuItem).isTopLevelMenu() ) + { + FlatUIUtils.setColor( g, hoverBackground, menuItem.getBackground() ); + g.fillRect( 0, 0, menuItem.getWidth(), menuItem.getHeight() ); + } else + super.paintBackground( g, selectionBackground ); + } } } diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRadioButtonMenuItemUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRadioButtonMenuItemUI.java index ef55d3ec..6204500f 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRadioButtonMenuItemUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatRadioButtonMenuItemUI.java @@ -16,12 +16,12 @@ package com.formdev.flatlaf.ui; -import static com.formdev.flatlaf.util.UIScale.scale; +import java.awt.Color; +import java.awt.Dimension; import java.awt.Graphics; -import java.awt.Rectangle; -import java.beans.PropertyChangeListener; +import javax.swing.Icon; import javax.swing.JComponent; -import javax.swing.JMenuItem; +import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.basic.BasicRadioButtonMenuItemUI; @@ -48,11 +48,25 @@ import javax.swing.plaf.basic.BasicRadioButtonMenuItemUI; * @uiDefault RadioButtonMenuItem.opaque boolean * @uiDefault RadioButtonMenuItem.evenHeight boolean * + * + * + * @uiDefault RadioButtonMenuItem.checkBackground Color + * + * + * + * @uiDefault MenuItem.minimumIconSize Dimension + * @uiDefault MenuItem.textAcceleratorGap int + * @uiDefault MenuItem.acceleratorArrowGap int + * @uiDefault MenuItem.textArrowGap int + * * @author Karl Tauber */ public class FlatRadioButtonMenuItemUI extends BasicRadioButtonMenuItemUI { + private Color checkBackground; + private FlatMenuItemRenderer renderer; + public static ComponentUI createUI( JComponent c ) { return new FlatRadioButtonMenuItemUI(); } @@ -61,25 +75,30 @@ public class FlatRadioButtonMenuItemUI protected void installDefaults() { super.installDefaults(); - // scale - defaultTextIconGap = scale( defaultTextIconGap ); - } - - /** - * Scale defaultTextIconGap again if iconTextGap property has changed. - */ - @Override - protected PropertyChangeListener createPropertyChangeListener( JComponent c ) { - PropertyChangeListener superListener = super.createPropertyChangeListener( c ); - return e -> { - superListener.propertyChange( e ); - if( e.getPropertyName() == "iconTextGap" ) - defaultTextIconGap = scale( defaultTextIconGap ); - }; + checkBackground = UIManager.getColor( "RadioButtonMenuItem.checkBackground" ); + renderer = createRenderer(); } @Override - protected void paintText( Graphics g, JMenuItem menuItem, Rectangle textRect, String text ) { - FlatMenuItemUI.paintText( g, menuItem, textRect, text, disabledForeground, selectionForeground ); + protected void uninstallDefaults() { + super.uninstallDefaults(); + + checkBackground = null; + renderer = null; + } + + protected FlatMenuItemRenderer createRenderer() { + return new FlatMenuItemRenderer( menuItem, checkIcon, arrowIcon, acceleratorFont, acceleratorDelimiter ); + } + + @Override + protected Dimension getPreferredMenuItemSize( JComponent c, Icon checkIcon, Icon arrowIcon, int defaultTextIconGap ) { + return renderer.getPreferredMenuItemSize(); + } + + @Override + public void paint( Graphics g, JComponent c ) { + renderer.paintMenuItem( g, selectionBackground, selectionForeground, disabledForeground, + checkBackground, acceleratorForeground, acceleratorSelectionForeground ); } } diff --git a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarkLaf.properties b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarkLaf.properties index 914a3cf9..6cc37334 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarkLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatDarkLaf.properties @@ -29,6 +29,8 @@ @disabledText=#777777 @textComponentBackground=#45494A @menuBackground=darken(@background,5%) +@menuHoverBackground=lighten(@menuBackground,10%) +@menuCheckBackground=lighten(@menuBackground,15%) @cellFocusColor=#000000 @icon=#adadad @@ -53,7 +55,7 @@ *.disabledBackground=@background *.disabledForeground=@disabledText *.disabledText=@disabledText -*.acceleratorForeground=#bbbbbb +*.acceleratorForeground=darken(@foreground,15%) *.acceleratorSelectionForeground=@selectionForeground @@ -170,7 +172,7 @@ Menu.icon.disabledArrowColor=#606060 #---- MenuBar ---- MenuBar.borderColor=#515151 -MenuBar.hoverBackground=lighten($MenuBar.background,10%) +MenuBar.hoverBackground=@menuHoverBackground #---- MenuItemCheckBox ---- diff --git a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties index aa1521f4..af705b1f 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLaf.properties @@ -165,6 +165,7 @@ CheckBoxMenuItem.margin=@menuItemMargin CheckBoxMenuItem.opaque=false CheckBoxMenuItem.borderPainted=true CheckBoxMenuItem.background=@menuBackground +CheckBoxMenuItem.checkBackground=@menuCheckBackground #---- ColorChooser ---- @@ -299,7 +300,7 @@ Menu.background=@menuBackground MenuBar.border=com.formdev.flatlaf.ui.FlatMenuBarBorder MenuBar.background=@menuBackground -MenuBar.itemMargins=3,3,3,3 +MenuBar.itemMargins=3,8,3,8 #---- MenuItem ---- @@ -311,9 +312,18 @@ MenuItem.margin=@menuItemMargin MenuItem.opaque=false MenuItem.borderPainted=true MenuItem.background=@menuBackground +MenuItem.minimumWidth=72 +MenuItem.minimumIconSize=16,16 +MenuItem.textAcceleratorGap=24 +MenuItem.textArrowGap=8 MenuItem.acceleratorDelimiter=- [mac]MenuItem.acceleratorDelimiter= +# for MenuItem.selectionType=underline +MenuItem.underlineSelectionBackground=@menuHoverBackground +MenuItem.underlineSelectionColor=$TabbedPane.underlineColor +MenuItem.underlineSelectionHeight=3 + #---- OptionPane ---- @@ -391,6 +401,7 @@ RadioButtonMenuItem.margin=@menuItemMargin RadioButtonMenuItem.opaque=false RadioButtonMenuItem.borderPainted=true RadioButtonMenuItem.background=@menuBackground +RadioButtonMenuItem.checkBackground=@menuCheckBackground #---- ScrollBar ---- diff --git a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLightLaf.properties b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLightLaf.properties index d5e44045..12e9bc61 100644 --- a/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLightLaf.properties +++ b/flatlaf-core/src/main/resources/com/formdev/flatlaf/FlatLightLaf.properties @@ -29,6 +29,8 @@ @disabledText=#8C8C8C @textComponentBackground=#ffffff @menuBackground=#fff +@menuHoverBackground=darken(@menuBackground,10%) +@menuCheckBackground=darken(@menuBackground,15%) @cellFocusColor=#000000 @icon=#afafaf @@ -53,7 +55,7 @@ *.disabledBackground=@background *.disabledForeground=@disabledText *.disabledText=@disabledText -*.acceleratorForeground=#505050 +*.acceleratorForeground=lighten(@foreground,30%) *.acceleratorSelectionForeground=@selectionForeground @@ -177,7 +179,7 @@ Menu.icon.disabledArrowColor=#ABABAB #---- MenuBar ---- MenuBar.borderColor=#cdcdcd -MenuBar.hoverBackground=darken($MenuBar.background,10%) +MenuBar.hoverBackground=@menuHoverBackground #---- MenuItemCheckBox ---- diff --git a/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DemoFrame.java b/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DemoFrame.java index e204a15f..92ec5ead 100644 --- a/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DemoFrame.java +++ b/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DemoFrame.java @@ -59,6 +59,11 @@ class DemoFrame } ); } + private void underlineMenuSelection() { + UIManager.put( "MenuItem.selectionType", underlineMenuSelectionMenuItem.isSelected() ? "underline" : null ); + FlatLaf.updateUI(); + } + private void fontFamilyChanged( ActionEvent e ) { String fontFamily = e.getActionCommand(); @@ -132,6 +137,8 @@ class DemoFrame JMenuItem restoreFontMenuItem = new JMenuItem(); JMenuItem incrFontMenuItem = new JMenuItem(); JMenuItem decrFontMenuItem = new JMenuItem(); + JMenu optionsMenu = new JMenu(); + underlineMenuSelectionMenuItem = new JCheckBoxMenuItem(); JMenu helpMenu = new JMenu(); JMenuItem aboutMenuItem = new JMenuItem(); JToolBar toolBar1 = new JToolBar(); @@ -355,6 +362,17 @@ class DemoFrame } menuBar1.add(fontMenu); + //======== optionsMenu ======== + { + optionsMenu.setText("Options"); + + //---- underlineMenuSelectionMenuItem ---- + underlineMenuSelectionMenuItem.setText("Use underline menu selection"); + underlineMenuSelectionMenuItem.addActionListener(e -> underlineMenuSelection()); + optionsMenu.add(underlineMenuSelectionMenuItem); + } + menuBar1.add(optionsMenu); + //======== helpMenu ======== { helpMenu.setText("Help"); @@ -481,6 +499,7 @@ class DemoFrame // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables private JMenu fontMenu; + private JCheckBoxMenuItem underlineMenuSelectionMenuItem; private JTabbedPane tabbedPane; private ControlBar controlBar; // JFormDesigner - End of variables declaration //GEN-END:variables diff --git a/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DemoFrame.jfd b/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DemoFrame.jfd index 12717383..c3df8d44 100644 --- a/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DemoFrame.jfd +++ b/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DemoFrame.jfd @@ -310,6 +310,18 @@ new FormModel { addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "decrFont", false ) ) } ) } ) + add( new FormContainer( "javax.swing.JMenu", new FormLayoutManager( class javax.swing.JMenu ) ) { + name: "optionsMenu" + "text": "Options" + add( new FormComponent( "javax.swing.JCheckBoxMenuItem" ) { + name: "underlineMenuSelectionMenuItem" + "text": "Use underline menu selection" + auxiliary() { + "JavaCodeGenerator.variableLocal": false + } + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "underlineMenuSelection", false ) ) + } ) + } ) add( new FormContainer( "javax.swing.JMenu", new FormLayoutManager( class javax.swing.JMenu ) ) { name: "helpMenu" "text": "Help" diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatMenusTest.java b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatMenusTest.java index 52d8390a..deeff5d4 100644 --- a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatMenusTest.java +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatMenusTest.java @@ -18,8 +18,13 @@ package com.formdev.flatlaf.testing; import java.awt.Component; import java.awt.Container; +import java.awt.Dimension; +import java.awt.Graphics; import java.awt.event.*; +import java.util.function.Supplier; import javax.swing.*; +import com.formdev.flatlaf.FlatLaf; +import com.formdev.flatlaf.util.UIScale; import net.miginfocom.swing.*; /** @@ -31,12 +36,15 @@ public class FlatMenusTest public static void main( String[] args ) { SwingUtilities.invokeLater( () -> { FlatTestFrame frame = FlatTestFrame.create( args, "FlatMenusTest" ); + frame.useApplyComponentOrientation = true; frame.showFrame( FlatMenusTest::new ); } ); } FlatMenusTest() { initComponents(); + + largerCheckBox.setSelected( LargerMenuItem.useLargerSize ); } private void armedChanged() { @@ -54,6 +62,11 @@ public class FlatMenusTest } } + private void underlineChanged() { + UIManager.put( "MenuItem.selectionType", underlineCheckBox.isSelected() ? "underline" : null ); + FlatLaf.updateUI(); + } + private void showPopupMenuButtonActionPerformed(ActionEvent e) { Component invoker = (Component) e.getSource(); PopupMenu popupMenu = new PopupMenu(); @@ -61,16 +74,102 @@ public class FlatMenusTest popupMenu.show( invoker, 0, invoker.getHeight() ); } + private void largerChanged() { + LargerMenuItem.useLargerSize = largerCheckBox.isSelected(); + menuBar2.revalidate(); + } + + private void accelChanged() { + updateAccel( menuBar2, () -> { + return accelCheckBox.isSelected() ? getRandomKeyStroke() : null; + } ); + } + + private void updateAccel( Component c, Supplier keyStrokeSupplier ) { + if( c instanceof JMenuItem && !(c instanceof JMenu) ) + ((JMenuItem)c).setAccelerator( keyStrokeSupplier.get() ); + + if( c instanceof Container ) { + for( Component c2 : ((Container)c).getComponents() ) + updateAccel( c2, keyStrokeSupplier ); + } + if( c instanceof JMenu ) { + randomKeyStrokeIndex = 0; + JMenu menu = (JMenu) c; + int itemCount = menu.getItemCount(); + for( int i = 0; i < itemCount; i++ ) + updateAccel( menu.getItem( i ), keyStrokeSupplier ); + } + } + + private KeyStroke getRandomKeyStroke() { + if( randomKeyStrokeIndex >= randomKeyStrokes.length ) + randomKeyStrokeIndex = 0; + return randomKeyStrokes[randomKeyStrokeIndex++]; + } + + private int randomKeyStrokeIndex = 0; + private final KeyStroke[] randomKeyStrokes = { + KeyStroke.getKeyStroke( KeyEvent.VK_F2, 0 ), + KeyStroke.getKeyStroke( KeyEvent.VK_A, KeyEvent.CTRL_MASK ), + KeyStroke.getKeyStroke( KeyEvent.VK_B, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK ), + KeyStroke.getKeyStroke( KeyEvent.VK_BACK_SPACE, 0 ), + KeyStroke.getKeyStroke( KeyEvent.VK_PAGE_UP, 0 ), + KeyStroke.getKeyStroke( KeyEvent.VK_C, KeyEvent.ALT_MASK ), + KeyStroke.getKeyStroke( KeyEvent.VK_ENTER, 0 ), + KeyStroke.getKeyStroke( KeyEvent.VK_F10, 0 ), + KeyStroke.getKeyStroke( KeyEvent.VK_0, 0 ), + }; + private void initComponents() { // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents JLabel menuBarLabel = new JLabel(); JMenuBar menuBar1 = new JMenuBar(); JMenu menu5 = new JMenu(); + JMenuItem menuItem35 = new JMenuItem(); JMenuItem menuItem7 = new JMenuItem(); + JMenuItem menuItem34 = new JMenuItem(); JMenuItem menuItem8 = new JMenuItem(); + JMenu menu11 = new JMenu(); + JMenuItem menuItem36 = new JMenuItem(); + JMenuItem menuItem37 = new JMenuItem(); + JCheckBoxMenuItem checkBoxMenuItem6 = new JCheckBoxMenuItem(); + JCheckBoxMenuItem checkBoxMenuItem7 = new JCheckBoxMenuItem(); + JRadioButtonMenuItem radioButtonMenuItem5 = new JRadioButtonMenuItem(); + JRadioButtonMenuItem radioButtonMenuItem6 = new JRadioButtonMenuItem(); + JRadioButtonMenuItem radioButtonMenuItem8 = new JRadioButtonMenuItem(); + JRadioButtonMenuItem radioButtonMenuItem9 = new JRadioButtonMenuItem(); JMenu menu6 = new JMenu(); JMenuItem menuItem5 = new JMenuItem(); JMenuItem menuItem6 = new JMenuItem(); + menuBar2 = new JMenuBar(); + JMenu menu8 = new JMenu(); + FlatMenusTest.LargerMenuItem menuItem13 = new FlatMenusTest.LargerMenuItem(); + FlatMenusTest.LargerMenuItem menuItem14 = new FlatMenusTest.LargerMenuItem(); + FlatMenusTest.LargerMenuItem menuItem27 = new FlatMenusTest.LargerMenuItem(); + FlatMenusTest.LargerMenuItem menuItem15 = new FlatMenusTest.LargerMenuItem(); + FlatMenusTest.LargerMenuItem menuItem16 = new FlatMenusTest.LargerMenuItem(); + FlatMenusTest.LargerMenuItem menuItem28 = new FlatMenusTest.LargerMenuItem(); + FlatMenusTest.LargerMenuItem menuItem18 = new FlatMenusTest.LargerMenuItem(); + FlatMenusTest.LargerMenuItem menuItem17 = new FlatMenusTest.LargerMenuItem(); + FlatMenusTest.LargerMenuItem menuItem19 = new FlatMenusTest.LargerMenuItem(); + JMenuItem menuItem31 = new JMenuItem(); + JMenu menu9 = new JMenu(); + FlatMenusTest.LargerMenuItem menuItem20 = new FlatMenusTest.LargerMenuItem(); + FlatMenusTest.LargerMenuItem menuItem21 = new FlatMenusTest.LargerMenuItem(); + FlatMenusTest.LargerMenuItem menuItem29 = new FlatMenusTest.LargerMenuItem(); + FlatMenusTest.LargerMenuItem menuItem22 = new FlatMenusTest.LargerMenuItem(); + FlatMenusTest.LargerMenuItem menuItem23 = new FlatMenusTest.LargerMenuItem(); + FlatMenusTest.LargerMenuItem menuItem30 = new FlatMenusTest.LargerMenuItem(); + FlatMenusTest.LargerMenuItem menuItem25 = new FlatMenusTest.LargerMenuItem(); + FlatMenusTest.LargerMenuItem menuItem24 = new FlatMenusTest.LargerMenuItem(); + FlatMenusTest.LargerMenuItem menuItem26 = new FlatMenusTest.LargerMenuItem(); + JMenuItem menuItem32 = new JMenuItem(); + JMenu menu10 = new JMenu(); + FlatMenusTest.LargerMenuItem menuItem33 = new FlatMenusTest.LargerMenuItem(); + JPanel panel5 = new JPanel(); + largerCheckBox = new JCheckBox(); + accelCheckBox = new JCheckBox(); JPanel panel1 = new JPanel(); JLabel menuLabel = new JLabel(); JMenu menu1 = new JMenu(); @@ -100,6 +199,7 @@ public class FlatMenusTest JLabel popupMenuLabel = new JLabel(); JButton showPopupMenuButton = new JButton(); armedCheckBox = new JCheckBox(); + underlineCheckBox = new JCheckBox(); //======== this ======== setLayout(new MigLayout( @@ -114,6 +214,7 @@ public class FlatMenusTest "[]" + "[top]" + "[]" + + "[]" + "[]")); //---- menuBarLabel ---- @@ -127,16 +228,77 @@ public class FlatMenusTest { menu5.setText("text"); menu5.setMnemonic('T'); + menu5.setIcon(new ImageIcon(getClass().getResource("/com/formdev/flatlaf/testing/disabled_icons_test/intellij-showReadAccess.png"))); + + //---- menuItem35 ---- + menuItem35.setText("text"); + menu5.add(menuItem35); //---- menuItem7 ---- menuItem7.setText("text"); menuItem7.setMnemonic('X'); + menuItem7.setIcon(new ImageIcon(getClass().getResource("/com/formdev/flatlaf/testing/disabled_icons_test/intellij-showWriteAccess.png"))); + menuItem7.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_J, KeyEvent.CTRL_MASK|KeyEvent.SHIFT_MASK)); menu5.add(menuItem7); + //---- menuItem34 ---- + menuItem34.setText("longer text longer text"); + menuItem34.setMnemonic('E'); + menuItem34.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, 0)); + menu5.add(menuItem34); + //---- menuItem8 ---- - menuItem8.setText("text"); + menuItem8.setText("longer text longer text longer"); menuItem8.setMnemonic('E'); menu5.add(menuItem8); + + //======== menu11 ======== + { + menu11.setText("sub menu"); + + //---- menuItem36 ---- + menuItem36.setText("text"); + menu11.add(menuItem36); + + //---- menuItem37 ---- + menuItem37.setText("text"); + menu11.add(menuItem37); + } + menu5.add(menu11); + menu5.addSeparator(); + + //---- checkBoxMenuItem6 ---- + checkBoxMenuItem6.setText("check"); + checkBoxMenuItem6.setSelected(true); + menu5.add(checkBoxMenuItem6); + + //---- checkBoxMenuItem7 ---- + checkBoxMenuItem7.setText("check with icon"); + checkBoxMenuItem7.setSelected(true); + checkBoxMenuItem7.setIcon(new ImageIcon(getClass().getResource("/com/formdev/flatlaf/testing/disabled_icons_test/intellij-showReadAccess.png"))); + menu5.add(checkBoxMenuItem7); + menu5.addSeparator(); + + //---- radioButtonMenuItem5 ---- + radioButtonMenuItem5.setText("radio 1"); + radioButtonMenuItem5.setSelected(true); + menu5.add(radioButtonMenuItem5); + + //---- radioButtonMenuItem6 ---- + radioButtonMenuItem6.setText("radio 2"); + menu5.add(radioButtonMenuItem6); + menu5.addSeparator(); + + //---- radioButtonMenuItem8 ---- + radioButtonMenuItem8.setText("radio with icon 1"); + radioButtonMenuItem8.setSelected(true); + radioButtonMenuItem8.setIcon(new ImageIcon(getClass().getResource("/com/formdev/flatlaf/testing/disabled_icons_test/intellij-showReadAccess.png"))); + menu5.add(radioButtonMenuItem8); + + //---- radioButtonMenuItem9 ---- + radioButtonMenuItem9.setText("radio with icon 2"); + radioButtonMenuItem9.setIcon(new ImageIcon(getClass().getResource("/com/formdev/flatlaf/testing/disabled_icons_test/intellij-showWriteAccess.png"))); + menu5.add(radioButtonMenuItem9); } menuBar1.add(menu5); @@ -154,7 +316,182 @@ public class FlatMenusTest } menuBar1.add(menu6); } - add(menuBar1, "cell 1 0 4 1,growx"); + add(menuBar1, "cell 1 0 2 1,growx"); + + //======== menuBar2 ======== + { + + //======== menu8 ======== + { + menu8.setText("text position"); + menu8.setIcon(new ImageIcon(getClass().getResource("/com/formdev/flatlaf/testing/disabled_icons_test/intellij-menu-paste.png"))); + menu8.setHorizontalTextPosition(SwingConstants.CENTER); + menu8.setVerticalTextPosition(SwingConstants.BOTTOM); + + //---- menuItem13 ---- + menuItem13.setText("vert top"); + menuItem13.setIcon(new ImageIcon(getClass().getResource("/com/formdev/flatlaf/testing/disabled_icons_test/intellij-menu-paste@2x.png"))); + menuItem13.setVerticalTextPosition(SwingConstants.TOP); + menu8.add(menuItem13); + + //---- menuItem14 ---- + menuItem14.setText("vert bottom"); + menuItem14.setIcon(new ImageIcon(getClass().getResource("/com/formdev/flatlaf/testing/disabled_icons_test/intellij-menu-paste@2x.png"))); + menuItem14.setVerticalTextPosition(SwingConstants.BOTTOM); + menu8.add(menuItem14); + + //---- menuItem27 ---- + menuItem27.setText("horz leading"); + menuItem27.setIcon(new ImageIcon(getClass().getResource("/com/formdev/flatlaf/testing/disabled_icons_test/intellij-menu-paste@2x.png"))); + menuItem27.setHorizontalTextPosition(SwingConstants.LEADING); + menu8.add(menuItem27); + + //---- menuItem15 ---- + menuItem15.setText("horz left"); + menuItem15.setIcon(new ImageIcon(getClass().getResource("/com/formdev/flatlaf/testing/disabled_icons_test/intellij-menu-paste@2x.png"))); + menuItem15.setHorizontalTextPosition(SwingConstants.LEFT); + menu8.add(menuItem15); + + //---- menuItem16 ---- + menuItem16.setText("horz right"); + menuItem16.setIcon(new ImageIcon(getClass().getResource("/com/formdev/flatlaf/testing/disabled_icons_test/intellij-menu-paste@2x.png"))); + menuItem16.setHorizontalTextPosition(SwingConstants.RIGHT); + menu8.add(menuItem16); + + //---- menuItem28 ---- + menuItem28.setText("horz trailing"); + menuItem28.setIcon(new ImageIcon(getClass().getResource("/com/formdev/flatlaf/testing/disabled_icons_test/intellij-menu-paste@2x.png"))); + menu8.add(menuItem28); + + //---- menuItem18 ---- + menuItem18.setText("horz center / vert top"); + menuItem18.setIcon(new ImageIcon(getClass().getResource("/com/formdev/flatlaf/testing/disabled_icons_test/intellij-menu-paste@2x.png"))); + menuItem18.setHorizontalTextPosition(SwingConstants.CENTER); + menuItem18.setVerticalTextPosition(SwingConstants.TOP); + menu8.add(menuItem18); + + //---- menuItem17 ---- + menuItem17.setText("horz center / vert bottom"); + menuItem17.setIcon(new ImageIcon(getClass().getResource("/com/formdev/flatlaf/testing/disabled_icons_test/intellij-menu-paste@2x.png"))); + menuItem17.setHorizontalTextPosition(SwingConstants.CENTER); + menuItem17.setVerticalTextPosition(SwingConstants.BOTTOM); + menu8.add(menuItem17); + + //---- menuItem19 ---- + menuItem19.setText("horz center / vert center"); + menuItem19.setIcon(new ImageIcon(getClass().getResource("/com/formdev/flatlaf/testing/disabled_icons_test/intellij-menu-paste@2x.png"))); + menuItem19.setHorizontalTextPosition(SwingConstants.CENTER); + menu8.add(menuItem19); + + //---- menuItem31 ---- + menuItem31.setText("1234567890123456789012345678901234567890"); + menu8.add(menuItem31); + } + menuBar2.add(menu8); + + //======== menu9 ======== + { + menu9.setText("alignment"); + menu9.setIcon(new ImageIcon(getClass().getResource("/com/formdev/flatlaf/testing/disabled_icons_test/intellij-menu-paste.png"))); + menu9.setHorizontalTextPosition(SwingConstants.CENTER); + menu9.setVerticalTextPosition(SwingConstants.TOP); + + //---- menuItem20 ---- + menuItem20.setText("vert top"); + menuItem20.setIcon(new ImageIcon(getClass().getResource("/com/formdev/flatlaf/testing/disabled_icons_test/intellij-menu-paste@2x.png"))); + menuItem20.setVerticalAlignment(SwingConstants.TOP); + menu9.add(menuItem20); + + //---- menuItem21 ---- + menuItem21.setText("vert bottom"); + menuItem21.setIcon(new ImageIcon(getClass().getResource("/com/formdev/flatlaf/testing/disabled_icons_test/intellij-menu-paste@2x.png"))); + menuItem21.setVerticalAlignment(SwingConstants.BOTTOM); + menu9.add(menuItem21); + + //---- menuItem29 ---- + menuItem29.setText("horz leading"); + menuItem29.setIcon(new ImageIcon(getClass().getResource("/com/formdev/flatlaf/testing/disabled_icons_test/intellij-menu-paste@2x.png"))); + menu9.add(menuItem29); + + //---- menuItem22 ---- + menuItem22.setText("horz left"); + menuItem22.setIcon(new ImageIcon(getClass().getResource("/com/formdev/flatlaf/testing/disabled_icons_test/intellij-menu-paste@2x.png"))); + menuItem22.setHorizontalAlignment(SwingConstants.LEFT); + menu9.add(menuItem22); + + //---- menuItem23 ---- + menuItem23.setText("horz right"); + menuItem23.setIcon(new ImageIcon(getClass().getResource("/com/formdev/flatlaf/testing/disabled_icons_test/intellij-menu-paste@2x.png"))); + menuItem23.setHorizontalAlignment(SwingConstants.RIGHT); + menu9.add(menuItem23); + + //---- menuItem30 ---- + menuItem30.setText("horz trailing"); + menuItem30.setIcon(new ImageIcon(getClass().getResource("/com/formdev/flatlaf/testing/disabled_icons_test/intellij-menu-paste@2x.png"))); + menuItem30.setHorizontalAlignment(SwingConstants.TRAILING); + menu9.add(menuItem30); + + //---- menuItem25 ---- + menuItem25.setText("horz center / vert top"); + menuItem25.setIcon(new ImageIcon(getClass().getResource("/com/formdev/flatlaf/testing/disabled_icons_test/intellij-menu-paste@2x.png"))); + menuItem25.setHorizontalAlignment(SwingConstants.CENTER); + menuItem25.setVerticalAlignment(SwingConstants.TOP); + menu9.add(menuItem25); + + //---- menuItem24 ---- + menuItem24.setText("horz center / vert bottom"); + menuItem24.setIcon(new ImageIcon(getClass().getResource("/com/formdev/flatlaf/testing/disabled_icons_test/intellij-menu-paste@2x.png"))); + menuItem24.setHorizontalAlignment(SwingConstants.CENTER); + menuItem24.setVerticalAlignment(SwingConstants.BOTTOM); + menu9.add(menuItem24); + + //---- menuItem26 ---- + menuItem26.setText("horz center / vert center"); + menuItem26.setIcon(new ImageIcon(getClass().getResource("/com/formdev/flatlaf/testing/disabled_icons_test/intellij-menu-paste@2x.png"))); + menuItem26.setHorizontalAlignment(SwingConstants.CENTER); + menu9.add(menuItem26); + + //---- menuItem32 ---- + menuItem32.setText("1234567890123456789012345678901234567890"); + menu9.add(menuItem32); + } + menuBar2.add(menu9); + + //======== menu10 ======== + { + menu10.setIcon(new ImageIcon(getClass().getResource("/com/formdev/flatlaf/testing/disabled_icons_test/intellij-menu-paste@2x.png"))); + menu10.setHorizontalTextPosition(SwingConstants.CENTER); + menu10.setVerticalTextPosition(SwingConstants.TOP); + + //---- menuItem33 ---- + menuItem33.setIcon(new ImageIcon(getClass().getResource("/com/formdev/flatlaf/testing/disabled_icons_test/intellij-menu-paste@2x.png"))); + menu10.add(menuItem33); + } + menuBar2.add(menu10); + } + add(menuBar2, "cell 3 0 2 1,growx"); + + //======== panel5 ======== + { + panel5.setLayout(new MigLayout( + "ltr,insets 0,hidemode 3", + // columns + "[]", + // rows + "[]0" + + "[]")); + + //---- largerCheckBox ---- + largerCheckBox.setText("larger"); + largerCheckBox.addActionListener(e -> largerChanged()); + panel5.add(largerCheckBox, "cell 0 0"); + + //---- accelCheckBox ---- + accelCheckBox.setText("accel"); + accelCheckBox.addActionListener(e -> accelChanged()); + panel5.add(accelCheckBox, "cell 0 1"); + } + add(panel5, "cell 3 0 2 1"); //======== panel1 ======== { @@ -197,7 +534,7 @@ public class FlatMenusTest panel1.add(checkBoxMenuItemLabel, "cell 0 2"); //---- checkBoxMenuItem1 ---- - checkBoxMenuItem1.setText("enabled"); + checkBoxMenuItem1.setText("enabled"); checkBoxMenuItem1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0)); checkBoxMenuItem1.setMnemonic('A'); panel1.add(checkBoxMenuItem1, "cell 1 2"); @@ -361,13 +698,34 @@ public class FlatMenusTest armedCheckBox.setMnemonic('A'); armedCheckBox.addActionListener(e -> armedChanged()); add(armedCheckBox, "cell 0 3"); + + //---- underlineCheckBox ---- + underlineCheckBox.setText("underline menu selection"); + underlineCheckBox.addActionListener(e -> underlineChanged()); + add(underlineCheckBox, "cell 0 4 2 1"); + + //---- buttonGroup1 ---- + ButtonGroup buttonGroup1 = new ButtonGroup(); + buttonGroup1.add(radioButtonMenuItem5); + buttonGroup1.add(radioButtonMenuItem6); + + //---- buttonGroup2 ---- + ButtonGroup buttonGroup2 = new ButtonGroup(); + buttonGroup2.add(radioButtonMenuItem8); + buttonGroup2.add(radioButtonMenuItem9); // JFormDesigner - End of component initialization //GEN-END:initComponents } // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables + private JMenuBar menuBar2; + private JCheckBox largerCheckBox; + private JCheckBox accelCheckBox; private JCheckBox armedCheckBox; + private JCheckBox underlineCheckBox; // JFormDesigner - End of variables declaration //GEN-END:variables + //---- class PopupMenu ---------------------------------------------------- + private class PopupMenu extends JPopupMenu { private PopupMenu() { initComponents(); @@ -417,4 +775,30 @@ public class FlatMenusTest // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables // JFormDesigner - End of variables declaration //GEN-END:variables } + + //---- class LargerMenuItem ----------------------------------------------- + + public static class LargerMenuItem + extends JMenuItem + { + static boolean useLargerSize = true; + + @Override + public Dimension getPreferredSize() { + Dimension size = super.getPreferredSize(); + return useLargerSize + ? new Dimension( size.width + UIScale.scale( 40 ), + size.height + UIScale.scale( 30 ) ) + : size; + } + + @Override + protected void paintComponent( Graphics g ) { + super.paintComponent( g ); + + g.setColor( UIManager.getColor( "Separator.foreground" ) ); + g.drawLine( 0, 0, getWidth(), 0 ); + g.drawLine( 0, getHeight(), getWidth(), getHeight() ); + } + } } diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatMenusTest.jfd b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatMenusTest.jfd index 2700ef0b..5e30b3da 100644 --- a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatMenusTest.jfd +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatMenusTest.jfd @@ -1,4 +1,4 @@ -JFDML JFormDesigner: "7.0.0.0.194" Java: "13.0.1" encoding: "UTF-8" +JFDML JFormDesigner: "7.0.1.0.272" Java: "13.0.2" encoding: "UTF-8" new FormModel { contentType: "form/swing" @@ -9,7 +9,7 @@ new FormModel { add( new FormContainer( "com.formdev.flatlaf.testing.FlatTestPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) { "$layoutConstraints": "ltr,insets dialog,hidemode 3" "$columnConstraints": "[125][][][][]" - "$rowConstraints": "[][top][][]" + "$rowConstraints": "[][top][][][]" } ) { name: "this" add( new FormComponent( "javax.swing.JLabel" ) { @@ -24,16 +24,85 @@ new FormModel { name: "menu5" "text": "text" "mnemonic": 84 + "icon": new com.jformdesigner.model.SwingIcon( 0, "/com/formdev/flatlaf/testing/disabled_icons_test/intellij-showReadAccess.png" ) + add( new FormComponent( "javax.swing.JMenuItem" ) { + name: "menuItem35" + "text": "text" + } ) add( new FormComponent( "javax.swing.JMenuItem" ) { name: "menuItem7" "text": "text" "mnemonic": 88 + "icon": new com.jformdesigner.model.SwingIcon( 0, "/com/formdev/flatlaf/testing/disabled_icons_test/intellij-showWriteAccess.png" ) + "accelerator": static javax.swing.KeyStroke getKeyStroke( 74, 195, false ) + } ) + add( new FormComponent( "javax.swing.JMenuItem" ) { + name: "menuItem34" + "text": "longer text longer text" + "mnemonic": 69 + "accelerator": static javax.swing.KeyStroke getKeyStroke( 115, 0, false ) } ) add( new FormComponent( "javax.swing.JMenuItem" ) { name: "menuItem8" - "text": "text" + "text": "longer text longer text longer" "mnemonic": 69 } ) + add( new FormContainer( "javax.swing.JMenu", new FormLayoutManager( class javax.swing.JMenu ) ) { + name: "menu11" + "text": "sub menu" + add( new FormComponent( "javax.swing.JMenuItem" ) { + name: "menuItem36" + "text": "text" + } ) + add( new FormComponent( "javax.swing.JMenuItem" ) { + name: "menuItem37" + "text": "text" + } ) + } ) + add( new FormComponent( "javax.swing.JPopupMenu$Separator" ) { + name: "separator3" + } ) + add( new FormComponent( "javax.swing.JCheckBoxMenuItem" ) { + name: "checkBoxMenuItem6" + "text": "check" + "selected": true + } ) + add( new FormComponent( "javax.swing.JCheckBoxMenuItem" ) { + name: "checkBoxMenuItem7" + "text": "check with icon" + "selected": true + "icon": new com.jformdesigner.model.SwingIcon( 0, "/com/formdev/flatlaf/testing/disabled_icons_test/intellij-showReadAccess.png" ) + } ) + add( new FormComponent( "javax.swing.JPopupMenu$Separator" ) { + name: "separator5" + } ) + add( new FormComponent( "javax.swing.JRadioButtonMenuItem" ) { + name: "radioButtonMenuItem5" + "text": "radio 1" + "$buttonGroup": new FormReference( "buttonGroup1" ) + "selected": true + } ) + add( new FormComponent( "javax.swing.JRadioButtonMenuItem" ) { + name: "radioButtonMenuItem6" + "text": "radio 2" + "$buttonGroup": new FormReference( "buttonGroup1" ) + } ) + add( new FormComponent( "javax.swing.JPopupMenu$Separator" ) { + name: "separator4" + } ) + add( new FormComponent( "javax.swing.JRadioButtonMenuItem" ) { + name: "radioButtonMenuItem8" + "text": "radio with icon 1" + "selected": true + "$buttonGroup": new FormReference( "buttonGroup2" ) + "icon": new com.jformdesigner.model.SwingIcon( 0, "/com/formdev/flatlaf/testing/disabled_icons_test/intellij-showReadAccess.png" ) + } ) + add( new FormComponent( "javax.swing.JRadioButtonMenuItem" ) { + name: "radioButtonMenuItem9" + "text": "radio with icon 2" + "$buttonGroup": new FormReference( "buttonGroup2" ) + "icon": new com.jformdesigner.model.SwingIcon( 0, "/com/formdev/flatlaf/testing/disabled_icons_test/intellij-showWriteAccess.png" ) + } ) } ) add( new FormContainer( "javax.swing.JMenu", new FormLayoutManager( class javax.swing.JMenu ) ) { name: "menu6" @@ -48,7 +117,186 @@ new FormModel { } ) } ) }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { - "value": "cell 1 0 4 1,growx" + "value": "cell 1 0 2 1,growx" + } ) + add( new FormContainer( "javax.swing.JMenuBar", new FormLayoutManager( class javax.swing.JMenuBar ) ) { + name: "menuBar2" + auxiliary() { + "JavaCodeGenerator.variableLocal": false + } + add( new FormContainer( "javax.swing.JMenu", new FormLayoutManager( class javax.swing.JMenu ) ) { + name: "menu8" + "text": "text position" + "icon": &SwingIcon0 new com.jformdesigner.model.SwingIcon( 0, "/com/formdev/flatlaf/testing/disabled_icons_test/intellij-menu-paste.png" ) + "horizontalTextPosition": 0 + "verticalTextPosition": 3 + add( new FormComponent( "com.formdev.flatlaf.testing.FlatMenusTest$LargerMenuItem" ) { + name: "menuItem13" + "text": "vert top" + "icon": &SwingIcon1 new com.jformdesigner.model.SwingIcon( 0, "/com/formdev/flatlaf/testing/disabled_icons_test/intellij-menu-paste@2x.png" ) + "verticalTextPosition": 1 + } ) + add( new FormComponent( "com.formdev.flatlaf.testing.FlatMenusTest$LargerMenuItem" ) { + name: "menuItem14" + "text": "vert bottom" + "icon": #SwingIcon1 + "verticalTextPosition": 3 + } ) + add( new FormComponent( "com.formdev.flatlaf.testing.FlatMenusTest$LargerMenuItem" ) { + name: "menuItem27" + "text": "horz leading" + "icon": &SwingIcon2 new com.jformdesigner.model.SwingIcon( 0, "/com/formdev/flatlaf/testing/disabled_icons_test/intellij-menu-paste@2x.png" ) + "horizontalTextPosition": 10 + } ) + add( new FormComponent( "com.formdev.flatlaf.testing.FlatMenusTest$LargerMenuItem" ) { + name: "menuItem15" + "text": "horz left" + "icon": #SwingIcon2 + "horizontalTextPosition": 2 + } ) + add( new FormComponent( "com.formdev.flatlaf.testing.FlatMenusTest$LargerMenuItem" ) { + name: "menuItem16" + "text": "horz right" + "icon": #SwingIcon2 + "horizontalTextPosition": 4 + } ) + add( new FormComponent( "com.formdev.flatlaf.testing.FlatMenusTest$LargerMenuItem" ) { + name: "menuItem28" + "text": "horz trailing" + "icon": #SwingIcon2 + } ) + add( new FormComponent( "com.formdev.flatlaf.testing.FlatMenusTest$LargerMenuItem" ) { + name: "menuItem18" + "text": "horz center / vert top" + "icon": #SwingIcon2 + "horizontalTextPosition": 0 + "verticalTextPosition": 1 + } ) + add( new FormComponent( "com.formdev.flatlaf.testing.FlatMenusTest$LargerMenuItem" ) { + name: "menuItem17" + "text": "horz center / vert bottom" + "icon": #SwingIcon2 + "horizontalTextPosition": 0 + "verticalTextPosition": 3 + } ) + add( new FormComponent( "com.formdev.flatlaf.testing.FlatMenusTest$LargerMenuItem" ) { + name: "menuItem19" + "text": "horz center / vert center" + "icon": #SwingIcon2 + "horizontalTextPosition": 0 + } ) + add( new FormComponent( "javax.swing.JMenuItem" ) { + name: "menuItem31" + "text": "1234567890123456789012345678901234567890" + } ) + } ) + add( new FormContainer( "javax.swing.JMenu", new FormLayoutManager( class javax.swing.JMenu ) ) { + name: "menu9" + "text": "alignment" + "icon": #SwingIcon0 + "horizontalTextPosition": 0 + "verticalTextPosition": 1 + add( new FormComponent( "com.formdev.flatlaf.testing.FlatMenusTest$LargerMenuItem" ) { + name: "menuItem20" + "text": "vert top" + "icon": #SwingIcon1 + "verticalAlignment": 1 + } ) + add( new FormComponent( "com.formdev.flatlaf.testing.FlatMenusTest$LargerMenuItem" ) { + name: "menuItem21" + "text": "vert bottom" + "icon": #SwingIcon1 + "verticalAlignment": 3 + } ) + add( new FormComponent( "com.formdev.flatlaf.testing.FlatMenusTest$LargerMenuItem" ) { + name: "menuItem29" + "text": "horz leading" + "icon": #SwingIcon2 + } ) + add( new FormComponent( "com.formdev.flatlaf.testing.FlatMenusTest$LargerMenuItem" ) { + name: "menuItem22" + "text": "horz left" + "icon": #SwingIcon2 + "horizontalAlignment": 2 + } ) + add( new FormComponent( "com.formdev.flatlaf.testing.FlatMenusTest$LargerMenuItem" ) { + name: "menuItem23" + "text": "horz right" + "icon": #SwingIcon2 + "horizontalAlignment": 4 + } ) + add( new FormComponent( "com.formdev.flatlaf.testing.FlatMenusTest$LargerMenuItem" ) { + name: "menuItem30" + "text": "horz trailing" + "icon": #SwingIcon2 + "horizontalAlignment": 11 + } ) + add( new FormComponent( "com.formdev.flatlaf.testing.FlatMenusTest$LargerMenuItem" ) { + name: "menuItem25" + "text": "horz center / vert top" + "icon": #SwingIcon2 + "horizontalAlignment": 0 + "verticalAlignment": 1 + } ) + add( new FormComponent( "com.formdev.flatlaf.testing.FlatMenusTest$LargerMenuItem" ) { + name: "menuItem24" + "text": "horz center / vert bottom" + "icon": #SwingIcon2 + "horizontalAlignment": 0 + "verticalAlignment": 3 + } ) + add( new FormComponent( "com.formdev.flatlaf.testing.FlatMenusTest$LargerMenuItem" ) { + name: "menuItem26" + "text": "horz center / vert center" + "icon": #SwingIcon2 + "horizontalAlignment": 0 + } ) + add( new FormComponent( "javax.swing.JMenuItem" ) { + name: "menuItem32" + "text": "1234567890123456789012345678901234567890" + } ) + } ) + add( new FormContainer( "javax.swing.JMenu", new FormLayoutManager( class javax.swing.JMenu ) ) { + name: "menu10" + "icon": new com.jformdesigner.model.SwingIcon( 0, "/com/formdev/flatlaf/testing/disabled_icons_test/intellij-menu-paste@2x.png" ) + "horizontalTextPosition": 0 + "verticalTextPosition": 1 + add( new FormComponent( "com.formdev.flatlaf.testing.FlatMenusTest$LargerMenuItem" ) { + name: "menuItem33" + "icon": #SwingIcon1 + } ) + } ) + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 3 0 2 1,growx" + } ) + add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) { + "$columnConstraints": "[]" + "$rowConstraints": "[]0[]" + "$layoutConstraints": "ltr,insets 0,hidemode 3" + } ) { + name: "panel5" + add( new FormComponent( "javax.swing.JCheckBox" ) { + name: "largerCheckBox" + "text": "larger" + auxiliary() { + "JavaCodeGenerator.variableLocal": false + } + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "largerChanged", false ) ) + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 0 0" + } ) + add( new FormComponent( "javax.swing.JCheckBox" ) { + name: "accelCheckBox" + "text": "accel" + auxiliary() { + "JavaCodeGenerator.variableLocal": false + } + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "accelChanged", false ) ) + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 0 1" + } ) + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 3 0 2 1" } ) add( new FormContainer( "javax.swing.JPanel", new FormLayoutManager( class net.miginfocom.swing.MigLayout ) { "$columnConstraints": "[125,left][fill]" @@ -92,7 +340,7 @@ new FormModel { } ) add( new FormComponent( "javax.swing.JCheckBoxMenuItem" ) { name: "checkBoxMenuItem1" - "text": "enabled" + "text": "enabled" "accelerator": &KeyStroke0 static javax.swing.KeyStroke getKeyStroke( 112, 0, false ) "mnemonic": 65 }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { @@ -280,6 +528,16 @@ new FormModel { }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { "value": "cell 0 3" } ) + add( new FormComponent( "javax.swing.JCheckBox" ) { + name: "underlineCheckBox" + "text": "underline menu selection" + auxiliary() { + "JavaCodeGenerator.variableLocal": false + } + addEvent( new FormEvent( "java.awt.event.ActionListener", "actionPerformed", "underlineChanged", false ) ) + }, new FormLayoutConstraints( class net.miginfocom.layout.CC ) { + "value": "cell 0 4 2 1" + } ) }, new FormLayoutConstraints( null ) { "location": new java.awt.Point( 0, 0 ) "size": new java.awt.Dimension( 790, 380 ) @@ -321,5 +579,15 @@ new FormModel { }, new FormLayoutConstraints( null ) { "location": new java.awt.Point( 0, 430 ) } ) + add( new FormNonVisual( "javax.swing.ButtonGroup" ) { + name: "buttonGroup1" + }, new FormLayoutConstraints( null ) { + "location": new java.awt.Point( 0, 564 ) + } ) + add( new FormNonVisual( "javax.swing.ButtonGroup" ) { + name: "buttonGroup2" + }, new FormLayoutConstraints( null ) { + "location": new java.awt.Point( 0, 616 ) + } ) } } diff --git a/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatDarkLaf_1.8.0_202-mac.txt b/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatDarkLaf_1.8.0_202-mac.txt index 5f51b85a..5ff98c35 100644 --- a/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatDarkLaf_1.8.0_202-mac.txt +++ b/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatDarkLaf_1.8.0_202-mac.txt @@ -138,12 +138,13 @@ CheckBox.textShiftOffset 0 #---- CheckBoxMenuItem ---- CheckBoxMenuItem.acceleratorFont [active] $defaultFont [UI] -CheckBoxMenuItem.acceleratorForeground #bbbbbb javax.swing.plaf.ColorUIResource [UI] +CheckBoxMenuItem.acceleratorForeground #959595 javax.swing.plaf.ColorUIResource [UI] CheckBoxMenuItem.acceleratorSelectionForeground #bbbbbb javax.swing.plaf.ColorUIResource [UI] CheckBoxMenuItem.arrowIcon [lazy] 6,10 com.formdev.flatlaf.icons.FlatMenuItemArrowIcon [UI] CheckBoxMenuItem.background #303234 javax.swing.plaf.ColorUIResource [UI] CheckBoxMenuItem.border [lazy] 0,0,0,0 false com.formdev.flatlaf.ui.FlatMenuItemBorder [UI] CheckBoxMenuItem.borderPainted true +CheckBoxMenuItem.checkBackground #55585c javax.swing.plaf.ColorUIResource [UI] CheckBoxMenuItem.checkIcon [lazy] 15,15 com.formdev.flatlaf.icons.FlatCheckBoxMenuItemIcon [UI] CheckBoxMenuItem.disabledForeground #777777 javax.swing.plaf.ColorUIResource [UI] CheckBoxMenuItem.font [active] $defaultFont [UI] @@ -206,6 +207,7 @@ Component.disabledBorderColor #646464 javax.swing.plaf.ColorUIResource [UI] Component.focusColor #3d6185 javax.swing.plaf.ColorUIResource [UI] Component.focusWidth 0 Component.focusedBorderColor #466d94 javax.swing.plaf.ColorUIResource [UI] +Component.grayFilter [lazy] [unknown type] com.formdev.flatlaf.util.GrayFilter Component.hideMnemonics true Component.innerFocusWidth 0.5 Component.linkColor #589df6 javax.swing.plaf.ColorUIResource [UI] @@ -461,7 +463,7 @@ ListUI com.formdev.flatlaf.ui.FlatListUI #---- Menu ---- Menu.acceleratorFont [active] $defaultFont [UI] -Menu.acceleratorForeground #bbbbbb javax.swing.plaf.ColorUIResource [UI] +Menu.acceleratorForeground #959595 javax.swing.plaf.ColorUIResource [UI] Menu.acceleratorSelectionForeground #bbbbbb javax.swing.plaf.ColorUIResource [UI] Menu.arrowIcon [lazy] 6,10 com.formdev.flatlaf.icons.FlatMenuArrowIcon [UI] Menu.background #303234 javax.swing.plaf.ColorUIResource [UI] @@ -496,7 +498,7 @@ MenuBar.font [active] $defaultFont [UI] MenuBar.foreground #bbbbbb javax.swing.plaf.ColorUIResource [UI] MenuBar.highlight #242424 javax.swing.plaf.ColorUIResource [UI] MenuBar.hoverBackground #484c4f javax.swing.plaf.ColorUIResource [UI] -MenuBar.itemMargins 3,3,3,3 javax.swing.plaf.InsetsUIResource [UI] +MenuBar.itemMargins 3,8,3,8 javax.swing.plaf.InsetsUIResource [UI] MenuBar.shadow #646464 javax.swing.plaf.ColorUIResource [UI] MenuBar.windowBindings length=2 [Ljava.lang.Object; [0] F10 @@ -508,7 +510,7 @@ MenuBarUI com.formdev.flatlaf.ui.FlatMenuBarUI MenuItem.acceleratorDelimiter MenuItem.acceleratorFont [active] $defaultFont [UI] -MenuItem.acceleratorForeground #bbbbbb javax.swing.plaf.ColorUIResource [UI] +MenuItem.acceleratorForeground #959595 javax.swing.plaf.ColorUIResource [UI] MenuItem.acceleratorSelectionForeground #bbbbbb javax.swing.plaf.ColorUIResource [UI] MenuItem.arrowIcon [lazy] 6,10 com.formdev.flatlaf.icons.FlatMenuItemArrowIcon [UI] MenuItem.background #303234 javax.swing.plaf.ColorUIResource [UI] @@ -518,9 +520,16 @@ MenuItem.disabledForeground #777777 javax.swing.plaf.ColorUIResource [UI] MenuItem.font [active] $defaultFont [UI] MenuItem.foreground #bbbbbb javax.swing.plaf.ColorUIResource [UI] MenuItem.margin 2,8,2,8 javax.swing.plaf.InsetsUIResource [UI] +MenuItem.minimumIconSize 16,16 javax.swing.plaf.DimensionUIResource [UI] +MenuItem.minimumWidth 72 MenuItem.opaque false MenuItem.selectionBackground #4b6eaf javax.swing.plaf.ColorUIResource [UI] MenuItem.selectionForeground #bbbbbb javax.swing.plaf.ColorUIResource [UI] +MenuItem.textAcceleratorGap 24 +MenuItem.textArrowGap 8 +MenuItem.underlineSelectionBackground #484c4f javax.swing.plaf.ColorUIResource [UI] +MenuItem.underlineSelectionColor #4a88c7 javax.swing.plaf.ColorUIResource [UI] +MenuItem.underlineSelectionHeight 3 #---- MenuItemCheckBox ---- @@ -682,12 +691,13 @@ RadioButton.textShiftOffset 0 #---- RadioButtonMenuItem ---- RadioButtonMenuItem.acceleratorFont [active] $defaultFont [UI] -RadioButtonMenuItem.acceleratorForeground #bbbbbb javax.swing.plaf.ColorUIResource [UI] +RadioButtonMenuItem.acceleratorForeground #959595 javax.swing.plaf.ColorUIResource [UI] RadioButtonMenuItem.acceleratorSelectionForeground #bbbbbb javax.swing.plaf.ColorUIResource [UI] RadioButtonMenuItem.arrowIcon [lazy] 6,10 com.formdev.flatlaf.icons.FlatMenuItemArrowIcon [UI] RadioButtonMenuItem.background #303234 javax.swing.plaf.ColorUIResource [UI] RadioButtonMenuItem.border [lazy] 0,0,0,0 false com.formdev.flatlaf.ui.FlatMenuItemBorder [UI] RadioButtonMenuItem.borderPainted true +RadioButtonMenuItem.checkBackground #55585c javax.swing.plaf.ColorUIResource [UI] RadioButtonMenuItem.checkIcon [lazy] 15,15 com.formdev.flatlaf.icons.FlatRadioButtonMenuItemIcon [UI] RadioButtonMenuItem.disabledForeground #777777 javax.swing.plaf.ColorUIResource [UI] RadioButtonMenuItem.font [active] $defaultFont [UI] diff --git a/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatDarkLaf_1.8.0_202.txt b/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatDarkLaf_1.8.0_202.txt index 297b0e0e..fc85fc5e 100644 --- a/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatDarkLaf_1.8.0_202.txt +++ b/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatDarkLaf_1.8.0_202.txt @@ -138,12 +138,13 @@ CheckBox.textShiftOffset 0 #---- CheckBoxMenuItem ---- CheckBoxMenuItem.acceleratorFont [active] $defaultFont [UI] -CheckBoxMenuItem.acceleratorForeground #bbbbbb javax.swing.plaf.ColorUIResource [UI] +CheckBoxMenuItem.acceleratorForeground #959595 javax.swing.plaf.ColorUIResource [UI] CheckBoxMenuItem.acceleratorSelectionForeground #bbbbbb javax.swing.plaf.ColorUIResource [UI] CheckBoxMenuItem.arrowIcon [lazy] 6,10 com.formdev.flatlaf.icons.FlatMenuItemArrowIcon [UI] CheckBoxMenuItem.background #303234 javax.swing.plaf.ColorUIResource [UI] CheckBoxMenuItem.border [lazy] 0,0,0,0 false com.formdev.flatlaf.ui.FlatMenuItemBorder [UI] CheckBoxMenuItem.borderPainted true +CheckBoxMenuItem.checkBackground #55585c javax.swing.plaf.ColorUIResource [UI] CheckBoxMenuItem.checkIcon [lazy] 15,15 com.formdev.flatlaf.icons.FlatCheckBoxMenuItemIcon [UI] CheckBoxMenuItem.disabledForeground #777777 javax.swing.plaf.ColorUIResource [UI] CheckBoxMenuItem.font [active] $defaultFont [UI] @@ -205,6 +206,7 @@ Component.disabledBorderColor #646464 javax.swing.plaf.ColorUIResource [UI] Component.focusColor #3d6185 javax.swing.plaf.ColorUIResource [UI] Component.focusWidth 0 Component.focusedBorderColor #466d94 javax.swing.plaf.ColorUIResource [UI] +Component.grayFilter [lazy] [unknown type] com.formdev.flatlaf.util.GrayFilter Component.hideMnemonics true Component.innerFocusWidth 0.5 Component.linkColor #589df6 javax.swing.plaf.ColorUIResource [UI] @@ -460,7 +462,7 @@ ListUI com.formdev.flatlaf.ui.FlatListUI #---- Menu ---- Menu.acceleratorFont [active] $defaultFont [UI] -Menu.acceleratorForeground #bbbbbb javax.swing.plaf.ColorUIResource [UI] +Menu.acceleratorForeground #959595 javax.swing.plaf.ColorUIResource [UI] Menu.acceleratorSelectionForeground #bbbbbb javax.swing.plaf.ColorUIResource [UI] Menu.arrowIcon [lazy] 6,10 com.formdev.flatlaf.icons.FlatMenuArrowIcon [UI] Menu.background #303234 javax.swing.plaf.ColorUIResource [UI] @@ -495,7 +497,7 @@ MenuBar.font [active] $defaultFont [UI] MenuBar.foreground #bbbbbb javax.swing.plaf.ColorUIResource [UI] MenuBar.highlight #242424 javax.swing.plaf.ColorUIResource [UI] MenuBar.hoverBackground #484c4f javax.swing.plaf.ColorUIResource [UI] -MenuBar.itemMargins 3,3,3,3 javax.swing.plaf.InsetsUIResource [UI] +MenuBar.itemMargins 3,8,3,8 javax.swing.plaf.InsetsUIResource [UI] MenuBar.shadow #646464 javax.swing.plaf.ColorUIResource [UI] MenuBar.windowBindings length=2 [Ljava.lang.Object; [0] F10 @@ -507,7 +509,7 @@ MenuBarUI com.formdev.flatlaf.ui.FlatMenuBarUI MenuItem.acceleratorDelimiter - MenuItem.acceleratorFont [active] $defaultFont [UI] -MenuItem.acceleratorForeground #bbbbbb javax.swing.plaf.ColorUIResource [UI] +MenuItem.acceleratorForeground #959595 javax.swing.plaf.ColorUIResource [UI] MenuItem.acceleratorSelectionForeground #bbbbbb javax.swing.plaf.ColorUIResource [UI] MenuItem.arrowIcon [lazy] 6,10 com.formdev.flatlaf.icons.FlatMenuItemArrowIcon [UI] MenuItem.background #303234 javax.swing.plaf.ColorUIResource [UI] @@ -517,9 +519,16 @@ MenuItem.disabledForeground #777777 javax.swing.plaf.ColorUIResource [UI] MenuItem.font [active] $defaultFont [UI] MenuItem.foreground #bbbbbb javax.swing.plaf.ColorUIResource [UI] MenuItem.margin 2,8,2,8 javax.swing.plaf.InsetsUIResource [UI] +MenuItem.minimumIconSize 16,16 javax.swing.plaf.DimensionUIResource [UI] +MenuItem.minimumWidth 72 MenuItem.opaque false MenuItem.selectionBackground #4b6eaf javax.swing.plaf.ColorUIResource [UI] MenuItem.selectionForeground #bbbbbb javax.swing.plaf.ColorUIResource [UI] +MenuItem.textAcceleratorGap 24 +MenuItem.textArrowGap 8 +MenuItem.underlineSelectionBackground #484c4f javax.swing.plaf.ColorUIResource [UI] +MenuItem.underlineSelectionColor #4a88c7 javax.swing.plaf.ColorUIResource [UI] +MenuItem.underlineSelectionHeight 3 #---- MenuItemCheckBox ---- @@ -680,12 +689,13 @@ RadioButton.textShiftOffset 0 #---- RadioButtonMenuItem ---- RadioButtonMenuItem.acceleratorFont [active] $defaultFont [UI] -RadioButtonMenuItem.acceleratorForeground #bbbbbb javax.swing.plaf.ColorUIResource [UI] +RadioButtonMenuItem.acceleratorForeground #959595 javax.swing.plaf.ColorUIResource [UI] RadioButtonMenuItem.acceleratorSelectionForeground #bbbbbb javax.swing.plaf.ColorUIResource [UI] RadioButtonMenuItem.arrowIcon [lazy] 6,10 com.formdev.flatlaf.icons.FlatMenuItemArrowIcon [UI] RadioButtonMenuItem.background #303234 javax.swing.plaf.ColorUIResource [UI] RadioButtonMenuItem.border [lazy] 0,0,0,0 false com.formdev.flatlaf.ui.FlatMenuItemBorder [UI] RadioButtonMenuItem.borderPainted true +RadioButtonMenuItem.checkBackground #55585c javax.swing.plaf.ColorUIResource [UI] RadioButtonMenuItem.checkIcon [lazy] 15,15 com.formdev.flatlaf.icons.FlatRadioButtonMenuItemIcon [UI] RadioButtonMenuItem.disabledForeground #777777 javax.swing.plaf.ColorUIResource [UI] RadioButtonMenuItem.font [active] $defaultFont [UI] diff --git a/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatLightLaf_1.8.0_202-mac.txt b/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatLightLaf_1.8.0_202-mac.txt index bac5ba54..02a2427a 100644 --- a/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatLightLaf_1.8.0_202-mac.txt +++ b/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatLightLaf_1.8.0_202-mac.txt @@ -139,12 +139,13 @@ CheckBox.textShiftOffset 0 #---- CheckBoxMenuItem ---- CheckBoxMenuItem.acceleratorFont [active] $defaultFont [UI] -CheckBoxMenuItem.acceleratorForeground #505050 javax.swing.plaf.ColorUIResource [UI] +CheckBoxMenuItem.acceleratorForeground #4d4d4d javax.swing.plaf.ColorUIResource [UI] CheckBoxMenuItem.acceleratorSelectionForeground #ffffff javax.swing.plaf.ColorUIResource [UI] CheckBoxMenuItem.arrowIcon [lazy] 6,10 com.formdev.flatlaf.icons.FlatMenuItemArrowIcon [UI] CheckBoxMenuItem.background #ffffff javax.swing.plaf.ColorUIResource [UI] CheckBoxMenuItem.border [lazy] 0,0,0,0 false com.formdev.flatlaf.ui.FlatMenuItemBorder [UI] CheckBoxMenuItem.borderPainted true +CheckBoxMenuItem.checkBackground #d9d9d9 javax.swing.plaf.ColorUIResource [UI] CheckBoxMenuItem.checkIcon [lazy] 15,15 com.formdev.flatlaf.icons.FlatCheckBoxMenuItemIcon [UI] CheckBoxMenuItem.disabledForeground #8c8c8c javax.swing.plaf.ColorUIResource [UI] CheckBoxMenuItem.font [active] $defaultFont [UI] @@ -207,6 +208,7 @@ Component.disabledBorderColor #cfcfcf javax.swing.plaf.ColorUIResource [UI] Component.focusColor #97c3f3 javax.swing.plaf.ColorUIResource [UI] Component.focusWidth 0 Component.focusedBorderColor #87afda javax.swing.plaf.ColorUIResource [UI] +Component.grayFilter [lazy] [unknown type] com.formdev.flatlaf.util.GrayFilter Component.hideMnemonics true Component.innerFocusWidth 0.5 Component.linkColor #2470b3 javax.swing.plaf.ColorUIResource [UI] @@ -463,7 +465,7 @@ ListUI com.formdev.flatlaf.ui.FlatListUI #---- Menu ---- Menu.acceleratorFont [active] $defaultFont [UI] -Menu.acceleratorForeground #505050 javax.swing.plaf.ColorUIResource [UI] +Menu.acceleratorForeground #4d4d4d javax.swing.plaf.ColorUIResource [UI] Menu.acceleratorSelectionForeground #ffffff javax.swing.plaf.ColorUIResource [UI] Menu.arrowIcon [lazy] 6,10 com.formdev.flatlaf.icons.FlatMenuArrowIcon [UI] Menu.background #ffffff javax.swing.plaf.ColorUIResource [UI] @@ -498,7 +500,7 @@ MenuBar.font [active] $defaultFont [UI] MenuBar.foreground #000000 javax.swing.plaf.ColorUIResource [UI] MenuBar.highlight #ffffff javax.swing.plaf.ColorUIResource [UI] MenuBar.hoverBackground #e6e6e6 javax.swing.plaf.ColorUIResource [UI] -MenuBar.itemMargins 3,3,3,3 javax.swing.plaf.InsetsUIResource [UI] +MenuBar.itemMargins 3,8,3,8 javax.swing.plaf.InsetsUIResource [UI] MenuBar.shadow #c4c4c4 javax.swing.plaf.ColorUIResource [UI] MenuBar.windowBindings length=2 [Ljava.lang.Object; [0] F10 @@ -510,7 +512,7 @@ MenuBarUI com.formdev.flatlaf.ui.FlatMenuBarUI MenuItem.acceleratorDelimiter MenuItem.acceleratorFont [active] $defaultFont [UI] -MenuItem.acceleratorForeground #505050 javax.swing.plaf.ColorUIResource [UI] +MenuItem.acceleratorForeground #4d4d4d javax.swing.plaf.ColorUIResource [UI] MenuItem.acceleratorSelectionForeground #ffffff javax.swing.plaf.ColorUIResource [UI] MenuItem.arrowIcon [lazy] 6,10 com.formdev.flatlaf.icons.FlatMenuItemArrowIcon [UI] MenuItem.background #ffffff javax.swing.plaf.ColorUIResource [UI] @@ -520,9 +522,16 @@ MenuItem.disabledForeground #8c8c8c javax.swing.plaf.ColorUIResource [UI] MenuItem.font [active] $defaultFont [UI] MenuItem.foreground #000000 javax.swing.plaf.ColorUIResource [UI] MenuItem.margin 2,8,2,8 javax.swing.plaf.InsetsUIResource [UI] +MenuItem.minimumIconSize 16,16 javax.swing.plaf.DimensionUIResource [UI] +MenuItem.minimumWidth 72 MenuItem.opaque false MenuItem.selectionBackground #2675bf javax.swing.plaf.ColorUIResource [UI] MenuItem.selectionForeground #ffffff javax.swing.plaf.ColorUIResource [UI] +MenuItem.textAcceleratorGap 24 +MenuItem.textArrowGap 8 +MenuItem.underlineSelectionBackground #e6e6e6 javax.swing.plaf.ColorUIResource [UI] +MenuItem.underlineSelectionColor #4083c9 javax.swing.plaf.ColorUIResource [UI] +MenuItem.underlineSelectionHeight 3 #---- MenuItemCheckBox ---- @@ -684,12 +693,13 @@ RadioButton.textShiftOffset 0 #---- RadioButtonMenuItem ---- RadioButtonMenuItem.acceleratorFont [active] $defaultFont [UI] -RadioButtonMenuItem.acceleratorForeground #505050 javax.swing.plaf.ColorUIResource [UI] +RadioButtonMenuItem.acceleratorForeground #4d4d4d javax.swing.plaf.ColorUIResource [UI] RadioButtonMenuItem.acceleratorSelectionForeground #ffffff javax.swing.plaf.ColorUIResource [UI] RadioButtonMenuItem.arrowIcon [lazy] 6,10 com.formdev.flatlaf.icons.FlatMenuItemArrowIcon [UI] RadioButtonMenuItem.background #ffffff javax.swing.plaf.ColorUIResource [UI] RadioButtonMenuItem.border [lazy] 0,0,0,0 false com.formdev.flatlaf.ui.FlatMenuItemBorder [UI] RadioButtonMenuItem.borderPainted true +RadioButtonMenuItem.checkBackground #d9d9d9 javax.swing.plaf.ColorUIResource [UI] RadioButtonMenuItem.checkIcon [lazy] 15,15 com.formdev.flatlaf.icons.FlatRadioButtonMenuItemIcon [UI] RadioButtonMenuItem.disabledForeground #8c8c8c javax.swing.plaf.ColorUIResource [UI] RadioButtonMenuItem.font [active] $defaultFont [UI] diff --git a/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatLightLaf_1.8.0_202.txt b/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatLightLaf_1.8.0_202.txt index 4d98bec9..119b4e7d 100644 --- a/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatLightLaf_1.8.0_202.txt +++ b/flatlaf-testing/src/main/resources/com/formdev/flatlaf/testing/uidefaults/FlatLightLaf_1.8.0_202.txt @@ -139,12 +139,13 @@ CheckBox.textShiftOffset 0 #---- CheckBoxMenuItem ---- CheckBoxMenuItem.acceleratorFont [active] $defaultFont [UI] -CheckBoxMenuItem.acceleratorForeground #505050 javax.swing.plaf.ColorUIResource [UI] +CheckBoxMenuItem.acceleratorForeground #4d4d4d javax.swing.plaf.ColorUIResource [UI] CheckBoxMenuItem.acceleratorSelectionForeground #ffffff javax.swing.plaf.ColorUIResource [UI] CheckBoxMenuItem.arrowIcon [lazy] 6,10 com.formdev.flatlaf.icons.FlatMenuItemArrowIcon [UI] CheckBoxMenuItem.background #ffffff javax.swing.plaf.ColorUIResource [UI] CheckBoxMenuItem.border [lazy] 0,0,0,0 false com.formdev.flatlaf.ui.FlatMenuItemBorder [UI] CheckBoxMenuItem.borderPainted true +CheckBoxMenuItem.checkBackground #d9d9d9 javax.swing.plaf.ColorUIResource [UI] CheckBoxMenuItem.checkIcon [lazy] 15,15 com.formdev.flatlaf.icons.FlatCheckBoxMenuItemIcon [UI] CheckBoxMenuItem.disabledForeground #8c8c8c javax.swing.plaf.ColorUIResource [UI] CheckBoxMenuItem.font [active] $defaultFont [UI] @@ -206,6 +207,7 @@ Component.disabledBorderColor #cfcfcf javax.swing.plaf.ColorUIResource [UI] Component.focusColor #97c3f3 javax.swing.plaf.ColorUIResource [UI] Component.focusWidth 0 Component.focusedBorderColor #87afda javax.swing.plaf.ColorUIResource [UI] +Component.grayFilter [lazy] [unknown type] com.formdev.flatlaf.util.GrayFilter Component.hideMnemonics true Component.innerFocusWidth 0.5 Component.linkColor #2470b3 javax.swing.plaf.ColorUIResource [UI] @@ -462,7 +464,7 @@ ListUI com.formdev.flatlaf.ui.FlatListUI #---- Menu ---- Menu.acceleratorFont [active] $defaultFont [UI] -Menu.acceleratorForeground #505050 javax.swing.plaf.ColorUIResource [UI] +Menu.acceleratorForeground #4d4d4d javax.swing.plaf.ColorUIResource [UI] Menu.acceleratorSelectionForeground #ffffff javax.swing.plaf.ColorUIResource [UI] Menu.arrowIcon [lazy] 6,10 com.formdev.flatlaf.icons.FlatMenuArrowIcon [UI] Menu.background #ffffff javax.swing.plaf.ColorUIResource [UI] @@ -497,7 +499,7 @@ MenuBar.font [active] $defaultFont [UI] MenuBar.foreground #000000 javax.swing.plaf.ColorUIResource [UI] MenuBar.highlight #ffffff javax.swing.plaf.ColorUIResource [UI] MenuBar.hoverBackground #e6e6e6 javax.swing.plaf.ColorUIResource [UI] -MenuBar.itemMargins 3,3,3,3 javax.swing.plaf.InsetsUIResource [UI] +MenuBar.itemMargins 3,8,3,8 javax.swing.plaf.InsetsUIResource [UI] MenuBar.shadow #c4c4c4 javax.swing.plaf.ColorUIResource [UI] MenuBar.windowBindings length=2 [Ljava.lang.Object; [0] F10 @@ -509,7 +511,7 @@ MenuBarUI com.formdev.flatlaf.ui.FlatMenuBarUI MenuItem.acceleratorDelimiter - MenuItem.acceleratorFont [active] $defaultFont [UI] -MenuItem.acceleratorForeground #505050 javax.swing.plaf.ColorUIResource [UI] +MenuItem.acceleratorForeground #4d4d4d javax.swing.plaf.ColorUIResource [UI] MenuItem.acceleratorSelectionForeground #ffffff javax.swing.plaf.ColorUIResource [UI] MenuItem.arrowIcon [lazy] 6,10 com.formdev.flatlaf.icons.FlatMenuItemArrowIcon [UI] MenuItem.background #ffffff javax.swing.plaf.ColorUIResource [UI] @@ -519,9 +521,16 @@ MenuItem.disabledForeground #8c8c8c javax.swing.plaf.ColorUIResource [UI] MenuItem.font [active] $defaultFont [UI] MenuItem.foreground #000000 javax.swing.plaf.ColorUIResource [UI] MenuItem.margin 2,8,2,8 javax.swing.plaf.InsetsUIResource [UI] +MenuItem.minimumIconSize 16,16 javax.swing.plaf.DimensionUIResource [UI] +MenuItem.minimumWidth 72 MenuItem.opaque false MenuItem.selectionBackground #2675bf javax.swing.plaf.ColorUIResource [UI] MenuItem.selectionForeground #ffffff javax.swing.plaf.ColorUIResource [UI] +MenuItem.textAcceleratorGap 24 +MenuItem.textArrowGap 8 +MenuItem.underlineSelectionBackground #e6e6e6 javax.swing.plaf.ColorUIResource [UI] +MenuItem.underlineSelectionColor #4083c9 javax.swing.plaf.ColorUIResource [UI] +MenuItem.underlineSelectionHeight 3 #---- MenuItemCheckBox ---- @@ -682,12 +691,13 @@ RadioButton.textShiftOffset 0 #---- RadioButtonMenuItem ---- RadioButtonMenuItem.acceleratorFont [active] $defaultFont [UI] -RadioButtonMenuItem.acceleratorForeground #505050 javax.swing.plaf.ColorUIResource [UI] +RadioButtonMenuItem.acceleratorForeground #4d4d4d javax.swing.plaf.ColorUIResource [UI] RadioButtonMenuItem.acceleratorSelectionForeground #ffffff javax.swing.plaf.ColorUIResource [UI] RadioButtonMenuItem.arrowIcon [lazy] 6,10 com.formdev.flatlaf.icons.FlatMenuItemArrowIcon [UI] RadioButtonMenuItem.background #ffffff javax.swing.plaf.ColorUIResource [UI] RadioButtonMenuItem.border [lazy] 0,0,0,0 false com.formdev.flatlaf.ui.FlatMenuItemBorder [UI] RadioButtonMenuItem.borderPainted true +RadioButtonMenuItem.checkBackground #d9d9d9 javax.swing.plaf.ColorUIResource [UI] RadioButtonMenuItem.checkIcon [lazy] 15,15 com.formdev.flatlaf.icons.FlatRadioButtonMenuItemIcon [UI] RadioButtonMenuItem.disabledForeground #8c8c8c javax.swing.plaf.ColorUIResource [UI] RadioButtonMenuItem.font [active] $defaultFont [UI]