Browse Source

REPORT-99485 模版tab下拉框绘制

newui
vito 10 months ago
parent
commit
4eef4fdf23
  1. 52
      designer-base/src/main/java/com/fine/theme/light/ui/FineTemplateListMenuItemUI.java
  2. 248
      designer-base/src/main/java/com/fr/design/file/MultiTemplateTabMenuFactory.java
  3. 10
      designer-base/src/main/java/com/fr/design/file/MultiTemplateTabPane.java
  4. 153
      designer-base/src/main/java/com/fr/design/file/TemplateListMenuItem.java
  5. 33
      designer-base/src/main/java/com/fr/design/gui/imenu/UIScrollPopUpMenu.java
  6. 1
      designer-base/src/main/resources/com/fine/theme/light/ui/laf/FineLaf.properties

52
designer-base/src/main/java/com/fine/theme/light/ui/FineTemplateListMenuItemUI.java

@ -0,0 +1,52 @@
package com.fine.theme.light.ui;
import com.formdev.flatlaf.ui.FlatUIUtils;
import javax.swing.JComponent;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.PanelUI;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Insets;
import java.awt.geom.RoundRectangle2D;
/**
* 模版列表菜单ui
*
* @author vito
* @since 11.0
* Created on 2024/1/11
*/
public class FineTemplateListMenuItemUI extends PanelUI {
/**
* 创建UI
*
* @param c 组件
* @return ComponentUI
*/
public static ComponentUI createUI(JComponent c) {
return new FineTemplateListMenuItemUI();
}
@Override
public void update(Graphics g, JComponent c) {
Color color = g.getColor();
g.setColor(c.getBackground());
Insets insets = c.getInsets();
Object[] old = FlatUIUtils.setRenderingHints(g);
((Graphics2D) g).fill(new RoundRectangle2D.Float(
insets.left, insets.top,
(float) c.getWidth() - insets.left - insets.right,
(float) c.getHeight() - insets.top - insets.bottom,
3, 3));
g.setColor(color);
FlatUIUtils.resetRenderingHints(g, old);
super.paint(g, c);
}
@Override
public void uninstallUI(JComponent c) {
super.uninstallUI(c);
}
}

248
designer-base/src/main/java/com/fr/design/file/MultiTemplateTabMenuFactory.java

