CheckBox and RadioButton: use Component.focusWidth in icons

This commit is contained in:
Karl Tauber
2019-08-27 09:42:23 +02:00
parent 3275c0f374
commit 2acc4a0da1
2 changed files with 19 additions and 13 deletions

View File

@@ -36,6 +36,9 @@ import com.formdev.flatlaf.util.UIScale;
public class FlatCheckBoxIcon
implements Icon, UIResource
{
protected final int focusWidth = UIManager.getInt( "Component.focusWidth" );
protected final int iconSize = 15 + (focusWidth * 2);
@Override
public void paintIcon( Component c, Graphics g, int x, int y ) {
Graphics2D g2 = (Graphics2D) g.create();
@@ -82,33 +85,36 @@ public class FlatCheckBoxIcon
}
protected void paintFocusBorder( Graphics2D g2 ) {
g2.fillRoundRect( 1, 0, 18, 18, 8, 8 );
g2.fillRoundRect( 1, 0, iconSize - 1, iconSize - 1, 8, 8 );
}
protected void paintBorder( Graphics2D g2 ) {
g2.fillRoundRect( 3, 2, 14, 14, 4, 4 );
g2.fillRoundRect( focusWidth + 1, focusWidth, 14, 14, 4, 4 );
}
protected void paintBackground( Graphics2D g2 ) {
g2.fillRoundRect( 4, 3, 12, 12, 4, 4 );
g2.fillRoundRect( focusWidth + 2, focusWidth + 1, 12, 12, 4, 4 );
}
protected void paintCheckmark( Graphics2D g2 ) {
g2.setStroke( new BasicStroke( 1.9f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND ) );
Path2D.Float path = new Path2D.Float();
path.moveTo( 6.5f, 9.5f );
path.lineTo( 8.6f, 12f );
path.lineTo( 13.25f, 5.5f );
path.moveTo( 4.5f, 7.5f );
path.lineTo( 6.6f, 10f );
path.lineTo( 11.25f, 3.5f );
g2.translate( focusWidth, focusWidth );
g2.setStroke( new BasicStroke( 1.9f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND ) );
g2.draw( path );
g2.translate( -focusWidth, -focusWidth );
}
@Override
public int getIconWidth() {
return scale( 19 );
return scale( iconSize );
}
@Override
public int getIconHeight() {
return scale( 19 );
return scale( iconSize );
}
}

View File

@@ -28,21 +28,21 @@ public class FlatRadioButtonIcon
{
@Override
protected void paintFocusBorder( Graphics2D g2 ) {
g2.fillOval( 0, 0, 19, 19 );
g2.fillOval( 0, 0, iconSize, iconSize );
}
@Override
protected void paintBorder( Graphics2D g2 ) {
g2.fillOval( 2, 2, 15, 15 );
g2.fillOval( focusWidth, focusWidth, 15, 15 );
}
@Override
protected void paintBackground( Graphics2D g2 ) {
g2.fillOval( 3, 3, 13, 13 );
g2.fillOval( focusWidth + 1, focusWidth + 1, 13, 13 );
}
@Override
protected void paintCheckmark( Graphics2D g2 ) {
g2.fillOval( 7, 7, 5, 5 );
g2.fillOval( focusWidth + 5, focusWidth + 5, 5, 5 );
}
}