|
|
|
@ -50,8 +50,6 @@ 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; |
|
|
|
|
|
|
|
|
|
import static com.fine.theme.utils.FineClientProperties.BUTTON_TYPE_TOOLBAR_BUTTON; |
|
|
|
|
import static com.fine.theme.utils.FineUIScale.scale; |
|
|
|
@ -227,19 +225,17 @@ public class MultiTemplateTabPane extends Row {
|
|
|
|
|
/** |
|
|
|
|
* 判断模板是否可以关闭,两个条件:1、是否满足CloseOption里面的条件(在左侧、在右侧等)2、是否和当前正在编辑模板属于同一种模板tab操作类型 |
|
|
|
|
* |
|
|
|
|
* @param closeJTemplate |
|
|
|
|
* @param tplIndex |
|
|
|
|
* @param i |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
public boolean shouldClose(JTemplate closeJTemplate, int tplIndex, int i) { |
|
|
|
|
public boolean shouldClose(int tplIndex, int i) { |
|
|
|
|
boolean matchOption = this.closeOption.shouldClose(tplIndex, i); |
|
|
|
|
JTemplate currentTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
|
|
|
|
if (!JTemplate.isValid(currentTemplate)) { |
|
|
|
|
return matchOption; |
|
|
|
|
} |
|
|
|
|
return matchOption && ComparatorUtils.equals(closeJTemplate.getTemplateTabOperatorType(), |
|
|
|
|
currentTemplate.getTemplateTabOperatorType()); |
|
|
|
|
return matchOption; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -365,7 +361,7 @@ public class MultiTemplateTabPane extends Row {
|
|
|
|
|
JTemplate<?, ?> currentTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
|
|
|
|
closeTemplate(closeCondition, templates, currentTemplate); |
|
|
|
|
|
|
|
|
|
if (openedTemplate.size() == 0) { |
|
|
|
|
if (openedTemplate.isEmpty()) { |
|
|
|
|
DesignerContext.getDesignerFrame().addAndActivateJTemplate(); |
|
|
|
|
} else if (option == CloseOption.All) { |
|
|
|
|
//openedTemplate(0)是JVirtualTemplate时需重新打开
|
|
|
|
@ -380,7 +376,7 @@ public class MultiTemplateTabPane extends Row {
|
|
|
|
|
|
|
|
|
|
private void closeTemplate(CloseCondition closeCondition, JTemplate<?, ?>[] templates, JTemplate<?, ?> currentTemplate) { |
|
|
|
|
for (int i = 0; i < templates.length; i++) { |
|
|
|
|
if (closeCondition.shouldClose(templates[i], tplIndex, i)) { |
|
|
|
|
if (closeCondition.shouldClose(tplIndex, i)) { |
|
|
|
|
JTemplate<?, ?> jTemplate = templates[i]; |
|
|
|
|
if (jTemplate == currentTemplate) { |
|
|
|
|
currentTemplate = option == CloseOption.All ? null : templates[tplIndex]; |
|
|
|
@ -415,20 +411,18 @@ public class MultiTemplateTabPane extends Row {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 关闭所有指定模板tab操作类型的模板 |
|
|
|
|
* |
|
|
|
|
* @param operatorType |
|
|
|
|
*/ |
|
|
|
|
public void closeOtherByOperatorType(String operatorType) { |
|
|
|
|
public void closeOther() { |
|
|
|
|
JTemplate<?, ?> currentEditingTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
|
|
|
|
SaveSomeTemplatePane saveSomeTempaltePane = new SaveSomeTemplatePane(false); |
|
|
|
|
if (saveSomeTempaltePane.showSavePane(null, false, true)) { |
|
|
|
|
SaveSomeTemplatePane saveSomeTemplatePane = new SaveSomeTemplatePane(false); |
|
|
|
|
if (saveSomeTemplatePane.showSavePane(null, false, true)) { |
|
|
|
|
List<JTemplate<?, ?>> openedTemplate = HistoryTemplateListCache.getInstance().getHistoryList(); |
|
|
|
|
|
|
|
|
|
JTemplate<?, ?>[] templates = new JTemplate<?, ?>[openedTemplate.size()]; |
|
|
|
|
for (int i = 0; i < openedTemplate.size(); i++) { |
|
|
|
|
templates[i] = openedTemplate.get(i); |
|
|
|
|
} |
|
|
|
|
closeTemplate(templates, currentEditingTemplate, operatorType); |
|
|
|
|
closeTemplate(templates, currentEditingTemplate); |
|
|
|
|
|
|
|
|
|
DesignerContext.getDesignerFrame().activateJTemplate(currentEditingTemplate); |
|
|
|
|
MultiTemplateTabPane.getInstance().repaint(); |
|
|
|
@ -439,14 +433,10 @@ public class MultiTemplateTabPane extends Row {
|
|
|
|
|
* 关闭指定的非当前编辑模板 |
|
|
|
|
* |
|
|
|
|
* @param templates |
|
|
|
|
* @param operatorType |
|
|
|
|
*/ |
|
|
|
|
private static void closeTemplate(JTemplate<?, ?>[] templates, JTemplate<?, ?> currentEditingTemplate, String operatorType) { |
|
|
|
|
for (int i = 0; i < templates.length; i++) { |
|
|
|
|
JTemplate<?, ?> jTemplate = templates[i]; |
|
|
|
|
boolean needClose = ComparatorUtils.equals(operatorType, jTemplate.getTemplateTabOperatorType()) |
|
|
|
|
&& jTemplate != currentEditingTemplate; |
|
|
|
|
if (!needClose) { |
|
|
|
|
private static void closeTemplate(JTemplate<?, ?>[] templates, JTemplate<?, ?> currentEditingTemplate) { |
|
|
|
|
for (JTemplate<?, ?> jTemplate : templates) { |
|
|
|
|
if (jTemplate == currentEditingTemplate) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
MultiTemplateTabPane.getInstance().closeFormat(jTemplate); |
|
|
|
@ -471,11 +461,6 @@ public class MultiTemplateTabPane extends Row {
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String tempalteShowName(JTemplate<?, ?> template) { |
|
|
|
|
return template.getTabShowName(template); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public String getTemplateShowNameByIndex(int index) { |
|
|
|
|
JTemplate template = openedTemplate.get(index); |
|
|
|
|
return template.getTabShowName(template); |
|
|
|
@ -566,67 +551,14 @@ public class MultiTemplateTabPane extends Row {
|
|
|
|
|
minPaintIndex = 0; |
|
|
|
|
maxPaintIndex = openedTemplate.size() - 1; |
|
|
|
|
} |
|
|
|
|
//需要根据每个tab的宽度重新check下实际的maxPaintIndex和minPaintIndex
|
|
|
|
|
checkActualPaintIndex(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 先计算出需要补充的tab个数 |
|
|
|
|
* |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private int calTabCountComplemented() { |
|
|
|
|
int a = 0; |
|
|
|
|
for (int i = minPaintIndex; i <= maxPaintIndex; i++) { |
|
|
|
|
JTemplate template = openedTemplate.get(i); |
|
|
|
|
if (!showJTemplateTab(template)) { |
|
|
|
|
a++; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return a; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 由于可能存在宽度为0的tab,所以这边需要重新check下,先往后补,再往前补 |
|
|
|
|
* 个数小于最多能容纳的个数的情况下,看看宽度每个要画多少 |
|
|
|
|
*/ |
|
|
|
|
private void checkActualPaintIndex() { |
|
|
|
|
int tabCount = calTabCountComplemented(); |
|
|
|
|
if (tabCount == 0) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (maxPaintIndex < openedTemplate.size() - 1) { |
|
|
|
|
for (int i = maxPaintIndex + 1; i < openedTemplate.size(); i++) { |
|
|
|
|
JTemplate template = openedTemplate.get(i); |
|
|
|
|
if (showJTemplateTab(template)) { |
|
|
|
|
tabCount--; |
|
|
|
|
} |
|
|
|
|
maxPaintIndex++; |
|
|
|
|
if (tabCount == 0) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (minPaintIndex > 0) { |
|
|
|
|
for (int i = minPaintIndex - 1; i >= 0; i--) { |
|
|
|
|
JTemplate template = openedTemplate.get(i); |
|
|
|
|
if (showJTemplateTab(template)) { |
|
|
|
|
tabCount--; |
|
|
|
|
} |
|
|
|
|
minPaintIndex--; |
|
|
|
|
if (tabCount == 0) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//个数小于最多能容纳的个数的情况下,看看宽度每个要画多少
|
|
|
|
|
private void calculateRealAverageWidth(double maxwidth, int templateNum) { |
|
|
|
|
JTemplate jTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
|
|
|
|
List<JTemplate<?, ?>> showTemplates = getOpenedJTemplatesByOperator(jTemplate.getTemplateTabOperatorType()); |
|
|
|
|
|
|
|
|
|
List<JTemplate<?, ?>> showTemplates = getOpenedJTemplates(); |
|
|
|
|
int num = Math.min(showTemplates.size(), templateNum); |
|
|
|
|
tabWidth = (int) (maxwidth / (num)); |
|
|
|
|
if (tabWidth > scale(MAXWIDTH)) { |
|
|
|
@ -639,7 +571,6 @@ public class MultiTemplateTabPane extends Row {
|
|
|
|
|
|
|
|
|
|
public void setIsCloseCurrent(boolean isCloseCurrent) { |
|
|
|
|
this.isCloseCurrent = isCloseCurrent; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -658,12 +589,9 @@ public class MultiTemplateTabPane extends Row {
|
|
|
|
|
Toolkit.i18nText("Fine-Design_Basic_Dialog_Prompt"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); |
|
|
|
|
if (returnVal == JOptionPane.YES_OPTION) { |
|
|
|
|
CallbackSaveWorker worker = specifiedTemplate.save(); |
|
|
|
|
worker.addSuccessCallback(new Runnable() { |
|
|
|
|
@Override |
|
|
|
|
public void run() { |
|
|
|
|
FineLoggerFactory.getLogger().info(Toolkit.i18nText("Fine-Design_Basic_Template_Already_Saved", specifiedTemplate.getEditingFILE().getName())); |
|
|
|
|
closeTpl(specifiedTemplate); |
|
|
|
|
} |
|
|
|
|
worker.addSuccessCallback(() -> { |
|
|
|
|
FineLoggerFactory.getLogger().info(Toolkit.i18nText("Fine-Design_Basic_Template_Already_Saved", specifiedTemplate.getEditingFILE().getName())); |
|
|
|
|
closeTpl(specifiedTemplate); |
|
|
|
|
}); |
|
|
|
|
worker.start(specifiedTemplate.getRuntimeId()); |
|
|
|
|
} else if (returnVal == JOptionPane.NO_OPTION) { |
|
|
|
@ -738,9 +666,7 @@ public class MultiTemplateTabPane extends Row {
|
|
|
|
|
// 关闭的模板是当前选中的模板时,需要重新计算下一个待展示的模板的index
|
|
|
|
|
if (selectedIndex >= maxPaintIndex) { |
|
|
|
|
// selectIndex 不会 <0 因为如果关闭的是打开的最后一个模板,那么关闭之后 openedTemplate.isEmpty() = true
|
|
|
|
|
selectedIndex = calNextShowJTemplateIndex(selectedIndex - 1); |
|
|
|
|
} else { |
|
|
|
|
selectedIndex = calNextShowJTemplateIndex(selectedIndex); |
|
|
|
|
selectedIndex--; |
|
|
|
|
} |
|
|
|
|
isCloseCurrent = false; |
|
|
|
|
} |
|
|
|
@ -757,23 +683,11 @@ public class MultiTemplateTabPane extends Row {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 计算下一个可以展示的模板index |
|
|
|
|
* |
|
|
|
|
* @param currentIndex |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
public int calNextShowJTemplateIndex(int currentIndex) { |
|
|
|
|
JTemplate jTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
|
|
|
|
return MultiTemplateTabUtils.calShowTemplateIndex(currentIndex, openedTemplate, jTemplate.getTemplateTabOperatorType()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean isOverCloseIcon(int evtX) { |
|
|
|
|
boolean isOverCloseIcon = false; |
|
|
|
|
// todo
|
|
|
|
|
for (int i = 0; i < startX.length; i++) { |
|
|
|
|
if (evtX >= startX[i] && evtX <= startX[i] + clodeIcon.getIconWidth()) { |
|
|
|
|
for (int x : startX) { |
|
|
|
|
if (evtX >= x && evtX <= x + clodeIcon.getIconWidth()) { |
|
|
|
|
isOverCloseIcon = true; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
@ -791,7 +705,7 @@ public class MultiTemplateTabPane extends Row {
|
|
|
|
|
private int getTemplateIndex(int evtX) { |
|
|
|
|
int textX = scale(LEADING_WIDTH); |
|
|
|
|
for (int i = minPaintIndex; i <= maxPaintIndex; i++) { |
|
|
|
|
int textWidth = showJTemplateTab(openedTemplate.get(i)) ? tabWidth : 0; |
|
|
|
|
int textWidth = tabWidth; |
|
|
|
|
if (evtX >= textX && evtX < textX + textWidth) { |
|
|
|
|
return i; |
|
|
|
|
} |
|
|
|
@ -971,28 +885,6 @@ public class MultiTemplateTabPane extends Row {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 判断是否显示在tab栏上 |
|
|
|
|
* |
|
|
|
|
* @param jTemplate |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private boolean showJTemplateTab(JTemplate jTemplate) { |
|
|
|
|
JTemplate current = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
|
|
|
|
return ComparatorUtils.equals(current.getTemplateTabOperatorType(), jTemplate.getTemplateTabOperatorType()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取tab操作类型的模板 |
|
|
|
|
* |
|
|
|
|
* @param operator |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
public List<JTemplate<?, ?>> getOpenedJTemplatesByOperator(String operator) { |
|
|
|
|
return openedTemplate.stream().filter((jTemplate) -> ComparatorUtils.equals(jTemplate.getTemplateTabOperatorType(), operator)) |
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取所有模板 |
|
|
|
|
* |
|
|
|
@ -1002,16 +894,6 @@ public class MultiTemplateTabPane extends Row {
|
|
|
|
|
return Collections.unmodifiableList(openedTemplate); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 根据tab操作类型进行分类 |
|
|
|
|
* |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
public Map<String, List<JTemplate<?, ?>>> getOpenedJTemplatesByCategory() { |
|
|
|
|
return openedTemplate.stream() |
|
|
|
|
.collect(Collectors.groupingBy(JTemplate::getTemplateTabOperatorType)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 返回当前tab数量 |
|
|
|
|
* |
|
|
|
|