package com.fr.design.mainframe; import com.fine.theme.utils.FineUIUtils; import com.formdev.flatlaf.ui.FlatUIUtils; import com.formdev.flatlaf.util.ScaledEmptyBorder; import com.fr.design.DesignState; import com.fr.design.base.mode.DesignModeContext; import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.file.MultiTemplateTabPane; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UICombinationButton; import com.fr.design.gui.itoolbar.UIToolbar; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.mainframe.toolbar.ToolBarMenuDock; import com.fr.design.mainframe.toolbar.ToolBarMenuDockPlus; import org.jetbrains.annotations.Nullable; import javax.swing.JComponent; import javax.swing.JPanel; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java.awt.FlowLayout; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import static com.fine.theme.utils.FineUIScale.scale; import static com.fine.theme.utils.FineUIStyle.NORMAL_COLOR; import static com.fine.theme.utils.FineUIStyle.TOP_TOOLS; import static com.fine.theme.utils.FineUIStyle.setStyle; /** * @author shine * @version 10.0 * Created by shine on 2021/4/6 */ public class CenterRegionContainerPane extends JPanel { private static volatile CenterRegionContainerPane THIS; private static final int LEFT_ALIGN_GAP = -5; private DesktopCardPane centerTemplateCardPane; private JPanel toolbarPane;//撤销重做 等工具栏 + 模板tab标签 + maybe have cpt 字体 private JComponent toolbarComponent;//cpt 字体 等工具栏 private JPanel eastPane;//=largeToolbar+eastCenterPane private UICombinationButton largeToolbar;//预览 private JPanel eastCenterPane;//=combineUp + templateTabPane private UIToolbar combineUp;//撤销重做 等工具栏 private MultiTemplateTabPane templateTabPane;//新建模板 + 模板tab标签 public static CenterRegionContainerPane getInstance() { if (THIS == null) { synchronized (CenterRegionContainerPane.class) { if (THIS == null) { THIS = new CenterRegionContainerPane(); } } } return THIS; } public CenterRegionContainerPane() { toolbarPane = new JPanel(); toolbarPane.setBorder(new ScaledEmptyBorder(10, 0, 0, 0)); toolbarPane.setLayout(FRGUIPaneFactory.createBorderLayout()); eastPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); largeToolbar = getToolBarMenuDock().createLargeToolbar(); eastCenterPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); combineUpTooBar(); templateTabPane = initTemplateTabPane(); eastCenterPane.add(templateTabPane, BorderLayout.NORTH); eastCenterPane.add(combineUp, BorderLayout.CENTER); eastPane.add(eastCenterPane, BorderLayout.CENTER); toolbarPane.add(eastPane, BorderLayout.NORTH); Color tabPaneColor = FineUIUtils.getUIColor("TemplateTabPane.background", "fill.gray"); toolbarPane.setBackground(tabPaneColor); eastCenterPane.setBackground(tabPaneColor); this.setLayout(new BorderLayout()); this.add(centerTemplateCardPane = new DesktopCardPane(), BorderLayout.CENTER); centerTemplateCardPane.setBorder(new ScaledEmptyBorder(10, 10, 10, 10)); this.add(toolbarPane, BorderLayout.NORTH); setStyle(this, NORMAL_COLOR); } private MultiTemplateTabPane initTemplateTabPane() { MultiTemplateTabPane templateTabPane = MultiTemplateTabPane.getInstance(); return templateTabPane; } public ToolBarMenuDock getToolBarMenuDock() { return DesignerContext.getDesignerFrame().getToolBarMenuDock(); } /** * 创建上工具栏 */ private void combineUpTooBar() { combineUp = new UIToolbar(FlowLayout.LEFT); setStyle(combineUp, TOP_TOOLS); combineUp.setBorder(new ScaledEmptyBorder(10, 5, 10, 10)); combineUp.setLayout(new FlowLayout(FlowLayout.LEFT, scale(5), 0)); setUpUpToolBar(null); } /** * 重置上工具栏 */ private void resetCombineUpTooBar(JComponent[] toolbar4Form, ToolBarMenuDockPlus plus) { combineUp.removeAll(); setUpUpToolBar(toolbar4Form); plus.insertToCombineUpToolbar(combineUp); } /** * 重置多工作簿面板 */ private void resetMultiTemplateTablePane() { MultiTemplateTabPane.getInstance().resetMultiTemplateTabPane(); } /** * 填充上工具栏的中的工具 * * @param toolbar4Form 目标组件 */ private void setUpUpToolBar(@Nullable JComponent[] toolbar4Form) { combineUp.add(largeToolbar); UIButton[] fixButtons = getToolBarMenuDock().createUp(); for (UIButton fixButton : fixButtons) { combineUp.add(fixButton); } if (!DesignModeContext.isAuthorityEditing()) { combineUp.addSeparator(new Dimension(2, 16)); if (toolbar4Form != null) { for (JComponent jComponent : toolbar4Form) { combineUp.add(jComponent); } } //添加检测按钮 addCheckButton(); } //添加分享按钮 addShareButton(); //添加插件中的按钮 addExtraButtons(); } private void addExtraButtons() { JTemplate jt = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); if (!JTemplate.isValid(jt)) { return; } UIButton[] extraButtons = jt.createExtraButtons(); for (UIButton extraButton : extraButtons) { combineUp.add(extraButton); } if (extraButtons.length > 0) { combineUp.addSeparator(new Dimension(2, 16)); } } private void addCheckButton() { JTemplate jt = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); if (!JTemplate.isValid(jt)) { return; } combineUp.addSeparator(new Dimension(2, 16)); UIButton[] checkButtons = jt.createCheckButton(); for (UIButton checkButton : checkButtons) { combineUp.add(checkButton); } } private void addShareButton() { JTemplate jt = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); if (!JTemplate.isValid(jt)) { return; } combineUp.addSeparator(new Dimension(2, 16)); UIButton[] shareButtons = jt.createShareButton(); for (UIButton shareButton : shareButtons) { combineUp.add(shareButton); } } /** * 检查 * * @param flag 组件是否可见 * @param al 组件名称 */ protected void checkCombineUp(boolean flag, ArrayList al) { //Yvan: 检查当前是否为WORK_SHEET状态,因为只有WORK_SHEET中含有格式刷组件,此时是不需要进行checkComponentsByNames的 JTemplate jTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); if (JTemplate.isValid(jTemplate)) { // 第一个条件满足后还需要添加一重判断,判断是编辑报表块还是参数面板,编辑报表块时则直接return if (jTemplate.getMenuState() == DesignState.WORK_SHEET && !jTemplate.isUpMode()) { return; } combineUp.checkComponentsByNames(flag, al); } } /** * 重置相关的工具条. * * @param plus 工具条中相关信息 */ protected void resetToolkitByPlus(ToolBarMenuDockPlus plus, ToolBarMenuDock ad, ToolKitConfigStrategy strategy) { resetMultiTemplateTablePane(); resetCombineUpTooBar(ad.resetUpToolBar(plus), plus); if (toolbarComponent != null) { toolbarPane.remove(toolbarComponent); } // 颜色,字体那些按钮的工具栏 toolbarPane.add(toolbarComponent = ad.resetToolBar(toolbarComponent, plus), BorderLayout.CENTER); setStyle(toolbarComponent, TOP_TOOLS); toolbarComponent.setBackground(FlatUIUtils.getUIColor("background.normal", Color.WHITE)); toolbarComponent.setBorder(new ScaledEmptyBorder(0, 5, 0, 10)); JPanel customNorthPane = strategy.customNorthPane(toolbarPane, plus); if (!isExist(customNorthPane)) { this.removeNorth(); this.add(customNorthPane, BorderLayout.NORTH); } if (strategy.hasCombineUp(plus)) { eastCenterPane.add(combineUp, BorderLayout.CENTER); } else { eastCenterPane.remove(combineUp); } } private void removeNorth() { Component[] components = this.getComponents(); for (Component c : components) { if (c != centerTemplateCardPane) { this.remove(c); } } } private boolean isExist(JPanel customNorthPane) { Component[] components = this.getComponents(); for (Component component : components) { if (component == customNorthPane) { return true; } } return false; } JComponent getToolbarComponent() { return this.toolbarComponent; } /** * 判断是否在权限编辑状态,若是在权限编辑状态,则需要有虚线框和关闭突变 */ protected void needToAddAuhtorityPaint() { MultiTemplateTabPane.getInstance().setToolBarEnable(DesignModeContext.isAuthorityEditing()); } protected DesktopCardPane getCenterTemplateCardPane() { return centerTemplateCardPane; } public Map getToolbarComponentState() { Map toolbarComponentState = new HashMap<>(); if (toolbarComponent instanceof UIToolbar) { toolbarComponentState.putAll(((UIToolbar) toolbarComponent).getComponentState()); } toolbarComponentState.putAll(combineUp.getComponentState()); return toolbarComponentState; } /** * 重置下RegionContainerpane */ public void resetCenterRegionContainerPane() { } }