diff --git a/designer-base/src/main/java/com/fine/theme/light/ui/FineTemplateTabPaneUI.java b/designer-base/src/main/java/com/fine/theme/light/ui/FineTemplateTabPaneUI.java index a1ecd9a5a8..f4dd3fbf7b 100644 --- a/designer-base/src/main/java/com/fine/theme/light/ui/FineTemplateTabPaneUI.java +++ b/designer-base/src/main/java/com/fine/theme/light/ui/FineTemplateTabPaneUI.java @@ -85,7 +85,6 @@ public class FineTemplateTabPaneUI extends PanelUI { private Icon closeHoverIcon; - private int leadingWidth; private int trailingWidth; protected FineTemplateTabPaneUI() { @@ -112,7 +111,6 @@ public class FineTemplateTabPaneUI extends PanelUI { moreAction = new LazyIcon("tool_more"); moreHoverAction = new LazyIcon("tool_more_hover"); fileIcon = new LazyIcon("cpt_icon"); - leadingWidth = scale(LEADING_WIDTH); trailingWidth = scale(TRAILING_WIDTH); borderWidth = FineUIUtils.getUIInt("TemplateTabPane.borderWidth", "TemplateTabPane.borderWidth"); @@ -138,7 +136,7 @@ public class FineTemplateTabPaneUI extends PanelUI { @Override public void update(Graphics g, JComponent c) { super.update(g, c); - double maxWidth = c.getWidth() - leadingWidth - trailingWidth; + double maxWidth = c.getWidth() - scale(LEADING_WIDTH) - trailingWidth; Graphics2D g2d = (Graphics2D) g; paintDefaultBackground(g2d); paintPaneUnderLine(c.getWidth(), g2d); @@ -170,7 +168,7 @@ public class FineTemplateTabPaneUI extends PanelUI { if (tabPane.getSelectedIndex() < 0) { tabPane.setSelectedIndex(0); } - double templateStartX = leadingWidth; + double templateStartX = scale(LEADING_WIDTH); //从可以开始展示在tab面板上的tab开始画 @@ -203,7 +201,7 @@ public class FineTemplateTabPaneUI extends PanelUI { private void paintSeparators(Graphics2D g2d) { g2d.setPaint(borderColor); - float x = leadingWidth; + float x = scale(LEADING_WIDTH); Pair viewRange = tabPane.getViewRange(); for (int i = viewRange.getFirst(); i <= viewRange.getSecond(); i++) { if (i != tabPane.getSelectedIndex() @@ -216,7 +214,7 @@ public class FineTemplateTabPaneUI extends PanelUI { private void paintTrailingAction(Graphics2D g2d, double tabPaneWidth) { - int x = leadingWidth + (int) tabPaneWidth + (trailingWidth - moreAction.getIconWidth()) / 2; + int x = scale(LEADING_WIDTH) + (int) tabPaneWidth + (trailingWidth - moreAction.getIconWidth()) / 2; int y = (tabHeight - moreAction.getIconHeight()) / 2; if (tabPane.isHoverMoreAction()) { moreHoverAction.paintIcon(tabPane, g2d, x, y); diff --git a/designer-base/src/main/java/com/fr/design/file/MultiTemplateTabPane.java b/designer-base/src/main/java/com/fr/design/file/MultiTemplateTabPane.java index e71cf8e22d..c463a8cc2c 100644 --- a/designer-base/src/main/java/com/fr/design/file/MultiTemplateTabPane.java +++ b/designer-base/src/main/java/com/fr/design/file/MultiTemplateTabPane.java @@ -4,7 +4,9 @@ package com.fr.design.file; import com.fine.swing.ui.layout.Layouts; import com.fine.swing.ui.layout.Row; import com.fine.theme.icon.LazyIcon; +import com.fine.theme.utils.FineUIScale; import com.fine.theme.utils.FineUIStyle; +import com.formdev.flatlaf.util.ScaledEmptyBorder; import com.fr.base.vcs.DesignerMode; import com.fr.design.actions.UpdateAction; import com.fr.design.actions.file.LocateAction; @@ -16,6 +18,7 @@ import com.fr.design.gui.imenu.UIScrollPopUpMenu; import com.fr.design.gui.itoolbar.UIToolbar; import com.fr.design.i18n.Toolkit; import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.DesignerFrame; import com.fr.design.mainframe.JTemplate; import com.fr.design.mainframe.manager.search.TemplateTreeSearchManager; import com.fr.design.mainframe.toolbar.ToolBarMenuDock; @@ -41,6 +44,7 @@ import javax.swing.ToolTipManager; import java.awt.AWTEvent; import java.awt.Color; import java.awt.Dimension; +import java.awt.FlowLayout; import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -81,8 +85,10 @@ public class MultiTemplateTabPane extends Row { /** * 前导动作区宽度 + * 最终宽度 = {@linkplain #SINGLE_BUTTON_WIDTH} * {@literal toolBar.getComponentCount()} */ - public static final int LEADING_WIDTH = 38; + public static int LEADING_WIDTH = 38; + public static int SINGLE_BUTTON_WIDTH = 38; //每个标签页的最大的长度和最小长度。这些长度均为均分 @@ -116,7 +122,7 @@ public class MultiTemplateTabPane extends Row { private Icon clodeIcon = new LazyIcon("clear"); private boolean isShowList = false; private JButton leadingActionButton; - public UIToolbar toolBar = ToolBarDef.createJToolBar(); + private final UIToolbar toolBar = new UIToolbar(); //自动新建的模板B若没有进行任何编辑,切换到其他 // @@ -179,18 +185,26 @@ public class MultiTemplateTabPane extends Row { } } }); - getToolBarMenuDock().createTemplateToolBarDef().updateToolBar(toolBar); - + ToolBarMenuDock toolBarMenuDock = getToolBarMenuDock(); + if (toolBarMenuDock != null) { + updateMultiTemplateToolBar(getToolBarMenuDock().createTemplateToolBarDef()); + } add( - Layouts.cell(toolBar).with(it -> { + Layouts.cell(getToolBar()).with(it -> { it.putClientProperty(BUTTON_TYPE, BUTTON_TYPE_TOOLBAR_BUTTON); + it.setOpaque(false); + it.setBorder(new ScaledEmptyBorder(3, -7, 3, -7)); FineUIStyle.setStyle(it, BUTTON_TAB_ACTION); }) ); } public ToolBarMenuDock getToolBarMenuDock() { - return DesignerContext.getDesignerFrame().getToolBarMenuDock(); + DesignerFrame designerFrame = DesignerContext.getDesignerFrame(); + if (designerFrame == null) { + return null; + } + return designerFrame.getToolBarMenuDock(); } /** @@ -970,4 +984,23 @@ public class MultiTemplateTabPane extends Row { public Pair getViewRange() { return new Pair<>(minPaintIndex, maxPaintIndex); } + + /** + * 获取多模板工具按钮 + * + * @return 工具按钮 + */ + public UIToolbar getToolBar() { + return this.toolBar; + } + + /** + * 生成多模板工具按钮 + * @param toolBarDef + */ + public void updateMultiTemplateToolBar(ToolBarDef toolBarDef) { + toolBarDef.updateToolBar(getToolBar()); + LEADING_WIDTH = getToolBar().getComponentCount() * SINGLE_BUTTON_WIDTH; + getToolBar().setLayout(new FlowLayout(FlowLayout.LEFT, FineUIScale.scale(14), 0)); + } } diff --git a/designer-base/src/test/java/com/fr/design/gui/storybook/components/TemplateTabStoryBoard.java b/designer-base/src/test/java/com/fr/design/gui/storybook/components/TemplateTabStoryBoard.java index 31e2406682..4985296af6 100644 --- a/designer-base/src/test/java/com/fr/design/gui/storybook/components/TemplateTabStoryBoard.java +++ b/designer-base/src/test/java/com/fr/design/gui/storybook/components/TemplateTabStoryBoard.java @@ -1,11 +1,20 @@ package com.fr.design.gui.storybook.components; +import com.fine.theme.icon.LazyIcon; +import com.fr.design.actions.UpdateAction; import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.file.MultiTemplateTabPane; import com.fr.design.gui.storybook.Story; import com.fr.design.gui.storybook.StoryBoard; +import com.fr.design.mainframe.DesignerContext; +import com.fr.design.mainframe.JWorkBook; +import com.fr.design.mainframe.toolbar.ToolBarMenuDock; +import com.fr.design.menu.ShortCut; import com.fr.value.NullableLazyValue; +import javax.swing.Icon; +import java.awt.event.ActionEvent; + /** * 新建模版Tab * @@ -29,7 +38,36 @@ public class TemplateTabStoryBoard extends StoryBoard { super("新建模版Tab"); init.getValue(); - add(MultiTemplateTabPane.getInstance()); + MultiTemplateTabPane multiTemplateTabPane = MultiTemplateTabPane.getInstance(); + multiTemplateTabPane.updateMultiTemplateToolBar(new ToolBarMenuDock() { + @Override + public ShortCut[] createNewFileShortCuts() { + return new ShortCut[0]; + } + + @Override + public ShortCut[] createNewTemplateShortCuts() { + return new ShortCut[]{new NewWorkBookToolBarAction()}; + } + }.createTemplateToolBarDef()); + multiTemplateTabPane.repaint(); + add(multiTemplateTabPane); + } + + public class NewWorkBookToolBarAction extends UpdateAction { + public NewWorkBookToolBarAction() { + this.setName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_M_New_WorkBook")); + this.setSmallIcon(icon()); + } + + protected Icon icon() { + return new LazyIcon("add_worksheet"); + } + + @Override + public void actionPerformed(ActionEvent e) { + DesignerContext.getDesignerFrame().addAndActivateJTemplate(new JWorkBook()); + } } diff --git a/designer-realize/src/main/java/com/fr/start/MainDesigner.java b/designer-realize/src/main/java/com/fr/start/MainDesigner.java index 0b9d487209..301da77587 100644 --- a/designer-realize/src/main/java/com/fr/start/MainDesigner.java +++ b/designer-realize/src/main/java/com/fr/start/MainDesigner.java @@ -1,6 +1,7 @@ package com.fr.start; +import com.fanruan.gui.UiInspector; import com.fine.theme.icon.LazyIcon; import com.fr.base.function.UITerminator; import com.fr.base.vcs.DesignerMode;