mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-08 15:00:54 +03:00
Button and ToggleButton: simplified/unified code of FlatButtonUI.getBackground() (issue #292)
This commit is contained in:
@@ -392,39 +392,31 @@ public class FlatButtonUI
|
|||||||
|
|
||||||
// selected state
|
// selected state
|
||||||
if( ((AbstractButton)c).isSelected() ) {
|
if( ((AbstractButton)c).isSelected() ) {
|
||||||
// in toolbar use same colors for disabled and enabled because
|
// in toolbar use same background colors for disabled and enabled because
|
||||||
// we assume that toolbar icon is shown disabled
|
// we assume that toolbar icon is shown disabled
|
||||||
return buttonStateColor( c,
|
return buttonStateColor( c,
|
||||||
toolBarButton ? toolbarSelectedBackground : selectedBackground,
|
toolBarButton ? toolbarSelectedBackground : selectedBackground,
|
||||||
toolBarButton ? toolbarSelectedBackground : disabledSelectedBackground,
|
toolBarButton ? toolbarSelectedBackground : disabledSelectedBackground,
|
||||||
null, null,
|
null,
|
||||||
|
null,
|
||||||
toolBarButton ? toolbarPressedBackground : pressedBackground );
|
toolBarButton ? toolbarPressedBackground : pressedBackground );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !c.isEnabled() )
|
|
||||||
return toolBarButton ? null : disabledBackground;
|
|
||||||
|
|
||||||
// toolbar button
|
// toolbar button
|
||||||
if( toolBarButton ) {
|
if( toolBarButton ) {
|
||||||
ButtonModel model = ((AbstractButton)c).getModel();
|
|
||||||
if( model.isPressed() )
|
|
||||||
return toolbarPressedBackground;
|
|
||||||
if( model.isRollover() )
|
|
||||||
return toolbarHoverBackground;
|
|
||||||
|
|
||||||
// use component background if explicitly set
|
|
||||||
Color bg = c.getBackground();
|
Color bg = c.getBackground();
|
||||||
if( isCustomBackground( bg ) )
|
return buttonStateColor( c,
|
||||||
return bg;
|
isCustomBackground( bg ) ? bg : null,
|
||||||
|
null,
|
||||||
// do not paint background
|
null,
|
||||||
return null;
|
toolbarHoverBackground,
|
||||||
|
toolbarPressedBackground );
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean def = isDefaultButton( c );
|
boolean def = isDefaultButton( c );
|
||||||
return buttonStateColor( c,
|
return buttonStateColor( c,
|
||||||
getBackgroundBase( c, def ),
|
getBackgroundBase( c, def ),
|
||||||
null,
|
disabledBackground,
|
||||||
isCustomBackground( c.getBackground() ) ? null : (def ? defaultFocusedBackground : focusedBackground),
|
isCustomBackground( c.getBackground() ) ? null : (def ? defaultFocusedBackground : focusedBackground),
|
||||||
def ? defaultHoverBackground : hoverBackground,
|
def ? defaultHoverBackground : hoverBackground,
|
||||||
def ? defaultPressedBackground : pressedBackground );
|
def ? defaultPressedBackground : pressedBackground );
|
||||||
@@ -446,16 +438,18 @@ public class FlatButtonUI
|
|||||||
public static Color buttonStateColor( Component c, Color enabledColor, Color disabledColor,
|
public static Color buttonStateColor( Component c, Color enabledColor, Color disabledColor,
|
||||||
Color focusedColor, Color hoverColor, Color pressedColor )
|
Color focusedColor, Color hoverColor, Color pressedColor )
|
||||||
{
|
{
|
||||||
AbstractButton b = (c instanceof AbstractButton) ? (AbstractButton) c : null;
|
|
||||||
|
|
||||||
if( !c.isEnabled() )
|
if( !c.isEnabled() )
|
||||||
return disabledColor;
|
return disabledColor;
|
||||||
|
|
||||||
if( pressedColor != null && b != null && b.getModel().isPressed() )
|
if( c instanceof AbstractButton ) {
|
||||||
return pressedColor;
|
ButtonModel model = ((AbstractButton)c).getModel();
|
||||||
|
|
||||||
if( hoverColor != null && b != null && b.getModel().isRollover() )
|
if( pressedColor != null && model.isPressed() )
|
||||||
return hoverColor;
|
return pressedColor;
|
||||||
|
|
||||||
|
if( hoverColor != null && model.isRollover() )
|
||||||
|
return hoverColor;
|
||||||
|
}
|
||||||
|
|
||||||
if( focusedColor != null && isFocusPainted( c ) && FlatUIUtils.isPermanentFocusOwner( c ) )
|
if( focusedColor != null && isFocusPainted( c ) && FlatUIUtils.isPermanentFocusOwner( c ) )
|
||||||
return focusedColor;
|
return focusedColor;
|
||||||
|
|||||||
Reference in New Issue
Block a user