From 0c9c0b11e940ccf60fb1d257977384d8ca79b21f Mon Sep 17 00:00:00 2001 From: "Leo.Qin" Date: Mon, 8 Jan 2024 20:56:16 +0800 Subject: [PATCH 1/3] =?UTF-8?q?REPORT-107973=20=E7=BF=BB=E6=96=B0=E4=B8=8A?= =?UTF-8?q?=E4=B8=8B=E6=96=87=E8=8F=9C=E5=8D=95=E5=BC=B9=E7=AA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fine/theme/light/ui/FineMenuItemUI.java | 50 +++++++++ .../com/fine/theme/light/ui/FineMenuUI.java | 49 +++++++++ .../light/ui/FinePopupMenuSeparatorUI.java | 70 ++++++++++++ .../fine/theme/light/ui/FinePopupMenuUI.java | 9 +- .../theme/utils/FineClientProperties.java | 6 ++ .../data/datapane/TableDataTreePane.java | 1 - .../fr/design/gui/imenu/UILockMenuItem.java | 3 +- .../com/fr/design/gui/imenu/UIMenuItem.java | 2 +- .../com/fr/design/menu/DottedSeparator.java | 28 ++--- .../com/fr/design/menu/LineSeparator.java | 24 ----- .../main/java/com/fr/design/menu/MenuDef.java | 38 ++++++- .../com/fr/design/menu/NameSeparator.java | 13 +-- .../fr/design/menu/SnapChatUpdateAction.java | 1 - .../theme/light/ui/laf/FineLaf.properties | 6 +- .../light/ui/laf/FineLightLaf.properties | 36 +++++-- .../components/PopupMenuStoryBoard.java | 102 ++++++++++++++++++ .../com/fr/grid/selection/CellSelection.java | 2 - .../java/com/fr/grid/selection/Selection.java | 5 + 18 files changed, 375 insertions(+), 70 deletions(-) create mode 100644 designer-base/src/main/java/com/fine/theme/light/ui/FineMenuItemUI.java create mode 100644 designer-base/src/main/java/com/fine/theme/light/ui/FineMenuUI.java create mode 100644 designer-base/src/main/java/com/fine/theme/light/ui/FinePopupMenuSeparatorUI.java create mode 100644 designer-base/src/test/java/com/fr/design/gui/storybook/components/PopupMenuStoryBoard.java 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 new file mode 100644 index 0000000000..e5b28b382b --- /dev/null +++ b/designer-base/src/main/java/com/fine/theme/light/ui/FineMenuItemUI.java @@ -0,0 +1,50 @@ +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; + +import javax.swing.JComponent; +import javax.swing.plaf.ComponentUI; +import java.awt.Graphics; + +/** + * menuItem UI类 + * + * @author Leo.Qin + * @since 11.0 + * Created on 2024/1/8 + */ +public class FineMenuItemUI extends FlatMenuItemUI { + int iconSize = 16; + int rightMargin = 10; + + /** + * 创建UI + * + * @param c + * @return + */ + public static ComponentUI createUI(JComponent c) { + return new FineMenuItemUI(); + } + + @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); + if (FineClientProperties.MENU_ITEM_TYPE_LOCK.equals(itemType)) { + g.drawImage(EditLockUtils.LOCKED_IMAGE, c.getWidth() - rightMargin - iconSize, (c.getHeight() - iconSize) / 2, iconSize, iconSize, null); + } + } +} 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 new file mode 100644 index 0000000000..fafe6f78ae --- /dev/null +++ b/designer-base/src/main/java/com/fine/theme/light/ui/FineMenuUI.java @@ -0,0 +1,49 @@ +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; +import javax.swing.plaf.ComponentUI; +import java.awt.Graphics; + +/** + * 弹窗菜单UI + * + * @author Leo.Qin + * @since 11.0 + * Created on 2024/1/8 + */ +public class FineMenuUI extends FlatMenuUI { + + + /** + * 创建UI + * + * @param c + * @return + */ + public static ComponentUI createUI(JComponent c) { + return new FineMenuUI(); + } + + @Override + protected void installDefaults() { + arrowIcon = new LazyIcon("triangle_right"); + super.installDefaults(); + } + + @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/FinePopupMenuSeparatorUI.java b/designer-base/src/main/java/com/fine/theme/light/ui/FinePopupMenuSeparatorUI.java new file mode 100644 index 0000000000..f5708005d6 --- /dev/null +++ b/designer-base/src/main/java/com/fine/theme/light/ui/FinePopupMenuSeparatorUI.java @@ -0,0 +1,70 @@ +package com.fine.theme.light.ui; + +import com.fine.theme.utils.FineUIUtils; +import com.formdev.flatlaf.ui.FlatPopupMenuSeparatorUI; +import com.formdev.flatlaf.ui.FlatUIUtils; + +import javax.swing.JComponent; +import javax.swing.JSeparator; +import javax.swing.plaf.ComponentUI; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Insets; +import java.awt.geom.Rectangle2D; + +import static com.formdev.flatlaf.util.UIScale.scale; + +/** + * popup弹窗分割线UI + * + * @author Leo.Qin + * @since 11.0 + * Created on 2024/1/8 + */ +public class FinePopupMenuSeparatorUI extends FlatPopupMenuSeparatorUI { + protected Insets insets; + + /** + * @param shared + * @since 2 + */ + protected FinePopupMenuSeparatorUI(boolean shared) { + super(shared); + } + + /** + * 创建UI类 + * + * @param c + * @return + */ + public static ComponentUI createUI(JComponent c) { + return new FinePopupMenuSeparatorUI(false); + } + + @Override + protected void installDefaults(JSeparator s) { + super.installDefaults(s); + insets = FineUIUtils.getAndScaleUIInsets("PopupMenuSeparator.Insets", new Insets(0, 10, 0, 10)); + } + + @Override + public void paint(Graphics g, JComponent c) { + Graphics2D g2 = (Graphics2D) g.create(); + try { + FlatUIUtils.setRenderingHints(g2); + g2.setColor(c.getForeground()); + + float width = scale((float) stripeWidth); + float indent = scale((float) stripeIndent); + + if (((JSeparator) c).getOrientation() == JSeparator.VERTICAL) { + g2.fill(new Rectangle2D.Float(indent, insets.left, width - (insets.left + insets.right), c.getHeight())); + } else { + g2.fill(new Rectangle2D.Float(insets.left, indent, c.getWidth() - (insets.left + insets.right), width)); + } + } finally { + g2.dispose(); + } + } +} 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 402734a77a..3a21e2cc44 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,5 +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.FlatPopupMenuUI; @@ -19,7 +20,7 @@ import java.awt.geom.RoundRectangle2D; */ public class FinePopupMenuUI extends FlatPopupMenuUI { private int arc; - private final int DEFAULT_ARC = 5; + private final int DEFAULT_ARC = 10; /** * 创建UI @@ -39,6 +40,12 @@ 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 aa50ebae8c..6d3ead4677 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 @@ -17,6 +17,12 @@ public interface FineClientProperties extends FlatClientProperties { String BUTTON_TYPE_LEFT_ROUND_RECT = "leftRoundRect"; String BUTTON_TYPE_RIGHT_ROUND_RECT = "rightRoundRect"; + //--------------------------- 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"; int GROUP_BUTTON_POSITION_INNER = 0; diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/TableDataTreePane.java b/designer-base/src/main/java/com/fr/design/data/datapane/TableDataTreePane.java index 2f385d8a47..faf4de9e34 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/TableDataTreePane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/TableDataTreePane.java @@ -182,7 +182,6 @@ public class TableDataTreePane extends BasicTableDataTreePane { popupMenu.add(copyAction.createMenuItem()); popupMenu.add(pasteAction.createMenuItem()); popupMenu.add(removeAction.createMenuItem()); - popupMenu.addSeparator(); // 监听 tableDataTree.addMouseListener(new MouseAdapter() { @Override diff --git a/designer-base/src/main/java/com/fr/design/gui/imenu/UILockMenuItem.java b/designer-base/src/main/java/com/fr/design/gui/imenu/UILockMenuItem.java index c609e5d5c7..4127b3eec8 100644 --- a/designer-base/src/main/java/com/fr/design/gui/imenu/UILockMenuItem.java +++ b/designer-base/src/main/java/com/fr/design/gui/imenu/UILockMenuItem.java @@ -1,5 +1,6 @@ package com.fr.design.gui.imenu; +import com.fine.theme.utils.FineClientProperties; import com.fr.design.editlock.EditLockChangeEvent; import com.fr.design.editlock.EditLockChangeListener; import com.fr.report.LockItem; @@ -32,7 +33,7 @@ public class UILockMenuItem extends UIMenuItem implements EditLockChangeListener this.lockedTooltips = lockedTooltips; this.normalTooltips = normalTooltips; this.lockItem = lockItem; - setUI(new UILockMenuItemUI()); + this.putClientProperty(FineClientProperties.MENU_ITEM_TYPE, FineClientProperties.MENU_ITEM_TYPE_LOCK); } public LockItem getLockItem() { diff --git a/designer-base/src/main/java/com/fr/design/gui/imenu/UIMenuItem.java b/designer-base/src/main/java/com/fr/design/gui/imenu/UIMenuItem.java index 3d7a0b85ba..337799dca3 100644 --- a/designer-base/src/main/java/com/fr/design/gui/imenu/UIMenuItem.java +++ b/designer-base/src/main/java/com/fr/design/gui/imenu/UIMenuItem.java @@ -8,7 +8,7 @@ import javax.swing.JMenuItem; public class UIMenuItem extends JMenuItem{ public UIMenuItem() { - this(StringUtils.BLANK); + this(StringUtils.EMPTY); } public UIMenuItem(String string) { diff --git a/designer-base/src/main/java/com/fr/design/menu/DottedSeparator.java b/designer-base/src/main/java/com/fr/design/menu/DottedSeparator.java index 7d1ec7b261..65dd153b6e 100644 --- a/designer-base/src/main/java/com/fr/design/menu/DottedSeparator.java +++ b/designer-base/src/main/java/com/fr/design/menu/DottedSeparator.java @@ -1,12 +1,15 @@ package com.fr.design.menu; +import com.fine.theme.utils.FineUIUtils; import com.fr.design.actions.UpdateAction; import com.fr.design.gui.imenu.UIMenuItem; +import javax.swing.UIManager; import java.awt.BasicStroke; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; +import java.awt.Insets; import java.awt.Stroke; import java.awt.event.ActionEvent; @@ -42,31 +45,32 @@ public class DottedSeparator extends UpdateAction { } private class MenuItem extends UIMenuItem { + + + private final Insets insets; + private final int height; + public MenuItem() { - this.setUI(null); + this.setEnabled(false); this.removeAll(); + insets = FineUIUtils.getAndScaleUIInsets("PopupMenuSeparator.Insets", new Insets(0, 10, 0, 10)); + height = FineUIUtils.getAndScaleInt("PopupMenuSeparator.height", 5); } public void paint(Graphics g) { int w = this.getWidth(); int h = this.getHeight(); Graphics2D g2d = (Graphics2D)g; - g2d.setColor(getBackground()); - g2d.fillRect(0, 0, w, h); - g2d.setColor(getForeground()); + g2d.setColor(UIManager.getColor("Separator.background")); + Stroke bs = new BasicStroke(1f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 2f, new float[] { 3, 1 }, 0); g2d.setStroke(bs); - g2d.drawLine(30, h / 2+1, w-4, h / 2+1); - this.setForeground(getForeground()); - super.paint(g); - } - - public Dimension getSize() { - return new Dimension(super.getSize().width, 8); + g2d.drawLine(insets.left, h / 2 + 1, w - insets.right, h / 2 + 1); } + @Override public Dimension getPreferredSize() { - return new Dimension(super.getPreferredSize().width, 8); + return new Dimension(super.getPreferredSize().width, height); } } diff --git a/designer-base/src/main/java/com/fr/design/menu/LineSeparator.java b/designer-base/src/main/java/com/fr/design/menu/LineSeparator.java index 1419d31d88..bfba89052a 100644 --- a/designer-base/src/main/java/com/fr/design/menu/LineSeparator.java +++ b/designer-base/src/main/java/com/fr/design/menu/LineSeparator.java @@ -4,9 +4,6 @@ import com.fr.design.actions.UpdateAction; import com.fr.design.gui.imenu.UIMenuItem; import java.awt.Color; -import java.awt.Dimension; -import java.awt.Graphics; -import java.awt.Graphics2D; import java.awt.event.ActionEvent; /** @@ -47,28 +44,7 @@ public class LineSeparator extends UpdateAction{ private class MenuItem extends UIMenuItem { public MenuItem() { - this.setUI(null); this.removeAll(); } - - public void paint(Graphics g) { - int w = this.getWidth(); - int h = this.getHeight(); - Graphics2D g2d = (Graphics2D)g; - g2d.setColor(getBackground()); - g2d.fillRect(0, 0, w, h); - g2d.setColor(getForeground()); - g2d.drawLine(4, h / 2+1, w-4, h / 2+1); -// this.setForeground(color); - super.paint(g); - } - - public Dimension getSize() { - return new Dimension(super.getSize().width, 8); - } - - public Dimension getPreferredSize() { - return new Dimension(super.getPreferredSize().width, 8); - } } } \ No newline at end of file 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 c46adb7997..17a0548561 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,6 +1,7 @@ package com.fr.design.menu; import com.fine.theme.icon.LazyIcon; +import com.fine.theme.utils.FineClientProperties; import com.fr.base.svg.IconUtils; import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.gui.ibutton.UIButton; @@ -17,8 +18,10 @@ import com.fr.stable.StringUtils; import javax.swing.Icon; import javax.swing.JMenu; +import javax.swing.JMenuItem; import javax.swing.JPopupMenu; import javax.swing.JToolBar; +import javax.swing.MenuElement; import javax.swing.event.MenuEvent; import javax.swing.event.MenuListener; import java.awt.Component; @@ -311,7 +314,13 @@ public class MenuDef extends ShortCut { */ public void updateMenu() { //peter:这个方法用来产生JMenu的孩子控件,但是不update,action. - this.updatePopupMenu(this.createJMenu().getPopupMenu()); + UIMenu jMenu = this.createJMenu(); + JPopupMenu jPopupMenu = jMenu.getPopupMenu(); + this.updatePopupMenu(jPopupMenu); + + if (jMenu instanceof UIHeadMenu) { + setToolBarClientProperty(jPopupMenu); + } //peter:需要设置JMenu的enabled属性. if (createdJMenu != null) { @@ -320,6 +329,26 @@ public class MenuDef extends ShortCut { } } + private void setToolBarClientProperty(JPopupMenu jPopupMenu) { + jPopupMenu.putClientProperty(FineClientProperties.POPUP_MENU_TYPE, FineClientProperties.POPUP_MENU_TYPE_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(); + setToolBarClientProperty(childPopupMenu); + } else if (subElement instanceof JMenuItem) { + JMenuItem jMenuItem = (JMenuItem) subElement; + jMenuItem.putClientProperty(FineClientProperties.POPUP_MENU_TYPE, FineClientProperties.POPUP_MENU_TYPE_TOOL_BAR); + } + } + } + + + + public void updateEnable() { setEnabled(checkEnable()); } @@ -350,8 +379,11 @@ public class MenuDef extends ShortCut { } nec_seperator = false; } - - shortcut.intoJPopupMenu(popupMenu); + if (shortcut instanceof LineSeparator) { + popupMenu.addSeparator(); + } else { + shortcut.intoJPopupMenu(popupMenu); + } isFirstItem = false; } diff --git a/designer-base/src/main/java/com/fr/design/menu/NameSeparator.java b/designer-base/src/main/java/com/fr/design/menu/NameSeparator.java index b22184eb8f..f5a0a1a756 100644 --- a/designer-base/src/main/java/com/fr/design/menu/NameSeparator.java +++ b/designer-base/src/main/java/com/fr/design/menu/NameSeparator.java @@ -5,6 +5,7 @@ import com.fr.design.actions.UpdateAction; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.imenu.UIMenuItem; +import javax.swing.UIManager; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.FontMetrics; @@ -44,21 +45,12 @@ public class NameSeparator extends UpdateAction { private class MenuItem extends UIMenuItem { public MenuItem(String text) { - this.setUI(null); + this.setEnabled(false); this.removeAll(); this.setLayout(new BorderLayout()); this.add(new CustomerLable(text, UILabel.LEFT), BorderLayout.CENTER); } - public void paint(Graphics g) { - int w = this.getWidth(); - int h = this.getHeight(); - Graphics2D g2d = (Graphics2D)g; - g2d.setColor(getBackground()); - g2d.fillRect(0, 0, w, h); - super.paint(g); - } - public Dimension getSize() { return new Dimension(super.getSize().width, 20); } @@ -85,6 +77,7 @@ public class NameSeparator extends UpdateAction { for (int i = 0; i < str.length(); i++) { strwidth = strwidth + fm.charWidth(str.charAt(i)); } + g2d.setColor(UIManager.getColor("Separator.background")); g2d.drawLine(strwidth + 4, h / 2+2, w, h / 2+2); super.paint(g); } diff --git a/designer-base/src/main/java/com/fr/design/menu/SnapChatUpdateAction.java b/designer-base/src/main/java/com/fr/design/menu/SnapChatUpdateAction.java index 8cc0734371..d35972989c 100644 --- a/designer-base/src/main/java/com/fr/design/menu/SnapChatUpdateAction.java +++ b/designer-base/src/main/java/com/fr/design/menu/SnapChatUpdateAction.java @@ -57,7 +57,6 @@ public abstract class SnapChatUpdateAction extends UpdateAction implements SnapC UIMenuItem menuItem = new UIMenuItem(this); // 设置名字用作单元测 menuItem.setName(getName()); - menuItem.setUI(new SnapChatMenuItemUI(this)); object = menuItem; this.putValue(UIMenuItem.class.getName(), object); diff --git a/designer-base/src/main/resources/com/fine/theme/light/ui/laf/FineLaf.properties b/designer-base/src/main/resources/com/fine/theme/light/ui/laf/FineLaf.properties index 55596987fe..8985e99dd0 100644 --- a/designer-base/src/main/resources/com/fine/theme/light/ui/laf/FineLaf.properties +++ b/designer-base/src/main/resources/com/fine/theme/light/ui/laf/FineLaf.properties @@ -13,14 +13,14 @@ FormattedTextFieldUI=com.formdev.flatlaf.ui.FlatFormattedTextFieldUI InternalFrameUI=com.formdev.flatlaf.ui.FlatInternalFrameUI LabelUI=com.formdev.flatlaf.ui.FlatLabelUI ListUI=com.formdev.flatlaf.ui.FlatListUI -MenuUI=com.formdev.flatlaf.ui.FlatMenuUI +MenuUI=com.fine.theme.light.ui.FineMenuUI MenuBarUI=com.formdev.flatlaf.ui.FlatMenuBarUI -MenuItemUI=com.formdev.flatlaf.ui.FlatMenuItemUI +MenuItemUI=com.fine.theme.light.ui.FineMenuItemUI OptionPaneUI=com.formdev.flatlaf.ui.FlatOptionPaneUI PanelUI=com.formdev.flatlaf.ui.FlatPanelUI PasswordFieldUI=com.formdev.flatlaf.ui.FlatPasswordFieldUI PopupMenuUI=com.fine.theme.light.ui.FinePopupMenuUI -PopupMenuSeparatorUI=com.formdev.flatlaf.ui.FlatPopupMenuSeparatorUI +PopupMenuSeparatorUI=com.fine.theme.light.ui.FinePopupMenuSeparatorUI ProgressBarUI=com.formdev.flatlaf.ui.FlatProgressBarUI RadioButtonUI=com.formdev.flatlaf.ui.FlatRadioButtonUI RadioButtonMenuItemUI=com.formdev.flatlaf.ui.FlatRadioButtonMenuItemUI 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 e492ad27db..cf3bebf167 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 @@ -135,6 +135,7 @@ text.highlight=fade(@foreground, 90%) fill.hover=#E6E9EF fill.click=#DADEE7 fill.normal=#FFFFFF +fill.gray=#F2F4F8 fill.disabled=#F2F4F8 border.divider=#DADEE7 tooltip.normal=#3F506A @@ -447,13 +448,17 @@ Menu.icon.disabledArrowColor = @buttonDisabledArrowColor Menu.border = com.formdev.flatlaf.ui.FlatMenuItemBorder Menu.arrowIcon = com.formdev.flatlaf.icons.FlatMenuArrowIcon Menu.checkIcon = null -Menu.margin = @menuItemMargin +Menu.margin=3,10,3,10 Menu.submenuPopupOffsetX = {scaledInteger}-4 Menu.submenuPopupOffsetY = {scaledInteger}-4 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 #---- MenuBar ---- @@ -471,25 +476,31 @@ MenuBar.selectionArc = $MenuItem.selectionArc MenuItem.border = com.formdev.flatlaf.ui.FlatMenuItemBorder MenuItem.arrowIcon = com.formdev.flatlaf.icons.FlatMenuItemArrowIcon MenuItem.checkIcon = null -MenuItem.margin=0,10,0,10 +MenuItem.margin=3,10,3,10 MenuItem.opaque = false MenuItem.borderPainted = true MenuItem.verticallyAlignText = true MenuItem.background = @menuBackground MenuItem.checkBackground = @menuCheckBackground MenuItem.checkMargins = 2,2,2,2 -MenuItem.minimumWidth = 72 +MenuItem.minimumWidth=150 MenuItem.minimumIconSize = 16,16 MenuItem.iconTextGap = 6 MenuItem.textAcceleratorGap = 24 MenuItem.textNoAcceleratorGap = 6 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,0,0,0 -MenuItem.selectionArc = 0 -MenuItem.selectionBackground=$brand.normal -MenuItem.selectionForeground=$text.white +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 @@ -497,6 +508,8 @@ MenuItem.underlineSelectionBackground = @menuHoverBackground MenuItem.underlineSelectionCheckBackground = @menuCheckBackground MenuItem.underlineSelectionColor = @accentUnderlineColor MenuItem.underlineSelectionHeight = 3 +#---- Separator ---- +Separator.background=$border.divider #---- OptionPane ---- @@ -557,16 +570,17 @@ 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%) -PopupMenu.arc=$Component.arc +PopupMenu.arc=10 #---- PopupMenuSeparator ---- - -PopupMenuSeparator.height = 9 +PopupMenuSeparator.height=5 PopupMenuSeparator.stripeWidth = 1 PopupMenuSeparator.stripeIndent=2 +PopupMenuSeparator.Insets=0,10,0,10 #---- ProgressBar ---- 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 new file mode 100644 index 0000000000..21066949fa --- /dev/null +++ b/designer-base/src/test/java/com/fr/design/gui/storybook/components/PopupMenuStoryBoard.java @@ -0,0 +1,102 @@ +package com.fr.design.gui.storybook.components; + +import com.fine.theme.icon.LazyIcon; +import com.fine.theme.utils.FineClientProperties; +import com.fr.design.gui.ibutton.UIButton; +import com.fr.design.gui.imenu.UIMenuItem; +import com.fr.design.gui.imenu.UIPopupMenu; +import com.fr.design.gui.storybook.Story; +import com.fr.design.gui.storybook.StoryBoard; +import com.fr.design.menu.DottedSeparator; +import com.fr.design.menu.NameSeparator; + +import javax.swing.JMenu; +import javax.swing.JMenuItem; +import javax.swing.JPopupMenu; +import javax.swing.MenuElement; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +import static com.fine.swing.ui.layout.Layouts.cell; +import static com.fine.swing.ui.layout.Layouts.column; + +/** + * 弹窗组件 + * + * @author Leo.Qin + * @since 11.0 + * Created on 2024/1/8 + */ +@Story +public class PopupMenuStoryBoard extends StoryBoard { + public PopupMenuStoryBoard() { + super("弹窗"); + add( + column(70, + cell(new UIButton("点击展示弹窗")).with(it -> { + UIPopupMenu popupMenu = new UIPopupMenu(); + popupMenu.add(new UIMenuItem("test1", new LazyIcon("edit"))); + popupMenu.add(new UIMenuItem("test2", new LazyIcon("cellHyperLinkAttr"))); + popupMenu.addSeparator(); + popupMenu.add(new UIMenuItem("test3", new LazyIcon("cellClear"))); + popupMenu.add(new NameSeparator("分割线").createMenuItem()); + popupMenu.add(new UIMenuItem("test4", new LazyIcon("cellOtherAttr"))); + popupMenu.add(new DottedSeparator().createMenuItem()); + popupMenu.add(new UIMenuItem("test5", new LazyIcon("cellExpandAttr"))); + + it.addMouseListener(new MouseAdapter() { + + + @Override + public void mouseClicked(MouseEvent e) { + popupMenu.show(it, e.getX(), e.getY()); + } + }); + }), + + cell(new UIButton("点击展示菜单栏弹窗")).with(it -> { + UIPopupMenu popupMenu = new UIPopupMenu(); + popupMenu.add(new UIMenuItem("test1", new LazyIcon("edit"))); + popupMenu.add(new UIMenuItem("test2", new LazyIcon("cellHyperLinkAttr"))); + popupMenu.addSeparator(); + popupMenu.add(new UIMenuItem("test3", new LazyIcon("cellClear"))); + popupMenu.add(new NameSeparator("分割线").createMenuItem()); + popupMenu.add(new UIMenuItem("test4", new LazyIcon("cellOtherAttr"))); + popupMenu.add(new DottedSeparator().createMenuItem()); + popupMenu.add(new UIMenuItem("test5", new LazyIcon("cellExpandAttr"))); + + it.addMouseListener(new MouseAdapter() { + + + @Override + public void mouseClicked(MouseEvent e) { + popupMenu.show(it, e.getX(), e.getY()); + } + }); + + setToolBarClientProperty(popupMenu); + }) + ) + ); + + } + + + private void setToolBarClientProperty(JPopupMenu jPopupMenu) { + jPopupMenu.putClientProperty(FineClientProperties.POPUP_MENU_TYPE, FineClientProperties.POPUP_MENU_TYPE_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(); + setToolBarClientProperty(childPopupMenu); + } else if (subElement instanceof JMenuItem) { + JMenuItem jMenuItem = (JMenuItem) subElement; + jMenuItem.putClientProperty(FineClientProperties.POPUP_MENU_TYPE, FineClientProperties.POPUP_MENU_TYPE_TOOL_BAR); + } + } + } + +} diff --git a/designer-realize/src/main/java/com/fr/grid/selection/CellSelection.java b/designer-realize/src/main/java/com/fr/grid/selection/CellSelection.java index 4d5fe8a62b..c5ec43463f 100644 --- a/designer-realize/src/main/java/com/fr/grid/selection/CellSelection.java +++ b/designer-realize/src/main/java/com/fr/grid/selection/CellSelection.java @@ -506,8 +506,6 @@ public class CellSelection extends Selection { popup.add(DeprecatedActionManager.getDeleteMenu(ePane)); popup.add(DeprecatedActionManager.getClearMenu(ePane)); - popup.addSeparator(); - addExtraMenu(ePane, popup); return popup; } diff --git a/designer-realize/src/main/java/com/fr/grid/selection/Selection.java b/designer-realize/src/main/java/com/fr/grid/selection/Selection.java index 1ddc54d432..d51707fb60 100644 --- a/designer-realize/src/main/java/com/fr/grid/selection/Selection.java +++ b/designer-realize/src/main/java/com/fr/grid/selection/Selection.java @@ -70,12 +70,17 @@ public abstract class Selection implements FCloneable, Serializable , Selectable * @param popupMenu */ public void addExtraMenu(ElementCasePane ePane, UIPopupMenu popupMenu) { + boolean existExtraMenu = false; Set selectionHandlerProviders = ExtraDesignClassManager.getInstance().getArray(RightSelectionHandlerProvider.XML_TAG); for (RightSelectionHandlerProvider handler : selectionHandlerProviders) { if (handler.accept(this)) { + existExtraMenu = true; handler.dmlMenu(ePane, popupMenu); } } + if (existExtraMenu) { + popupMenu.addSeparator(); + } } public abstract boolean clear(ElementCasePane.Clear type, ElementCasePane ePane); From e48414f96100b56836168f4a74381803b6acdc5c Mon Sep 17 00:00:00 2001 From: "Leo.Qin" Date: Tue, 9 Jan 2024 09:46:02 +0800 Subject: [PATCH 2/3] =?UTF-8?q?REPORT-107973=20=E7=BF=BB=E6=96=B0=E4=B8=8A?= =?UTF-8?q?=E4=B8=8B=E6=96=87=E8=8F=9C=E5=8D=95=E5=BC=B9=E7=AA=97=E3=80=82?= =?UTF-8?q?=E9=80=8F=E6=98=8E=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fine/theme/light/ui/FineButtonUI.java | 53 +++++++++++++++++++ .../fine/theme/light/ui/FineMenuItemUI.java | 9 ---- .../com/fine/theme/light/ui/FineMenuUI.java | 9 ---- .../fine/theme/light/ui/FinePopupMenuUI.java | 6 --- .../theme/utils/FineClientProperties.java | 6 ++- .../com/fine/theme/utils/FineUIStyle.java | 4 ++ .../fr/design/mainframe/JFormSliderPane.java | 4 ++ .../mainframe/loghandler/LogMessageBar.java | 4 ++ .../main/java/com/fr/design/menu/MenuDef.java | 10 ++-- .../ui/NotificationCenterPane.java | 4 ++ .../light/ui/laf/FineLightLaf.properties | 24 +++++---- .../components/PopupMenuStoryBoard.java | 9 ++-- .../alphafine/component/AlphaFinePane.java | 4 ++ 13 files changed, 103 insertions(+), 43 deletions(-) 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() { From af5775815287bd35b08fe7cf27303bebb2bfd563 Mon Sep 17 00:00:00 2001 From: "Leo.Qin" Date: Tue, 9 Jan 2024 10:07:23 +0800 Subject: [PATCH 3/3] =?UTF-8?q?REPORT-107973=20=E5=9B=9E=E9=80=80=E9=80=8F?= =?UTF-8?q?=E6=98=8E=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fine/theme/light/ui/FineButtonUI.java | 53 ------------------- .../theme/utils/FineClientProperties.java | 4 -- .../fr/design/mainframe/JFormSliderPane.java | 4 -- .../mainframe/loghandler/LogMessageBar.java | 4 -- .../ui/NotificationCenterPane.java | 4 -- .../alphafine/component/AlphaFinePane.java | 4 -- 6 files changed, 73 deletions(-) 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 420ab90d0a..d5b3c17f74 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,7 +6,6 @@ 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; @@ -97,58 +96,6 @@ 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/utils/FineClientProperties.java b/designer-base/src/main/java/com/fine/theme/utils/FineClientProperties.java index 3aaf9615a3..8883f88da4 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,10 +16,6 @@ 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 MENU_ITEM_TYPE = "MenuItemType"; 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 ec0bb70659..38a8d9d757 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,7 +1,6 @@ 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; @@ -35,7 +34,6 @@ 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; /** @@ -108,7 +106,6 @@ 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); @@ -120,7 +117,6 @@ 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 6ccbad1463..0712327eca 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,7 +1,6 @@ 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; @@ -10,8 +9,6 @@ import java.awt.BorderLayout; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import static com.formdev.flatlaf.FlatClientProperties.BUTTON_TYPE; - /** * 日志消息 * @@ -43,7 +40,6 @@ 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/notification/ui/NotificationCenterPane.java b/designer-base/src/main/java/com/fr/design/notification/ui/NotificationCenterPane.java index b0fec9776f..817afcdcd6 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,7 +1,6 @@ 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; @@ -12,8 +11,6 @@ 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; @@ -25,7 +22,6 @@ 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-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 676d2ddad0..34569667b2 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,7 +1,6 @@ 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; @@ -14,8 +13,6 @@ 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. */ @@ -32,7 +29,6 @@ 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() {