From 5cc3e4ffacf4837cc473fac8f0cfae112319d4a8 Mon Sep 17 00:00:00 2001 From: renekton Date: Mon, 12 Aug 2024 19:03:54 +0800 Subject: [PATCH] =?UTF-8?q?popupMenuUI=E9=87=8D=E5=86=99=EF=BC=8C=E6=B2=A1?= =?UTF-8?q?icon=E5=8E=BB=E9=99=A4icon=E7=BB=98=E7=94=BB=EF=BC=9B=E6=82=AC?= =?UTF-8?q?=E6=B5=AE=E5=85=83=E7=B4=A0=E6=82=AC=E6=B5=AE=E8=89=B2/?= =?UTF-8?q?=E8=BE=B9=E6=A1=86=E5=A2=9E=E5=8A=A0=EF=BC=8C=E9=97=B4=E8=B7=9D?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=AD=89=EF=BC=9B=E8=8B=B1=E6=96=87=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E5=90=AF=E5=8A=A8=E5=A4=B1=E8=B4=A5=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/gui/frpane/FineBreadcrumbPane.java | 310 ------------------ .../theme/TemplateThemeGridPagesPane.java | 31 +- .../java/com/fr/file/FILEChooserPane.java | 15 +- 3 files changed, 19 insertions(+), 337 deletions(-) delete mode 100644 designer-base/src/main/java/com/fr/design/gui/frpane/FineBreadcrumbPane.java diff --git a/designer-base/src/main/java/com/fr/design/gui/frpane/FineBreadcrumbPane.java b/designer-base/src/main/java/com/fr/design/gui/frpane/FineBreadcrumbPane.java deleted file mode 100644 index f95a699510..0000000000 --- a/designer-base/src/main/java/com/fr/design/gui/frpane/FineBreadcrumbPane.java +++ /dev/null @@ -1,310 +0,0 @@ -package com.fr.design.gui.frpane; - -import com.fine.swing.ui.layout.Row; -import com.fine.theme.utils.FineUIScale; -import com.fine.theme.utils.FineUIStyle; -import com.fine.theme.utils.FineUIUtils; -import com.finebi.cbb.utils.StringUtils; -import com.fr.design.gui.ibutton.UIButton; -import com.fr.design.gui.ilable.UILabel; -import com.fr.file.FILE; -import com.fr.general.ComparatorUtils; - -import javax.swing.BorderFactory; -import java.awt.Component; -import java.awt.Dimension; -import java.awt.Insets; -import java.util.ArrayList; -import java.util.List; - -/** - * @author Renekton - * @since 2024/08/08 - * @param - */ -public class FineBreadcrumbPane extends Row { - - private static final int SEP_HEIGHT = 20; - - private static final int BUTTON_HEIGHT = 20; - - private static final int MAX_BUTTON_WIDTH = FineUIScale.scale(150); - - private static final String DEFAULT_SEP = "/"; - - private BreadcrumbButton currentCrumb; - - private List breadcrumbs; - - private int componentWidth; - - private int hidingIndex; - - private String sep; - - public FineBreadcrumbPane() { - this(DEFAULT_SEP); - } - - /** - * 可传入分隔符号 - */ - public FineBreadcrumbPane(String sep) { - this.sep = sep; - this.breadcrumbs = new ArrayList<>(); - this.componentWidth = 0; - this.hidingIndex = -1; - } - - /** - * 初始化节点 - * @param data 节点数据 - * @param backListener 节点点击关联动作 - */ - public void init(T data, final BreadcrumbBackListener backListener) { - if (currentCrumb != null) { - return; - } - if (data instanceof FILE) { - FILE file = (FILE) data; - List files = new ArrayList<>(); - while (file != null) { - - if (StringUtils.isEmpty(file.getName())) { - break; - } - if (file.isDirectory()) { - files.add(file); - } - file = file.getParent(); - } - int size = files.size(); - currentCrumb = new BreadcrumbButton<>(getRootdata((T) files.get(size-1)), files.get(size-1)); - add(currentCrumb); - currentCrumb.setSelected(true); - currentCrumb.setForeground(FineUIUtils.getUIColor("Button.breadcrumbSelectedForeground", "Button.breadcrumbSelectedForeground")); - final int index = getComponentCount(); - addBreadcrumbListener(currentCrumb, index, backListener); - for (int i = size-2; i >= 0; i--) { - addCrumb((T) files.get(i), backListener); - } - } else if (data instanceof String) { - currentCrumb = new BreadcrumbButton<>(getRootdata(data), data); - add(currentCrumb); - final int index = getComponentCount(); - addBreadcrumbListener(currentCrumb, index, backListener); - } - repaint(); - - } - - /** - * 根节点重置 - * @param data 节点内容 - * @param backListener - */ - public void reset(T data, final BreadcrumbBackListener backListener) { - if (currentCrumb != null && ComparatorUtils.equals(data, currentCrumb.getContent())) { - return; - } - clear(); - init(data, backListener); - - } - - /** - * 添加节点 - * @param data - * @param backListener - */ - public void addCrumb(final T data, final BreadcrumbBackListener backListener) { - - if (currentCrumb != null) { - currentCrumb.setSelected(false); - currentCrumb.setForeground(FineUIUtils.getUIColor("Button.breadcrumbForeground", "Button.breadcrumbForeground")); - add(createSeparator()); - } - final BreadcrumbButton breadcrumb = createBreadcrumb(data); - int currentWidth = componentWidth + breadcrumb.getPreferredSize().width; - if (this.getVisibleRect().width != 0 && currentWidth > this.getVisibleRect().width) { - // 大于可见宽度,隐藏前面的目录 - for (int i = hidingIndex+1; i < breadcrumbs.size(); i++) { - int width = breadcrumbs.get(i).getPreferredSize().width; - breadcrumbs.get(i).setVisible(false); - hidingIndex = i; - currentWidth -= width; - if (currentWidth < this.getVisibleRect().width) { - if (breadcrumbs.get(i+1) instanceof UILabel) { - breadcrumbs.get(i+1).setVisible(false); - hidingIndex = i+1; - componentWidth = currentWidth - breadcrumb.getPreferredSize().width - breadcrumbs.get(i+1).getPreferredSize().width; - } else { - componentWidth = currentWidth - breadcrumb.getPreferredSize().width; - } - break; - } - } - } - add(breadcrumb); - currentCrumb = breadcrumb; - final int index = getComponentCount(); - addBreadcrumbListener(breadcrumb, index, backListener); - } - - private void removeTailCrumbs(int from) { - Component[] components = getComponents(); - for (int i = from; i < components.length; i++) { - remove(components[i]); - } - currentCrumb = (BreadcrumbButton) components[from-1]; - revalidate(); - repaint(); - } - - @Override - public void remove(Component comp) { - componentWidth -= comp.getPreferredSize().getWidth(); - breadcrumbs.remove(comp); - super.remove(comp); - } - - @Override - public Component add(Component comp) { - componentWidth += comp.getPreferredSize().getWidth(); - breadcrumbs.add(comp); - return super.add(comp); - } - - public void clear() { - - removeAll(); - currentCrumb = null; - componentWidth = 0; - breadcrumbs.clear(); - } - - protected Component createSeparator() { - UILabel separator = new UILabel(sep); - separator.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 2)); - separator.setPreferredSize(new Dimension(separator.getPreferredSize().width, FineUIScale.scale(SEP_HEIGHT))); - - return separator; - } - - protected BreadcrumbButton createBreadcrumb(T content) { - BreadcrumbButton button = new BreadcrumbButton(getdata(content), content); - button.setPreferredSize(new Dimension(Math.min(button.getPreferredSize().width, MAX_BUTTON_WIDTH), FineUIScale.scale(BUTTON_HEIGHT))); - button.setSelected(true); - button.setForeground(FineUIUtils.getUIColor("Button.breadcrumbSelectedForeground", "Button.breadcrumbSelectedForeground")); - return button; - } - - /** - * 节点点击事件 - * @param breadcrumb - * @param index - * @param backListener - */ - private void addBreadcrumbListener(BreadcrumbButton breadcrumb, int index, BreadcrumbBackListener backListener) { - breadcrumb.addActionListener(e -> { - removeTailCrumbs(index); - // 存在隐藏目录,弹出部分隐藏目录 - if (hidingIndex >= 0) { - int currentWidth = componentWidth; - for (int i = hidingIndex; i >= 0; i--) { - currentWidth += breadcrumbs.get(i).getPreferredSize().width; - if (currentWidth <= this.getVisibleRect().width) { - breadcrumbs.get(i).setVisible(true); - } else { - hidingIndex = i; - if (breadcrumbs.get(i+1) instanceof UILabel) { - currentWidth -= breadcrumbs.get(i+1).getPreferredSize().width; - breadcrumbs.get(i+1).setVisible(false); - hidingIndex = i+1; - } - componentWidth = currentWidth - breadcrumbs.get(i).getPreferredSize().width; - break; - } - } - if (currentWidth <= this.getVisibleRect().width) { - hidingIndex = -1; - componentWidth = currentWidth; - } - } - - breadcrumb.setSelected(true); - breadcrumb.setForeground(FineUIUtils.getUIColor("Button.breadcrumbSelectedForeground", "Button.breadcrumbSelectedForeground")); - if (breadcrumb != currentCrumb) { - currentCrumb = breadcrumb; - } - if (backListener != null) { - backListener.onBreadcrumbBack(breadcrumb.getContent()); - } - }); - } - - private String getRootdata(T data) { - if (data instanceof String) { - return (String) data; - } else if (data instanceof FILE){ - FILE file = (FILE) data; - if (file.getPath().endsWith("/") || file.getPath().endsWith("\\")) { - return file.getPath().replaceAll("[/\\\\]+", ""); - } else if (file.getPath().contains("/") || file.getPath().contains("\\")) { - return file.getPath().replaceAll("[/\\\\]+", sep); - } - return ((FILE)data).getPath(); - } - return (String) data; - } - - private String getdata(T data) { - if (data instanceof String) { - return (String) data; - } else if (data instanceof FILE){ - return ((FILE)data).getName(); - } - return (String) data; - } - - public static class BreadcrumbButton extends UIButton { - - private T content; - - public BreadcrumbButton(String data, T content) { - super(data); - BreadcrumbButton.this.content = content; - setMargin(new Insets(0, 0, 0, 0)); - setBorder(BorderFactory.createEmptyBorder()); - FineUIStyle.setStyle(BreadcrumbButton.this, FineUIStyle.BREADCRUMB_BUTTON); - setBorderPainted(false); - setOpaque(false); - } - - @Override - public Insets getMargin() { - Insets insets = super.getMargin(); - if (insets != null) { - insets.set(0, 0, 0, 0); - } - return insets; - } - - protected T getContent() { - return content; - } - - protected void setContent(T content) { - this.content = content; - } - } - - /** - * 节点点击关联动作监听器 - * @param - */ - public interface BreadcrumbBackListener { - void onBreadcrumbBack(T data); - } - -} diff --git a/designer-base/src/main/java/com/fr/design/mainframe/theme/TemplateThemeGridPagesPane.java b/designer-base/src/main/java/com/fr/design/mainframe/theme/TemplateThemeGridPagesPane.java index ee2322e602..704f9c1a35 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/theme/TemplateThemeGridPagesPane.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/theme/TemplateThemeGridPagesPane.java @@ -1,6 +1,5 @@ package com.fr.design.mainframe.theme; -import com.fine.theme.utils.FineUIScale; import com.fr.base.ScreenResolution; import com.fr.base.theme.FormTheme; import com.fr.base.theme.FormThemeConfig; @@ -13,7 +12,6 @@ import com.fr.design.dialog.BasicPane; import com.fr.design.event.ChangeEvent; import com.fr.design.event.ChangeListener; import com.fr.design.file.HistoryTemplateListCache; -import com.fr.design.gui.frpane.FineBreadcrumbPane; import com.fr.design.gui.frpane.FineTabbedPane; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.i18n.Toolkit; @@ -22,8 +20,6 @@ import com.fr.design.mainframe.JTemplate; import com.fr.design.mainframe.theme.dialog.TemplateThemeDialog; import com.fr.design.mainframe.theme.provider.ThemeManageActionProvider; import com.fr.design.mainframe.theme.ui.BreadcrumbBar; -import com.fr.file.FILE; -import com.fr.general.ComparatorUtils; import com.fr.stable.ArrayUtils; import com.fr.stable.unit.FU; import com.fr.third.javax.annotation.Nullable; @@ -39,7 +35,6 @@ import java.awt.CardLayout; import java.awt.Color; import java.awt.Component; import java.awt.Container; -import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; @@ -58,7 +53,7 @@ import java.util.Set; */ public class TemplateThemeGridPagesPane extends JPanel { public static final String COMPLETE_BUTTON = "theme_button_complete"; - private FineBreadcrumbPane breadcrumbBar; + private BreadcrumbBar breadcrumbBar; private JPanel contentPane; private CardLayout cardLayout; @@ -80,8 +75,8 @@ public class TemplateThemeGridPagesPane extends JPanel { setLayout(new BorderLayout()); setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 10)); - breadcrumbBar = new FineBreadcrumbPane(); - breadcrumbBar.setPreferredSize(new Dimension(this.getPreferredSize().width, FineUIScale.scale(20))); + breadcrumbBar = new BreadcrumbBar(); + breadcrumbBar.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0)); add(breadcrumbBar, BorderLayout.NORTH); contentPane = new JPanel(); @@ -109,14 +104,16 @@ public class TemplateThemeGridPagesPane extends JPanel { pageChangeListener.onPageChangeListener(); } breadcrumbBar.clear(); - breadcrumbBar.addCrumb(themeUsingPane.getTitle(), - data -> { - cardLayout.show(contentPane, themeUsingPane.getTitle()); - currentTemplateThemeGridPagePane = themeUsingPane; - if (pageChangeListener != null) { - pageChangeListener.onPageChangeListener(); - } - }); + breadcrumbBar.addCrumb(themeUsingPane.getTitle(), new BreadcrumbBar.BreadcrumbBackListener() { + @Override + public void onBreadcrumbBack(String text) { + cardLayout.show(contentPane, themeUsingPane.getTitle()); + currentTemplateThemeGridPagePane = themeUsingPane; + if (pageChangeListener != null) { + pageChangeListener.onPageChangeListener(); + } + } + }); } } @@ -127,7 +124,7 @@ public class TemplateThemeGridPagesPane extends JPanel { if (pageChangeListener != null) { pageChangeListener.onPageChangeListener(); } - breadcrumbBar.addCrumb(themeManagingPane.getTitle(),null); + breadcrumbBar.addCrumb(themeManagingPane.getTitle(), null); } } diff --git a/designer-base/src/main/java/com/fr/file/FILEChooserPane.java b/designer-base/src/main/java/com/fr/file/FILEChooserPane.java index 0d35aa843d..5830f16d9a 100644 --- a/designer-base/src/main/java/com/fr/file/FILEChooserPane.java +++ b/designer-base/src/main/java/com/fr/file/FILEChooserPane.java @@ -18,7 +18,6 @@ import com.fr.design.env.DesignerWorkspaceType; import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.file.NodeAuthProcessor; import com.fr.design.fun.ReportSupportedFileUIProvider; -import com.fr.design.gui.frpane.FineBreadcrumbPane; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UIButtonUI; import com.fr.design.gui.icombobox.UIComboBox; @@ -155,7 +154,6 @@ public class FILEChooserPane extends BasicPane { private FILEFilter filter; private LocationButtonPane locationBtnPane; // 显示location的Panel - private FineBreadcrumbPane locationBreadcrumbPane; private UIButton mkdirButton; private JList placesList; // File.listRoots() + Env + Favourite @@ -307,7 +305,7 @@ public class FILEChooserPane extends BasicPane { JPanel locationPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); // locationPane.setLayout(FRGUIPaneFactory.createBorderLayout()); - locationPane.add(locationBreadcrumbPane = new FineBreadcrumbPane(), BorderLayout.CENTER); + locationPane.add(locationBtnPane = new LocationButtonPane(), BorderLayout.CENTER); mkdirButton = initMkdirButton(); locationPane.add(mkdirButton, BorderLayout.EAST); @@ -350,7 +348,6 @@ public class FILEChooserPane extends BasicPane { Object selValue = placesList.getSelectedValue(); if (selValue instanceof FILE) { setSelectedDirectory((FILE) selValue); - locationBreadcrumbPane.reset(selValue, data -> setSelectedDirectory((FILE) data)); } } }); @@ -363,7 +360,6 @@ public class FILEChooserPane extends BasicPane { Object selValue = placesList.getSelectedValue(); if (selValue instanceof FILE) { setSelectedDirectory((FILE) selValue); - locationBreadcrumbPane.reset(selValue, data -> setSelectedDirectory((FILE) data)); } } }); @@ -422,8 +418,6 @@ public class FILEChooserPane extends BasicPane { setFileTextField((FILE) selValue); fileNameTextField.addDocumentListener(); } else { - locationBreadcrumbPane.addCrumb(selValue, - data -> setSelectedDirectory((FILE) data)); setSelectedDirectory((FILE) selValue); if (!((FILE) selValue).isDirectory()) { doOK(); @@ -572,7 +566,7 @@ public class FILEChooserPane extends BasicPane { } private void doCancel() { - //this.locationBtnPane.setPopDir(null); + this.locationBtnPane.setPopDir(null); dialogExit(); } @@ -1102,7 +1096,7 @@ public class FILEChooserPane extends BasicPane { } private void setTopPath(String path) { - this.locationBreadcrumbPane.init(path, null); + this.locationBtnPane.setTopPath(path); } @@ -1156,7 +1150,6 @@ public class FILEChooserPane extends BasicPane { } setSelectedDirectory(dir); - locationBreadcrumbPane.reset(dir, text -> setSelectedDirectory((FILE) text)); } /* @@ -1168,6 +1161,8 @@ public class FILEChooserPane extends BasicPane { } currentDirectory = dir; + + this.locationBtnPane.populate(currentDirectory); this.mkdirButton.setEnabled(currentDirectory != null); refreshSubFileListModel();