CheckBox and RadioButton: added RadioButton.icon.style (similar to CheckBox.icon.style) to support different styles for checkbox and radiobutton

(e.g. Material design uses filled checkboxes, but outlined radiobuttons)
This commit is contained in:
Karl Tauber
2021-11-03 11:27:18 +01:00
parent aa4e013097
commit 88576f68fd
7 changed files with 24 additions and 3 deletions

View File

@@ -86,7 +86,7 @@ import com.formdev.flatlaf.ui.FlatUIUtils;
public class FlatCheckBoxIcon public class FlatCheckBoxIcon
extends FlatAbstractIcon extends FlatAbstractIcon
{ {
protected final String style = UIManager.getString( "CheckBox.icon.style" ); protected final String style = UIManager.getString( getPropertyPrefix() + "icon.style" );
@Styleable protected float focusWidth = getUIFloat( "CheckBox.icon.focusWidth", UIManager.getInt( "Component.focusWidth" ), style ); @Styleable protected float focusWidth = getUIFloat( "CheckBox.icon.focusWidth", UIManager.getInt( "Component.focusWidth" ), style );
@Styleable protected Color focusColor = FlatUIUtils.getUIColor( "CheckBox.icon.focusColor", UIManager.getColor( "Component.focusColor" ) ); @Styleable protected Color focusColor = FlatUIUtils.getUIColor( "CheckBox.icon.focusColor", UIManager.getColor( "Component.focusColor" ) );
/** @since 2 */ @Styleable protected float borderWidth = getUIFloat( "CheckBox.icon.borderWidth", FlatUIUtils.getUIFloat( "Component.borderWidth", 1 ), style ); /** @since 2 */ @Styleable protected float borderWidth = getUIFloat( "CheckBox.icon.borderWidth", FlatUIUtils.getUIFloat( "Component.borderWidth", 1 ), style );
@@ -129,6 +129,10 @@ public class FlatCheckBoxIcon
/** @since 2 */ @Styleable protected Color pressedSelectedBackground = getUIColor( "CheckBox.icon.pressedSelectedBackground", style ); /** @since 2 */ @Styleable protected Color pressedSelectedBackground = getUIColor( "CheckBox.icon.pressedSelectedBackground", style );
/** @since 2 */ @Styleable protected Color pressedCheckmarkColor = getUIColor( "CheckBox.icon.pressedCheckmarkColor", style ); /** @since 2 */ @Styleable protected Color pressedCheckmarkColor = getUIColor( "CheckBox.icon.pressedCheckmarkColor", style );
protected String getPropertyPrefix() {
return "CheckBox.";
}
protected static Color getUIColor( String key, String style ) { protected static Color getUIColor( String key, String style ) {
if( style != null ) { if( style != null ) {
Color color = UIManager.getColor( styleKey( key, style ) ); Color color = UIManager.getColor( styleKey( key, style ) );

View File

@@ -29,6 +29,7 @@ import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable;
* is painted outside of the icon bounds. Make sure that the radiobutton * is painted outside of the icon bounds. Make sure that the radiobutton
* has margins, which are equal or greater than focusWidth. * has margins, which are equal or greater than focusWidth.
* *
* @uiDefault RadioButton.icon.style String optional; "outlined"/null (default) or "filled"
* @uiDefault RadioButton.icon.centerDiameter int or float * @uiDefault RadioButton.icon.centerDiameter int or float
* *
* @author Karl Tauber * @author Karl Tauber
@@ -38,6 +39,11 @@ public class FlatRadioButtonIcon
{ {
@Styleable protected float centerDiameter = getUIFloat( "RadioButton.icon.centerDiameter", 8, style ); @Styleable protected float centerDiameter = getUIFloat( "RadioButton.icon.centerDiameter", 8, style );
@Override
protected String getPropertyPrefix() {
return "RadioButton.";
}
@Override @Override
protected void paintFocusBorder( Component c, Graphics2D g ) { protected void paintFocusBorder( Component c, Graphics2D g ) {
// the outer focus border is painted outside of the icon // the outer focus border is painted outside of the icon

View File

@@ -155,7 +155,7 @@ CheckBox.icon.pressedBorderColor = $CheckBox.icon.focusedBorderColor
CheckBox.icon.pressedBackground = lighten($CheckBox.icon.background,6%,derived) CheckBox.icon.pressedBackground = lighten($CheckBox.icon.background,6%,derived)
# used if CheckBox.icon.style = filled # used if CheckBox.icon.style or RadioButton.icon.style = filled
# enabled # enabled
CheckBox.icon[filled].selectedBorderColor = $CheckBox.icon.checkmarkColor CheckBox.icon[filled].selectedBorderColor = $CheckBox.icon.checkmarkColor
CheckBox.icon[filled].selectedBackground = $CheckBox.icon.checkmarkColor CheckBox.icon[filled].selectedBackground = $CheckBox.icon.checkmarkColor

View File

@@ -64,3 +64,8 @@ Component.focusWidth = 2
Component.innerFocusWidth = 0 Component.innerFocusWidth = 0
Component.innerOutlineWidth = 0 Component.innerOutlineWidth = 0
Component.arrowType = triangle Component.arrowType = triangle
#---- RadioButton ----
RadioButton.icon.style = filled

View File

@@ -158,7 +158,7 @@ CheckBox.icon.pressedBorderColor = $CheckBox.icon.focusedBorderColor
CheckBox.icon.pressedBackground = darken($CheckBox.icon.background,10%,derived) CheckBox.icon.pressedBackground = darken($CheckBox.icon.background,10%,derived)
# used if CheckBox.icon.style = filled # used if CheckBox.icon.style or RadioButton.icon.style = filled
# enabled # enabled
CheckBox.icon[filled].selectedBorderColor = shade($CheckBox.icon[filled].selectedBackground,5%) CheckBox.icon[filled].selectedBorderColor = shade($CheckBox.icon[filled].selectedBackground,5%)
CheckBox.icon[filled].selectedBackground = @accentCheckmarkColor CheckBox.icon[filled].selectedBackground = @accentCheckmarkColor

View File

@@ -100,6 +100,11 @@
+ PasswordField.border [lazy] 3,3,3,3 false com.formdev.flatlaf.ui.FlatTextBorder [UI] + PasswordField.border [lazy] 3,3,3,3 false com.formdev.flatlaf.ui.FlatTextBorder [UI]
#---- RadioButton ----
+ RadioButton.icon.style filled
#---- ScrollPane ---- #---- ScrollPane ----
- ScrollPane.border [lazy] 1,1,1,1 false com.formdev.flatlaf.ui.FlatBorder [UI] - ScrollPane.border [lazy] 1,1,1,1 false com.formdev.flatlaf.ui.FlatBorder [UI]

View File

@@ -601,6 +601,7 @@ RadioButton.foreground
RadioButton.highlight RadioButton.highlight
RadioButton.icon RadioButton.icon
RadioButton.icon.centerDiameter RadioButton.icon.centerDiameter
RadioButton.icon.style
RadioButton.iconTextGap RadioButton.iconTextGap
RadioButton.icon[filled].centerDiameter RadioButton.icon[filled].centerDiameter
RadioButton.light RadioButton.light