CheckBox and RadioButton: support changing selected icon style from outline to filled

renamed CheckBox.icon.focusedColor to CheckBox.icon.focusColor
This commit is contained in:
Karl Tauber
2020-06-19 15:36:49 +02:00
parent 1ba27730d6
commit 84cc86bef7
10 changed files with 121 additions and 63 deletions

View File

@@ -3,6 +3,9 @@ FlatLaf Change Log
## Unreleased
- CheckBox and RadioButton: Support changing selected icon style from outline to
filled (as in FlatLaf IntelliJ theme) with `UIManager.put(
"CheckBox.icon.style", "filled" );`.
- Button and ToggleButton: Support disabled background color (use UI values
`Button.disabledBackground` and `ToggleButton.disabledBackground`). (issue
#112)

View File

@@ -511,7 +511,7 @@ public class IntelliJTheme
checkboxKeyMapping.put( "Checkbox.Border.Default", "CheckBox.icon.borderColor" );
checkboxKeyMapping.put( "Checkbox.Border.Disabled", "CheckBox.icon.disabledBorderColor" );
checkboxKeyMapping.put( "Checkbox.Focus.Thin.Default", "CheckBox.icon.focusedBorderColor" );
checkboxKeyMapping.put( "Checkbox.Focus.Wide", "CheckBox.icon.focusedColor" );
checkboxKeyMapping.put( "Checkbox.Focus.Wide", "CheckBox.icon.focusColor" );
checkboxKeyMapping.put( "Checkbox.Foreground.Disabled", "CheckBox.icon.disabledCheckmarkColor" );
checkboxKeyMapping.put( "Checkbox.Background.Selected", "CheckBox.icon.selectedBackground" );
checkboxKeyMapping.put( "Checkbox.Border.Selected", "CheckBox.icon.selectedBorderColor" );

View File

@@ -36,9 +36,11 @@ import com.formdev.flatlaf.ui.FlatUIUtils;
* is painted outside of the icon bounds. Make sure that the checkbox
* has margins, which are equal or greater than focusWidth.
*
* @uiDefault CheckBox.icon.style String optional; "outline"/null (default) or "filled"
* @uiDefault Component.focusWidth int
* @uiDefault Component.focusColor Color
* @uiDefault CheckBox.icon.focusedColor Color optional; defaults to Component.focusColor
* @uiDefault CheckBox.icon.focusWidth int optional; defaults to Component.focusWidth
* @uiDefault CheckBox.icon.focusColor Color optional; defaults to Component.focusColor
* @uiDefault CheckBox.icon.borderColor Color
* @uiDefault CheckBox.icon.background Color
* @uiDefault CheckBox.icon.selectedBorderColor Color
@@ -50,6 +52,7 @@ import com.formdev.flatlaf.ui.FlatUIUtils;
* @uiDefault CheckBox.icon.focusedBorderColor Color
* @uiDefault CheckBox.icon.focusedBackground Color optional
* @uiDefault CheckBox.icon.selectedFocusedBorderColor Color optional
* @uiDefault CheckBox.icon.selectedFocusedBackground Color optional
* @uiDefault CheckBox.icon.hoverBorderColor Color optional
* @uiDefault CheckBox.icon.hoverBackground Color optional
* @uiDefault CheckBox.icon.selectedHoverBackground Color optional
@@ -62,36 +65,62 @@ import com.formdev.flatlaf.ui.FlatUIUtils;
public class FlatCheckBoxIcon
extends FlatAbstractIcon
{
public final int focusWidth = UIManager.getInt( "Component.focusWidth" );
protected final Color focusColor = FlatUIUtils.getUIColor( "CheckBox.icon.focusedColor",
protected final String style = UIManager.getString( "CheckBox.icon.style" );
public final int focusWidth = getUIInt( "CheckBox.icon.focusWidth",
UIManager.getInt( "Component.focusWidth" ), style );
protected final Color focusColor = FlatUIUtils.getUIColor( "CheckBox.icon.focusColor",
UIManager.getColor( "Component.focusColor" ) );
protected final int arc = FlatUIUtils.getUIInt( "CheckBox.arc", 2 );
// enabled
protected final Color borderColor = UIManager.getColor( "CheckBox.icon.borderColor" );
protected final Color background = UIManager.getColor( "CheckBox.icon.background" );
protected final Color selectedBorderColor = UIManager.getColor( "CheckBox.icon.selectedBorderColor" );
protected final Color selectedBackground = UIManager.getColor( "CheckBox.icon.selectedBackground" );
protected final Color checkmarkColor = UIManager.getColor( "CheckBox.icon.checkmarkColor" );
protected final Color borderColor = getUIColor( "CheckBox.icon.borderColor", style );
protected final Color background = getUIColor( "CheckBox.icon.background", style );
protected final Color selectedBorderColor = getUIColor( "CheckBox.icon.selectedBorderColor", style );
protected final Color selectedBackground = getUIColor( "CheckBox.icon.selectedBackground", style );
protected final Color checkmarkColor = getUIColor( "CheckBox.icon.checkmarkColor", style );
// disabled
protected final Color disabledBorderColor = UIManager.getColor( "CheckBox.icon.disabledBorderColor" );
protected final Color disabledBackground = UIManager.getColor( "CheckBox.icon.disabledBackground" );
protected final Color disabledCheckmarkColor = UIManager.getColor( "CheckBox.icon.disabledCheckmarkColor" );
protected final Color disabledBorderColor = getUIColor( "CheckBox.icon.disabledBorderColor", style );
protected final Color disabledBackground = getUIColor( "CheckBox.icon.disabledBackground", style );
protected final Color disabledCheckmarkColor = getUIColor( "CheckBox.icon.disabledCheckmarkColor", style );
// focused
protected final Color focusedBorderColor = UIManager.getColor( "CheckBox.icon.focusedBorderColor" );
protected final Color focusedBackground = UIManager.getColor( "CheckBox.icon.focusedBackground" );
protected final Color selectedFocusedBorderColor = UIManager.getColor( "CheckBox.icon.selectedFocusedBorderColor" );
protected final Color focusedBorderColor = getUIColor( "CheckBox.icon.focusedBorderColor", style );
protected final Color focusedBackground = getUIColor( "CheckBox.icon.focusedBackground", style );
protected final Color selectedFocusedBorderColor = getUIColor( "CheckBox.icon.selectedFocusedBorderColor", style );
protected final Color selectedFocusedBackground = getUIColor( "CheckBox.icon.selectedFocusedBackground", style );
protected final Color selectedFocusedCheckmarkColor = getUIColor( "CheckBox.icon.selectedFocusedCheckmarkColor", style );
// hover
protected final Color hoverBorderColor = UIManager.getColor( "CheckBox.icon.hoverBorderColor" );
protected final Color hoverBackground = UIManager.getColor( "CheckBox.icon.hoverBackground" );
protected final Color selectedHoverBackground = UIManager.getColor( "CheckBox.icon.selectedHoverBackground" );
protected final Color hoverBorderColor = getUIColor( "CheckBox.icon.hoverBorderColor", style );
protected final Color hoverBackground = getUIColor( "CheckBox.icon.hoverBackground", style );
protected final Color selectedHoverBackground = getUIColor( "CheckBox.icon.selectedHoverBackground", style );
// pressed
protected final Color pressedBackground = UIManager.getColor( "CheckBox.icon.pressedBackground" );
protected final Color selectedPressedBackground = UIManager.getColor( "CheckBox.icon.selectedPressedBackground" );
protected final Color pressedBackground = getUIColor( "CheckBox.icon.pressedBackground", style );
protected final Color selectedPressedBackground = getUIColor( "CheckBox.icon.selectedPressedBackground", style );
protected static Color getUIColor( String key, String style ) {
if( style != null ) {
Color color = UIManager.getColor( styleKey( key, style ) );
if( color != null )
return color;
}
return UIManager.getColor( key );
}
protected static int getUIInt( String key, int defaultValue, String style ) {
if( style != null ) {
Object value = UIManager.get( styleKey( key, style ) );
if( value instanceof Integer )
return (Integer) value;
}
return FlatUIUtils.getUIInt( key, defaultValue );
}
private static String styleKey( String key, String style ) {
return key.replace( ".icon.", ".icon[" + style + "]." );
}
static final int ICON_SIZE = 15;
@@ -103,9 +132,10 @@ public class FlatCheckBoxIcon
protected void paintIcon( Component c, Graphics2D g2 ) {
boolean indeterminate = c instanceof JComponent && clientPropertyEquals( (JComponent) c, SELECTED_STATE, SELECTED_STATE_INDETERMINATE );
boolean selected = indeterminate || (c instanceof AbstractButton && ((AbstractButton)c).isSelected());
boolean isFocused = FlatUIUtils.isPermanentFocusOwner( c );
// paint focused border
if( FlatUIUtils.isPermanentFocusOwner( c ) && focusWidth > 0 ) {
if( isFocused && focusWidth > 0 ) {
g2.setColor( focusColor );
paintFocusBorder( g2 );
}
@@ -123,15 +153,19 @@ public class FlatCheckBoxIcon
g2.setColor( FlatUIUtils.deriveColor( FlatButtonUI.buttonStateColor( c,
selected ? selectedBackground : background,
disabledBackground,
focusedBackground,
selected && selectedHoverBackground != null ? selectedHoverBackground : hoverBackground,
selected && selectedPressedBackground != null ? selectedPressedBackground : pressedBackground ),
(selected && selectedFocusedBackground != null) ? selectedFocusedBackground : focusedBackground,
(selected && selectedHoverBackground != null) ? selectedHoverBackground : hoverBackground,
(selected && selectedPressedBackground != null) ? selectedPressedBackground : pressedBackground ),
background ) );
paintBackground( g2 );
// paint checkmark
if( selected || indeterminate ) {
g2.setColor( c.isEnabled() ? checkmarkColor : disabledCheckmarkColor );
g2.setColor( c.isEnabled()
? ((selected && isFocused && selectedFocusedCheckmarkColor != null)
? selectedFocusedCheckmarkColor
: checkmarkColor)
: disabledCheckmarkColor );
if( indeterminate )
paintIndeterminate( g2 );
else

View File

@@ -18,7 +18,6 @@ package com.formdev.flatlaf.icons;
import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D;
import com.formdev.flatlaf.ui.FlatUIUtils;
/**
* Icon for {@link javax.swing.JRadioButton}.
@@ -34,7 +33,7 @@ import com.formdev.flatlaf.ui.FlatUIUtils;
public class FlatRadioButtonIcon
extends FlatCheckBoxIcon
{
protected final int centerDiameter = FlatUIUtils.getUIInt( "RadioButton.icon.centerDiameter", 8 );
protected final int centerDiameter = getUIInt( "RadioButton.icon.centerDiameter", 8, style );
@Override
protected void paintFocusBorder( Graphics2D g2 ) {

View File

@@ -99,8 +99,8 @@ Button.toolbar.pressedBackground=lighten($Button.background,4%,derived)
# enabled
CheckBox.icon.borderColor=#6B6B6B
CheckBox.icon.background=#43494A
CheckBox.icon.selectedBorderColor=#6B6B6B
CheckBox.icon.selectedBackground=#43494A
CheckBox.icon.selectedBorderColor=$CheckBox.icon.borderColor
CheckBox.icon.selectedBackground=$CheckBox.icon.background
CheckBox.icon.checkmarkColor=#A7A7A7
# disabled
@@ -119,6 +119,16 @@ CheckBox.icon.hoverBackground=lighten($CheckBox.icon.background,3%,derived)
# pressed
CheckBox.icon.pressedBackground=lighten($CheckBox.icon.background,6%,derived)
# used if CheckBox.icon.style=filled
# enabled
CheckBox.icon[filled].selectedBorderColor=$CheckBox.icon.checkmarkColor
CheckBox.icon[filled].selectedBackground=$CheckBox.icon.checkmarkColor
CheckBox.icon[filled].checkmarkColor=$CheckBox.icon.background
# hover
CheckBox.icon[filled].selectedHoverBackground=darken($CheckBox.icon[filled].selectedBackground,3%)
# pressed
CheckBox.icon[filled].selectedPressedBackground=darken($CheckBox.icon[filled].selectedBackground,6%)
#---- ComboBox ----
@@ -224,6 +234,11 @@ ProgressBar.selectionForeground=@foreground
ProgressBar.selectionBackground=@foreground
#---- RadioButton ----
RadioButton.icon[filled].centerDiameter=5
#---- ScrollBar ----
ScrollBar.track=lighten(@background,1%,derived noAutoInverse)

View File

@@ -35,19 +35,8 @@ Button.default.borderWidth=1
#---- CheckBox ----
# enabled
CheckBox.icon.selectedBorderColor=#4B97D9
CheckBox.icon.selectedBackground=#4F9EE3
CheckBox.icon.checkmarkColor=#FFFFFF
# focused
CheckBox.icon.selectedFocusedBorderColor=#ACCFF7
# hover
CheckBox.icon.selectedHoverBackground=#5E94CE
# pressed
CheckBox.icon.selectedPressedBackground=#72A1D4
CheckBox.icon.style=filled
CheckBox.icon[filled].focusWidth=2
#---- Component ----
@@ -56,8 +45,3 @@ Component.focusWidth=2
Component.innerFocusWidth=0
Component.innerOutlineWidth=0
Component.arrowType=triangle
#---- RadioButton ----
RadioButton.icon.centerDiameter=5

View File

@@ -102,7 +102,7 @@ Button.toolbar.pressedBackground=darken($Button.background,15%,derived)
CheckBox.icon.borderColor=#b0b0b0
CheckBox.icon.background=#FFFFFF
CheckBox.icon.selectedBorderColor=$CheckBox.icon.borderColor
CheckBox.icon.selectedBackground=#FFFFFF
CheckBox.icon.selectedBackground=$CheckBox.icon.background
CheckBox.icon.checkmarkColor=#4F9EE3
# disabled
@@ -122,6 +122,21 @@ CheckBox.icon.hoverBackground=$Button.hoverBackground
CheckBox.icon.pressedBackground=$Button.pressedBackground
# used if CheckBox.icon.style=filled
# enabled
CheckBox.icon[filled].selectedBorderColor=#4B97D9
CheckBox.icon[filled].selectedBackground=#4F9EE3
CheckBox.icon[filled].checkmarkColor=#FFFFFF
# focused
CheckBox.icon[filled].selectedFocusedBorderColor=#ACCFF7
CheckBox.icon[filled].selectedFocusedBackground=$CheckBox.icon[filled].selectedBackground
CheckBox.icon[filled].selectedFocusedCheckmarkColor=$CheckBox.icon.focusedBackground
# hover
CheckBox.icon[filled].selectedHoverBackground=#5E94CE
# pressed
CheckBox.icon[filled].selectedPressedBackground=#72A1D4
#---- ComboBox ----
ComboBox.background=@textComponentBackground
@@ -231,6 +246,11 @@ ProgressBar.selectionForeground=@textComponentBackground
ProgressBar.selectionBackground=@foreground
#---- RadioButton ----
RadioButton.icon[filled].centerDiameter=5
#---- ScrollBar ----
ScrollBar.track=lighten(@background,1%,derived noAutoInverse)

View File

@@ -130,6 +130,11 @@ CheckBox.icon.selectedBorderColor #6b6b6b javax.swing.plaf.ColorUIResource [U
CheckBox.icon.selectedFocusedBorderColor #466d94 javax.swing.plaf.ColorUIResource [UI]
CheckBox.icon [lazy] 15,15 com.formdev.flatlaf.icons.FlatCheckBoxIcon [UI]
CheckBox.iconTextGap 4
CheckBox.icon[filled].checkmarkColor #43494a javax.swing.plaf.ColorUIResource [UI]
CheckBox.icon[filled].selectedBackground #a7a7a7 javax.swing.plaf.ColorUIResource [UI]
CheckBox.icon[filled].selectedBorderColor #a7a7a7 javax.swing.plaf.ColorUIResource [UI]
CheckBox.icon[filled].selectedHoverBackground #9f9f9f javax.swing.plaf.ColorUIResource [UI]
CheckBox.icon[filled].selectedPressedBackground #989898 javax.swing.plaf.ColorUIResource [UI]
CheckBox.margin 2,2,2,2 javax.swing.plaf.InsetsUIResource [UI]
CheckBox.rollover true
CheckBox.textIconGap 4
@@ -704,6 +709,7 @@ RadioButton.highlight #242424 javax.swing.plaf.ColorUIResource [UI]
RadioButton.icon.centerDiameter 8
RadioButton.icon [lazy] 15,15 com.formdev.flatlaf.icons.FlatRadioButtonIcon [UI]
RadioButton.iconTextGap 4
RadioButton.icon[filled].centerDiameter 5
RadioButton.light #313131 javax.swing.plaf.ColorUIResource [UI]
RadioButton.margin 2,2,2,2 javax.swing.plaf.InsetsUIResource [UI]
RadioButton.rollover true

View File

@@ -34,22 +34,13 @@
- Button.focusedBackground #e3f1fa javax.swing.plaf.ColorUIResource [UI]
- CheckBox.icon.checkmarkColor #4f9ee3 javax.swing.plaf.ColorUIResource [UI]
+ CheckBox.icon.checkmarkColor #ffffff javax.swing.plaf.ColorUIResource [UI]
- CheckBox.icon.focusedBackground #e3f1fa javax.swing.plaf.ColorUIResource [UI]
- CheckBox.icon.selectedBackground #ffffff javax.swing.plaf.ColorUIResource [UI]
+ CheckBox.icon.selectedBackground #4f9ee3 javax.swing.plaf.ColorUIResource [UI]
+ CheckBox.icon.style filled
- CheckBox.icon.selectedBorderColor #b0b0b0 javax.swing.plaf.ColorUIResource [UI]
+ CheckBox.icon.selectedBorderColor #4b97d9 javax.swing.plaf.ColorUIResource [UI]
+ CheckBox.icon[filled].focusWidth 2
+ CheckBox.icon.selectedFocusedBorderColor #accff7 javax.swing.plaf.ColorUIResource [UI]
+ CheckBox.icon.selectedHoverBackground #5e94ce javax.swing.plaf.ColorUIResource [UI]
+ CheckBox.icon.selectedPressedBackground #72a1d4 javax.swing.plaf.ColorUIResource [UI]
- CheckBox.icon[filled].selectedFocusedCheckmarkColor #e3f1fa javax.swing.plaf.ColorUIResource [UI]
- ComboBox.border [lazy] 1,1,1,1 false com.formdev.flatlaf.ui.FlatRoundBorder [UI]
+ ComboBox.border [lazy] 3,3,3,3 false com.formdev.flatlaf.ui.FlatRoundBorder [UI]
@@ -80,9 +71,6 @@
- PasswordField.border [lazy] 1,1,1,1 false com.formdev.flatlaf.ui.FlatTextBorder [UI]
+ PasswordField.border [lazy] 3,3,3,3 false com.formdev.flatlaf.ui.FlatTextBorder [UI]
- RadioButton.icon.centerDiameter 8
+ RadioButton.icon.centerDiameter 5
- ScrollPane.border [lazy] 1,1,1,1 false com.formdev.flatlaf.ui.FlatBorder [UI]
+ ScrollPane.border [lazy] 3,3,3,3 false com.formdev.flatlaf.ui.FlatBorder [UI]

View File

@@ -131,6 +131,14 @@ CheckBox.icon.selectedBackground #ffffff javax.swing.plaf.ColorUIResource [UI
CheckBox.icon.selectedBorderColor #b0b0b0 javax.swing.plaf.ColorUIResource [UI]
CheckBox.icon [lazy] 15,15 com.formdev.flatlaf.icons.FlatCheckBoxIcon [UI]
CheckBox.iconTextGap 4
CheckBox.icon[filled].checkmarkColor #ffffff javax.swing.plaf.ColorUIResource [UI]
CheckBox.icon[filled].selectedBackground #4f9ee3 javax.swing.plaf.ColorUIResource [UI]
CheckBox.icon[filled].selectedBorderColor #4b97d9 javax.swing.plaf.ColorUIResource [UI]
CheckBox.icon[filled].selectedFocusedBackground #4f9ee3 javax.swing.plaf.ColorUIResource [UI]
CheckBox.icon[filled].selectedFocusedBorderColor #accff7 javax.swing.plaf.ColorUIResource [UI]
CheckBox.icon[filled].selectedFocusedCheckmarkColor #e3f1fa javax.swing.plaf.ColorUIResource [UI]
CheckBox.icon[filled].selectedHoverBackground #5e94ce javax.swing.plaf.ColorUIResource [UI]
CheckBox.icon[filled].selectedPressedBackground #72a1d4 javax.swing.plaf.ColorUIResource [UI]
CheckBox.margin 2,2,2,2 javax.swing.plaf.InsetsUIResource [UI]
CheckBox.rollover true
CheckBox.textIconGap 4
@@ -706,6 +714,7 @@ RadioButton.highlight #ffffff javax.swing.plaf.ColorUIResource [UI]
RadioButton.icon.centerDiameter 8
RadioButton.icon [lazy] 15,15 com.formdev.flatlaf.icons.FlatRadioButtonIcon [UI]
RadioButton.iconTextGap 4
RadioButton.icon[filled].centerDiameter 5
RadioButton.light #e3e3e3 javax.swing.plaf.ColorUIResource [UI]
RadioButton.margin 2,2,2,2 javax.swing.plaf.InsetsUIResource [UI]
RadioButton.rollover true