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 1/2] =?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() { From 824b8953a4d1fd508c7edde6cbc608955b823b69 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:04:02 +0800 Subject: [PATCH 2/2] =?UTF-8?q?REPORT-111995=20=E5=BC=B9=E5=87=BA=E9=9D=A2?= =?UTF-8?q?=E6=9D=BF=E9=80=82=E9=85=8DDPI=E7=BC=A9=E6=94=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/dialog/BasicDialog.java | 22 +++++++++++++++---- .../com/fr/design/formula/FormulaPane.java | 5 ++--- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/dialog/BasicDialog.java b/designer-base/src/main/java/com/fr/design/dialog/BasicDialog.java index 3b3b1d620f..8eb0594415 100644 --- a/designer-base/src/main/java/com/fr/design/dialog/BasicDialog.java +++ b/designer-base/src/main/java/com/fr/design/dialog/BasicDialog.java @@ -1,8 +1,11 @@ package com.fr.design.dialog; +import com.fine.theme.utils.FineUIScale; import com.fr.common.annotations.Open; -import java.awt.*; +import java.awt.Dialog; +import java.awt.Dimension; +import java.awt.Frame; @Open public abstract class BasicDialog extends UIDialog { @@ -12,7 +15,7 @@ public abstract class BasicDialog extends UIDialog { public static final Dimension LARGE = new Dimension(900, 600); public static final Dimension CHART = new Dimension(760, 560); public static final Dimension MAP_SIZE = new Dimension(760, 450); - public static final Dimension UPDATE_ONLINE_SIZE = new Dimension(600,300); + public static final Dimension UPDATE_ONLINE_SIZE = new Dimension(600, 300); public static final Dimension TOOLBAR_SIZE = new Dimension(660, 327); public BasicDialog(Frame parent) { @@ -40,12 +43,23 @@ public abstract class BasicDialog extends UIDialog { super(parent, pane, isNeedButtonPane); } + /** + * 设置对话框大小,方法内已进行dpi适配,传参无需考虑dpi适配 + * + * @param d 对话框尺寸 + */ protected void setBasicDialogSize(Dimension d) { - super.setSize(d.width, d.height); + super.setSize(FineUIScale.scale(d.width), FineUIScale.scale(d.height)); } + /** + * 设置对话框大小,方法内已进行dpi适配,传参无需考虑dpi适配 + * + * @param w 宽度 + * @param h 高度 + */ protected void setBasicDialogSize(int w, int h) { - super.setSize(w, h); + setBasicDialogSize(new Dimension(w, h)); } @Override diff --git a/designer-base/src/main/java/com/fr/design/formula/FormulaPane.java b/designer-base/src/main/java/com/fr/design/formula/FormulaPane.java index 35c5a2c68f..9caae7461a 100644 --- a/designer-base/src/main/java/com/fr/design/formula/FormulaPane.java +++ b/designer-base/src/main/java/com/fr/design/formula/FormulaPane.java @@ -41,7 +41,6 @@ import com.fr.design.gui.itextarea.UITextArea; import com.fr.design.gui.itextfield.UITextField; import com.fr.design.gui.syntax.ui.rsyntaxtextarea.RSyntaxTextArea; import com.fr.design.gui.syntax.ui.rsyntaxtextarea.SyntaxConstants; -import com.fr.design.i18n.DesignSizeI18nManager; import com.fr.design.i18n.Toolkit; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.mainframe.DesignerContext; @@ -749,8 +748,8 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula { } public BasicDialog showLargeWindow(Window window, DialogActionListener l) { - int width = FineUIScale.scale(900); - int height = FineUIScale.scale(600); + int width = 900; + int height = 900; BasicDialog basicDialog = super.showWindowWithCustomSize(window, l, new Dimension(width, height)); basicDialog.setMinimumSize(new Dimension(width, height)); basicDialog.setResizable(true);