support CompoundBorder as component border with FlatBorder on the outside

This commit is contained in:
Karl Tauber
2020-05-19 23:24:00 +02:00
parent 815e23b930
commit 2a0403a988
5 changed files with 933 additions and 14 deletions

View File

@@ -32,7 +32,6 @@ import javax.swing.JSpinner;
import javax.swing.JTextField;
import javax.swing.LookAndFeel;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.UIResource;
import javax.swing.plaf.basic.BasicTextFieldUI;
@@ -152,14 +151,12 @@ public class FlatTextFieldUI
}
static void paintBackground( Graphics g, JTextComponent c, boolean isIntelliJTheme ) {
Border border = c.getBorder();
// do not paint background if:
// - not opaque and
// - border is not a flat border and
// - opaque was explicitly set (to false)
// (same behaviour as in AquaTextFieldUI)
if( !c.isOpaque() && !(border instanceof FlatBorder) && FlatUIUtils.hasOpaqueBeenExplicitlySet( c ) )
if( !c.isOpaque() && FlatUIUtils.getOutsideFlatBorder( c ) == null && FlatUIUtils.hasOpaqueBeenExplicitlySet( c ) )
return;
float focusWidth = FlatUIUtils.getBorderFocusWidth( c );

View File

@@ -40,6 +40,7 @@ import javax.swing.JComponent;
import javax.swing.LookAndFeel;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.border.CompoundBorder;
import javax.swing.plaf.UIResource;
import com.formdev.flatlaf.FlatClientProperties;
import com.formdev.flatlaf.util.DerivedColor;
@@ -152,9 +153,9 @@ public class FlatUIUtils
* Returns the scaled thickness of the outer focus border for the given component.
*/
public static float getBorderFocusWidth( JComponent c ) {
Border border = c.getBorder();
return (border instanceof FlatBorder)
? UIScale.scale( (float) ((FlatBorder)border).getFocusWidth( c ) )
FlatBorder border = getOutsideFlatBorder( c );
return (border != null)
? UIScale.scale( (float) border.getFocusWidth( c ) )
: 0;
}
@@ -162,9 +163,9 @@ public class FlatUIUtils
* Returns the scaled arc diameter of the border for the given component.
*/
public static float getBorderArc( JComponent c ) {
Border border = c.getBorder();
return (border instanceof FlatBorder)
? UIScale.scale( (float) ((FlatBorder)border).getArc( c ) )
FlatBorder border = getOutsideFlatBorder( c );
return (border != null)
? UIScale.scale( (float) border.getArc( c ) )
: 0;
}
@@ -172,6 +173,18 @@ public class FlatUIUtils
return getBorderArc( c ) >= c.getHeight();
}
public static FlatBorder getOutsideFlatBorder( JComponent c ) {
Border border = c.getBorder();
for(;;) {
if( border instanceof FlatBorder )
return (FlatBorder) border;
else if( border instanceof CompoundBorder )
border = ((CompoundBorder)border).getOutsideBorder();
else
return null;
}
}
/**
* Sets rendering hints used for painting.
*/

View File

@@ -21,7 +21,6 @@ import java.awt.Insets;
import java.beans.PropertyChangeListener;
import java.util.function.Function;
import javax.swing.JComponent;
import javax.swing.border.Border;
/**
* Support for MigLayout visual paddings.
@@ -75,9 +74,9 @@ public class MigLayoutVisualPadding
return;
install( c, c2 -> {
Border border = c2.getBorder();
if( border instanceof FlatBorder ) {
int focusWidth = ((FlatBorder)border).getFocusWidth( c2 );
FlatBorder border = FlatUIUtils.getOutsideFlatBorder( c2 );
if( border != null ) {
int focusWidth = border.getFocusWidth( c2 );
return new Insets( focusWidth, focusWidth, focusWidth, focusWidth );
} else
return null;