Browse Source

Pull request #13513: REPORT-99485 模版tab下拉框绘制&图标

Merge in DESIGN/design from ~VITO/c-design:newui to newui

* commit 'e971ae2e82928e801e061cb65a8e540f2cf6c798':
  REPORT-99485 图标去除阴影
  无jira任务 代码质量
  REPORT-99485 模版tab下拉框绘制
newui
vito-刘恒霖 11 months ago
parent
commit
c666c64eb9
  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. 147
      designer-base/src/main/java/com/fr/design/file/TemplateListMenuItem.java
  5. 19
      designer-base/src/main/java/com/fr/design/gui/imenu/UIScrollPopUpMenu.java
  6. 14
      designer-base/src/main/resources/com/fine/theme/icon/font/shadow.svg
  7. 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();
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")));
Component[] items = createCurrentTabs();
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;
}
/**
* 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);
return new TemplateListMenuItem(menu, 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操作类型进行分类
*

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

@ -0,0 +1,147 @@
package com.fr.design.file;
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);
}
}

19
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,8 +27,7 @@ public class UIScrollPopUpMenu extends UIPopupMenu {
setOpaque(false);
setLayout(new ScrollPopupMenuLayout());
super.add(getScrollBar());
addMouseWheelListener(new MouseWheelListener() {
public void mouseWheelMoved(MouseWheelEvent e) {
addMouseWheelListener(e -> {
UIScrollBar scrollBar = getScrollBar();
int amount = (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL)
? e.getUnitsToScroll() * scrollBar.getUnitIncrement()
@ -39,22 +35,9 @@ public class UIScrollPopUpMenu extends UIPopupMenu {
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 组件

14
designer-base/src/main/resources/com/fine/theme/icon/font/shadow.svg

@ -1,17 +1,5 @@
<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
<g filter="url(#filter0_d_5856_25936)">
<g>
<path fill-rule="evenodd" clip-rule="evenodd" d="M16.5 17.0102C15.5 17.0102 17.5 17.0102 16.5 17.0102C11 17.0102 6.5 14.5102 6.5 9.51019C6.5 5.36806 10.7533 2.01019 16 2.01019C20.5558 2.01019 24.3627 4.54197 25.2862 7.92058C25.4435 8.4959 24.9677 9.01019 24.3713 9.01019C23.8563 9.01019 23.434 8.61981 23.2633 8.13399C22.4302 5.76241 19.4941 4.01019 16 4.01019C11.8579 4.01019 8.5 6.47263 8.5 9.51019C8.50981 13.5102 13.5 15.0102 16.5 15.0102C23.4792 15.0102 25.5 18.5 25.5 22.5C25.5 26.5 21.2259 30 15.9792 30C11.4235 30 7.61674 27.4683 6.69307 24.0899C6.53578 23.5145 7.01157 23.0002 7.60801 23.0002C8.12293 23.0002 8.54528 23.3906 8.71597 23.8764C9.5492 26.2479 12.4852 28 15.9792 28C20.1214 28 23.4792 25.5376 23.4792 22.5C23.4792 19.4624 21.5 17.0102 16.5 17.0102Z" fill="#0A1C38" fill-opacity="0.9" shape-rendering="crispEdges"/>
</g>
<defs>
<filter id="filter0_d_5856_25936" x="5.5" y="2.01019" width="21" height="29.9898" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
<feFlood flood-opacity="0" result="BackgroundImageFix"/>
<feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0" result="hardAlpha"/>
<feOffset dy="1"/>
<feGaussianBlur stdDeviation="0.5"/>
<feComposite in2="hardAlpha" operator="out"/>
<feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.25 0"/>
<feBlend mode="normal" in2="BackgroundImageFix" result="effect1_dropShadow_5856_25936"/>
<feBlend mode="normal" in="SourceGraphic" in2="effect1_dropShadow_5856_25936" result="shape"/>
</filter>
</defs>
</svg>

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 948 B

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