From faff0f39595a2704f4183eac3b650ac1d4d19a5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Levy=2EXie-=E8=A7=A3=E5=AE=89=E6=A3=AE?= Date: Thu, 7 Dec 2023 16:37:39 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-107972=20=E8=AE=BE=E8=AE=A1=E5=99=A8?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F=E7=BF=BB=E6=96=B0-UIComboBox=E7=BF=BB?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fine/theme/light/ui/FineComboBoxUI.java | 41 ++++++++++ .../fine/theme/light/ui/FineLightIconSet.java | 1 + .../java/com/fr/design/event/HoverAware.java | 13 ++++ .../gui/icombobox/ExtendedComboBox.java | 4 +- .../design/gui/icombobox/FRTreeComboBox.java | 78 +------------------ .../fr/design/gui/icombobox/UIComboBox.java | 47 ++++++----- .../com/fine/theme/icon/down_arrow.svg | 5 ++ .../fine/theme/icon/down_arrow_disable.svg | 5 ++ .../light/ui/laf/FineLightLaf.properties | 28 ++++--- 9 files changed, 113 insertions(+), 109 deletions(-) create mode 100644 designer-base/src/main/java/com/fine/theme/light/ui/FineComboBoxUI.java create mode 100644 designer-base/src/main/java/com/fr/design/event/HoverAware.java create mode 100644 designer-base/src/main/resources/com/fine/theme/icon/down_arrow.svg create mode 100644 designer-base/src/main/resources/com/fine/theme/icon/down_arrow_disable.svg diff --git a/designer-base/src/main/java/com/fine/theme/light/ui/FineComboBoxUI.java b/designer-base/src/main/java/com/fine/theme/light/ui/FineComboBoxUI.java new file mode 100644 index 0000000000..a335aba921 --- /dev/null +++ b/designer-base/src/main/java/com/fine/theme/light/ui/FineComboBoxUI.java @@ -0,0 +1,41 @@ +package com.fine.theme.light.ui; + +import com.formdev.flatlaf.ui.FlatComboBoxUI; + +import javax.swing.JComponent; +import javax.swing.JButton; +import javax.swing.SwingConstants; +import javax.swing.plaf.ComponentUI; +import java.awt.Graphics2D; + +/** + * 提供 {@link javax.swing.JComboBox} 的UI类 + * + * @author Levy.Xie + * @since 11.0 + * Created on 2023/12/07 + */ +public class FineComboBoxUI extends FlatComboBoxUI { + + public static ComponentUI createUI(JComponent c) { + return new FineComboBoxUI(); + } + + @Override + protected JButton createArrowButton() { + return new FineComboBoxButton(); + } + + protected class FineComboBoxButton extends FlatComboBoxButton { + + @Override + protected void paintArrow(Graphics2D g) { + if (isPopupVisible(comboBox)) { + setDirection(SwingConstants.NORTH); + } else { + setDirection(SwingConstants.SOUTH); + } + super.paintArrow(g); + } + } +} diff --git a/designer-base/src/main/java/com/fine/theme/light/ui/FineLightIconSet.java b/designer-base/src/main/java/com/fine/theme/light/ui/FineLightIconSet.java index 40ee8c30aa..489c6d2219 100644 --- a/designer-base/src/main/java/com/fine/theme/light/ui/FineLightIconSet.java +++ b/designer-base/src/main/java/com/fine/theme/light/ui/FineLightIconSet.java @@ -34,6 +34,7 @@ public class FineLightIconSet extends AbstractIconSet { new SvgIconSource("add", "com/fine/theme/icon/add.svg", true), new SvgIconSource("drag_left", "com/fine/theme/icon/drag_left.svg", true), new SvgIconSource("drag_right", "com/fine/theme/icon/drag_right.svg", true), + new SvgIconSource("down_arrow", "com/fine/theme/icon/down_arrow.svg", true), // 数据集相关Icon new SvgIconSource("database", "com/fine/theme/icon/dataset/database.svg", true), diff --git a/designer-base/src/main/java/com/fr/design/event/HoverAware.java b/designer-base/src/main/java/com/fr/design/event/HoverAware.java new file mode 100644 index 0000000000..36af8275db --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/event/HoverAware.java @@ -0,0 +1,13 @@ +package com.fr.design.event; + +/** + * 组件判断是否被hover的能力接口 + * + * @author Levy.Xie + * @since 11.0 + * Created on 2023/12/07 + */ +public interface HoverAware { + + boolean isHovered(); +} diff --git a/designer-base/src/main/java/com/fr/design/gui/icombobox/ExtendedComboBox.java b/designer-base/src/main/java/com/fr/design/gui/icombobox/ExtendedComboBox.java index 70fa9dccdf..9fc3d9e172 100644 --- a/designer-base/src/main/java/com/fr/design/gui/icombobox/ExtendedComboBox.java +++ b/designer-base/src/main/java/com/fr/design/gui/icombobox/ExtendedComboBox.java @@ -1,12 +1,12 @@ package com.fr.design.gui.icombobox; +import com.fine.theme.light.ui.FineComboBoxUI; import com.fr.common.inputevent.InputEventBaseOnOS; import java.awt.Component; import java.awt.Dimension; import java.awt.Point; import java.awt.Rectangle; -import java.awt.event.InputEvent; import java.awt.event.MouseEvent; import java.util.Vector; @@ -54,7 +54,7 @@ public class ExtendedComboBox extends UIComboBox { return dim; } - static class ExtendedComboBoxUI extends UIBasicComboBoxUI { + static class ExtendedComboBoxUI extends FineComboBoxUI { public static ComponentUI createUI(JComponent c) { return new ExtendedComboBoxUI(); } diff --git a/designer-base/src/main/java/com/fr/design/gui/icombobox/FRTreeComboBox.java b/designer-base/src/main/java/com/fr/design/gui/icombobox/FRTreeComboBox.java index c122394476..abb6f2d982 100644 --- a/designer-base/src/main/java/com/fr/design/gui/icombobox/FRTreeComboBox.java +++ b/designer-base/src/main/java/com/fr/design/gui/icombobox/FRTreeComboBox.java @@ -1,5 +1,6 @@ package com.fr.design.gui.icombobox; +import com.fine.theme.light.ui.FineComboBoxUI; import com.fr.design.constants.UIConstants; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ilable.UILabel; @@ -248,8 +249,7 @@ public class FRTreeComboBox extends UIComboBox { private static TreePopup treePopup; - protected static class FRTreeComboBoxUI extends BasicComboBoxUI implements MouseListener{ - private boolean isRollover = false; + protected static class FRTreeComboBoxUI extends FineComboBoxUI { public FRTreeComboBoxUI() { super(); @@ -258,81 +258,7 @@ public class FRTreeComboBox extends UIComboBox { treePopup = new TreePopup(comboBox); return treePopup; } - @Override - protected UIButton createArrowButton() { - arrowButton = new UIButton(UIConstants.ARROW_DOWN_ICON){ - /** - * 组件是否需要响应添加的观察者事件 - * - * @return 如果需要响应观察者事件则返回true,否则返回false - */ - @Override - public boolean shouldResponseChangeListener() { - return false; - } - }; - ((UIButton) arrowButton).setRoundBorder(true, Constants.LEFT); - arrowButton.addMouseListener(this); - comboBox.addMouseListener(this); - return (UIButton) arrowButton; - } - - public void paint(Graphics g, JComponent c) { - super.paint(g, c); - Graphics2D g2d = (Graphics2D)g; - g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - Color linecolor = null; - if (comboBox.isPopupVisible()) { - linecolor = UIConstants.LINE_COLOR; - arrowButton.setSelected(true); - } else if (isRollover) { - linecolor = UIConstants.LIGHT_BLUE; - } else { - linecolor = UIConstants.LINE_COLOR; - arrowButton.setSelected(false); - } - g2d.setColor(linecolor); - if (!comboBox.isPopupVisible()) { - g2d.drawRoundRect(0, 0, c.getWidth() - arrowButton.getWidth() + 3, c.getHeight() - 1, UIConstants.LARGEARC, UIConstants.LARGEARC); - } else { - g2d.drawRoundRect(0, 0, c.getWidth() , c.getHeight() + 3, UIConstants.LARGEARC, UIConstants.LARGEARC ); - g2d.drawLine(0, c.getHeight()-1, c.getWidth(), c.getHeight()-1); - } - } - - - - private void setRollover(boolean isRollover) { - if (this.isRollover != isRollover) { - this.isRollover = isRollover; - comboBox.repaint(); - } - } - @Override - public void mouseEntered(MouseEvent e) { - setRollover(true); - } - - @Override - public void mouseExited(MouseEvent e) { - setRollover(false); - } - - @Override - public void mouseClicked(MouseEvent e) { - // do nothing - } - - @Override - public void mousePressed(MouseEvent e) { - - } - - @Override - public void mouseReleased(MouseEvent e) { - - } } /** diff --git a/designer-base/src/main/java/com/fr/design/gui/icombobox/UIComboBox.java b/designer-base/src/main/java/com/fr/design/gui/icombobox/UIComboBox.java index e7f6578dc9..62ac619181 100644 --- a/designer-base/src/main/java/com/fr/design/gui/icombobox/UIComboBox.java +++ b/designer-base/src/main/java/com/fr/design/gui/icombobox/UIComboBox.java @@ -1,13 +1,16 @@ package com.fr.design.gui.icombobox; +import com.fine.theme.light.ui.FineComboBoxUI; import com.fr.design.event.GlobalNameListener; import com.fr.design.event.GlobalNameObserver; import com.fr.design.event.UIObserver; import com.fr.design.event.UIObserverListener; +import com.fr.design.event.HoverAware; import javax.swing.ComboBoxModel; import javax.swing.JComboBox; import javax.swing.ListCellRenderer; +import javax.swing.UIManager; import javax.swing.plaf.ComboBoxUI; import javax.swing.plaf.basic.ComboPopup; import java.awt.Dimension; @@ -15,6 +18,8 @@ import java.awt.event.FocusAdapter; import java.awt.event.FocusEvent; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; import java.util.List; import java.util.Vector; @@ -28,16 +33,13 @@ import java.util.Vector; * @author zhou * @since 2012-5-9下午3:18:58 */ -public class UIComboBox extends JComboBox implements UIObserver, GlobalNameObserver { +public class UIComboBox extends JComboBox implements UIObserver, GlobalNameObserver, HoverAware { - /** - * - */ private static final long serialVersionUID = 1L; - private static final int SIZE = 20; + private static final int SIZE = UIManager.getInt("ComboBox.comboHeight"); - private static final int SIZE5 = 5; + private static final int RENDER_FIX_SIZE = 5; protected UIObserverListener uiObserverListener; @@ -45,6 +47,8 @@ public class UIComboBox extends JComboBox implements UIObserver, GlobalNameObser private GlobalNameListener globalNameListener = null; + private boolean hovered; + public UIComboBox() { super(); init(); @@ -67,7 +71,6 @@ public class UIComboBox extends JComboBox implements UIObserver, GlobalNameObser private void init() { setOpaque(false); -// setUI(getUIComboBoxUI()); setRenderer(new UIComboBoxRenderer()); setEditor(new UIComboBoxEditor()); initListener(); @@ -93,6 +96,18 @@ public class UIComboBox extends JComboBox implements UIObserver, GlobalNameObser } } }); + this.addMouseListener(new MouseAdapter() { + @Override + public void mouseEntered(MouseEvent e) { + hovered = true; + repaint(); + } + @Override + public void mouseExited(MouseEvent e) { + hovered = false; + repaint(); + } + }); } } @@ -104,7 +119,7 @@ public class UIComboBox extends JComboBox implements UIObserver, GlobalNameObser protected ComboBoxUI getUIComboBoxUI() { - return new UIComboBoxUI(); + return new FineComboBoxUI(); } /** @@ -129,7 +144,7 @@ public class UIComboBox extends JComboBox implements UIObserver, GlobalNameObser @Override public Dimension getPreferredSize() { //加5的原因在于:render里,每一个项前面了空了一格,要多几像素 - return new Dimension(super.getPreferredSize().width + SIZE5, SIZE); + return new Dimension(super.getPreferredSize().width + RENDER_FIX_SIZE, SIZE); } public void refreshBoxItems(List list) { @@ -161,15 +176,6 @@ public class UIComboBox extends JComboBox implements UIObserver, GlobalNameObser } -// /** -// * -// */ -// @Override -// public void updateUI() { -// setUI(getUIComboBoxUI()); -// } - - /** * @param listener 观察者监听事件 */ @@ -210,5 +216,8 @@ public class UIComboBox extends JComboBox implements UIObserver, GlobalNameObser return true; } - + @Override + public boolean isHovered() { + return hovered; + } } \ No newline at end of file diff --git a/designer-base/src/main/resources/com/fine/theme/icon/down_arrow.svg b/designer-base/src/main/resources/com/fine/theme/icon/down_arrow.svg new file mode 100644 index 0000000000..1b2194ef08 --- /dev/null +++ b/designer-base/src/main/resources/com/fine/theme/icon/down_arrow.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/designer-base/src/main/resources/com/fine/theme/icon/down_arrow_disable.svg b/designer-base/src/main/resources/com/fine/theme/icon/down_arrow_disable.svg new file mode 100644 index 0000000000..65d7345b73 --- /dev/null +++ b/designer-base/src/main/resources/com/fine/theme/icon/down_arrow_disable.svg @@ -0,0 +1,5 @@ + + + + + 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 64685e8553..a81e07fbad 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 @@ -47,7 +47,7 @@ ButtonUI = com.formdev.flatlaf.ui.FlatButtonUI CheckBoxUI = com.formdev.flatlaf.ui.FlatCheckBoxUI CheckBoxMenuItemUI = com.formdev.flatlaf.ui.FlatCheckBoxMenuItemUI ColorChooserUI = com.formdev.flatlaf.ui.FlatColorChooserUI -ComboBoxUI = com.formdev.flatlaf.ui.FlatComboBoxUI +ComboBoxUI = com.fine.theme.light.ui.FineComboBoxUI DesktopIconUI = com.formdev.flatlaf.ui.FlatDesktopIconUI DesktopPaneUI = com.formdev.flatlaf.ui.FlatDesktopPaneUI EditorPaneUI = com.formdev.flatlaf.ui.FlatEditorPaneUI @@ -161,6 +161,10 @@ controlHighlight = lighten($controlShadow,12%) controlLtHighlight = lighten($controlShadow,25%) controlDkShadow = darken($controlShadow,15%) DarkenedFontColor = #091E40 +defaultBorderColor = #DADEE7 +defaultHighlightBorderColor = #2576EF +defaultBorderFocusShadow = #2576ef19 +defaultBorderFocusWidth = 1 #---- Button ---- @@ -277,7 +281,7 @@ ColorChooser.swatchesDefaultRecentColor = $control #---- ComboBox ---- -ComboBox.border = com.formdev.flatlaf.ui.FlatRoundBorder +ComboBox.border = com.fine.theme.light.ui.FineRoundBorder ComboBox.padding = @componentMargin ComboBox.minimumWidth = 72 ComboBox.editorColumns = 0 @@ -285,21 +289,21 @@ ComboBox.maximumRowCount = 15 [mac]ComboBox.showPopupOnNavigation = true # allowed values: auto, button or none ComboBox.buttonStyle = auto -ComboBox.background = @componentBackground +ComboBox.background = #FFF ComboBox.buttonBackground = $ComboBox.background ComboBox.buttonEditableBackground = darken($ComboBox.background,2%) -ComboBox.buttonSeparatorColor = $Component.borderColor +ComboBox.buttonSeparatorColor = $ComboBox.background ComboBox.buttonDisabledSeparatorColor = $Component.disabledBorderColor -ComboBox.buttonArrowColor = @buttonArrowColor +ComboBox.buttonArrowColor = #0A1C38 ComboBox.buttonDisabledArrowColor = @buttonDisabledArrowColor -ComboBox.buttonHoverArrowColor = @buttonHoverArrowColor -ComboBox.buttonPressedArrowColor = @buttonPressedArrowColor +ComboBox.buttonHoverArrowColor = #0A1C38 +ComboBox.buttonPressedArrowColor = #0A1C38 ComboBox.popupInsets = 0,0,0,0 ComboBox.selectionInsets = 0,0,0,0 ComboBox.selectionArc = 0 -ComboBox.borderCornerRadius = $Popup.borderCornerRadius - +ComboBox.borderCornerRadius = 3 +ComboBox.comboHeight = 24 #---- Component ---- @@ -1061,7 +1065,7 @@ Tree.icon.openColor = @icon Tree.hash = darken($Tree.background,10%) #---- West ---- -West.border = #DADEE7 +West.border = $defaultBorderColor #---- ExpandablePane ---- ExpandablePane.HeaderPane.borderInsets=0, 6, 0, 6 ExpandablePane.HeaderPane.hGap=2 @@ -1070,7 +1074,7 @@ HeaderPane.width=248 HeaderPane.height=24 #---- East ---- -East.border = #DADEE7 +East.border = $defaultBorderColor East.TabSelectedColor = #B3CFF9 #---- South ---- @@ -1086,7 +1090,7 @@ South.SheetSelectedColor = #FFF North.userinfoLabel.borderMargins=2, 16, 2, 16 North.userinfoLabel.width=80 North.userinfoLabel.height=24 -North.border = #DADEE7 +North.border = $defaultBorderColor North.coverPane.background = #0a1c38 North.coverPane.radius = 8