Browse Source

REPORT-111995 提供仅悬浮时显示滚动条的滚动面板组件

newui
Levy.Xie-解安森 10 months ago
parent
commit
e9fb43562c
  1. 73
      designer-base/src/main/java/com/fine/theme/light/ui/CollapsibleScrollBarLayerUI.java
  2. 17
      designer-base/src/main/java/com/fine/theme/utils/FineUIUtils.java
  3. 32
      designer-base/src/main/java/com/fr/design/data/datapane/management/search/pane/TableDataSearchRemindPane.java
  4. 29
      designer-base/src/main/java/com/fr/design/mainframe/manager/search/searcher/control/pane/TemplateSearchRemindPane.java

73
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<UIScrollPane> {
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<? extends UIScrollPane> 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;
}
}
}

17
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<UIScrollPane> createCollapsibleScrollBarLayer(Component c) {
return new JLayer<>(new UIScrollPane(c, ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER),
new CollapsibleScrollBarLayerUI());
}
}

32
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<UIScrollPane> 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() {

29
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<UIScrollPane> 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() {

Loading…
Cancel
Save