mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-06 22:10:54 +03:00
ToolBar: no longer use special rollover border for buttons in toolbar (issue #36)
This commit is contained in:
@@ -15,6 +15,8 @@ FlatLaf Change Log
|
|||||||
`false`. (issue #58, PR #63)
|
`false`. (issue #58, PR #63)
|
||||||
- ToggleButton: Make toggle button square if it has an icon but no text or text
|
- ToggleButton: Make toggle button square if it has an icon but no text or text
|
||||||
is "..." or a single character.
|
is "..." or a single character.
|
||||||
|
- ToolBar: No longer use special rollover border for buttons in toolbar. (issue
|
||||||
|
#36)
|
||||||
|
|
||||||
|
|
||||||
## 0.26
|
## 0.26
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import java.awt.Paint;
|
|||||||
import javax.swing.AbstractButton;
|
import javax.swing.AbstractButton;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.plaf.UIResource;
|
import javax.swing.plaf.UIResource;
|
||||||
|
import com.formdev.flatlaf.util.UIScale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Border for {@link javax.swing.JButton}.
|
* Border for {@link javax.swing.JButton}.
|
||||||
@@ -61,11 +62,15 @@ public class FlatButtonBorder
|
|||||||
protected final Color defaultFocusedBorderColor = UIManager.getColor( "Button.default.focusedBorderColor" );
|
protected final Color defaultFocusedBorderColor = UIManager.getColor( "Button.default.focusedBorderColor" );
|
||||||
protected final Color defaultFocusColor = UIManager.getColor( "Button.default.focusColor" );
|
protected final Color defaultFocusColor = UIManager.getColor( "Button.default.focusColor" );
|
||||||
protected final int defaultBorderWidth = UIManager.getInt( "Button.default.borderWidth" );
|
protected final int defaultBorderWidth = UIManager.getInt( "Button.default.borderWidth" );
|
||||||
|
protected final Insets toolbarMargin = UIManager.getInsets( "Button.toolbar.margin" );
|
||||||
protected final int arc = UIManager.getInt( "Button.arc" );
|
protected final int arc = UIManager.getInt( "Button.arc" );
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void paintBorder( Component c, Graphics g, int x, int y, int width, int height ) {
|
public void paintBorder( Component c, Graphics g, int x, int y, int width, int height ) {
|
||||||
if( FlatButtonUI.isContentAreaFilled( c ) && !FlatButtonUI.isHelpButton( c ) && !FlatToggleButtonUI.isTabButton( c ) )
|
if( FlatButtonUI.isContentAreaFilled( c ) &&
|
||||||
|
!FlatButtonUI.isToolBarButton( c ) &&
|
||||||
|
!FlatButtonUI.isHelpButton( c ) &&
|
||||||
|
!FlatToggleButtonUI.isTabButton( c ) )
|
||||||
super.paintBorder( c, g, x, y, width, height );
|
super.paintBorder( c, g, x, y, width, height );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,11 +100,22 @@ public class FlatButtonBorder
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Insets getBorderInsets( Component c, Insets insets ) {
|
public Insets getBorderInsets( Component c, Insets insets ) {
|
||||||
|
if( FlatButtonUI.isToolBarButton( c ) ) {
|
||||||
|
// In toolbars, use button margin only if explicitly set.
|
||||||
|
// Otherwise use toolbar margin specified in UI defaults.
|
||||||
|
Insets margin = (c instanceof AbstractButton)
|
||||||
|
? ((AbstractButton)c).getMargin()
|
||||||
|
: null;
|
||||||
|
|
||||||
|
FlatUIUtils.setInsets( insets, UIScale.scale(
|
||||||
|
(margin != null && !(margin instanceof UIResource)) ? margin : toolbarMargin ) );
|
||||||
|
} else {
|
||||||
insets = super.getBorderInsets( c, insets );
|
insets = super.getBorderInsets( c, insets );
|
||||||
|
|
||||||
// use smaller left and right insets for icon-only buttons (so that they are square)
|
// use smaller left and right insets for icon-only buttons (so that they are square)
|
||||||
if( FlatButtonUI.isIconOnlyButton( c ) && ((AbstractButton)c).getMargin() instanceof UIResource )
|
if( FlatButtonUI.isIconOnlyButton( c ) && ((AbstractButton)c).getMargin() instanceof UIResource )
|
||||||
insets.left = insets.right = Math.min( insets.top, insets.bottom );
|
insets.left = insets.right = Math.min( insets.top, insets.bottom );
|
||||||
|
}
|
||||||
|
|
||||||
return insets;
|
return insets;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -240,7 +240,7 @@ public class FlatButtonUI
|
|||||||
return c instanceof JButton && clientPropertyEquals( (JButton) c, BUTTON_TYPE, BUTTON_TYPE_HELP );
|
return c instanceof JButton && clientPropertyEquals( (JButton) c, BUTTON_TYPE, BUTTON_TYPE_HELP );
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean isToolBarButton( JComponent c ) {
|
static boolean isToolBarButton( Component c ) {
|
||||||
return c.getParent() instanceof JToolBar;
|
return c.getParent() instanceof JToolBar;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,7 +269,7 @@ public class FlatButtonUI
|
|||||||
FlatUIUtils.setRenderingHints( g2 );
|
FlatUIUtils.setRenderingHints( g2 );
|
||||||
|
|
||||||
Border border = c.getBorder();
|
Border border = c.getBorder();
|
||||||
float focusWidth = (border instanceof FlatBorder) ? scale( (float) getFocusWidth( c ) ) : 0;
|
float focusWidth = (border instanceof FlatBorder && !isToolBarButton( c )) ? scale( (float) getFocusWidth( c ) ) : 0;
|
||||||
float arc = ((border instanceof FlatButtonBorder && !isSquareButton( c )) || isToolBarButton( c ))
|
float arc = ((border instanceof FlatButtonBorder && !isSquareButton( c )) || isToolBarButton( c ))
|
||||||
? scale( (float) this.arc ) : 0;
|
? scale( (float) this.arc ) : 0;
|
||||||
boolean def = isDefaultButton( c );
|
boolean def = isDefaultButton( c );
|
||||||
|
|||||||
@@ -16,18 +16,14 @@
|
|||||||
|
|
||||||
package com.formdev.flatlaf.ui;
|
package com.formdev.flatlaf.ui;
|
||||||
|
|
||||||
import static com.formdev.flatlaf.util.UIScale.scale;
|
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
import java.awt.event.ContainerEvent;
|
import java.awt.event.ContainerEvent;
|
||||||
import java.awt.event.ContainerListener;
|
import java.awt.event.ContainerListener;
|
||||||
import javax.swing.AbstractButton;
|
import javax.swing.AbstractButton;
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.UIManager;
|
|
||||||
import javax.swing.border.Border;
|
import javax.swing.border.Border;
|
||||||
import javax.swing.border.EmptyBorder;
|
|
||||||
import javax.swing.plaf.ComponentUI;
|
import javax.swing.plaf.ComponentUI;
|
||||||
import javax.swing.plaf.UIResource;
|
|
||||||
import javax.swing.plaf.basic.BasicToolBarUI;
|
import javax.swing.plaf.basic.BasicToolBarUI;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,28 +41,15 @@ import javax.swing.plaf.basic.BasicToolBarUI;
|
|||||||
* @uiDefault ToolBar.floatingForeground Color
|
* @uiDefault ToolBar.floatingForeground Color
|
||||||
* @uiDefault ToolBar.isRollover boolean
|
* @uiDefault ToolBar.isRollover boolean
|
||||||
*
|
*
|
||||||
* <!-- FlatToolBarUI -->
|
|
||||||
*
|
|
||||||
* @uiDefault ToolBar.buttonMargins Insets
|
|
||||||
*
|
|
||||||
* @author Karl Tauber
|
* @author Karl Tauber
|
||||||
*/
|
*/
|
||||||
public class FlatToolBarUI
|
public class FlatToolBarUI
|
||||||
extends BasicToolBarUI
|
extends BasicToolBarUI
|
||||||
{
|
{
|
||||||
private Border rolloverBorder;
|
|
||||||
|
|
||||||
public static ComponentUI createUI( JComponent c ) {
|
public static ComponentUI createUI( JComponent c ) {
|
||||||
return new FlatToolBarUI();
|
return new FlatToolBarUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void uninstallUI( JComponent c ) {
|
|
||||||
super.uninstallUI( c );
|
|
||||||
|
|
||||||
rolloverBorder = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ContainerListener createToolBarContListener() {
|
protected ContainerListener createToolBarContListener() {
|
||||||
return new ToolBarContListener() {
|
return new ToolBarContListener() {
|
||||||
@@ -90,26 +73,15 @@ public class FlatToolBarUI
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
// disable rollover border
|
||||||
protected Border createRolloverBorder() {
|
@Override protected void setBorderToRollover( Component c ) {}
|
||||||
return getRolloverBorder();
|
@Override protected void setBorderToNonRollover( Component c ) {}
|
||||||
}
|
@Override protected void setBorderToNormal( Component c ) {}
|
||||||
|
@Override protected void installRolloverBorders( JComponent c ) {}
|
||||||
@Override
|
@Override protected void installNonRolloverBorders( JComponent c ) {}
|
||||||
protected Border createNonRolloverBorder() {
|
@Override protected void installNormalBorders( JComponent c ) {}
|
||||||
return getRolloverBorder();
|
@Override protected Border createRolloverBorder() { return null; }
|
||||||
}
|
@Override protected Border createNonRolloverBorder() { return null; }
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Border getNonRolloverBorder( AbstractButton b ) {
|
|
||||||
return getRolloverBorder();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Border getRolloverBorder() {
|
|
||||||
if( rolloverBorder == null )
|
|
||||||
rolloverBorder = new FlatRolloverMarginBorder();
|
|
||||||
return rolloverBorder;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setOrientation( int orientation ) {
|
public void setOrientation( int orientation ) {
|
||||||
@@ -123,46 +95,4 @@ public class FlatToolBarUI
|
|||||||
|
|
||||||
super.setOrientation( orientation );
|
super.setOrientation( orientation );
|
||||||
}
|
}
|
||||||
|
|
||||||
//---- class FlatRolloverMarginBorder -------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Uses button margin only if explicitly set.
|
|
||||||
* Otherwise uses insets specified in constructor.
|
|
||||||
*/
|
|
||||||
private static class FlatRolloverMarginBorder
|
|
||||||
extends EmptyBorder
|
|
||||||
{
|
|
||||||
public FlatRolloverMarginBorder() {
|
|
||||||
super( UIManager.getInsets( "ToolBar.buttonMargins" ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Insets getBorderInsets( Component c, Insets insets ) {
|
|
||||||
Insets margin = (c instanceof AbstractButton)
|
|
||||||
? ((AbstractButton) c).getMargin()
|
|
||||||
: null;
|
|
||||||
|
|
||||||
if( margin == null || margin instanceof UIResource ) {
|
|
||||||
insets.top = top;
|
|
||||||
insets.left = left;
|
|
||||||
insets.bottom = bottom;
|
|
||||||
insets.right = right;
|
|
||||||
} else {
|
|
||||||
// margin explicitly set
|
|
||||||
insets.top = margin.top;
|
|
||||||
insets.left = margin.left;
|
|
||||||
insets.bottom = margin.bottom;
|
|
||||||
insets.right = margin.right;
|
|
||||||
}
|
|
||||||
|
|
||||||
// scale
|
|
||||||
insets.top = scale( insets.top );
|
|
||||||
insets.left = scale( insets.left );
|
|
||||||
insets.bottom = scale( insets.bottom );
|
|
||||||
insets.right = scale( insets.right );
|
|
||||||
|
|
||||||
return insets;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,6 +84,13 @@ public class FlatUIUtils
|
|||||||
insets1.right + insets2.right );
|
insets1.right + insets2.right );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setInsets( Insets dest, Insets src ) {
|
||||||
|
dest.top = src.top;
|
||||||
|
dest.left = src.left;
|
||||||
|
dest.bottom = src.bottom;
|
||||||
|
dest.right = src.right;
|
||||||
|
}
|
||||||
|
|
||||||
public static Color getUIColor( String key, int defaultColorRGB ) {
|
public static Color getUIColor( String key, int defaultColorRGB ) {
|
||||||
Color color = UIManager.getColor( key );
|
Color color = UIManager.getColor( key );
|
||||||
return (color != null) ? color : new Color( defaultColorRGB );
|
return (color != null) ? color : new Color( defaultColorRGB );
|
||||||
|
|||||||
@@ -103,6 +103,8 @@ Button.defaultButtonFollowsFocus=false
|
|||||||
|
|
||||||
Button.default.borderWidth=1
|
Button.default.borderWidth=1
|
||||||
|
|
||||||
|
Button.toolbar.margin=3,3,3,3
|
||||||
|
|
||||||
|
|
||||||
#---- Caret ----
|
#---- Caret ----
|
||||||
|
|
||||||
@@ -503,7 +505,6 @@ ToggleButton.tab.focusBackground=$TabbedPane.focusColor
|
|||||||
|
|
||||||
ToolBar.border=com.formdev.flatlaf.ui.FlatToolBarBorder
|
ToolBar.border=com.formdev.flatlaf.ui.FlatToolBarBorder
|
||||||
ToolBar.isRollover=true
|
ToolBar.isRollover=true
|
||||||
ToolBar.buttonMargins=3,3,3,3
|
|
||||||
ToolBar.gripColor=@icon
|
ToolBar.gripColor=@icon
|
||||||
ToolBar.dockingBackground=@background
|
ToolBar.dockingBackground=@background
|
||||||
ToolBar.floatingBackground=@background
|
ToolBar.floatingBackground=@background
|
||||||
|
|||||||
Reference in New Issue
Block a user