mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-15 08:17:12 -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
|
@Override
|
||||||
public Insets getBorderInsets( Component c, Insets insets ) {
|
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();
|
boolean leftToRight = left == right || c.getComponentOrientation().isLeftToRight();
|
||||||
insets.left = scale( leftToRight ? left : right );
|
insets.left = scale( leftToRight ? left : right );
|
||||||
insets.top = scale( top );
|
insets.top = scale( top );
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.formdev.flatlaf.ui;
|
package com.formdev.flatlaf.ui;
|
||||||
|
|
||||||
import static com.formdev.flatlaf.util.UIScale.scale;
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
@@ -48,15 +47,10 @@ public class FlatListCellBorder
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Insets getBorderInsets( Component c, Insets insets ) {
|
public Insets getBorderInsets( Component c, Insets insets ) {
|
||||||
Insets margins = getStyleFromListUI( c, ui -> ui.cellMargins );
|
Insets m = getStyleFromListUI( c, ui -> ui.cellMargins );
|
||||||
if( margins != null ) {
|
if( m != null )
|
||||||
boolean leftToRight = margins.left == margins.right || c.getComponentOrientation().isLeftToRight();
|
return scaleInsets( c, insets, m.top, m.left, m.bottom, m.right );
|
||||||
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;
|
|
||||||
}
|
|
||||||
return super.getBorderInsets( c, insets );
|
return super.getBorderInsets( c, insets );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.formdev.flatlaf.ui;
|
package com.formdev.flatlaf.ui;
|
||||||
|
|
||||||
import static com.formdev.flatlaf.util.UIScale.scale;
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
@@ -48,15 +47,10 @@ public class FlatTableCellBorder
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Insets getBorderInsets( Component c, Insets insets ) {
|
public Insets getBorderInsets( Component c, Insets insets ) {
|
||||||
Insets margins = getStyleFromTableUI( c, ui -> ui.cellMargins );
|
Insets m = getStyleFromTableUI( c, ui -> ui.cellMargins );
|
||||||
if( margins != null ) {
|
if( m != null )
|
||||||
boolean leftToRight = margins.left == margins.right || c.getComponentOrientation().isLeftToRight();
|
return scaleInsets( c, insets, m.top, m.left, m.bottom, m.right );
|
||||||
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;
|
|
||||||
}
|
|
||||||
return super.getBorderInsets( c, insets );
|
return super.getBorderInsets( c, insets );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user