mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-06 14:00:55 +03:00
FlatLineBorder: use arc from Label or Panel, if not specified in border (issue #842)
This commit is contained in:
@@ -646,7 +646,7 @@ class UIDefaultsLoader
|
|||||||
: 1f;
|
: 1f;
|
||||||
int arc = (parts.size() >= 7) && !parts.get( 6 ).isEmpty()
|
int arc = (parts.size() >= 7) && !parts.get( 6 ).isEmpty()
|
||||||
? parseInteger( parts.get( 6 ) )
|
? parseInteger( parts.get( 6 ) )
|
||||||
: 0;
|
: -1;
|
||||||
|
|
||||||
return (LazyValue) t -> {
|
return (LazyValue) t -> {
|
||||||
return (lineColor != null || arc > 0)
|
return (lineColor != null || arc > 0)
|
||||||
|
|||||||
@@ -23,6 +23,9 @@ import java.awt.Graphics;
|
|||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.plaf.ComponentUI;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Line border for various components.
|
* Line border for various components.
|
||||||
@@ -45,7 +48,7 @@ public class FlatLineBorder
|
|||||||
/** @since 2 */ private final int arc;
|
/** @since 2 */ private final int arc;
|
||||||
|
|
||||||
public FlatLineBorder( Insets insets, Color lineColor ) {
|
public FlatLineBorder( Insets insets, Color lineColor ) {
|
||||||
this( insets, lineColor, 1f, 0 );
|
this( insets, lineColor, 1f, -1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @since 2 */
|
/** @since 2 */
|
||||||
@@ -92,11 +95,26 @@ public class FlatLineBorder
|
|||||||
if( lineColor == null || lineThickness <= 0 )
|
if( lineColor == null || lineThickness <= 0 )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
int arc = getArc();
|
||||||
|
if( arc < 0 ) {
|
||||||
|
// get arc from label or panel
|
||||||
|
ComponentUI ui = (c instanceof JLabel)
|
||||||
|
? ((JLabel)c).getUI()
|
||||||
|
: (c instanceof JPanel ? ((JPanel)c).getUI() : null);
|
||||||
|
if( ui instanceof FlatLabelUI )
|
||||||
|
arc = ((FlatLabelUI)ui).arc;
|
||||||
|
else if( ui instanceof FlatPanelUI )
|
||||||
|
arc = ((FlatPanelUI)ui).arc;
|
||||||
|
|
||||||
|
if( arc < 0 )
|
||||||
|
arc = 0;
|
||||||
|
}
|
||||||
|
|
||||||
Graphics2D g2 = (Graphics2D) g.create();
|
Graphics2D g2 = (Graphics2D) g.create();
|
||||||
try {
|
try {
|
||||||
FlatUIUtils.setRenderingHints( g2 );
|
FlatUIUtils.setRenderingHints( g2 );
|
||||||
FlatUIUtils.paintOutlinedComponent( g2, x, y, width, height,
|
FlatUIUtils.paintOutlinedComponent( g2, x, y, width, height,
|
||||||
0, 0, 0, scale( lineThickness ), scale( getArc() ), null, lineColor, null );
|
0, 0, 0, scale( lineThickness ), scale( arc ), null, lineColor, null );
|
||||||
} finally {
|
} finally {
|
||||||
g2.dispose();
|
g2.dispose();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ public class TestUIDefaultsLoader
|
|||||||
assertBorderEquals( new FlatEmptyBorder( insets ), "1,2,3,4" );
|
assertBorderEquals( new FlatEmptyBorder( insets ), "1,2,3,4" );
|
||||||
assertBorderEquals( new FlatEmptyBorder( insets ), "1,2,3,4,,," );
|
assertBorderEquals( new FlatEmptyBorder( insets ), "1,2,3,4,,," );
|
||||||
assertBorderEquals( new FlatLineBorder( insets, Color.red ), "1,2,3,4,#f00" );
|
assertBorderEquals( new FlatLineBorder( insets, Color.red ), "1,2,3,4,#f00" );
|
||||||
assertBorderEquals( new FlatLineBorder( insets, Color.red, 2.5f, 0 ), "1,2,3,4,#f00,2.5" );
|
assertBorderEquals( new FlatLineBorder( insets, Color.red, 2.5f, -1 ), "1,2,3,4,#f00,2.5" );
|
||||||
assertBorderEquals( new FlatLineBorder( insets, Color.red, 2.5f, 6 ), "1,2,3,4,#f00,2.5,6" );
|
assertBorderEquals( new FlatLineBorder( insets, Color.red, 2.5f, 6 ), "1,2,3,4,#f00,2.5,6" );
|
||||||
assertBorderEquals( new FlatLineBorder( insets, Color.red, 1, 6 ), "1,2,3,4,#f00,,6" );
|
assertBorderEquals( new FlatLineBorder( insets, Color.red, 1, 6 ), "1,2,3,4,#f00,,6" );
|
||||||
assertBorderEquals( new FlatLineBorder( insets, null, 1, 6 ), "1,2,3,4,,,6" );
|
assertBorderEquals( new FlatLineBorder( insets, null, 1, 6 ), "1,2,3,4,,,6" );
|
||||||
|
|||||||
@@ -553,7 +553,7 @@ class MoreComponentsPanel
|
|||||||
|
|
||||||
//---- label10 ----
|
//---- label10 ----
|
||||||
label10.setText("rounded border");
|
label10.setText("rounded border");
|
||||||
label10.putClientProperty("FlatLaf.style", "border: 2,10,2,10,#135b76,1,999");
|
label10.putClientProperty("FlatLaf.style", "arc: 999; border: 2,10,2,10,#135b76");
|
||||||
label10.setBackground(new Color(0xb8e4f3));
|
label10.setBackground(new Color(0xb8e4f3));
|
||||||
label10.setForeground(new Color(0x135b76));
|
label10.setForeground(new Color(0x135b76));
|
||||||
add(label10, "cell 1 13 4 1");
|
add(label10, "cell 1 13 4 1");
|
||||||
|
|||||||
@@ -517,7 +517,7 @@ new FormModel {
|
|||||||
add( new FormComponent( "javax.swing.JLabel" ) {
|
add( new FormComponent( "javax.swing.JLabel" ) {
|
||||||
name: "label10"
|
name: "label10"
|
||||||
"text": "rounded border"
|
"text": "rounded border"
|
||||||
"$client.FlatLaf.style": "border: 2,10,2,10,#135b76,1,999"
|
"$client.FlatLaf.style": "arc: 999; border: 2,10,2,10,#135b76"
|
||||||
"background": new java.awt.Color( 184, 228, 243, 255 )
|
"background": new java.awt.Color( 184, 228, 243, 255 )
|
||||||
"foreground": new java.awt.Color( 19, 91, 118, 255 )
|
"foreground": new java.awt.Color( 19, 91, 118, 255 )
|
||||||
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
}, new FormLayoutConstraints( class net.miginfocom.layout.CC ) {
|
||||||
|
|||||||
Reference in New Issue
Block a user