@ -1,42 +1,27 @@
package com.fr.design.file;
import com.fr.base.svg.IconUtils;
import com.fr.design.constants.UIConstants;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.imenu.UIMenuItem;
import com.fr.design.gui.imenu.UIScrollPopUpMenu;
import com.fr.design.i18n.Toolkit;
import com.fr.design.mainframe.JTemplate;
import com.fr.design.utils.TemplateUtils;
import com.fr.stable.StringUtils;
import com.fr.stable.collections.CollectionUtils;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* 右侧下拉菜单的工厂类
*
* @author Carlson
* @since 11.0
* created on 2023-04-14
**/
public class MultiTemplateTabMenuFactory {
private static final Icon CLOSE = IconUtils.readIcon("/com/fr/design/standard/close/close");
private static final Icon MOUSE_OVER_CLOSE = IconUtils.readIcon("/com/fr/design/standard/close/close_mouseover.svg");
private static final Icon MOUSE_PRESS_CLOSE = IconUtils.readIcon("/com/fr/design/standard/close/close_press.svg");
private static final int ITEM_SIZE = 25;
@ -50,6 +35,7 @@ public class MultiTemplateTabMenuFactory {
/**
* 返回右侧下拉菜单的工厂类
*
* @return
*/
public static MultiTemplateTabMenuFactory getInstance() {
@ -61,29 +47,12 @@ public class MultiTemplateTabMenuFactory {
*/
public UIScrollPopUpMenu createMenu() {
menu = new UIScrollPopUpMenu();
menu.setBorder(BorderFactory.createEmptyBorder(-3, 3, 3, 0));
menu.add(initCloseOther());
menu.add(createEmptyRow());
menu.addSeparator();
menu.add(createEmptyRow());
menu.add(createCategory(Toolkit.i18nText("Fine-Design_Basic_Tab_Current_Category_Templates")));
Component[] items = createCurrentCategory();
Component[] items = createCurrentTabs();
for (Component item : items) {
menu.add(item);
}
items = createOtherCategory();
if (items.length > 0) {
menu.addSeparator();
menu.add(createEmptyRow());
menu.add(createCategory(Toolkit.i18nText("Fine-Design_Basic_Tab_Other_Category_Templates")));
for (Component item : items) {
menu.add(item);
}
}
Dimension dimension = menu.getPreferredSize();
dimension.width += ITEM_SIZE;
menu.setPreferredSize(dimension);
return menu;
}
@ -91,18 +60,10 @@ public class MultiTemplateTabMenuFactory {
* 关闭其它按钮
*/
private UIMenuItem initCloseOther() {
UIMenuItem closeOther = new UIMenuItem(Toolkit.i18nText("Fine-Design_Basic_Tab_Close_Other_Templates_Of_Current_Category"));
UIMenuItem closeOther = new UIMenuItem(Toolkit.i18nText("Fine-Design_Close_Other_templates"));
closeOther.setHorizontalAlignment(SwingConstants.CENTER);
Dimension dimension = closeOther.getPreferredSize();
dimension.height = ITEM_SIZE;
closeOther.setPreferredSize(dimension);
String currentOperator = getCurrentTabOperatorType();
closeOther.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
MultiTemplateTabPane.getInstance().closeOtherByOperatorType(currentOperator);
}
});
closeOther.addActionListener(e -> MultiTemplateTabPane.getInstance().closeOtherByOperatorType(currentOperator));
if (MultiTemplateTabPane.getInstance().getOpenedJTemplatesByOperator(currentOperator).size() <= 1) {
closeOther.setEnabled(false);
}
@ -124,47 +85,18 @@ public class MultiTemplateTabMenuFactory {
};
}
/**
* 模板分类item
*/
private UIButton createCategory(String categoryName) {
UIButton button = new UIButton(categoryName);
button.setBorderPainted(false);
button.setExtraPainted(false);
button.setPreferredSize(new Dimension(menu.getWidth(), ITEM_SIZE));
button.setOpaque(true);
button.setBackground(UIConstants.NORMAL_BACKGROUND);
button.setHorizontalAlignment(SwingConstants.LEFT);
button.setForeground(UIConstants.FLESH_BLUE);
return button;
}
/**
* 创建 当前分类模板 item数组
*/
private Component[] createCurrentCategory() {
return createListDownItem(MultiTemplateTabPane.getInstance().getOpenedJTemplatesByOperator(getCurrentTabOperatorType()));
private Component[] createCurrentTabs() {
return createListDownItem(MultiTemplateTabPane.getInstance().getOpenedJTemplates());
}
private String getCurrentTabOperatorType(){
JTemplate jTemplate= HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
private String getCurrentTabOperatorType() {
JTemplate jTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
return jTemplate.getTemplateTabOperatorType();
}
/**
* 创建 其它分类模板 item数组
*/
private Component[] createOtherCategory() {
String currentOperator = getCurrentTabOperatorType();
List<JTemplate<?, ?>> openedTemplates = new ArrayList<>();
Map<String, List<JTemplate<?, ?>>> map = MultiTemplateTabPane.getInstance().getOpenedJTemplatesByCategory();
for (Map.Entry<String, List<JTemplate<?, ?>>> entry : map.entrySet()) {
if (!StringUtils.equals(currentOperator, entry.getKey())) {
openedTemplates.addAll(entry.getValue());
}
}
return createListDownItem(openedTemplates);
}
/**
* 根据template列表创建多个item
@ -184,166 +116,8 @@ public class MultiTemplateTabMenuFactory {
* 根据template对象创建item
*/
private Component createListDownMenuItem(JTemplate<?, ?> template) {
JPanel jPanel = new JPanel();
jPanel.setPreferredSize(new Dimension(menu.getWidth(), ITEM_SIZE));
jPanel.setLayout(new BorderLayout());
MenuItemButtonGroup menuItemButtonGroup = new MenuItemButtonGroup(template);
if (template == HistoryTemplateListCache.getInstance().getCurrentEditingTemplate()) {
menuItemButtonGroup.templateButton.setForeground(UIConstants.FLESH_BLUE);
}
jPanel.add(menuItemButtonGroup.iconButton, BorderLayout.WEST);
jPanel.add(menuItemButtonGroup.templateButton, BorderLayout.CENTER);
jPanel.add(menuItemButtonGroup.closeButton, BorderLayout.EAST);
return jPanel;
return new TemplateListMenuItem(menu, template);
}
/**
* menu的item由模板图标模板名模板关闭按钮组成
*/
private class MenuItemButtonGroup {
private final UIButton iconButton;
private final UIButton templateButton;
private final UIButton closeButton;
public MenuItemButtonGroup(JTemplate<?, ?> template) {
iconButton = createIconButton(template);
templateButton = createTemplateButton(template);
closeButton = createCloseButton();
initListener(template);
}
/**
* item[0] 模板图标按钮初始化
*/
private UIButton createIconButton(JTemplate<?, ?> template) {
UIButton button = new UIButton(template.getIcon(), template.getIcon(), template.getIcon());
button.setPreferredSize(new Dimension(ITEM_SIZE, ITEM_SIZE));
button.setOpaque(true);
button.setBackground(UIConstants.NORMAL_BACKGROUND);
return button;
}
/**
* item[1] 切换模板按钮初始化
*/
private UIButton createTemplateButton(JTemplate<?, ?> template) {
UIButton button = new UIButton(TemplateUtils.createLockeTemplatedName(template, template.getTemplateName()));
button.setBorderPainted(false);
button.setExtraPainted(false);
button.setPreferredSize(new Dimension(menu.getWidth() - ITEM_SIZE * 2, ITEM_SIZE));
button.setOpaque(true);
button.setBackground(UIConstants.NORMAL_BACKGROUND);
button.setHorizontalAlignment(SwingConstants.LEFT);
return button;
}
/**
* item[2] 关闭模板图标按钮初始化
*/
private UIButton createCloseButton() {
UIButton button = new UIButton(CLOSE, MOUSE_OVER_CLOSE, MOUSE_PRESS_CLOSE);
button.setPreferredSize(new Dimension(ITEM_SIZE, ITEM_SIZE));
button.setOpaque(true);
button.setBackground(UIConstants.NORMAL_BACKGROUND);
button.setVisible(false);
return button;
}
private void initListener(JTemplate<?, ?> template) {
initIconButtonListener();
initTemplateButtonListener(template);
initCloseButtonListener(template);
}
/**
* item[0] 模板图标按钮鼠标事件
*/
private void initIconButtonListener() {
iconButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
fireMouseEnteredEvent();
}
@Override
public void mouseExited(MouseEvent e) {
fireMouseExitedEvent();
}
});
}
/**
* item[1] 切换模板按钮鼠标事件
*/
private void initTemplateButtonListener(JTemplate<?, ?> template) {
templateButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
menu.setVisible(false);
MultiTemplateTabPane.getInstance().switchJTemplate(template);
}
@Override
public void mouseEntered(MouseEvent e) {
fireMouseEnteredEvent();
}
@Override
public void mouseExited(MouseEvent e) {
fireMouseExitedEvent();
}
});
}
/**
* item[2] 关闭模板按钮鼠标事件
*/
private void initCloseButtonListener(JTemplate<?, ?> template) {
closeButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
menu.setVisible(false);
MultiTemplateTabPane.getInstance().setIsCloseCurrent(template == HistoryTemplateListCache.getInstance().getCurrentEditingTemplate());
MultiTemplateTabPane.getInstance().closeFormat(template);
MultiTemplateTabPane.getInstance().closeSpecifiedTemplate(template);
}
@Override
public void mouseEntered(MouseEvent e) {
fireMouseEnteredEvent();
}
@Override
public void mouseExited(MouseEvent e) {
fireMouseExitedEvent();
}
});
}
/**
* mouse移入item范围
*/
private void fireMouseEnteredEvent() {
iconButton.setBackground(UIConstants.HOVER_BLUE);
templateButton.setBackground(UIConstants.HOVER_BLUE);
closeButton.setBackground(UIConstants.HOVER_BLUE);
closeButton.setVisible(true);
}
/**
* mouse移出item范围
*/
private void fireMouseExitedEvent() {
iconButton.setBackground(UIConstants.NORMAL_BACKGROUND);
templateButton.setBackground(UIConstants.NORMAL_BACKGROUND);
closeButton.setBackground(UIConstants.NORMAL_BACKGROUND);
closeButton.setVisible(false);
}
}
}

