From e9fb43562ced06314af62a4945ffe0ef7cfb8b7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Levy=2EXie-=E8=A7=A3=E5=AE=89=E6=A3=AE?= Date: Thu, 25 Jan 2024 20:02:38 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-111995=20=E6=8F=90=E4=BE=9B=E4=BB=85?= =?UTF-8?q?=E6=82=AC=E6=B5=AE=E6=97=B6=E6=98=BE=E7=A4=BA=E6=BB=9A=E5=8A=A8?= =?UTF-8?q?=E6=9D=A1=E7=9A=84=E6=BB=9A=E5=8A=A8=E9=9D=A2=E6=9D=BF=E7=BB=84?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../light/ui/CollapsibleScrollBarLayerUI.java | 73 +++++++++++++++++++ .../com/fine/theme/utils/FineUIUtils.java | 17 ++++- .../pane/TableDataSearchRemindPane.java | 32 ++++---- .../pane/TemplateSearchRemindPane.java | 29 ++++---- 4 files changed, 120 insertions(+), 31 deletions(-) create mode 100644 designer-base/src/main/java/com/fine/theme/light/ui/CollapsibleScrollBarLayerUI.java diff --git a/designer-base/src/main/java/com/fine/theme/light/ui/CollapsibleScrollBarLayerUI.java b/designer-base/src/main/java/com/fine/theme/light/ui/CollapsibleScrollBarLayerUI.java new file mode 100644 index 0000000000..86160ea975 --- /dev/null +++ b/designer-base/src/main/java/com/fine/theme/light/ui/CollapsibleScrollBarLayerUI.java @@ -0,0 +1,73 @@ +package com.fine.theme.light.ui; + +import com.fr.design.gui.icontainer.UIScrollPane; + +import javax.swing.JComponent; +import javax.swing.JLayer; +import javax.swing.JScrollPane; +import javax.swing.ScrollPaneConstants; +import javax.swing.plaf.LayerUI; +import java.awt.AWTEvent; +import java.awt.Component; +import java.awt.event.MouseEvent; + +/** + * 滚动面板的装饰层UI,支持滚动条仅当悬浮时显示 + * 使用见工具类: {@link com.fine.theme.utils.FineUIUtils#createCollapsibleScrollBarLayer(Component)} + * + * @author Levy.Xie + * @since 11.0 + * Created on 2024/01/25 + */ +public class CollapsibleScrollBarLayerUI extends LayerUI { + private final int verticalPolicy; + private final int horizontalPolicy; + + public CollapsibleScrollBarLayerUI() { + this(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); + } + + public CollapsibleScrollBarLayerUI(int verticalPolicy, int horizontalPolicy) { + this.verticalPolicy = verticalPolicy; + this.horizontalPolicy = horizontalPolicy; + } + + @Override + public void installUI(JComponent c) { + super.installUI(c); + if (c instanceof JLayer) { + ((JLayer) c).setLayerEventMask(AWTEvent.MOUSE_EVENT_MASK); + } + } + + @Override + public void uninstallUI(JComponent c) { + if (c instanceof JLayer) { + ((JLayer) c).setLayerEventMask(0); + } + super.uninstallUI(c); + } + + @Override + protected void processMouseEvent(MouseEvent e, JLayer l) { + JScrollPane view = l.getView(); + switch (e.getID()) { + case MouseEvent.MOUSE_ENTERED: + // 在鼠标进入时恢复滚动条显示策略 + if (view != null) { + view.setVerticalScrollBarPolicy(verticalPolicy); + view.setHorizontalScrollBarPolicy(horizontalPolicy); + } + break; + case MouseEvent.MOUSE_EXITED: + // 在鼠标退出时隐藏滚动条 + if (view != null) { + view.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER); + view.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + } + break; + default: + break; + } + } +} diff --git a/designer-base/src/main/java/com/fine/theme/utils/FineUIUtils.java b/designer-base/src/main/java/com/fine/theme/utils/FineUIUtils.java index 225fce4be5..46891db208 100644 --- a/designer-base/src/main/java/com/fine/theme/utils/FineUIUtils.java +++ b/designer-base/src/main/java/com/fine/theme/utils/FineUIUtils.java @@ -1,12 +1,16 @@ package com.fine.theme.utils; +import com.fine.theme.light.ui.CollapsibleScrollBarLayerUI; import com.formdev.flatlaf.ui.FlatUIUtils; import com.fr.design.border.FineBorderFactory; +import com.fr.design.gui.icontainer.UIScrollPane; import com.fr.stable.os.OperatingSystem; import com.fr.value.AtomicClearableLazyValue; -import javax.swing.UIManager; import javax.swing.JLabel; +import javax.swing.JLayer; +import javax.swing.ScrollPaneConstants; +import javax.swing.UIManager; import java.awt.Color; import java.awt.Component; import java.awt.Composite; @@ -376,4 +380,15 @@ public class FineUIUtils { FineUIStyle.setStyle(label, FineUIStyle.LABEL_BOLD); } + /** + * 创建一个UIScrollPane的装饰层,内部的ScrollPane仅当悬浮时显示滚动条 + * + * @param c 组件 + * @return UIScrollPane的装饰层 + */ + public static JLayer createCollapsibleScrollBarLayer(Component c) { + return new JLayer<>(new UIScrollPane(c, ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER), + new CollapsibleScrollBarLayerUI()); + } + } diff --git a/designer-base/src/main/java/com/fr/design/data/datapane/management/search/pane/TableDataSearchRemindPane.java b/designer-base/src/main/java/com/fr/design/data/datapane/management/search/pane/TableDataSearchRemindPane.java index bab21699cb..2b4778dae6 100644 --- a/designer-base/src/main/java/com/fr/design/data/datapane/management/search/pane/TableDataSearchRemindPane.java +++ b/designer-base/src/main/java/com/fr/design/data/datapane/management/search/pane/TableDataSearchRemindPane.java @@ -1,5 +1,7 @@ package com.fr.design.data.datapane.management.search.pane; +import com.fine.theme.utils.FineUIStyle; +import com.fine.theme.utils.FineUIUtils; import com.fr.base.svg.IconUtils; import com.fr.design.constants.UIConstants; import com.fr.design.data.datapane.TableDataTree; @@ -7,23 +9,24 @@ import com.fr.design.data.datapane.management.search.TableDataTreeSearchManager; import com.fr.design.gui.icontainer.UIScrollPane; import com.fr.design.gui.ilable.UILabel; import com.fr.design.i18n.Toolkit; -import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.search.TreeSearchStatus; import com.fr.design.search.event.TreeSearchStatusChangeEvent; import com.fr.design.search.event.TreeSearchStatusChangeListener; -import javax.swing.BorderFactory; +import javax.swing.JLayer; import javax.swing.JPanel; import javax.swing.SwingConstants; import java.awt.BorderLayout; import java.awt.CardLayout; -import java.awt.Color; -import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; +import static com.fine.swing.ui.layout.Layouts.cell; +import static com.fine.swing.ui.layout.Layouts.column; +import static com.fine.swing.ui.layout.Layouts.flex; + /** * @author Yvan */ @@ -81,7 +84,7 @@ public class TableDataSearchRemindPane extends JPanel implements TreeSearchStatu private class TreePane extends JPanel implements TreeSearchStatusChange { - private UIScrollPane scrollPane; + private JLayer scrollPane; private JPanel notFoundPane; @@ -97,21 +100,18 @@ public class TableDataSearchRemindPane extends JPanel implements TreeSearchStatu private void init(TableDataTree tableDataTree) { - scrollPane = new UIScrollPane(tableDataTree); - scrollPane.setBorder(null); + scrollPane = FineUIUtils.createCollapsibleScrollBarLayer(tableDataTree); - notFoundPane = FRGUIPaneFactory.createVerticalFlowLayout_Pane(true, FlowLayout.LEADING, 0, 5); UILabel emptyPicLabel = new UILabel(); emptyPicLabel.setIcon(IconUtils.readIcon("com/fr/base/images/share/no_match_icon.png")); emptyPicLabel.setHorizontalAlignment(SwingConstants.CENTER); - emptyPicLabel.setPreferredSize(new Dimension(240, 100)); - UILabel textLabel = new UILabel(Toolkit.i18nText("Fine-Design_Tree_Search_Not_Match"), SwingConstants.CENTER); -// textLabel.setForeground(Color.gray); + UILabel textLabel = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Tree_Search_Not_Match"), SwingConstants.CENTER); + FineUIStyle.setStyle(textLabel, FineUIStyle.LABEL_TIP); textLabel.setHorizontalAlignment(SwingConstants.CENTER); - textLabel.setPreferredSize(new Dimension(240, 20)); - notFoundPane.add(emptyPicLabel); - notFoundPane.add(textLabel); - notFoundPane.setBorder(BorderFactory.createEmptyBorder(80, 0, 0, 0)); + + notFoundPane = column(10, + flex(1), cell(emptyPicLabel), cell(textLabel), flex(1.5) + ).getComponent(); cardLayout = new CardLayout(); this.setLayout(cardLayout); @@ -168,7 +168,7 @@ public class TableDataSearchRemindPane extends JPanel implements TreeSearchStatu this.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 0)); // 初始情况下为Not_Begin textLabel = new UILabel(); - textLabel.setForeground(Color.gray); + FineUIStyle.setStyle(textLabel, FineUIStyle.LABEL_TIP); stopLabel = new UILabel(); stopLabel.setForeground(UIConstants.NORMAL_BLUE); stopSearch = new MouseAdapter() { diff --git a/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/pane/TemplateSearchRemindPane.java b/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/pane/TemplateSearchRemindPane.java index bdb6a32819..b23b3c073f 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/pane/TemplateSearchRemindPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/pane/TemplateSearchRemindPane.java @@ -1,5 +1,7 @@ package com.fr.design.mainframe.manager.search.searcher.control.pane; +import com.fine.theme.utils.FineUIStyle; +import com.fine.theme.utils.FineUIUtils; import com.fr.base.svg.IconUtils; import com.fr.design.constants.UIConstants; import com.fr.design.gui.itree.filetree.EnvFileTree; @@ -12,18 +14,20 @@ import com.fr.design.i18n.Toolkit; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.mainframe.manager.search.TemplateTreeSearchManager; -import javax.swing.BorderFactory; +import javax.swing.JLayer; import javax.swing.JPanel; import javax.swing.SwingConstants; import java.awt.BorderLayout; import java.awt.CardLayout; -import java.awt.Color; -import java.awt.Dimension; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.FlowLayout; +import static com.fine.swing.ui.layout.Layouts.cell; +import static com.fine.swing.ui.layout.Layouts.column; +import static com.fine.swing.ui.layout.Layouts.flex; + /** * 模板搜索提示面板:整合了模板树和提示面板 */ @@ -94,7 +98,7 @@ public class TemplateSearchRemindPane extends JPanel implements TreeSearchStatus private class TreePane extends JPanel implements TemplateSearchRemindPane.TreeSearchStatusChange { - private UIScrollPane scrollPane; + private JLayer scrollPane; private JPanel notFoundPane; @@ -110,21 +114,18 @@ public class TemplateSearchRemindPane extends JPanel implements TreeSearchStatus private void init(EnvFileTree templateFileTree) { - scrollPane = new UIScrollPane(templateFileTree); - scrollPane.setBorder(null); + scrollPane = FineUIUtils.createCollapsibleScrollBarLayer(templateFileTree); - notFoundPane = FRGUIPaneFactory.createVerticalFlowLayout_Pane(true, FlowLayout.LEADING, 0, 5); UILabel emptyPicLabel = new UILabel(); emptyPicLabel.setIcon(IconUtils.readIcon("com/fr/base/images/share/no_match_icon.png")); emptyPicLabel.setHorizontalAlignment(SwingConstants.CENTER); - emptyPicLabel.setPreferredSize(new Dimension(240, 100)); UILabel textLabel = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Tree_Search_Not_Match"), SwingConstants.CENTER); - textLabel.setForeground(Color.gray); + FineUIStyle.setStyle(textLabel, FineUIStyle.LABEL_TIP); textLabel.setHorizontalAlignment(SwingConstants.CENTER); - textLabel.setPreferredSize(new Dimension(240, 20)); - notFoundPane.add(emptyPicLabel); - notFoundPane.add(textLabel); - notFoundPane.setBorder(BorderFactory.createEmptyBorder(80, 0, 0, 0)); + + notFoundPane = column(10, + flex(1), cell(emptyPicLabel), cell(textLabel), flex(1.5) + ).getComponent(); cardLayout = new CardLayout(); this.setLayout(cardLayout); @@ -181,7 +182,7 @@ public class TemplateSearchRemindPane extends JPanel implements TreeSearchStatus this.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 0)); // 初始情况下为Not_Begin textLabel = new UILabel(); - textLabel.setForeground(Color.gray); + FineUIStyle.setStyle(textLabel, FineUIStyle.LABEL_TIP); stopLabel = new UILabel(); stopLabel.setForeground(UIConstants.NORMAL_BLUE); stopSearch = new MouseAdapter() {