mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-10 22:17:13 -06:00
ToolBar: added empty space around buttons in toolbar (issue #56)
This commit is contained in:
@@ -17,6 +17,8 @@ FlatLaf Change Log
|
||||
is "..." or a single character.
|
||||
- ToolBar: No longer use special rollover border for buttons in toolbar. (issue
|
||||
#36)
|
||||
- ToolBar: Added empty space around buttons in toolbar (see UI default value
|
||||
`Button.toolbar.spacingInsets`). (issue #56)
|
||||
- Fixed "illegal reflective access operation" warning on macOS when using Java
|
||||
12 or later. (issue #60, PR #61)
|
||||
|
||||
|
||||
@@ -44,6 +44,8 @@ import com.formdev.flatlaf.util.UIScale;
|
||||
* @uiDefault Button.default.focusedBorderColor Color
|
||||
* @uiDefault Button.default.focusColor Color
|
||||
* @uiDefault Button.default.borderWidth int
|
||||
* @uiDefault Button.toolbar.margin Insets
|
||||
* @uiDefault Button.toolbar.spacingInsets Insets
|
||||
* @uiDefault Button.arc int
|
||||
*
|
||||
* @author Karl Tauber
|
||||
@@ -63,6 +65,7 @@ public class FlatButtonBorder
|
||||
protected final Color defaultFocusColor = UIManager.getColor( "Button.default.focusColor" );
|
||||
protected final int defaultBorderWidth = UIManager.getInt( "Button.default.borderWidth" );
|
||||
protected final Insets toolbarMargin = UIManager.getInsets( "Button.toolbar.margin" );
|
||||
protected final Insets toolbarSpacingInsets = UIManager.getInsets( "Button.toolbar.spacingInsets" );
|
||||
protected final int arc = UIManager.getInt( "Button.arc" );
|
||||
|
||||
@Override
|
||||
@@ -107,8 +110,8 @@ public class FlatButtonBorder
|
||||
? ((AbstractButton)c).getMargin()
|
||||
: null;
|
||||
|
||||
FlatUIUtils.setInsets( insets, UIScale.scale(
|
||||
(margin != null && !(margin instanceof UIResource)) ? margin : toolbarMargin ) );
|
||||
FlatUIUtils.setInsets( insets, UIScale.scale( FlatUIUtils.addInsets( toolbarSpacingInsets,
|
||||
(margin != null && !(margin instanceof UIResource)) ? margin : toolbarMargin ) ) );
|
||||
} else {
|
||||
insets = super.getBorderInsets( c, insets );
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import java.awt.FontMetrics;
|
||||
import java.awt.GradientPaint;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.geom.RoundRectangle2D;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
@@ -82,6 +83,7 @@ import com.formdev.flatlaf.util.UIScale;
|
||||
* @uiDefault Button.shadowWidth int default is 2
|
||||
* @uiDefault Button.shadowColor Color optional
|
||||
* @uiDefault Button.default.shadowColor Color optional
|
||||
* @uiDefault Button.toolbar.spacingInsets Insets
|
||||
* @uiDefault Button.toolbar.hoverBackground Color
|
||||
* @uiDefault Button.toolbar.pressedBackground Color
|
||||
*
|
||||
@@ -114,6 +116,7 @@ public class FlatButtonUI
|
||||
protected Color shadowColor;
|
||||
protected Color defaultShadowColor;
|
||||
|
||||
protected Insets toolbarSpacingInsets;
|
||||
protected Color toolbarHoverBackground;
|
||||
protected Color toolbarPressedBackground;
|
||||
|
||||
@@ -166,6 +169,7 @@ public class FlatButtonUI
|
||||
defaultPressedBackground = UIManager.getColor( "Button.default.pressedBackground" );
|
||||
defaultBoldText = UIManager.getBoolean( "Button.default.boldText" );
|
||||
|
||||
toolbarSpacingInsets = UIManager.getInsets( "Button.toolbar.spacingInsets" );
|
||||
toolbarHoverBackground = UIManager.getColor( prefix + "toolbar.hoverBackground" );
|
||||
toolbarPressedBackground = UIManager.getColor( prefix + "toolbar.pressedBackground" );
|
||||
|
||||
@@ -269,27 +273,42 @@ public class FlatButtonUI
|
||||
FlatUIUtils.setRenderingHints( g2 );
|
||||
|
||||
Border border = c.getBorder();
|
||||
float focusWidth = (border instanceof FlatBorder && !isToolBarButton( c )) ? scale( (float) getFocusWidth( c ) ) : 0;
|
||||
float arc = ((border instanceof FlatButtonBorder && !isSquareButton( c )) || isToolBarButton( c ))
|
||||
boolean isToolBarButton = isToolBarButton( c );
|
||||
float focusWidth = (border instanceof FlatBorder && !isToolBarButton) ? scale( (float) getFocusWidth( c ) ) : 0;
|
||||
float arc = ((border instanceof FlatButtonBorder && !isSquareButton( c )) || isToolBarButton)
|
||||
? scale( (float) this.arc ) : 0;
|
||||
boolean def = isDefaultButton( c );
|
||||
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int width = c.getWidth();
|
||||
int height = c.getHeight();
|
||||
|
||||
if( isToolBarButton ) {
|
||||
Insets spacing = UIScale.scale( toolbarSpacingInsets );
|
||||
x += spacing.left;
|
||||
y += spacing.top;
|
||||
width -= spacing.left + spacing.right;
|
||||
height -= spacing.top + spacing.bottom;
|
||||
}
|
||||
|
||||
// paint shadow
|
||||
Color shadowColor = def ? defaultShadowColor : this.shadowColor;
|
||||
if( shadowColor != null && shadowWidth > 0 && focusWidth > 0 && !c.hasFocus() && c.isEnabled() ) {
|
||||
if( !isToolBarButton && shadowColor != null && shadowWidth > 0 && focusWidth > 0 && !c.hasFocus() && c.isEnabled() ) {
|
||||
g2.setColor( shadowColor );
|
||||
g2.fill( new RoundRectangle2D.Float( focusWidth, focusWidth + UIScale.scale( (float) shadowWidth ),
|
||||
c.getWidth() - focusWidth * 2, c.getHeight() - focusWidth * 2, arc, arc ) );
|
||||
width - focusWidth * 2, height - focusWidth * 2, arc, arc ) );
|
||||
}
|
||||
|
||||
// paint background
|
||||
Color startBg = def ? defaultBackground : startBackground;
|
||||
Color endBg = def ? defaultEndBackground : endBackground;
|
||||
if( background == startBg && endBg != null && !startBg.equals( endBg ) )
|
||||
g2.setPaint( new GradientPaint( 0, 0, startBg, 0, c.getHeight(), endBg ) );
|
||||
g2.setPaint( new GradientPaint( 0, 0, startBg, 0, height, endBg ) );
|
||||
else
|
||||
FlatUIUtils.setColor( g2, background, def ? defaultBackground : c.getBackground() );
|
||||
FlatUIUtils.paintComponentBackground( g2, 0, 0, c.getWidth(), c.getHeight(), focusWidth, arc );
|
||||
|
||||
FlatUIUtils.paintComponentBackground( g2, x, y, width, height, focusWidth, arc );
|
||||
} finally {
|
||||
g2.dispose();
|
||||
}
|
||||
|
||||
@@ -104,6 +104,7 @@ Button.defaultButtonFollowsFocus=false
|
||||
Button.default.borderWidth=1
|
||||
|
||||
Button.toolbar.margin=3,3,3,3
|
||||
Button.toolbar.spacingInsets=1,2,1,2
|
||||
|
||||
|
||||
#---- Caret ----
|
||||
@@ -513,6 +514,8 @@ ToolBar.separatorSize=null
|
||||
ToolBar.separatorWidth=7
|
||||
ToolBar.separatorColor=$Separator.foreground
|
||||
|
||||
ToolBar.spacingBorder=$Button.toolbar.spacingInsets
|
||||
|
||||
|
||||
#---- ToolTip ----
|
||||
|
||||
|
||||
@@ -114,7 +114,9 @@ Button.textIconGap 4
|
||||
Button.textShiftOffset 0
|
||||
Button.toolBarBorderBackground #999999 javax.swing.plaf.ColorUIResource [UI]
|
||||
Button.toolbar.hoverBackground #4c5052 javax.swing.plaf.ColorUIResource [UI]
|
||||
Button.toolbar.margin 3,3,3,3 javax.swing.plaf.InsetsUIResource [UI]
|
||||
Button.toolbar.pressedBackground #555a5d javax.swing.plaf.ColorUIResource [UI]
|
||||
Button.toolbar.spacingInsets 1,2,1,2 javax.swing.plaf.InsetsUIResource [UI]
|
||||
ButtonUI com.formdev.flatlaf.ui.FlatButtonUI
|
||||
|
||||
|
||||
@@ -1890,7 +1892,6 @@ ToolBar.ancestorInputMap [lazy] 8 javax.swing.plaf.InputMapUIResource [
|
||||
ToolBar.background #3c3f41 javax.swing.plaf.ColorUIResource [UI]
|
||||
ToolBar.border [lazy] 0,0,0,0 false com.formdev.flatlaf.ui.FlatToolBarBorder [UI]
|
||||
ToolBar.borderColor #cccccc javax.swing.plaf.ColorUIResource [UI]
|
||||
ToolBar.buttonMargins 3,3,3,3 javax.swing.plaf.InsetsUIResource [UI]
|
||||
ToolBar.darkShadow #7a8a99 javax.swing.plaf.ColorUIResource [UI]
|
||||
ToolBar.dockingBackground #3c3f41 javax.swing.plaf.ColorUIResource [UI]
|
||||
ToolBar.dockingForeground #6382bf javax.swing.plaf.ColorUIResource [UI]
|
||||
@@ -1911,6 +1912,7 @@ ToolBar.rolloverBorder [lazy] javax.swing.border.CompoundBorder
|
||||
ToolBar.separatorColor #515151 javax.swing.plaf.ColorUIResource [UI]
|
||||
ToolBar.separatorWidth 7
|
||||
ToolBar.shadow #b8cfe5 javax.swing.plaf.ColorUIResource [UI]
|
||||
ToolBar.spacingBorder [lazy] 1,2,1,2 false com.formdev.flatlaf.ui.FlatEmptyBorder [UI]
|
||||
|
||||
|
||||
#---- ToolBarSeparator ----
|
||||
|
||||
@@ -115,7 +115,9 @@ Button.textIconGap 4
|
||||
Button.textShiftOffset 0
|
||||
Button.toolBarBorderBackground #999999 javax.swing.plaf.ColorUIResource [UI]
|
||||
Button.toolbar.hoverBackground #dfdfdf javax.swing.plaf.ColorUIResource [UI]
|
||||
Button.toolbar.margin 3,3,3,3 javax.swing.plaf.InsetsUIResource [UI]
|
||||
Button.toolbar.pressedBackground #d8d8d8 javax.swing.plaf.ColorUIResource [UI]
|
||||
Button.toolbar.spacingInsets 1,2,1,2 javax.swing.plaf.InsetsUIResource [UI]
|
||||
ButtonUI com.formdev.flatlaf.ui.FlatButtonUI
|
||||
|
||||
|
||||
@@ -1892,7 +1894,6 @@ ToolBar.ancestorInputMap [lazy] 8 javax.swing.plaf.InputMapUIResource [
|
||||
ToolBar.background #f2f2f2 javax.swing.plaf.ColorUIResource [UI]
|
||||
ToolBar.border [lazy] 0,0,0,0 false com.formdev.flatlaf.ui.FlatToolBarBorder [UI]
|
||||
ToolBar.borderColor #cccccc javax.swing.plaf.ColorUIResource [UI]
|
||||
ToolBar.buttonMargins 3,3,3,3 javax.swing.plaf.InsetsUIResource [UI]
|
||||
ToolBar.darkShadow #7a8a99 javax.swing.plaf.ColorUIResource [UI]
|
||||
ToolBar.dockingBackground #f2f2f2 javax.swing.plaf.ColorUIResource [UI]
|
||||
ToolBar.dockingForeground #6382bf javax.swing.plaf.ColorUIResource [UI]
|
||||
@@ -1913,6 +1914,7 @@ ToolBar.rolloverBorder [lazy] javax.swing.border.CompoundBorder
|
||||
ToolBar.separatorColor #d1d1d1 javax.swing.plaf.ColorUIResource [UI]
|
||||
ToolBar.separatorWidth 7
|
||||
ToolBar.shadow #b8cfe5 javax.swing.plaf.ColorUIResource [UI]
|
||||
ToolBar.spacingBorder [lazy] 1,2,1,2 false com.formdev.flatlaf.ui.FlatEmptyBorder [UI]
|
||||
|
||||
|
||||
#---- ToolBarSeparator ----
|
||||
|
||||
Reference in New Issue
Block a user