10
designer-base/src/main/java/com/fr/design/file/MultiTemplateTabPane.java

@ -48,6 +48,7 @@ import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@ -992,6 +993,15 @@ public class MultiTemplateTabPane extends Row {
.collect(Collectors.toList());
}
/**
* 获取所有模板
*
* @return 所有模板列表不可修改
*/
public List<JTemplate<?, ?>> getOpenedJTemplates() {
return Collections.unmodifiableList(openedTemplate);
}
/**
* 根据tab操作类型进行分类
*

153
designer-base/src/main/java/com/fr/design/file/TemplateListMenuItem.java

@ -0,0 +1,153 @@
package com.fr.design.file;
/**
* @author vito
* @since 11.0
* Created on 2024/1/11
*/
import com.fine.swing.ui.layout.Row;
import com.fine.theme.icon.LazyIcon;
import com.fine.theme.utils.FineUIScale;
import com.formdev.flatlaf.util.ScaledEmptyBorder;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.mainframe.JTemplate;
import com.fr.design.utils.TemplateUtils;
import javax.swing.JPopupMenu;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import java.awt.Dimension;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import static com.fine.swing.ui.layout.Layouts.cell;
/**
* menu的item由模板图标模板名模板关闭按钮组成
*
* @author vito
* @since 9.0
* Created on 2015.1
*/
public class TemplateListMenuItem extends Row {
private static final String UI_CLASS_ID = "TemplateListMenuItemUI";
private static final int WIDTH = 200;
private final UIButton templateButton;
private final UIButton closeButton;
private final JPopupMenu menu;
public TemplateListMenuItem(JPopupMenu menu, JTemplate<?, ?> template) {
this.menu = menu;
templateButton = createTemplateButton(template);
closeButton = createCloseButton();
add(
cell(templateButton).weight(1),
cell(closeButton)
);
setBorder(new ScaledEmptyBorder(0, 4, 0, 4));
setPreferredSize(new Dimension(FineUIScale.scale(WIDTH), templateButton.getPreferredSize().height));
initListener(template);
}
@Override
public String getUIClassID() {
return UI_CLASS_ID;
}
/**
* item[1] 切换模板按钮初始化
*/
private UIButton createTemplateButton(JTemplate<?, ?> template) {
UIButton button = new UIButton(
TemplateUtils.createLockeTemplatedName(template, template.getTemplateName()), template.getIcon());
button.setContentAreaFilled(false);
button.setHorizontalAlignment(SwingConstants.LEFT);
return button;
}
/**
* item[2] 关闭模板图标按钮初始化
*/
private UIButton createCloseButton() {
UIButton button = new UIButton(
new LazyIcon("clear"),
new LazyIcon("clear_hover"),
new LazyIcon("clear_hover"));
button.setContentAreaFilled(false);
button.setVisible(false);
return button;
}
private void initListener(JTemplate<?, ?> template) {
initTemplateButtonListener(template);
initCloseButtonListener(template);
}
/**
* item[1] 切换模板按钮鼠标事件
*/
private void initTemplateButtonListener(JTemplate<?, ?> template) {
templateButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
menu.setVisible(false);
MultiTemplateTabPane.getInstance().switchJTemplate(template);
}
@Override
public void mouseEntered(MouseEvent e) {
fireMouseEnteredEvent();
}
@Override
public void mouseExited(MouseEvent e) {
fireMouseExitedEvent();
}
});
}
/**
* item[2] 关闭模板按钮鼠标事件
*/
private void initCloseButtonListener(JTemplate<?, ?> template) {
closeButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
menu.setVisible(false);
MultiTemplateTabPane.getInstance().setIsCloseCurrent(template == HistoryTemplateListCache.getInstance().getCurrentEditingTemplate());
MultiTemplateTabPane.getInstance().closeFormat(template);
MultiTemplateTabPane.getInstance().closeSpecifiedTemplate(template);
}
@Override
public void mouseEntered(MouseEvent e) {
fireMouseEnteredEvent();
}
@Override
public void mouseExited(MouseEvent e) {
fireMouseExitedEvent();
}
});
}
/**
* mouse移入item范围
*/
private void fireMouseEnteredEvent() {
TemplateListMenuItem.this.setBackground(UIManager.getColor("MenuItem.selectionBackground"));
closeButton.setVisible(true);
}
/**
* mouse移出item范围
*/
private void fireMouseExitedEvent() {
TemplateListMenuItem.this.setBackground(TemplateListMenuItem.this.getParent().getBackground());
closeButton.setVisible(false);
}
}

