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 069bbda57..10c010187 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 @@ -73,6 +73,7 @@ public class MultiTemplateTabPane extends Row { private static final String UI_CLASS_ID = "TemplateTabPaneUI"; private static final int GAP = 6; private static final int SMALLGAP = 4; + private static final int DOUBLE_CLICK = 2; /** * 尾部动作区宽度 @@ -122,6 +123,8 @@ public class MultiTemplateTabPane extends Row { // 模板时,模板B会自动关闭 private JTemplate temTemplate = null; + private ActionListener newTemplateAction; + @Override public String getUIClassID() { return UI_CLASS_ID; @@ -203,8 +206,9 @@ public class MultiTemplateTabPane extends Row { * @param l 监听器 */ public void addLeadingAction(ActionListener l) { - leadingActionButton.removeActionListener(l); - leadingActionButton.addActionListener(l); + newTemplateAction = l; + leadingActionButton.removeActionListener(newTemplateAction); + leadingActionButton.addActionListener(newTemplateAction); } public void setLeadingActionEnable(boolean enable) { @@ -322,12 +326,7 @@ public class MultiTemplateTabPane extends Row { if (OK_OPTION == selVal) { CallbackSaveWorker worker = template.saveAs(); worker.start(template.getRuntimeId()); - worker.addSuccessCallback(new Runnable() { - @Override - public void run() { - gotoEditingTemplateLeaf(template.getPath()); - } - }); + worker.addSuccessCallback(() -> gotoEditingTemplateLeaf(template.getPath())); } } else { gotoEditingTemplateLeaf(template.getPath()); @@ -701,6 +700,18 @@ public class MultiTemplateTabPane extends Row { return evtX >= (maxWidth + SMALLGAP) && evtX <= (getWidth() - SMALLGAP); } + /** + * 判断是否在tab栏空白区 + * + * @param evtX x坐标 + * @return 是否在tab栏空白区 + */ + private boolean isOverBlank(int evtX) { + int tabWidths = (maxPaintIndex - minPaintIndex + 1) * tabWidth; + int leftX = tabWidths + scale(LEADING_WIDTH); + return evtX >= leftX && evtX <= getWidth() - scale(TRAILING_WIDTH); + } + private int getTemplateIndex(int evtX) { int textX = scale(LEADING_WIDTH); @@ -768,6 +779,15 @@ public class MultiTemplateTabPane extends Row { MultiTemplateTabPane.this.repaint(); } + @Override + public void mouseClicked(MouseEvent e) { + // 双击添加模板 + if (e.getClickCount() == DOUBLE_CLICK + && isOverBlank(e.getX())) { + newTemplateAction.actionPerformed(null); + } + } + /** * 按下 *