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