|
|
|
@ -8,20 +8,23 @@ 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.ExtraDesignClassManager; |
|
|
|
|
import com.fr.design.actions.UpdateAction; |
|
|
|
|
import com.fr.design.actions.file.LocateAction; |
|
|
|
|
import com.fr.design.actions.template.NewWorkBookToolButtonAction; |
|
|
|
|
import com.fr.design.constants.UIConstants; |
|
|
|
|
import com.fr.design.dialog.FineJOptionPane; |
|
|
|
|
import com.fr.design.fun.MenuHandler; |
|
|
|
|
import com.fr.design.fun.MultiTemplateTabPaneHandler; |
|
|
|
|
import com.fr.design.gui.imenu.UIMenuItem; |
|
|
|
|
import com.fr.design.gui.imenu.UIPopupMenu; |
|
|
|
|
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; |
|
|
|
|
import com.fr.design.menu.ShortCut; |
|
|
|
|
import com.fr.design.menu.ToolBarDef; |
|
|
|
|
import com.fr.design.utils.gui.GUICoreUtils; |
|
|
|
|
import com.fr.design.worker.WorkerManager; |
|
|
|
@ -51,8 +54,10 @@ import java.awt.event.ActionListener;
|
|
|
|
|
import java.awt.event.MouseAdapter; |
|
|
|
|
import java.awt.event.MouseEvent; |
|
|
|
|
import java.awt.event.MouseMotionAdapter; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Collections; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
|
|
import static com.fine.theme.utils.FineClientProperties.BUTTON_TYPE_TOOLBAR_BUTTON; |
|
|
|
|
import static com.fine.theme.utils.FineUIScale.scale; |
|
|
|
@ -87,7 +92,8 @@ public class MultiTemplateTabPane extends Row {
|
|
|
|
|
* 前导动作区宽度 |
|
|
|
|
* 最终宽度 = {@linkplain #SINGLE_BUTTON_WIDTH} * {@literal toolBar.getComponentCount()} |
|
|
|
|
*/ |
|
|
|
|
public static int LEADING_WIDTH = 38; |
|
|
|
|
public static int leadingWidth; |
|
|
|
|
// 每个按钮固定宽度大小
|
|
|
|
|
public static int SINGLE_BUTTON_WIDTH = 38; |
|
|
|
|
|
|
|
|
|
//每个标签页的最大的长度和最小长度。这些长度均为均分
|
|
|
|
@ -122,7 +128,7 @@ public class MultiTemplateTabPane extends Row {
|
|
|
|
|
private Icon clodeIcon = new LazyIcon("clear"); |
|
|
|
|
private boolean isShowList = false; |
|
|
|
|
private JButton leadingActionButton; |
|
|
|
|
private final UIToolbar toolBar = new UIToolbar(); |
|
|
|
|
private final UIToolbar leadingToolBar = new UIToolbar(); |
|
|
|
|
|
|
|
|
|
//自动新建的模板B若没有进行任何编辑,切换到其他
|
|
|
|
|
//
|
|
|
|
@ -185,12 +191,9 @@ public class MultiTemplateTabPane extends Row {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
ToolBarMenuDock toolBarMenuDock = getToolBarMenuDock(); |
|
|
|
|
if (toolBarMenuDock != null) { |
|
|
|
|
updateMultiTemplateToolBar(getToolBarMenuDock().createTemplateToolBarDef()); |
|
|
|
|
} |
|
|
|
|
preProcessMultiTemplateTabPane(); |
|
|
|
|
add( |
|
|
|
|
Layouts.cell(getToolBar()).with(it -> { |
|
|
|
|
Layouts.cell(getLeadingToolBar()).with(it -> { |
|
|
|
|
it.putClientProperty(BUTTON_TYPE, BUTTON_TYPE_TOOLBAR_BUTTON); |
|
|
|
|
it.setOpaque(false); |
|
|
|
|
it.setBorder(new ScaledEmptyBorder(3, -7, 3, -7)); |
|
|
|
@ -199,12 +202,8 @@ public class MultiTemplateTabPane extends Row {
|
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public ToolBarMenuDock getToolBarMenuDock() { |
|
|
|
|
DesignerFrame designerFrame = DesignerContext.getDesignerFrame(); |
|
|
|
|
if (designerFrame == null) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
return designerFrame.getToolBarMenuDock(); |
|
|
|
|
private void preProcessMultiTemplateTabPane() { |
|
|
|
|
updateLeadingToolBar(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -219,7 +218,7 @@ public class MultiTemplateTabPane extends Row {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void setToolBarEnable(boolean enable) { |
|
|
|
|
toolBar.setEnabled(enable); |
|
|
|
|
leadingToolBar.setEnabled(enable); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -505,7 +504,7 @@ public class MultiTemplateTabPane extends Row {
|
|
|
|
|
@Override |
|
|
|
|
public void paintComponent(Graphics g) { |
|
|
|
|
|
|
|
|
|
double maxWidth = getWidth() - scale(TRAILING_WIDTH) - scale(LEADING_WIDTH); //最大宽度
|
|
|
|
|
double maxWidth = getWidth() - scale(TRAILING_WIDTH) - scale(leadingWidth); //最大宽度
|
|
|
|
|
int maxTemplateNum = (int) (maxWidth) / scale(MINWIDTH); |
|
|
|
|
calMinAndMaxIndex(maxTemplateNum); |
|
|
|
|
calculateRealAverageWidth(maxWidth, maxTemplateNum); |
|
|
|
@ -515,7 +514,7 @@ public class MultiTemplateTabPane extends Row {
|
|
|
|
|
|
|
|
|
|
private void calculateClosePosition() { |
|
|
|
|
startX = new int[maxPaintIndex - minPaintIndex + 1]; |
|
|
|
|
double templateStartX = scale(LEADING_WIDTH); |
|
|
|
|
double templateStartX = scale(leadingWidth); |
|
|
|
|
for (int i = getViewRange().getFirst(); i <= getViewRange().getSecond(); i++) { |
|
|
|
|
int closePosition = (int) templateStartX + getTabWidth() - clodeIcon.getIconWidth() - GAP; |
|
|
|
|
startX[i - minPaintIndex] = closePosition; |
|
|
|
@ -703,7 +702,7 @@ public class MultiTemplateTabPane extends Row {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean isOverListDown(int evtX) { |
|
|
|
|
int maxWidth = getWidth() - scale(LEADING_WIDTH); |
|
|
|
|
int maxWidth = getWidth() - scale(leadingWidth); |
|
|
|
|
return evtX >= (maxWidth + SMALLGAP) && evtX <= (getWidth() - SMALLGAP); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -715,13 +714,13 @@ public class MultiTemplateTabPane extends Row {
|
|
|
|
|
*/ |
|
|
|
|
private boolean isOverBlank(int evtX) { |
|
|
|
|
int tabWidths = (maxPaintIndex - minPaintIndex + 1) * tabWidth; |
|
|
|
|
int leftX = tabWidths + scale(LEADING_WIDTH); |
|
|
|
|
int leftX = tabWidths + scale(leadingWidth); |
|
|
|
|
return evtX >= leftX && evtX <= getWidth() - scale(TRAILING_WIDTH); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int getTemplateIndex(int evtX) { |
|
|
|
|
int textX = scale(LEADING_WIDTH); |
|
|
|
|
int textX = scale(leadingWidth); |
|
|
|
|
for (int i = minPaintIndex; i <= maxPaintIndex; i++) { |
|
|
|
|
int textWidth = tabWidth; |
|
|
|
|
if (evtX >= textX && evtX < textX + textWidth) { |
|
|
|
@ -986,21 +985,72 @@ public class MultiTemplateTabPane extends Row {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取多模板工具按钮 |
|
|
|
|
* 获取前导区多模板工具按钮 |
|
|
|
|
* |
|
|
|
|
* @return 工具按钮 |
|
|
|
|
*/ |
|
|
|
|
public UIToolbar getToolBar() { |
|
|
|
|
return this.toolBar; |
|
|
|
|
public UIToolbar getLeadingToolBar() { |
|
|
|
|
return this.leadingToolBar; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 生成前导区多模板工具按钮 |
|
|
|
|
*/ |
|
|
|
|
public void updateLeadingToolBar() { |
|
|
|
|
createLeadingToolBarDef().updateToolBar(getLeadingToolBar()); |
|
|
|
|
leadingWidth = getLeadingToolBar().getComponentCount() * SINGLE_BUTTON_WIDTH; |
|
|
|
|
getLeadingToolBar().setLayout(new FlowLayout(FlowLayout.LEFT, FineUIScale.scale(14), 0)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 创建新建模板的前导区工具按钮 |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private ToolBarDef createLeadingToolBarDef() { |
|
|
|
|
ToolBarDef toolBarDef = ShortCut.asToolBarDef(createNewTemplateShortCuts()); |
|
|
|
|
insertLeadingToolButton(toolBarDef, MultiTemplateTabPaneHandler.LEADING_LOCATION); |
|
|
|
|
return toolBarDef; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 创建新建文件的按钮数组 |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
public ShortCut[] createNewTemplateShortCuts() { |
|
|
|
|
ArrayList<ShortCut> shortCuts = new ArrayList<ShortCut>(); |
|
|
|
|
shortCuts.add(new NewWorkBookToolButtonAction()); |
|
|
|
|
return shortCuts.toArray(new ShortCut[0]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 生成多模板工具按钮 |
|
|
|
|
* @param toolBarDef |
|
|
|
|
* 插入插件中的按钮 |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
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)); |
|
|
|
|
protected void insertLeadingToolButton(ToolBarDef toolBarDef, String anchor) { |
|
|
|
|
Set<MultiTemplateTabPaneHandler> set = ExtraDesignClassManager.getInstance().getArray(MultiTemplateTabPaneHandler.MARK_STRING); |
|
|
|
|
List<MultiTemplateTabPaneHandler> target = new ArrayList<>(); |
|
|
|
|
for (MultiTemplateTabPaneHandler handler : set) { |
|
|
|
|
if (ComparatorUtils.equals(handler.category(), anchor)) { |
|
|
|
|
target.add(handler); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (MultiTemplateTabPaneHandler handler : target) { |
|
|
|
|
int insertPosition = handler.insertPosition(toolBarDef.getShortCutCount()); |
|
|
|
|
if (insertPosition == MenuHandler.HIDE) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
ShortCut shortCut = handler.shortcut(); |
|
|
|
|
if (shortCut == null) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (insertPosition == MenuHandler.LAST) { |
|
|
|
|
toolBarDef.addShortCut(shortCut); |
|
|
|
|
} else { |
|
|
|
|
toolBarDef.insertShortCut(insertPosition, shortCut); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|