Browse Source

popupMenuUI重写,没icon去除icon绘画;悬浮元素悬浮色/边框增加,间距调整等;英文版本启动失败修复

newui
renekton 3 months ago
parent
commit
5cc3e4ffac
  1. 310
      designer-base/src/main/java/com/fr/design/gui/frpane/FineBreadcrumbPane.java
  2. 19
      designer-base/src/main/java/com/fr/design/mainframe/theme/TemplateThemeGridPagesPane.java
  3. 15
      designer-base/src/main/java/com/fr/file/FILEChooserPane.java

310
designer-base/src/main/java/com/fr/design/gui/frpane/FineBreadcrumbPane.java

@ -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 <T>
*/
public class FineBreadcrumbPane <T> 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<Component> 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<T> backListener) {
if (currentCrumb != null) {
return;
}
if (data instanceof FILE) {
FILE file = (FILE) data;
List<FILE> 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<T> 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<T> 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 <T> 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 <T>
*/
public interface BreadcrumbBackListener <T> {
void onBreadcrumbBack(T data);
}
}

19
designer-base/src/main/java/com/fr/design/mainframe/theme/TemplateThemeGridPagesPane.java

@ -1,6 +1,5 @@
package com.fr.design.mainframe.theme; package com.fr.design.mainframe.theme;
import com.fine.theme.utils.FineUIScale;
import com.fr.base.ScreenResolution; import com.fr.base.ScreenResolution;
import com.fr.base.theme.FormTheme; import com.fr.base.theme.FormTheme;
import com.fr.base.theme.FormThemeConfig; 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.ChangeEvent;
import com.fr.design.event.ChangeListener; import com.fr.design.event.ChangeListener;
import com.fr.design.file.HistoryTemplateListCache; 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.frpane.FineTabbedPane;
import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.i18n.Toolkit; 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.dialog.TemplateThemeDialog;
import com.fr.design.mainframe.theme.provider.ThemeManageActionProvider; import com.fr.design.mainframe.theme.provider.ThemeManageActionProvider;
import com.fr.design.mainframe.theme.ui.BreadcrumbBar; 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.ArrayUtils;
import com.fr.stable.unit.FU; import com.fr.stable.unit.FU;
import com.fr.third.javax.annotation.Nullable; import com.fr.third.javax.annotation.Nullable;
@ -39,7 +35,6 @@ import java.awt.CardLayout;
import java.awt.Color; import java.awt.Color;
import java.awt.Component; import java.awt.Component;
import java.awt.Container; import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.RenderingHints; import java.awt.RenderingHints;
@ -58,7 +53,7 @@ import java.util.Set;
*/ */
public class TemplateThemeGridPagesPane extends JPanel { public class TemplateThemeGridPagesPane extends JPanel {
public static final String COMPLETE_BUTTON = "theme_button_complete"; public static final String COMPLETE_BUTTON = "theme_button_complete";
private FineBreadcrumbPane breadcrumbBar; private BreadcrumbBar breadcrumbBar;
private JPanel contentPane; private JPanel contentPane;
private CardLayout cardLayout; private CardLayout cardLayout;
@ -80,8 +75,8 @@ public class TemplateThemeGridPagesPane extends JPanel {
setLayout(new BorderLayout()); setLayout(new BorderLayout());
setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 10)); setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 10));
breadcrumbBar = new FineBreadcrumbPane(); breadcrumbBar = new BreadcrumbBar();
breadcrumbBar.setPreferredSize(new Dimension(this.getPreferredSize().width, FineUIScale.scale(20))); breadcrumbBar.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0));
add(breadcrumbBar, BorderLayout.NORTH); add(breadcrumbBar, BorderLayout.NORTH);
contentPane = new JPanel(); contentPane = new JPanel();
@ -109,13 +104,15 @@ public class TemplateThemeGridPagesPane extends JPanel {
pageChangeListener.onPageChangeListener(); pageChangeListener.onPageChangeListener();
} }
breadcrumbBar.clear(); breadcrumbBar.clear();
breadcrumbBar.addCrumb(themeUsingPane.getTitle(), breadcrumbBar.addCrumb(themeUsingPane.getTitle(), new BreadcrumbBar.BreadcrumbBackListener() {
data -> { @Override
public void onBreadcrumbBack(String text) {
cardLayout.show(contentPane, themeUsingPane.getTitle()); cardLayout.show(contentPane, themeUsingPane.getTitle());
currentTemplateThemeGridPagePane = themeUsingPane; currentTemplateThemeGridPagePane = themeUsingPane;
if (pageChangeListener != null) { if (pageChangeListener != null) {
pageChangeListener.onPageChangeListener(); pageChangeListener.onPageChangeListener();
} }
}
}); });
} }
} }
@ -127,7 +124,7 @@ public class TemplateThemeGridPagesPane extends JPanel {
if (pageChangeListener != null) { if (pageChangeListener != null) {
pageChangeListener.onPageChangeListener(); pageChangeListener.onPageChangeListener();
} }
breadcrumbBar.addCrumb(themeManagingPane.getTitle(),null); breadcrumbBar.addCrumb(themeManagingPane.getTitle(), null);
} }
} }

