diff --git a/designer-base/src/main/java/com/fine/theme/light/ui/FinePopupMenuBorder.java b/designer-base/src/main/java/com/fine/theme/light/ui/FinePopupMenuBorder.java new file mode 100644 index 000000000..63bf5e88e --- /dev/null +++ b/designer-base/src/main/java/com/fine/theme/light/ui/FinePopupMenuBorder.java @@ -0,0 +1,19 @@ +package com.fine.theme.light.ui; + +import com.fine.theme.utils.FineUIUtils; +import com.formdev.flatlaf.ui.FlatPopupMenuBorder; + +/** + * PopupMenu Border类 + * + * @author Leo.Qin + * @since 11.0 + * Created on 2023/12/25 + */ +public class FinePopupMenuBorder extends FlatPopupMenuBorder { + + @Override + public int getArc() { + return FineUIUtils.getAndScaleInt("PopupMenu.arc", 5); + } +} 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 new file mode 100644 index 000000000..402734a77 --- /dev/null +++ b/designer-base/src/main/java/com/fine/theme/light/ui/FinePopupMenuUI.java @@ -0,0 +1,57 @@ +package com.fine.theme.light.ui; + +import com.fine.theme.utils.FineUIUtils; +import com.formdev.flatlaf.ui.FlatPopupMenuUI; + +import javax.swing.JComponent; +import javax.swing.plaf.ComponentUI; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.RenderingHints; +import java.awt.geom.RoundRectangle2D; + +/** + * PopupMenu UI类 + * + * @author Leo.Qin + * @since 11.0 + * Created on 2023/12/25 + */ +public class FinePopupMenuUI extends FlatPopupMenuUI { + private int arc; + private final int DEFAULT_ARC = 5; + + /** + * 创建UI + * + * @param c 组件 + * @return UI + */ + public static ComponentUI createUI(JComponent c) { + return new FinePopupMenuUI(); + } + + @Override + public void installDefaults() { + super.installDefaults(); + arc = FineUIUtils.getAndScaleInt("PopupMenu.arc", DEFAULT_ARC); + } + + @Override + public void paint(Graphics g, JComponent c) { + // 绘制圆角矩形作为弹窗背景 + Graphics2D g2d = (Graphics2D) g; + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + RoundRectangle2D roundRect = new RoundRectangle2D.Double(0, 0, c.getWidth(), c.getHeight(), arc, arc); + g2d.setColor(c.getBackground()); + g2d.fill(roundRect); + + // 绘制组件内容 + super.paint(g, c); + } + + @Override + public void update(Graphics g, JComponent c) { + paint(g, c); + } +} diff --git a/designer-base/src/main/java/com/fine/theme/light/ui/FineTooltipUI.java b/designer-base/src/main/java/com/fine/theme/light/ui/FineTooltipUI.java index a82d0477a..87b029529 100644 --- a/designer-base/src/main/java/com/fine/theme/light/ui/FineTooltipUI.java +++ b/designer-base/src/main/java/com/fine/theme/light/ui/FineTooltipUI.java @@ -9,13 +9,13 @@ import com.fr.stable.Constants; import javax.swing.JComponent; import javax.swing.JToolTip; import javax.swing.SwingUtilities; -import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import java.awt.Dimension; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Insets; +import java.awt.RenderingHints; import java.util.List; /** @@ -39,9 +39,11 @@ public class FineTooltipUI extends FlatToolTipUI { @Override public void paint(Graphics g, JComponent c) { + Graphics2D g2d = (Graphics2D) g; + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - g.setColor(c.getBackground()); - g.fillRoundRect(0, 0, c.getWidth(), c.getHeight(), arc, arc); + g2d.setColor(c.getBackground()); + g2d.fillRoundRect(0, 0, c.getWidth(), c.getHeight(), arc, arc); String text = ((JToolTip) c).getTipText(); if (text == null || text.isEmpty()) { @@ -49,7 +51,6 @@ public class FineTooltipUI extends FlatToolTipUI { } Insets insets = c.getInsets(); - Graphics2D g2d = (Graphics2D) g; FontMetrics fm = g2d.getFontMetrics(); int x = insets.left; diff --git a/designer-base/src/main/java/com/fine/theme/light/ui/laf/FineLaf.java b/designer-base/src/main/java/com/fine/theme/light/ui/laf/FineLaf.java index 568310df5..079d013d6 100644 --- a/designer-base/src/main/java/com/fine/theme/light/ui/laf/FineLaf.java +++ b/designer-base/src/main/java/com/fine/theme/light/ui/laf/FineLaf.java @@ -2,6 +2,8 @@ package com.fine.theme.light.ui.laf; import com.formdev.flatlaf.FlatLaf; +import javax.swing.PopupFactory; + /** * Fine designer new look and feel * FineLaf.properties 定义公共属性,如UI等, @@ -25,4 +27,10 @@ public abstract class FineLaf extends FlatLaf { public String getDescription() { return "Fine New Look and Feel"; } + + @Override + public void initialize() { + super.initialize(); + PopupFactory.setSharedInstance(new PopupFactory()); + } } diff --git a/designer-base/src/main/java/com/fr/design/gui/imenu/UIPopupEastAttrMenu.java b/designer-base/src/main/java/com/fr/design/gui/imenu/UIPopupEastAttrMenu.java index 42b04e03a..a7d7144e1 100644 --- a/designer-base/src/main/java/com/fr/design/gui/imenu/UIPopupEastAttrMenu.java +++ b/designer-base/src/main/java/com/fr/design/gui/imenu/UIPopupEastAttrMenu.java @@ -1,28 +1,11 @@ package com.fr.design.gui.imenu; -import java.awt.Graphics; -import java.awt.Insets; - import javax.swing.JPopupMenu; -import com.fr.design.constants.UIConstants; - public class UIPopupEastAttrMenu extends JPopupMenu { public UIPopupEastAttrMenu() { super(); - setBackground(UIConstants.NORMAL_BACKGROUND); - } - - @Override - protected void paintBorder(Graphics g) { - g.setColor(UIConstants.POP_DIALOG_BORDER); - g.drawRect(0, 0, getWidth() - 1, getHeight() - 1); - } - - @Override - public Insets getInsets() { - return new Insets(0, 1, 1, 1); } } \ No newline at end of file diff --git a/designer-base/src/main/java/com/fr/design/gui/imenu/UIPopupMenu.java b/designer-base/src/main/java/com/fr/design/gui/imenu/UIPopupMenu.java index e2a2546b2..b09989f95 100644 --- a/designer-base/src/main/java/com/fr/design/gui/imenu/UIPopupMenu.java +++ b/designer-base/src/main/java/com/fr/design/gui/imenu/UIPopupMenu.java @@ -1,11 +1,6 @@ package com.fr.design.gui.imenu; -import com.fr.design.constants.UIConstants; - import javax.swing.JPopupMenu; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.Insets; public class UIPopupMenu extends JPopupMenu{ private static final float DEFAULT_REC = 8f; @@ -15,32 +10,6 @@ public class UIPopupMenu extends JPopupMenu{ public static UIPopupMenu EMPTY = new UIPopupMenu(); public UIPopupMenu() { super(); -// setBackground(UIConstants.NORMAL_BACKGROUND); - } - - @Override - protected void paintComponent(Graphics g) { -// Graphics2D g2d = (Graphics2D) g; -// Shape shape = new RoundRectangle2D.Double(0, 0, getWidth(), getHeight(), rec, rec); -// g2d.setClip(shape); -// g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - super.paintComponent(g); - } - - @Override - protected void paintBorder(Graphics g) { - Graphics2D g2d = (Graphics2D) g; - g2d.setColor(UIConstants.UIPOPUPMENU_LINE_COLOR); -// g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - g2d.drawRoundRect(0, 0, getWidth() - 1, getHeight() - 1, (int) rec, (int) rec); - } - - @Override - public Insets getInsets() { - if(onlyText) { - return super.getInsets(); - } - return new Insets(10, 2, 10, 10); } public void setOnlyText(boolean onlyText) { 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 32e958fa3..e176263d9 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 @@ -19,7 +19,7 @@ MenuItemUI=com.formdev.flatlaf.ui.FlatMenuItemUI OptionPaneUI=com.formdev.flatlaf.ui.FlatOptionPaneUI PanelUI=com.formdev.flatlaf.ui.FlatPanelUI PasswordFieldUI=com.formdev.flatlaf.ui.FlatPasswordFieldUI -PopupMenuUI=com.formdev.flatlaf.ui.FlatPopupMenuUI +PopupMenuUI=com.fine.theme.light.ui.FinePopupMenuUI PopupMenuSeparatorUI=com.formdev.flatlaf.ui.FlatPopupMenuSeparatorUI ProgressBarUI=com.formdev.flatlaf.ui.FlatProgressBarUI RadioButtonUI=com.formdev.flatlaf.ui.FlatRadioButtonUI 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 e1a2c1965..e23f80bd9 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 @@ -547,14 +547,14 @@ PopupToolPane.height=34 PopupToolPane.borderInsets=0, 10, 0, 10 #---- PopupMenu ---- - -PopupMenu.border = com.formdev.flatlaf.ui.FlatPopupMenuBorder -PopupMenu.borderInsets = 4,1,4,1 +PopupMenu.border=com.fine.theme.light.ui.FinePopupMenuBorder +PopupMenu.borderInsets=10,0,10,0 PopupMenu.borderCornerRadius = $Popup.borderCornerRadius -PopupMenu.background = @menuBackground +PopupMenu.background=$background.normal PopupMenu.scrollArrowColor = @buttonArrowColor -PopupMenu.borderColor = shade(@background,28%) +PopupMenu.borderColor=$border.divider PopupMenu.hoverScrollArrowBackground = darken(@background,5%) +PopupMenu.arc=$Component.arc #---- PopupMenuSeparator ---- diff --git a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/local/GroupPane.java b/designer-form/src/main/java/com/fr/design/mainframe/share/ui/local/GroupPane.java index 0a4aacfc9..429269a1c 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/local/GroupPane.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/share/ui/local/GroupPane.java @@ -289,7 +289,6 @@ public class GroupPane extends JPanel { public void mouseClicked(MouseEvent e) { UIPopupMenu popupMenu = new UIPopupMenu(); popupMenu.setOnlyText(true); - popupMenu.setBackground(UIConstants.DEFAULT_BG_RULER); popupMenu.add(new PopupMenuItem(new RenameAction())); popupMenu.add(new PopupMenuItem(new RemoveAction()));