mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-11 06:27:13 -06:00
ToggleButton: support pressed background
This commit is contained in:
@@ -183,10 +183,9 @@ public class FlatButtonUI
|
||||
if( !c.isEnabled() )
|
||||
return null;
|
||||
|
||||
ButtonModel model = ((AbstractButton)c).getModel();
|
||||
|
||||
// toolbar button
|
||||
if( isToolBarButton( c ) ) {
|
||||
ButtonModel model = ((AbstractButton)c).getModel();
|
||||
if( model.isPressed() )
|
||||
return toolbarPressedBackground;
|
||||
if( model.isRollover() )
|
||||
@@ -197,26 +196,32 @@ public class FlatButtonUI
|
||||
}
|
||||
|
||||
boolean def = isDefaultButton( c );
|
||||
return buttonStateColor( c,
|
||||
def ? defaultBackground : c.getBackground(),
|
||||
null,
|
||||
def ? defaultFocusedBackground : focusedBackground,
|
||||
def ? defaultHoverBackground : hoverBackground,
|
||||
def ? defaultPressedBackground : pressedBackground );
|
||||
}
|
||||
|
||||
if( model.isPressed() ) {
|
||||
Color color = def ? defaultPressedBackground : pressedBackground;
|
||||
if( color != null )
|
||||
return color;
|
||||
}
|
||||
public static Color buttonStateColor( Component c, Color enabledColor, Color disabledColor,
|
||||
Color focusedColor, Color hoverColor, Color pressedColor )
|
||||
{
|
||||
AbstractButton b = (c instanceof AbstractButton) ? (AbstractButton) c : null;
|
||||
|
||||
if( model.isRollover() ) {
|
||||
Color color = def ? defaultHoverBackground : hoverBackground;
|
||||
if( color != null )
|
||||
return color;
|
||||
}
|
||||
if( !c.isEnabled() )
|
||||
return disabledColor;
|
||||
|
||||
if( c.hasFocus() ) {
|
||||
Color color = def ? defaultFocusedBackground : focusedBackground;
|
||||
if( color != null )
|
||||
return color;
|
||||
}
|
||||
if( pressedColor != null && b != null && b.getModel().isPressed() )
|
||||
return pressedColor;
|
||||
|
||||
return def ? defaultBackground : c.getBackground();
|
||||
if( hoverColor != null && b != null && b.getModel().isRollover() )
|
||||
return hoverColor;
|
||||
|
||||
if( focusedColor != null && c.hasFocus() )
|
||||
return focusedColor;
|
||||
|
||||
return enabledColor;
|
||||
}
|
||||
|
||||
protected Color getForeground( JComponent c ) {
|
||||
|
||||
@@ -30,11 +30,15 @@ import javax.swing.plaf.ComponentUI;
|
||||
*
|
||||
* @uiDefault Component.focusWidth int
|
||||
* @uiDefault ToggleButton.arc int
|
||||
* @uiDefault ToggleButton.pressedBackground Color
|
||||
* @uiDefault ToggleButton.disabledText Color
|
||||
* @uiDefault ToggleButton.toolbar.hoverBackground Color
|
||||
* @uiDefault ToggleButton.toolbar.pressedBackground Color
|
||||
* @uiDefault ToggleButton.selectedBackground Color
|
||||
* @uiDefault ToggleButton.selectedForeground Color
|
||||
* @uiDefault ToggleButton.disabledSelectedBackground Color
|
||||
* @uiDefault ToggleButton.toolbar.hoverBackground Color
|
||||
* @uiDefault ToggleButton.toolbar.pressedBackground Color
|
||||
* @uiDefault ToggleButton.toolbar.selectedBackground Color
|
||||
*
|
||||
*
|
||||
* @author Karl Tauber
|
||||
*/
|
||||
@@ -45,6 +49,8 @@ public class FlatToggleButtonUI
|
||||
protected Color selectedForeground;
|
||||
protected Color disabledSelectedBackground;
|
||||
|
||||
protected Color toolbarSelectedBackground;
|
||||
|
||||
private static ComponentUI instance;
|
||||
|
||||
public static ComponentUI createUI( JComponent c ) {
|
||||
@@ -65,6 +71,8 @@ public class FlatToggleButtonUI
|
||||
selectedBackground = UIManager.getColor( "ToggleButton.selectedBackground" );
|
||||
selectedForeground = UIManager.getColor( "ToggleButton.selectedForeground" );
|
||||
disabledSelectedBackground = UIManager.getColor( "ToggleButton.disabledSelectedBackground" );
|
||||
|
||||
toolbarSelectedBackground = UIManager.getColor( "ToggleButton.toolbar.selectedBackground" );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -72,9 +80,14 @@ public class FlatToggleButtonUI
|
||||
ButtonModel model = ((AbstractButton)c).getModel();
|
||||
|
||||
if( model.isSelected() ) {
|
||||
return isToolBarButton( c )
|
||||
? toolbarPressedBackground
|
||||
: (c.isEnabled() ? selectedBackground : disabledSelectedBackground);
|
||||
// in toolbar use same colors for disabled and enabled because
|
||||
// we assume that toolbar icon is shown disabled
|
||||
boolean toolBarButton = isToolBarButton( c );
|
||||
return buttonStateColor( c,
|
||||
toolBarButton ? toolbarSelectedBackground : selectedBackground,
|
||||
toolBarButton ? toolbarSelectedBackground : disabledSelectedBackground,
|
||||
null, null,
|
||||
toolBarButton ? toolbarPressedBackground : pressedBackground );
|
||||
}
|
||||
|
||||
return super.getBackground( c );
|
||||
|
||||
@@ -79,7 +79,7 @@ Button.default.focusedBorderColor=537699
|
||||
Button.default.focusColor=43688c
|
||||
|
||||
Button.toolbar.hoverBackground=4c5052
|
||||
Button.toolbar.pressedBackground=5c6164
|
||||
Button.toolbar.pressedBackground=555a5d
|
||||
|
||||
|
||||
#---- CheckBox ----
|
||||
@@ -211,10 +211,12 @@ TableHeader.bottomSeparatorColor=585858
|
||||
|
||||
#---- ToggleButton ----
|
||||
|
||||
ToggleButton.selectedBackground=5c6164
|
||||
ToggleButton.selectedBackground=64696C
|
||||
ToggleButton.selectedForeground=@foreground
|
||||
ToggleButton.disabledSelectedBackground=525658
|
||||
|
||||
ToggleButton.toolbar.selectedBackground=5c6164
|
||||
|
||||
|
||||
#---- ToolTip ----
|
||||
|
||||
|
||||
@@ -354,6 +354,7 @@ ToggleButton.arc=6
|
||||
ToggleButton.rollover=true
|
||||
|
||||
ToggleButton.background=@@Button.background
|
||||
ToggleButton.pressedBackground=@@Button.pressedBackground
|
||||
|
||||
ToggleButton.toolbar.hoverBackground=@@Button.toolbar.hoverBackground
|
||||
ToggleButton.toolbar.pressedBackground=@@Button.toolbar.pressedBackground
|
||||
|
||||
@@ -80,7 +80,7 @@ Button.default.focusedBorderColor=a8cef6
|
||||
Button.default.focusColor=97c3f3
|
||||
|
||||
Button.toolbar.hoverBackground=dfdfdf
|
||||
Button.toolbar.pressedBackground=cfcfcf
|
||||
Button.toolbar.pressedBackground=d8d8d8
|
||||
|
||||
|
||||
#---- CheckBox ----
|
||||
@@ -221,6 +221,8 @@ ToggleButton.selectedBackground=cfcfcf
|
||||
ToggleButton.selectedForeground=@foreground
|
||||
ToggleButton.disabledSelectedBackground=dfdfdf
|
||||
|
||||
ToggleButton.toolbar.selectedBackground=cfcfcf
|
||||
|
||||
|
||||
#---- ToolTip ----
|
||||
|
||||
|
||||
@@ -243,6 +243,8 @@ ToggleButton.focusedBackground=00ffff
|
||||
ToggleButton.hoverBackground=ffff00
|
||||
ToggleButton.pressedBackground=FFC800
|
||||
|
||||
ToggleButton.toolbar.selectedBackground=dddddd
|
||||
|
||||
|
||||
#---- ToolTip ----
|
||||
|
||||
|
||||
Reference in New Issue
Block a user