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 c70be48b..501602b6 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 @@ -67,14 +67,14 @@ public class FlatCheckBoxMenuItemIcon g2.draw( path ); } - private Color getCheckmarkColor( Component c ) { + protected Color getCheckmarkColor( Component c ) { if( c instanceof JMenuItem && ((JMenuItem)c).isArmed() && !isUnderlineSelection() ) return selectionForeground; return c.isEnabled() ? checkmarkColor : disabledCheckmarkColor; } - private boolean isUnderlineSelection() { + protected 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 2f4af4de..2c401f61 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 @@ -65,14 +65,14 @@ public class FlatMenuArrowIcon } } - private Color getArrowColor( Component c ) { + protected Color getArrowColor( Component c ) { if( c instanceof JMenu && ((JMenu)c).isSelected() && !isUnderlineSelection() ) return selectionForeground; return c.isEnabled() ? arrowColor : disabledArrowColor; } - private boolean isUnderlineSelection() { + protected 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/FlatComboBoxUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java index 2b275952..cd2f5ac3 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatComboBoxUI.java @@ -317,12 +317,11 @@ public class FlatComboBoxUI // use non-UIResource colors because when SwingUtilities.updateComponentTreeUI() // is used, then the editor is updated after the combobox and the // colors are again replaced with default colors - boolean enabled = editor.isEnabled(); - editor.setForeground( FlatUIUtils.nonUIResource( (enabled || editor instanceof JTextComponent) - ? comboBox.getForeground() - : disabledForeground ) ); - if( editor instanceof JTextComponent ) - ((JTextComponent)editor).setDisabledTextColor( FlatUIUtils.nonUIResource( disabledForeground ) ); + boolean isTextComponent = editor instanceof JTextComponent; + editor.setForeground( FlatUIUtils.nonUIResource( getForeground( isTextComponent || editor.isEnabled() ) ) ); + + if( isTextComponent ) + ((JTextComponent)editor).setDisabledTextColor( FlatUIUtils.nonUIResource( getForeground( false ) ) ); } @Override @@ -358,9 +357,7 @@ public class FlatComboBoxUI boolean isLeftToRight = comboBox.getComponentOrientation().isLeftToRight(); // paint background - g2.setColor( enabled - ? (editableBackground != null && comboBox.isEditable() ? editableBackground : c.getBackground()) - : getDisabledBackground( comboBox ) ); + g2.setColor( getBackground( enabled ) ); FlatUIUtils.paintComponentBackground( g2, 0, 0, width, height, focusWidth, arc ); // paint arrow button background @@ -399,8 +396,8 @@ public class FlatComboBoxUI uninstallCellPaddingBorder( c ); boolean enabled = comboBox.isEnabled(); - c.setForeground( enabled ? comboBox.getForeground() : disabledForeground ); - c.setBackground( enabled ? comboBox.getBackground() : getDisabledBackground( comboBox ) ); + c.setBackground( getBackground( enabled ) ); + c.setForeground( getForeground( enabled ) ); boolean shouldValidate = (c instanceof JPanel); if( padding != null ) @@ -420,8 +417,14 @@ public class FlatComboBoxUI // not necessary because already painted in update() } - private Color getDisabledBackground( JComponent c ) { - return isIntelliJTheme ? FlatUIUtils.getParentBackground( c ) : disabledBackground; + protected Color getBackground( boolean enabled ) { + return enabled + ? (editableBackground != null && comboBox.isEditable() ? editableBackground : comboBox.getBackground()) + : (isIntelliJTheme ? FlatUIUtils.getParentBackground( comboBox ) : disabledBackground); + } + + protected Color getForeground( boolean enabled ) { + return enabled ? comboBox.getForeground() : disabledForeground; } @Override 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 index 4bd7107c..064b582f 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuItemRenderer.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatMenuItemRenderer.java @@ -371,7 +371,7 @@ debug*/ return menuItem instanceof JMenu && ((JMenu)menuItem).isTopLevelMenu(); } - private boolean isUnderlineSelection() { + protected boolean isUnderlineSelection() { return "underline".equals( UIManager.getString( "MenuItem.selectionType" ) ); } @@ -416,6 +416,13 @@ debug*/ if( accelerator == cachedAccelerator ) return cachedAcceleratorText; + cachedAccelerator = accelerator; + cachedAcceleratorText = getTextForAccelerator( accelerator ); + + return cachedAcceleratorText; + } + + protected String getTextForAccelerator( KeyStroke accelerator ) { StringBuilder buf = new StringBuilder(); int modifiers = accelerator.getModifiers(); if( modifiers != 0 ) @@ -427,10 +434,7 @@ debug*/ else buf.append( accelerator.getKeyChar() ); - cachedAccelerator = accelerator; - cachedAcceleratorText = buf.toString(); - - return cachedAcceleratorText; + return buf.toString(); } //---- class MinSizeIcon -------------------------------------------------- diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatScrollBarUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatScrollBarUI.java index b62f5f2c..26571390 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatScrollBarUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatScrollBarUI.java @@ -240,7 +240,7 @@ public class FlatScrollBarUI return button; } - private boolean isShowButtons() { + protected boolean isShowButtons() { Object showButtons = scrollbar.getClientProperty( FlatClientProperties.SCROLL_BAR_SHOW_BUTTONS ); if( showButtons == null && scrollbar.getParent() instanceof JScrollPane ) showButtons = ((JScrollPane)scrollbar.getParent()).getClientProperty( FlatClientProperties.SCROLL_BAR_SHOW_BUTTONS ); diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSpinnerUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSpinnerUI.java index 7b55f0f0..c3626299 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSpinnerUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatSpinnerUI.java @@ -206,8 +206,8 @@ public class FlatSpinnerUI // use non-UIResource colors because when SwingUtilities.updateComponentTreeUI() // is used, then the text field is updated after the spinner and the // colors are again replaced with default colors - textField.setForeground( FlatUIUtils.nonUIResource( spinner.getForeground() ) ); - textField.setDisabledTextColor( FlatUIUtils.nonUIResource( disabledForeground ) ); + textField.setForeground( FlatUIUtils.nonUIResource( getForeground( true ) ) ); + textField.setDisabledTextColor( FlatUIUtils.nonUIResource( getForeground( false ) ) ); } } @@ -217,6 +217,16 @@ public class FlatSpinnerUI : null; } + protected Color getBackground( boolean enabled ) { + return enabled + ? spinner.getBackground() + : (isIntelliJTheme ? FlatUIUtils.getParentBackground( spinner ) : disabledBackground); + } + + protected Color getForeground( boolean enabled ) { + return enabled ? spinner.getForeground() : disabledForeground; + } + @Override protected LayoutManager createLayout() { return getHandler(); @@ -266,9 +276,7 @@ public class FlatSpinnerUI boolean isLeftToRight = spinner.getComponentOrientation().isLeftToRight(); // paint background - g2.setColor( enabled - ? c.getBackground() - : (isIntelliJTheme ? FlatUIUtils.getParentBackground( c ) : disabledBackground) ); + g2.setColor( getBackground( enabled ) ); FlatUIUtils.paintComponentBackground( g2, 0, 0, width, height, focusWidth, arc ); // paint arrow buttons background diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTabbedPaneUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTabbedPaneUI.java index 1a8cf0ca..2b5f26b8 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTabbedPaneUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTabbedPaneUI.java @@ -333,28 +333,30 @@ public class FlatTabbedPaneUI // paint tab separators if( clientPropertyBoolean( tabPane, TABBED_PANE_SHOW_TAB_SEPARATORS, showTabSeparators ) && !isLastInRun( tabIndex ) ) - { - float sepWidth = UIScale.scale( 1f ); - float offset = tabSeparatorsFullHeight ? 0 : UIScale.scale( 5f ); - - g.setColor( (tabSeparatorColor != null) ? tabSeparatorColor : contentAreaColor ); - if( tabPlacement == LEFT || tabPlacement == RIGHT ) { - // paint tab separator at bottom side - ((Graphics2D)g).fill( new Rectangle2D.Float( x + offset, y + h - sepWidth, w - (offset * 2), sepWidth ) ); - } else if( tabPane.getComponentOrientation().isLeftToRight() ) { - // paint tab separator at right side - ((Graphics2D)g).fill( new Rectangle2D.Float( x + w - sepWidth, y + offset, sepWidth, h - (offset * 2) ) ); - } else { - // paint tab separator at left side - ((Graphics2D)g).fill( new Rectangle2D.Float( x, y + offset, sepWidth, h - (offset * 2) ) ); - } - } + paintTabSeparator( g, tabPlacement, x, y, w, h ); if( isSelected ) paintTabSelection( g, tabPlacement, x, y, w, h ); } - protected void paintTabSelection( Graphics g, int tabPlacement, int x, int y, int w, int h ) { + protected void paintTabSeparator( Graphics g, int tabPlacement, int x, int y, int w, int h ) { + float sepWidth = UIScale.scale( 1f ); + float offset = tabSeparatorsFullHeight ? 0 : UIScale.scale( 5f ); + + g.setColor( (tabSeparatorColor != null) ? tabSeparatorColor : contentAreaColor ); + if( tabPlacement == LEFT || tabPlacement == RIGHT ) { + // paint tab separator at bottom side + ((Graphics2D)g).fill( new Rectangle2D.Float( x + offset, y + h - sepWidth, w - (offset * 2), sepWidth ) ); + } else if( tabPane.getComponentOrientation().isLeftToRight() ) { + // paint tab separator at right side + ((Graphics2D)g).fill( new Rectangle2D.Float( x + w - sepWidth, y + offset, sepWidth, h - (offset * 2) ) ); + } else { + // paint tab separator at left side + ((Graphics2D)g).fill( new Rectangle2D.Float( x, y + offset, sepWidth, h - (offset * 2) ) ); + } + } + + protected void paintTabSelection( Graphics g, int tabPlacement, int x, int y, int w, int h ) { // increase clip bounds in scroll-tab-layout to paint over the separator line Rectangle clipBounds = isScrollTabLayout() ? g.getClipBounds() : null; if( clipBounds != null ) { diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTableCellBorder.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTableCellBorder.java index 05669edf..cd25abae 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTableCellBorder.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTableCellBorder.java @@ -86,7 +86,7 @@ public class FlatTableCellBorder /** * Checks whether at least one selected cell is editable. */ - private boolean isSelectionEditable( JTable table ) { + protected boolean isSelectionEditable( JTable table ) { if( table.getRowSelectionAllowed() ) { int columnCount = table.getColumnCount(); int[] selectedRows = table.getSelectedRows(); diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/ColorFunctions.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/ColorFunctions.java index 9f0592a7..471dd7c0 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/ColorFunctions.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/ColorFunctions.java @@ -35,7 +35,7 @@ public class ColorFunctions return HSLColor.toRGB( hsl, alpha ); } - private static float clamp( float value ) { + public static float clamp( float value ) { return (value < 0) ? 0 : ((value > 100) diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/SystemInfo.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/SystemInfo.java index 8ae25ce0..c9459817 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/SystemInfo.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/SystemInfo.java @@ -68,7 +68,7 @@ public class SystemInfo IS_KDE = (IS_LINUX && System.getenv( "KDE_FULL_SESSION" ) != null); } - private static long scanVersion( String version ) { + public static long scanVersion( String version ) { int major = 1; int minor = 0; int micro = 0; @@ -86,7 +86,7 @@ public class SystemInfo return toVersion( major, minor, micro, patch ); } - private static long toVersion( int major, int minor, int micro, int patch ) { + public static long toVersion( int major, int minor, int micro, int patch ) { return ((long) major << 48) + ((long) minor << 32) + ((long) micro << 16) + patch; } }