mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-11 06:27:13 -06:00
Styling: reduce duplicate code in list and table cell borders
This commit is contained in:
@@ -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 );
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user