33
designer-base/src/main/java/com/fr/design/gui/imenu/UIScrollPopUpMenu.java

@ -6,13 +6,11 @@ import com.fr.design.gui.iscrollbar.UIScrollBar;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.LayoutManager;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
/**
* Author : daisy
@ -21,7 +19,6 @@ import java.awt.event.MouseWheelListener;
*/
public class UIScrollPopUpMenu extends UIPopupMenu {
private static final int MAX_SHOW_NUM = 27;
private static final float REC = 8f;
private UIScrollBar scrollBar;
@ -30,31 +27,17 @@ public class UIScrollPopUpMenu extends UIPopupMenu {
setOpaque(false);
setLayout(new ScrollPopupMenuLayout());
super.add(getScrollBar());
addMouseWheelListener(new MouseWheelListener() {
public void mouseWheelMoved(MouseWheelEvent e) {
UIScrollBar scrollBar = getScrollBar();
int amount = (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL)
? e.getUnitsToScroll() * scrollBar.getUnitIncrement()
: (e.getWheelRotation() < 0 ? -1 : 1) * scrollBar.getBlockIncrement();
scrollBar.setValue(scrollBar.getValue() + amount);
e.consume();
}
addMouseWheelListener(e -> {
UIScrollBar scrollBar = getScrollBar();
int amount = (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL)
? e.getUnitsToScroll() * scrollBar.getUnitIncrement()
: (e.getWheelRotation() < 0 ? -1 : 1) * scrollBar.getBlockIncrement();
scrollBar.setValue(scrollBar.getValue() + amount);
e.consume();
});
}
public void paintChildren(Graphics g) {
// Graphics2D g2d = (Graphics2D) g;
// int rec = (int) REC;
// g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// g2d.setColor(UIConstants.NORMAL_BACKGROUND);
// g2d.fillRoundRect(1, 1, getWidth() - 2, getHeight() - 2, rec, rec);
// Insets insets = getInsets();
// g.clipRect(insets.left, insets.top, getWidth(), getHeight() - insets.top - insets.bottom);
super.paintChildren(g);
}
/**
* 展现 popupmenu
* @param invoker 组件

1
designer-base/src/main/resources/com/fine/theme/light/ui/laf/FineLaf.properties

@ -16,6 +16,7 @@ ListUI=com.formdev.flatlaf.ui.FlatListUI
MenuUI=com.formdev.flatlaf.ui.FlatMenuUI
MenuBarUI=com.formdev.flatlaf.ui.FlatMenuBarUI
MenuItemUI=com.fine.theme.light.ui.FineMenuItemUI
TemplateListMenuItemUI=com.fine.theme.light.ui.FineTemplateListMenuItemUI
OptionPaneUI=com.formdev.flatlaf.ui.FlatOptionPaneUI
PanelUI=com.formdev.flatlaf.ui.FlatPanelUI
PasswordFieldUI=com.formdev.flatlaf.ui.FlatPasswordFieldUI

Loading…
Cancel
Save