Skip to content

Commit

Permalink
FlatLineBorder: support specifying painted line thickness
Browse files Browse the repository at this point in the history
  • Loading branch information
DevCharly committed Mar 29, 2020
1 parent 5ed40ca commit 60c6c5b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -332,16 +332,17 @@ else if( key.endsWith( "UI" ) )

private static Object parseBorder( String value, Function<String, String> resolver, List<ClassLoader> addonClassLoaders ) {
if( value.indexOf( ',' ) >= 0 ) {
// top,left,bottom,right[,lineColor]
// top,left,bottom,right[,lineColor[,lineThickness]]
List<String> parts = split( value, ',' );
Insets insets = parseInsets( value );
ColorUIResource lineColor = (parts.size() == 5)
ColorUIResource lineColor = (parts.size() >= 5)
? (ColorUIResource) parseColorOrFunction( resolver.apply( parts.get( 4 ) ), resolver, true )
: null;
float lineThickness = (parts.size() >= 6) ? parseFloat( parts.get( 5 ), true ) : 1f;

return (LazyValue) t -> {
return (lineColor != null)
? new FlatLineBorder( insets, lineColor )
? new FlatLineBorder( insets, lineColor, lineThickness )
: new FlatEmptyBorder( insets );
};
} else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,26 @@
/**
* Line border for various components.
*
* Paints a scaled 1px thick line around the component.
* The line thickness is not included in the border insets.
* The insets should be at least 1,1,1,1.
* Paints a scaled (usually 1px thick) line around the component.
* The line thickness is not added to the border insets.
* The insets should be at least have line thickness (usually 1,1,1,1).
*
* @author Karl Tauber
*/
public class FlatLineBorder
extends FlatEmptyBorder
{
private final Color lineColor;
private final float lineThickness;

public FlatLineBorder( Insets insets, Color lineColor ) {
this( insets, lineColor, 1f );
}

public FlatLineBorder( Insets insets, Color lineColor, float lineThickness ) {
super( insets );
this.lineColor = lineColor;
this.lineThickness = lineThickness;
}

@Override
Expand All @@ -48,7 +54,7 @@ public void paintBorder( Component c, Graphics g, int x, int y, int width, int h
try {
FlatUIUtils.setRenderingHints( g2 );
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 {
g2.dispose();
}
Expand Down

0 comments on commit 60c6c5b

Please sign in to comment.