FlatLineBorder: support specifying painted line thickness

This commit is contained in:
Karl Tauber
2020-03-29 23:30:04 +02:00
parent 5ed40cab1d
commit 60c6c5b37a
2 changed files with 14 additions and 7 deletions

View File

@@ -332,16 +332,17 @@ class UIDefaultsLoader
private static Object parseBorder( String value, Function<String, String> resolver, List<ClassLoader> addonClassLoaders ) { private static Object parseBorder( String value, Function<String, String> resolver, List<ClassLoader> addonClassLoaders ) {
if( value.indexOf( ',' ) >= 0 ) { if( value.indexOf( ',' ) >= 0 ) {
// top,left,bottom,right[,lineColor] // top,left,bottom,right[,lineColor[,lineThickness]]
List<String> parts = split( value, ',' ); List<String> parts = split( value, ',' );
Insets insets = parseInsets( value ); Insets insets = parseInsets( value );
ColorUIResource lineColor = (parts.size() == 5) ColorUIResource lineColor = (parts.size() >= 5)
? (ColorUIResource) parseColorOrFunction( resolver.apply( parts.get( 4 ) ), resolver, true ) ? (ColorUIResource) parseColorOrFunction( resolver.apply( parts.get( 4 ) ), resolver, true )
: null; : null;
float lineThickness = (parts.size() >= 6) ? parseFloat( parts.get( 5 ), true ) : 1f;
return (LazyValue) t -> { return (LazyValue) t -> {
return (lineColor != null) return (lineColor != null)
? new FlatLineBorder( insets, lineColor ) ? new FlatLineBorder( insets, lineColor, lineThickness )
: new FlatEmptyBorder( insets ); : new FlatEmptyBorder( insets );
}; };
} else } else

View File

@@ -26,9 +26,9 @@ import java.awt.Insets;
/** /**
* Line border for various components. * Line border for various components.
* *
* Paints a scaled 1px thick line around the component. * Paints a scaled (usually 1px thick) line around the component.
* The line thickness is not included in the border insets. * The line thickness is not added to the border insets.
* The insets should be at least 1,1,1,1. * The insets should be at least have line thickness (usually 1,1,1,1).
* *
* @author Karl Tauber * @author Karl Tauber
*/ */
@@ -36,10 +36,16 @@ public class FlatLineBorder
extends FlatEmptyBorder extends FlatEmptyBorder
{ {
private final Color lineColor; private final Color lineColor;
private final float lineThickness;
public FlatLineBorder( Insets insets, Color lineColor ) { public FlatLineBorder( Insets insets, Color lineColor ) {
this( insets, lineColor, 1f );
}
public FlatLineBorder( Insets insets, Color lineColor, float lineThickness ) {
super( insets ); super( insets );
this.lineColor = lineColor; this.lineColor = lineColor;
this.lineThickness = lineThickness;
} }
@Override @Override
@@ -48,7 +54,7 @@ public class FlatLineBorder
try { try {
FlatUIUtils.setRenderingHints( g2 ); FlatUIUtils.setRenderingHints( g2 );
g2.setColor( lineColor ); g2.setColor( lineColor );
FlatUIUtils.paintComponentBorder( g2, x, y, width, height, 0f, scale( 1f ), 0f ); FlatUIUtils.paintComponentBorder( g2, x, y, width, height, 0f, scale( lineThickness ), 0f );
} finally { } finally {
g2.dispose(); g2.dispose();
} }