diff --git a/designer-base/src/main/java/com/fine/theme/light/ui/FineButtonUI.java b/designer-base/src/main/java/com/fine/theme/light/ui/FineButtonUI.java index d5b3c17f74..420ab90d0a 100644 --- a/designer-base/src/main/java/com/fine/theme/light/ui/FineButtonUI.java +++ b/designer-base/src/main/java/com/fine/theme/light/ui/FineButtonUI.java @@ -6,6 +6,7 @@ import com.formdev.flatlaf.ui.FlatButtonUI; import com.formdev.flatlaf.ui.FlatUIUtils; import javax.swing.AbstractButton; +import javax.swing.ButtonModel; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.plaf.ComponentUI; @@ -96,6 +97,58 @@ public class FineButtonUI extends FlatButtonUI { } } + @Override + protected Color getBackground(JComponent c) { + if (isTransparentButton(c)) { + return buttonStateColor(c, + disabledBackground, + hoverBackground, + pressedBackground); + } else { + return super.getBackground(c); + } + } + + private boolean isTransparentButton(JComponent c) { + String buttonTypeStr = getButtonTypeStr((AbstractButton) c); + return FineClientProperties.BUTTON_TYPE_TRANSPARENT.equals(buttonTypeStr); + } + + /** + * 获取按钮状态颜色 + * + * @param c 组件 + * @param disabledColor 禁用颜色 + * @param hoverColor 鼠标悬停颜色 + * @param pressedColor 鼠标按下颜色 + * @return 按钮状态颜色 + */ + public static Color buttonStateColor(Component c, Color disabledColor, + Color hoverColor, Color pressedColor) { + + if (!c.isEnabled()) { + return disabledColor; + } + + ButtonModel model = ((AbstractButton) c).getModel(); + + if (pressedColor != null && model.isPressed()) { + return pressedColor; + } + + if (hoverColor != null && model.isRollover()) { + + return hoverColor; + } + + + if (c.isOpaque()) { + return c.getBackground(); + } + + return null; + } + /** * 创建UI */ diff --git a/designer-base/src/main/java/com/fine/theme/light/ui/FineMenuItemUI.java b/designer-base/src/main/java/com/fine/theme/light/ui/FineMenuItemUI.java index e5b28b382b..58237f59d9 100644 --- a/designer-base/src/main/java/com/fine/theme/light/ui/FineMenuItemUI.java +++ b/designer-base/src/main/java/com/fine/theme/light/ui/FineMenuItemUI.java @@ -1,7 +1,6 @@ package com.fine.theme.light.ui; import com.fine.theme.utils.FineClientProperties; -import com.fine.theme.utils.FineUIUtils; import com.formdev.flatlaf.ui.FlatMenuItemUI; import com.fr.design.editlock.EditLockUtils; @@ -32,14 +31,6 @@ public class FineMenuItemUI extends FlatMenuItemUI { @Override public void paint(Graphics g, JComponent c) { - Object clientProperty = c.getClientProperty(FineClientProperties.POPUP_MENU_TYPE); - if (FineClientProperties.POPUP_MENU_TYPE_TOOL_BAR.equals(clientProperty)) { - selectionBackground = FineUIUtils.getUIColor("Menu.toolbar.selectionBackground", "Menu.selectionBackground"); - selectionForeground = FineUIUtils.getUIColor("Menu.toolbar.selectionForeground", "Menu.selectionForeground"); - acceleratorForeground = FineUIUtils.getUIColor("Menu.toolbar.acceleratorForeground", "Menu.acceleratorForeground"); - acceleratorSelectionForeground = FineUIUtils.getUIColor("Menu.toolbar.acceleratorSelectionForeground", "Menu.acceleratorSelectionForeground"); - } - super.paint(g, c); Object itemType = c.getClientProperty(FineClientProperties.MENU_ITEM_TYPE); diff --git a/designer-base/src/main/java/com/fine/theme/light/ui/FineMenuUI.java b/designer-base/src/main/java/com/fine/theme/light/ui/FineMenuUI.java index fafe6f78ae..b71b816a07 100644 --- a/designer-base/src/main/java/com/fine/theme/light/ui/FineMenuUI.java +++ b/designer-base/src/main/java/com/fine/theme/light/ui/FineMenuUI.java @@ -1,8 +1,6 @@ package com.fine.theme.light.ui; import com.fine.theme.icon.LazyIcon; -import com.fine.theme.utils.FineClientProperties; -import com.fine.theme.utils.FineUIUtils; import com.formdev.flatlaf.ui.FlatMenuUI; import javax.swing.JComponent; @@ -37,13 +35,6 @@ public class FineMenuUI extends FlatMenuUI { @Override public void paint(Graphics g, JComponent c) { - Object clientProperty = c.getClientProperty(FineClientProperties.POPUP_MENU_TYPE); - if (FineClientProperties.POPUP_MENU_TYPE_TOOL_BAR.equals(clientProperty)) { - selectionBackground = FineUIUtils.getUIColor("MenuItem.toolbar.selectionBackground", "MenuItem.selectionBackground"); - selectionForeground = FineUIUtils.getUIColor("MenuItem.toolbar.selectionForeground", "MenuItem.selectionForeground"); - acceleratorForeground = FineUIUtils.getUIColor("MenuItem.toolbar.acceleratorForeground", "MenuItem.acceleratorForeground"); - acceleratorSelectionForeground = FineUIUtils.getUIColor("MenuItem.toolbar.acceleratorSelectionForeground", "MenuItem.acceleratorSelectionForeground"); - } super.paint(g, c); } } diff --git a/designer-base/src/main/java/com/fine/theme/light/ui/FinePopupMenuUI.java b/designer-base/src/main/java/com/fine/theme/light/ui/FinePopupMenuUI.java index 3a21e2cc44..58a37da791 100644 --- a/designer-base/src/main/java/com/fine/theme/light/ui/FinePopupMenuUI.java +++ b/designer-base/src/main/java/com/fine/theme/light/ui/FinePopupMenuUI.java @@ -1,6 +1,5 @@ package com.fine.theme.light.ui; -import com.fine.theme.utils.FineClientProperties; import com.fine.theme.utils.FineUIUtils; import com.formdev.flatlaf.ui.FlatPopupMenuUI; @@ -41,11 +40,6 @@ public class FinePopupMenuUI extends FlatPopupMenuUI { @Override public void paint(Graphics g, JComponent c) { - Object clientProperty = c.getClientProperty(FineClientProperties.POPUP_MENU_TYPE); - if (clientProperty != null && clientProperty.equals(FineClientProperties.POPUP_MENU_TYPE_TOOL_BAR)) { - c.setBackground(FineUIUtils.getUIColor("PopupMenu.toolbar.background", "PopupMenu.background")); - } - // 绘制圆角矩形作为弹窗背景 Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); diff --git a/designer-base/src/main/java/com/fine/theme/utils/FineClientProperties.java b/designer-base/src/main/java/com/fine/theme/utils/FineClientProperties.java index 6d3ead4677..3aaf9615a3 100644 --- a/designer-base/src/main/java/com/fine/theme/utils/FineClientProperties.java +++ b/designer-base/src/main/java/com/fine/theme/utils/FineClientProperties.java @@ -16,11 +16,13 @@ public interface FineClientProperties extends FlatClientProperties { String BUTTON_TYPE_LEFT_ROUND_RECT = "leftRoundRect"; String BUTTON_TYPE_RIGHT_ROUND_RECT = "rightRoundRect"; + /** + * 背景透明按钮,仅初始化背景不生效,悬浮、点击仍然生效 + */ + String BUTTON_TYPE_TRANSPARENT = "transparentButton"; //--------------------------- PopupMenu ----------------------- - String POPUP_MENU_TYPE = "popupMenuType"; String MENU_ITEM_TYPE = "MenuItemType"; - String POPUP_MENU_TYPE_TOOL_BAR = "toolBar"; String MENU_ITEM_TYPE_LOCK = "lock"; String BUTTON_GROUP_POSITION = "group_position"; diff --git a/designer-base/src/main/java/com/fine/theme/utils/FineUIStyle.java b/designer-base/src/main/java/com/fine/theme/utils/FineUIStyle.java index 1e029ed551..82172be6f7 100644 --- a/designer-base/src/main/java/com/fine/theme/utils/FineUIStyle.java +++ b/designer-base/src/main/java/com/fine/theme/utils/FineUIStyle.java @@ -27,6 +27,10 @@ public interface FineUIStyle { String BRAND_COLOR_LABEL = "brandColorLabel"; String BUTTON_TAB_ACTION = "tabAction"; + String MENU_TOOL_BAR = "menuToolBar"; + String MENU_ITEM_TOOL_BAR = "menuItemToolBar"; + String POPUP_MENU_TOOL_BAR = "popupMenuToolBar"; + /** * 添加组件的样式类,类似css,该方法会接在原样式后方 diff --git a/designer-base/src/main/java/com/fr/design/mainframe/JFormSliderPane.java b/designer-base/src/main/java/com/fr/design/mainframe/JFormSliderPane.java index 38a8d9d757..ec0bb70659 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/JFormSliderPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/JFormSliderPane.java @@ -1,6 +1,7 @@ package com.fr.design.mainframe; import com.fine.theme.icon.LazyIcon; +import com.fine.theme.utils.FineClientProperties; import com.fine.theme.utils.FineUIScale; import com.fine.theme.utils.FineUIUtils; import com.formdev.flatlaf.ui.FlatUIUtils; @@ -34,6 +35,7 @@ import java.math.BigDecimal; import static com.fine.theme.utils.FineUIStyle.LIGHT_GREY; import static com.fine.theme.utils.FineUIStyle.setStyle; +import static com.formdev.flatlaf.FlatClientProperties.BUTTON_TYPE; /** @@ -106,6 +108,7 @@ public class JFormSliderPane extends JPanel { }; downButton.setBorderPainted(false); downButton.setToolTipText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Scale_Down")); + downButton.putClientProperty(BUTTON_TYPE, FineClientProperties.BUTTON_TYPE_TRANSPARENT); upButton = new UIButton(new LazyIcon("zoomIn")) { public Point getToolTipLocation(MouseEvent event) { return new Point(event.getX(), event.getY() - TOOLTIP_Y); @@ -117,6 +120,7 @@ public class JFormSliderPane extends JPanel { upButton.setActionCommand("more"); downButton.addActionListener(buttonActionListener); upButton.addActionListener(buttonActionListener); + upButton.putClientProperty(BUTTON_TYPE, FineClientProperties.BUTTON_TYPE_TRANSPARENT); } private void initShowValField() { diff --git a/designer-base/src/main/java/com/fr/design/mainframe/loghandler/LogMessageBar.java b/designer-base/src/main/java/com/fr/design/mainframe/loghandler/LogMessageBar.java index 0712327eca..6ccbad1463 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/loghandler/LogMessageBar.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/loghandler/LogMessageBar.java @@ -1,6 +1,7 @@ package com.fr.design.mainframe.loghandler; import com.fine.theme.icon.LazyIcon; +import com.fine.theme.utils.FineClientProperties; import com.fr.design.dialog.BasicPane; import com.fr.design.gui.ibutton.UIButton; @@ -9,6 +10,8 @@ import java.awt.BorderLayout; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import static com.formdev.flatlaf.FlatClientProperties.BUTTON_TYPE; + /** * 日志消息 * @@ -40,6 +43,7 @@ public class LogMessageBar extends BasicPane { logButton = new UIButton(new LazyIcon("logMsg")); logButton.setToolTipText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Show_Log_Message")); logButton.set4ToolbarButton(); + logButton.putClientProperty(BUTTON_TYPE, FineClientProperties.BUTTON_TYPE_TRANSPARENT); add(logButton); logButton.addMouseListener(new MouseAdapter() { @Override diff --git a/designer-base/src/main/java/com/fr/design/menu/MenuDef.java b/designer-base/src/main/java/com/fr/design/menu/MenuDef.java index 17a0548561..5b82786abd 100644 --- a/designer-base/src/main/java/com/fr/design/menu/MenuDef.java +++ b/designer-base/src/main/java/com/fr/design/menu/MenuDef.java @@ -1,7 +1,7 @@ package com.fr.design.menu; import com.fine.theme.icon.LazyIcon; -import com.fine.theme.utils.FineClientProperties; +import com.fine.theme.utils.FineUIStyle; import com.fr.base.svg.IconUtils; import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.gui.ibutton.UIButton; @@ -35,6 +35,8 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import static com.fine.theme.utils.FineUIStyle.setStyle; + /** * Define Menu. */ @@ -330,18 +332,18 @@ public class MenuDef extends ShortCut { } private void setToolBarClientProperty(JPopupMenu jPopupMenu) { - jPopupMenu.putClientProperty(FineClientProperties.POPUP_MENU_TYPE, FineClientProperties.POPUP_MENU_TYPE_TOOL_BAR); + setStyle(jPopupMenu, FineUIStyle.POPUP_MENU_TOOL_BAR); MenuElement[] subElements = jPopupMenu.getSubElements(); for (MenuElement subElement : subElements) { if (subElement instanceof JMenu) { JMenu jMenu = (JMenu) subElement; - jMenu.putClientProperty(FineClientProperties.POPUP_MENU_TYPE, FineClientProperties.POPUP_MENU_TYPE_TOOL_BAR); + setStyle(jMenu, FineUIStyle.MENU_TOOL_BAR); JPopupMenu childPopupMenu = jMenu.getPopupMenu(); setToolBarClientProperty(childPopupMenu); } else if (subElement instanceof JMenuItem) { JMenuItem jMenuItem = (JMenuItem) subElement; - jMenuItem.putClientProperty(FineClientProperties.POPUP_MENU_TYPE, FineClientProperties.POPUP_MENU_TYPE_TOOL_BAR); + setStyle(jMenuItem, FineUIStyle.MENU_ITEM_TOOL_BAR); } } } diff --git a/designer-base/src/main/java/com/fr/design/notification/ui/NotificationCenterPane.java b/designer-base/src/main/java/com/fr/design/notification/ui/NotificationCenterPane.java index 817afcdcd6..b0fec9776f 100644 --- a/designer-base/src/main/java/com/fr/design/notification/ui/NotificationCenterPane.java +++ b/designer-base/src/main/java/com/fr/design/notification/ui/NotificationCenterPane.java @@ -1,6 +1,7 @@ package com.fr.design.notification.ui; import com.fine.theme.icon.LazyIcon; +import com.fine.theme.utils.FineClientProperties; import com.fr.design.dialog.BasicPane; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.i18n.Toolkit; @@ -11,6 +12,8 @@ import java.awt.BorderLayout; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import static com.formdev.flatlaf.FlatClientProperties.BUTTON_TYPE; + public class NotificationCenterPane extends BasicPane { private static NotificationCenterPane notificationCenterPane = new NotificationCenterPane(); private static UIButton notificationCenterButton; @@ -22,6 +25,7 @@ public class NotificationCenterPane extends BasicPane { notificationCenterButton.setIcon(new LazyIcon("notification")); notificationCenterButton.setToolTipText(Toolkit.i18nText("Fine-Design_Basic_Show_Notification")); notificationCenterButton.set4ToolbarButton(); + notificationCenterButton.putClientProperty(BUTTON_TYPE, FineClientProperties.BUTTON_TYPE_TRANSPARENT); this.add(notificationCenterButton); notificationCenterButton.addMouseListener(new MouseAdapter() { @Override diff --git a/designer-base/src/main/resources/com/fine/theme/light/ui/laf/FineLightLaf.properties b/designer-base/src/main/resources/com/fine/theme/light/ui/laf/FineLightLaf.properties index cf3bebf167..fd69ba49d3 100644 --- a/designer-base/src/main/resources/com/fine/theme/light/ui/laf/FineLightLaf.properties +++ b/designer-base/src/main/resources/com/fine/theme/light/ui/laf/FineLightLaf.properties @@ -455,10 +455,9 @@ Menu.opaque = false Menu.borderPainted = true Menu.background = @menuBackground Menu.selectionBackground=$fill.hover -Menu.toolbar.selectionBackground=$brand.normal -Menu.toolbar.selectionForeground=$text.white -Menu.toolbar.acceleratorForeground=@foreground -Menu.toolbar.acceleratorSelectionForeground=$text.white +#Menu.selectionForeground=$text.white +#Menu.acceleratorForeground=@foreground +#Menu.acceleratorSelectionForeground=$text.white #---- MenuBar ---- @@ -492,15 +491,11 @@ MenuItem.acceleratorArrowGap=4 MenuItem.acceleratorDelimiter = "+" MenuItem.acceleratorForeground=@foreground MenuItem.acceleratorSelectionForeground=@foreground -MenuItem.toolbar.acceleratorForeground=@foreground -MenuItem.toolbar.acceleratorSelectionForeground=$text.white [mac]MenuItem.acceleratorDelimiter = "" MenuItem.selectionInsets=0,4,0,4 MenuItem.selectionArc=4 MenuItem.selectionBackground=$fill.hover MenuItem.selectionForeground=@foreground -MenuItem.toolbar.selectionBackground=$brand.normal -MenuItem.toolbar.selectionForeground=$text.white MenuItem.disabledForeground=fade(@foreground,29%) # for MenuItem.selectionType = underline @@ -570,7 +565,6 @@ PopupMenu.border=com.fine.theme.light.ui.FinePopupMenuBorder PopupMenu.borderInsets=10,0,10,0 PopupMenu.borderCornerRadius = $Popup.borderCornerRadius PopupMenu.background=$background.normal -PopupMenu.toolbar.background=$fill.gray PopupMenu.scrollArrowColor = @buttonArrowColor PopupMenu.borderColor=$border.divider PopupMenu.hoverScrollArrowBackground = darken(@background,5%) @@ -1271,6 +1265,18 @@ CellOtherSetPane.height=$Component.defaultHeight [style]ToggleButton.inToolbarGroup = \ margin : 4,4,4,4; \ background : #fff +[style]Menu.menuToolBar=\ + selectionBackground : $brand.normal; \ + selectionForeground : $text.white; \ + acceleratorForeground : @foreground; \ + acceleratorSelectionForeground : $text.white +[style]MenuItem.menuItemToolBar=\ + selectionBackground : $brand.normal; \ + selectionForeground : $text.white; \ + acceleratorForeground : @foreground; \ + acceleratorSelectionForeground : $text.white +[style]PopupMenu.popupMenuToolBar=\ + background: $fill.gray #---- clearButton ---- # for clear/cancel button in text fields diff --git a/designer-base/src/test/java/com/fr/design/gui/storybook/components/PopupMenuStoryBoard.java b/designer-base/src/test/java/com/fr/design/gui/storybook/components/PopupMenuStoryBoard.java index 21066949fa..fb4354d3df 100644 --- a/designer-base/src/test/java/com/fr/design/gui/storybook/components/PopupMenuStoryBoard.java +++ b/designer-base/src/test/java/com/fr/design/gui/storybook/components/PopupMenuStoryBoard.java @@ -1,7 +1,7 @@ package com.fr.design.gui.storybook.components; import com.fine.theme.icon.LazyIcon; -import com.fine.theme.utils.FineClientProperties; +import com.fine.theme.utils.FineUIStyle; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.imenu.UIMenuItem; import com.fr.design.gui.imenu.UIPopupMenu; @@ -19,6 +19,7 @@ import java.awt.event.MouseEvent; import static com.fine.swing.ui.layout.Layouts.cell; import static com.fine.swing.ui.layout.Layouts.column; +import static com.fine.theme.utils.FineUIStyle.setStyle; /** * 弹窗组件 @@ -83,18 +84,18 @@ public class PopupMenuStoryBoard extends StoryBoard { private void setToolBarClientProperty(JPopupMenu jPopupMenu) { - jPopupMenu.putClientProperty(FineClientProperties.POPUP_MENU_TYPE, FineClientProperties.POPUP_MENU_TYPE_TOOL_BAR); + setStyle(jPopupMenu, FineUIStyle.POPUP_MENU_TOOL_BAR); MenuElement[] subElements = jPopupMenu.getSubElements(); for (MenuElement subElement : subElements) { if (subElement instanceof JMenu) { JMenu jMenu = (JMenu) subElement; - jMenu.putClientProperty(FineClientProperties.POPUP_MENU_TYPE, FineClientProperties.POPUP_MENU_TYPE_TOOL_BAR); JPopupMenu childPopupMenu = jMenu.getPopupMenu(); + setStyle(jMenu, FineUIStyle.MENU_TOOL_BAR); setToolBarClientProperty(childPopupMenu); } else if (subElement instanceof JMenuItem) { JMenuItem jMenuItem = (JMenuItem) subElement; - jMenuItem.putClientProperty(FineClientProperties.POPUP_MENU_TYPE, FineClientProperties.POPUP_MENU_TYPE_TOOL_BAR); + setStyle(jMenuItem, FineUIStyle.MENU_ITEM_TOOL_BAR); } } } diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/AlphaFinePane.java b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/AlphaFinePane.java index 34569667b2..676d2ddad0 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/AlphaFinePane.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/alphafine/component/AlphaFinePane.java @@ -1,6 +1,7 @@ package com.fr.design.mainframe.alphafine.component; import com.fine.theme.icon.LazyIcon; +import com.fine.theme.utils.FineClientProperties; import com.fr.design.actions.help.alphafine.AlphaFineContext; import com.fr.design.actions.help.alphafine.AlphaFineListener; import com.fr.design.dialog.BasicPane; @@ -13,6 +14,8 @@ import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import static com.formdev.flatlaf.FlatClientProperties.BUTTON_TYPE; + /** * Created by XiaXiang on 2017/3/21. */ @@ -29,6 +32,7 @@ public class AlphaFinePane extends BasicPane { UIButton refreshButton = new UIButton(); refreshButton.setIcon(new LazyIcon(("search"))); refreshButton.setToolTipText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_AlphaFine_Learn_More_About")); + refreshButton.putClientProperty(BUTTON_TYPE, FineClientProperties.BUTTON_TYPE_TRANSPARENT); refreshButton.set4ToolbarButton(); this.add(refreshButton); refreshButton.addActionListener(new ActionListener() {