15
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.HistoryTemplateListPane;
import com.fr.design.file.NodeAuthProcessor; import com.fr.design.file.NodeAuthProcessor;
import com.fr.design.fun.ReportSupportedFileUIProvider; 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.UIButton;
import com.fr.design.gui.ibutton.UIButtonUI; import com.fr.design.gui.ibutton.UIButtonUI;
import com.fr.design.gui.icombobox.UIComboBox; import com.fr.design.gui.icombobox.UIComboBox;
@ -155,7 +154,6 @@ public class FILEChooserPane extends BasicPane {
private FILEFilter filter; private FILEFilter filter;
private LocationButtonPane locationBtnPane; // 显示location的Panel private LocationButtonPane locationBtnPane; // 显示location的Panel
private FineBreadcrumbPane locationBreadcrumbPane;
private UIButton mkdirButton; private UIButton mkdirButton;
private JList placesList; // File.listRoots() + Env + Favourite private JList placesList; // File.listRoots() + Env + Favourite
@ -307,7 +305,7 @@ public class FILEChooserPane extends BasicPane {
JPanel locationPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); JPanel locationPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
// locationPane.setLayout(FRGUIPaneFactory.createBorderLayout()); // locationPane.setLayout(FRGUIPaneFactory.createBorderLayout());
locationPane.add(locationBreadcrumbPane = new FineBreadcrumbPane(), BorderLayout.CENTER); locationPane.add(locationBtnPane = new LocationButtonPane(), BorderLayout.CENTER);
mkdirButton = initMkdirButton(); mkdirButton = initMkdirButton();
locationPane.add(mkdirButton, BorderLayout.EAST); locationPane.add(mkdirButton, BorderLayout.EAST);
@ -350,7 +348,6 @@ public class FILEChooserPane extends BasicPane {
Object selValue = placesList.getSelectedValue(); Object selValue = placesList.getSelectedValue();
if (selValue instanceof FILE) { if (selValue instanceof FILE) {
setSelectedDirectory((FILE) selValue); setSelectedDirectory((FILE) selValue);
locationBreadcrumbPane.reset(selValue, data -> setSelectedDirectory((FILE) data));
} }
} }
}); });
@ -363,7 +360,6 @@ public class FILEChooserPane extends BasicPane {
Object selValue = placesList.getSelectedValue(); Object selValue = placesList.getSelectedValue();
if (selValue instanceof FILE) { if (selValue instanceof FILE) {
setSelectedDirectory((FILE) selValue); setSelectedDirectory((FILE) selValue);
locationBreadcrumbPane.reset(selValue, data -> setSelectedDirectory((FILE) data));
} }
} }
}); });
@ -422,8 +418,6 @@ public class FILEChooserPane extends BasicPane {
setFileTextField((FILE) selValue); setFileTextField((FILE) selValue);
fileNameTextField.addDocumentListener(); fileNameTextField.addDocumentListener();
} else { } else {
locationBreadcrumbPane.addCrumb(selValue,
data -> setSelectedDirectory((FILE) data));
setSelectedDirectory((FILE) selValue); setSelectedDirectory((FILE) selValue);
if (!((FILE) selValue).isDirectory()) { if (!((FILE) selValue).isDirectory()) {
doOK(); doOK();
@ -572,7 +566,7 @@ public class FILEChooserPane extends BasicPane {
} }
private void doCancel() { private void doCancel() {
//this.locationBtnPane.setPopDir(null); this.locationBtnPane.setPopDir(null);
dialogExit(); dialogExit();
} }
@ -1102,7 +1096,7 @@ public class FILEChooserPane extends BasicPane {
} }
private void setTopPath(String path) { 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); setSelectedDirectory(dir);
locationBreadcrumbPane.reset(dir, text -> setSelectedDirectory((FILE) text));
} }
/* /*
@ -1168,6 +1161,8 @@ public class FILEChooserPane extends BasicPane {
} }
currentDirectory = dir; currentDirectory = dir;
this.locationBtnPane.populate(currentDirectory);
this.mkdirButton.setEnabled(currentDirectory != null); this.mkdirButton.setEnabled(currentDirectory != null);
refreshSubFileListModel(); refreshSubFileListModel();

Loading…
Cancel
Save