mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-11 06:27:13 -06:00
ToolBar: added styling properties separatorWidth and separatorColor
This commit is contained in:
@@ -18,6 +18,7 @@ package com.formdev.flatlaf.ui;
|
||||
|
||||
import static com.formdev.flatlaf.util.UIScale.scale;
|
||||
import java.awt.Color;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
@@ -173,6 +174,12 @@ public class FlatToolBarSeparatorUI
|
||||
if( size != null )
|
||||
return scale( size );
|
||||
|
||||
// get separator width
|
||||
int separatorWidth = this.separatorWidth;
|
||||
FlatToolBarUI toolBarUI = getToolBarUI( c );
|
||||
if( toolBarUI != null && toolBarUI.separatorWidth != null )
|
||||
separatorWidth = toolBarUI.separatorWidth;
|
||||
|
||||
// make sure that gap on left and right side of line have same size
|
||||
int sepWidth = (scale( (separatorWidth - LINE_WIDTH) / 2 ) * 2) + scale( LINE_WIDTH );
|
||||
|
||||
@@ -196,6 +203,12 @@ public class FlatToolBarSeparatorUI
|
||||
float lineWidth = scale( 1f );
|
||||
float offset = scale( 2f );
|
||||
|
||||
// get separator color
|
||||
Color separatorColor = this.separatorColor;
|
||||
FlatToolBarUI toolBarUI = getToolBarUI( c );
|
||||
if( toolBarUI != null && toolBarUI.separatorColor != null )
|
||||
separatorColor = toolBarUI.separatorColor;
|
||||
|
||||
Object[] oldRenderingHints = FlatUIUtils.setRenderingHints( g );
|
||||
g.setColor( separatorColor );
|
||||
|
||||
@@ -210,4 +223,11 @@ public class FlatToolBarSeparatorUI
|
||||
private boolean isVertical( JComponent c ) {
|
||||
return ((JToolBar.Separator)c).getOrientation() == SwingConstants.VERTICAL;
|
||||
}
|
||||
|
||||
private FlatToolBarUI getToolBarUI( JComponent c ) {
|
||||
Container parent = c.getParent();
|
||||
return (parent instanceof JToolBar && ((JToolBar)parent).getUI() instanceof FlatToolBarUI)
|
||||
? (FlatToolBarUI) ((JToolBar)parent).getUI()
|
||||
: null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,6 +93,10 @@ public class FlatToolBarUI
|
||||
@Styleable protected Insets borderMargins;
|
||||
@Styleable protected Color gripColor;
|
||||
|
||||
// for FlatToolBarSeparatorUI
|
||||
/** @since 3.3 */ @Styleable protected Integer separatorWidth;
|
||||
/** @since 3.3 */ @Styleable protected Color separatorColor;
|
||||
|
||||
private FocusTraversalPolicy focusTraversalPolicy;
|
||||
private Boolean oldFloatable;
|
||||
private Map<String, Object> oldStyleValues;
|
||||
|
||||
@@ -925,7 +925,10 @@ public class TestFlatStyleableInfo
|
||||
"hoverButtonGroupBackground", Color.class,
|
||||
|
||||
"borderMargins", Insets.class,
|
||||
"gripColor", Color.class
|
||||
"gripColor", Color.class,
|
||||
|
||||
"separatorWidth", Integer.class,
|
||||
"separatorColor", Color.class
|
||||
);
|
||||
|
||||
assertMapEquals( expected, ui.getStyleableInfos( c ) );
|
||||
|
||||
@@ -902,6 +902,9 @@ public class TestFlatStyleableValue
|
||||
|
||||
testInsets( c, ui, "borderMargins", 1,2,3,4 );
|
||||
testColor( c, ui, "gripColor", 0x123456 );
|
||||
|
||||
testInteger( c, ui, "separatorWidth", 123 );
|
||||
testColor( c, ui, "separatorColor", 0x123456 );
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1146,6 +1146,9 @@ public class TestFlatStyling
|
||||
ui.applyStyle( "borderMargins: 1,2,3,4" );
|
||||
ui.applyStyle( "gripColor: #fff" );
|
||||
|
||||
ui.applyStyle( "separatorWidth: 6" );
|
||||
ui.applyStyle( "separatorColor: #fff" );
|
||||
|
||||
// JComponent properties
|
||||
ui.applyStyle( "background: #fff" );
|
||||
ui.applyStyle( "foreground: #fff" );
|
||||
|
||||
Reference in New Issue
Block a user