Styling: reduce duplicate code in list and table cell borders

This commit is contained in:
Karl Tauber
2021-06-24 17:53:19 +02:00
parent 5e5aa17e14
commit 8ba7f7f961
3 changed files with 14 additions and 20 deletions

View File

@@ -50,6 +50,12 @@ public class FlatEmptyBorder
@Override
public Insets getBorderInsets( Component c, Insets insets ) {
return scaleInsets( c, insets, top, left, bottom, right );
}
protected static Insets scaleInsets( Component c, Insets insets,
int top, int left, int bottom, int right )
{
boolean leftToRight = left == right || c.getComponentOrientation().isLeftToRight();
insets.left = scale( leftToRight ? left : right );
insets.top = scale( top );

View File

@@ -16,7 +16,6 @@
package com.formdev.flatlaf.ui;
import static com.formdev.flatlaf.util.UIScale.scale;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
@@ -48,15 +47,10 @@ public class FlatListCellBorder
@Override
public Insets getBorderInsets( Component c, Insets insets ) {
Insets margins = getStyleFromListUI( c, ui -> ui.cellMargins );
if( margins != null ) {
boolean leftToRight = margins.left == margins.right || c.getComponentOrientation().isLeftToRight();
insets.left = scale( leftToRight ? margins.left : margins.right );
insets.top = scale( margins.top );
insets.right = scale( leftToRight ? margins.right : margins.left );
insets.bottom = scale( margins.bottom );
return insets;
}
Insets m = getStyleFromListUI( c, ui -> ui.cellMargins );
if( m != null )
return scaleInsets( c, insets, m.top, m.left, m.bottom, m.right );
return super.getBorderInsets( c, insets );
}

View File

@@ -16,7 +16,6 @@
package com.formdev.flatlaf.ui;
import static com.formdev.flatlaf.util.UIScale.scale;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
@@ -48,15 +47,10 @@ public class FlatTableCellBorder
@Override
public Insets getBorderInsets( Component c, Insets insets ) {
Insets margins = getStyleFromTableUI( c, ui -> ui.cellMargins );
if( margins != null ) {
boolean leftToRight = margins.left == margins.right || c.getComponentOrientation().isLeftToRight();
insets.left = scale( leftToRight ? margins.left : margins.right );
insets.top = scale( margins.top );
insets.right = scale( leftToRight ? margins.right : margins.left );
insets.bottom = scale( margins.bottom );
return insets;
}
Insets m = getStyleFromTableUI( c, ui -> ui.cellMargins );
if( m != null )
return scaleInsets( c, insets, m.top, m.left, m.bottom, m.right );
return super.getBorderInsets( c, insets );
}