|
|
|
@ -1,9 +1,11 @@
|
|
|
|
|
package com.fine.theme.light.ui; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.fine.theme.utils.FineUIUtils; |
|
|
|
|
import com.formdev.flatlaf.ui.FlatStylingSupport.Styleable; |
|
|
|
|
import com.formdev.flatlaf.ui.FlatToggleButtonUI; |
|
|
|
|
import com.formdev.flatlaf.ui.FlatUIUtils; |
|
|
|
|
import com.fr.design.gui.ibutton.UIButton; |
|
|
|
|
import org.jetbrains.annotations.Nullable; |
|
|
|
|
|
|
|
|
|
import javax.swing.AbstractButton; |
|
|
|
@ -14,10 +16,12 @@ import javax.swing.plaf.ComponentUI;
|
|
|
|
|
import java.awt.Color; |
|
|
|
|
import java.awt.Component; |
|
|
|
|
import java.awt.Graphics; |
|
|
|
|
import java.awt.Graphics2D; |
|
|
|
|
|
|
|
|
|
import static com.formdev.flatlaf.FlatClientProperties.BUTTON_TYPE; |
|
|
|
|
import static com.formdev.flatlaf.FlatClientProperties.BUTTON_TYPE_TAB; |
|
|
|
|
import static com.formdev.flatlaf.FlatClientProperties.TAB_BUTTON_SELECTED_BACKGROUND; |
|
|
|
|
import static com.fine.theme.utils.FineClientProperties.BUTTON_TYPE_GROUP; |
|
|
|
|
import static com.fine.theme.utils.FineClientProperties.BUTTON_TYPE; |
|
|
|
|
import static com.fine.theme.utils.FineClientProperties.BUTTON_TYPE_TAB; |
|
|
|
|
import static com.fine.theme.utils.FineClientProperties.TAB_BUTTON_SELECTED_BACKGROUND; |
|
|
|
|
import static com.formdev.flatlaf.FlatClientProperties.clientPropertyColor; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -34,6 +38,15 @@ public class FineToggleButtonUI extends FlatToggleButtonUI {
|
|
|
|
|
@Styleable(dot = true) |
|
|
|
|
protected int tabArc; |
|
|
|
|
|
|
|
|
|
@Styleable(dot = true) |
|
|
|
|
protected Color groupBackground; |
|
|
|
|
|
|
|
|
|
@Styleable(dot = true) |
|
|
|
|
protected Color groupSelectedBackground; |
|
|
|
|
|
|
|
|
|
@Styleable(dot = true) |
|
|
|
|
protected Color groupSelectedForeground; |
|
|
|
|
|
|
|
|
|
public static ComponentUI createUI(JComponent c) { |
|
|
|
|
return FlatUIUtils.canUseSharedUI(c) |
|
|
|
|
? FlatUIUtils.createSharedUI(FlatToggleButtonUI.class, () -> new FineToggleButtonUI(true)) |
|
|
|
@ -48,6 +61,9 @@ public class FineToggleButtonUI extends FlatToggleButtonUI {
|
|
|
|
|
protected void installDefaults(AbstractButton b) { |
|
|
|
|
super.installDefaults(b); |
|
|
|
|
tabArc = UIManager.getInt("ToggleButton.tab.arc"); |
|
|
|
|
groupBackground = FineUIUtils.getUIColor("ToggleButton.group.background", "ToggleButton.background"); |
|
|
|
|
groupSelectedBackground = FineUIUtils.getUIColor("ToggleButton.group.selectedBackground", "ToggleButton.selectedBackground"); |
|
|
|
|
groupSelectedForeground = FineUIUtils.getUIColor("ToggleButton.group.selectedForeground", "ToggleButton.selectedForeground"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -63,30 +79,82 @@ public class FineToggleButtonUI extends FlatToggleButtonUI {
|
|
|
|
|
return c instanceof JToggleButton && BUTTON_TYPE_TAB.equals(getButtonTypeStr((JToggleButton) c)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static boolean isGroupButton(Component c) { |
|
|
|
|
return c instanceof UIButton && BUTTON_TYPE_GROUP.equals(getButtonTypeStr((UIButton) c)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void paint(Graphics g, JComponent c) { |
|
|
|
|
if (isGroupButton(c) || isTabButton(c)) { |
|
|
|
|
((AbstractButton)c).setMargin(FineUIUtils.getUIInsets("ToggleButton.compact.margin", "ToggleButton.margin")); |
|
|
|
|
} |
|
|
|
|
super.paint(g, c); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void paintBackground(Graphics g, JComponent c) { |
|
|
|
|
if (isTabButton(c)) { |
|
|
|
|
int height = c.getHeight(); |
|
|
|
|
int width = c.getWidth(); |
|
|
|
|
boolean selected = ((AbstractButton) c).isSelected(); |
|
|
|
|
Color enabledColor = selected ? clientPropertyColor(c, TAB_BUTTON_SELECTED_BACKGROUND, tabSelectedBackground) : null; |
|
|
|
|
|
|
|
|
|
// use component background if explicitly set
|
|
|
|
|
if (enabledColor == null) { |
|
|
|
|
Color bg = c.getBackground(); |
|
|
|
|
if (isCustomBackground(bg)) |
|
|
|
|
enabledColor = bg; |
|
|
|
|
} |
|
|
|
|
paintTabButton(g, c); |
|
|
|
|
} else if (isGroupButton(c)) { |
|
|
|
|
paintGroupButton(g, c); |
|
|
|
|
} else { |
|
|
|
|
super.paintBackground(g, c); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// paint background
|
|
|
|
|
Color background = buttonStateColor(c, enabledColor, |
|
|
|
|
null, tabFocusBackground, tabHoverBackground, null); |
|
|
|
|
if (background != null) { |
|
|
|
|
g.setColor(background); |
|
|
|
|
g.fillRoundRect(0, 0, width, height, tabArc, tabArc); |
|
|
|
|
protected void paintTabButton(Graphics g, JComponent c) { |
|
|
|
|
int height = c.getHeight(); |
|
|
|
|
int width = c.getWidth(); |
|
|
|
|
boolean selected = ((AbstractButton) c).isSelected(); |
|
|
|
|
Color enabledColor = selected ? clientPropertyColor(c, TAB_BUTTON_SELECTED_BACKGROUND, tabSelectedBackground) : null; |
|
|
|
|
|
|
|
|
|
// use component background if explicitly set
|
|
|
|
|
if (enabledColor == null) { |
|
|
|
|
Color bg = c.getBackground(); |
|
|
|
|
if (isCustomBackground(bg)) { |
|
|
|
|
enabledColor = bg; |
|
|
|
|
} |
|
|
|
|
} else |
|
|
|
|
super.paintBackground(g, c); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// paint background
|
|
|
|
|
Color background = buttonStateColor(c, enabledColor, |
|
|
|
|
null, tabFocusBackground, tabHoverBackground, null); |
|
|
|
|
if (background != null) { |
|
|
|
|
g.setColor(background); |
|
|
|
|
g.fillRoundRect(0, 0, width, height, tabArc, tabArc); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected void paintGroupButton(Graphics g, JComponent c) { |
|
|
|
|
Color background = getBackground(c); |
|
|
|
|
if (background == null) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
Graphics2D g2 = (Graphics2D) g.create(); |
|
|
|
|
try { |
|
|
|
|
FlatUIUtils.setRenderingHints(g2); |
|
|
|
|
g2.setColor(FlatUIUtils.deriveColor(background, getBackgroundBase(c, true))); |
|
|
|
|
float focusWidth = FlatUIUtils.getBorderFocusWidth(c); |
|
|
|
|
FlatUIUtils.paintComponentBackground(g2, 0, 0, c.getWidth(), c.getHeight(), focusWidth, 0); |
|
|
|
|
} finally { |
|
|
|
|
g2.dispose(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected Color getForeground(JComponent c) { |
|
|
|
|
if (isGroupButton(c) && ((AbstractButton)c).isSelected()) { |
|
|
|
|
return groupSelectedForeground; |
|
|
|
|
} |
|
|
|
|
return super.getForeground(c); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected Color getBackground(JComponent c) { |
|
|
|
|
if (isGroupButton(c)) { |
|
|
|
|
return ((AbstractButton)c).isSelected() ? groupSelectedBackground : groupBackground; |
|
|
|
|
} |
|
|
|
|
return super.getBackground(c); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|