From 953ea6a77c7ab649a3dd185633ecf3d5ca9b6e15 Mon Sep 17 00:00:00 2001 From: vito Date: Mon, 15 Jan 2024 17:05:12 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-99485=20=E9=80=82=E9=85=8DFVS=E6=9A=82?= =?UTF-8?q?=E6=97=B6=E7=BB=B4=E6=8C=81=E5=8F=AF=E7=94=A8=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/file/HistoryTemplateListCache.java | 4 +- .../file/MultiTemplateTabMenuFactory.java | 23 +-- .../fr/design/file/MultiTemplateTabPane.java | 158 +++--------------- .../fr/design/file/MultiTemplateTabUtils.java | 59 ------- .../fr/design/file/SaveSomeTemplatePane.java | 18 +- .../design/file/MultiTemplateTabPaneTest.java | 113 ++++++------- 6 files changed, 89 insertions(+), 286 deletions(-) delete mode 100644 designer-base/src/main/java/com/fr/design/file/MultiTemplateTabUtils.java diff --git a/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java b/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java index f895a4f5b4..ab5c485cc8 100644 --- a/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java +++ b/designer-base/src/main/java/com/fr/design/file/HistoryTemplateListCache.java @@ -298,9 +298,7 @@ public class HistoryTemplateListCache implements CallbackEvent { int index = iterator.nextIndex(); if (size == index + 1 && index > 0) { //如果删除的是后一个Tab,则定位到前一个 - MultiTemplateTabPane.getInstance().setSelectedIndex( - MultiTemplateTabPane.getInstance().calNextShowJTemplateIndex(index - 1)); - + MultiTemplateTabPane.getInstance().setSelectedIndex(index - 1); } } } diff --git a/designer-base/src/main/java/com/fr/design/file/MultiTemplateTabMenuFactory.java b/designer-base/src/main/java/com/fr/design/file/MultiTemplateTabMenuFactory.java index 66b7b27af9..251336b52c 100644 --- a/designer-base/src/main/java/com/fr/design/file/MultiTemplateTabMenuFactory.java +++ b/designer-base/src/main/java/com/fr/design/file/MultiTemplateTabMenuFactory.java @@ -6,10 +6,8 @@ import com.fr.design.i18n.Toolkit; import com.fr.design.mainframe.JTemplate; import com.fr.stable.collections.CollectionUtils; -import javax.swing.JPanel; import javax.swing.SwingConstants; import java.awt.Component; -import java.awt.Dimension; import java.util.List; @@ -23,8 +21,6 @@ import java.util.List; public class MultiTemplateTabMenuFactory { - private static final int ITEM_SIZE = 25; - private UIScrollPopUpMenu menu = null; private static MultiTemplateTabMenuFactory INSTANCE = new MultiTemplateTabMenuFactory(); @@ -62,29 +58,14 @@ public class MultiTemplateTabMenuFactory { private UIMenuItem initCloseOther() { UIMenuItem closeOther = new UIMenuItem(Toolkit.i18nText("Fine-Design_Close_Other_templates")); closeOther.setHorizontalAlignment(SwingConstants.CENTER); - String currentOperator = getCurrentTabOperatorType(); - closeOther.addActionListener(e -> MultiTemplateTabPane.getInstance().closeOtherByOperatorType(currentOperator)); - if (MultiTemplateTabPane.getInstance().getOpenedJTemplatesByOperator(currentOperator).size() <= 1) { + closeOther.addActionListener(e -> MultiTemplateTabPane.getInstance().closeOther()); + if (MultiTemplateTabPane.getInstance().getOpenedJTemplates().size() <= 1) { closeOther.setEnabled(false); } return closeOther; } - /** - * 美观用 - */ - private JPanel createEmptyRow() { - return new JPanel() { - @Override - public Dimension getPreferredSize() { - Dimension d = super.getPreferredSize(); - d.height = 1; - return d; - } - }; - } - /** * 创建 当前分类模板 item数组 */ 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 3f1b05d42d..069bbda57a 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 @@ -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> 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> showTemplates = getOpenedJTemplatesByOperator(jTemplate.getTemplateTabOperatorType()); - + List> 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> 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>> getOpenedJTemplatesByCategory() { - return openedTemplate.stream() - .collect(Collectors.groupingBy(JTemplate::getTemplateTabOperatorType)); - } - /** * 返回当前tab数量 * diff --git a/designer-base/src/main/java/com/fr/design/file/MultiTemplateTabUtils.java b/designer-base/src/main/java/com/fr/design/file/MultiTemplateTabUtils.java deleted file mode 100644 index 344abe64f2..0000000000 --- a/designer-base/src/main/java/com/fr/design/file/MultiTemplateTabUtils.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.fr.design.file; - -import com.fr.design.mainframe.JTemplate; -import com.fr.general.ComparatorUtils; - -import java.util.List; -import java.util.function.Predicate; - -public class MultiTemplateTabUtils { - /** - * 计算离currentIndex最近的相同模式的模板index值(优先左边) - * - * @param currentIndex 当前index - * @param openedTemplate 模板list - * @param type 当前显示模式 - * @return - */ - public static int calShowTemplateIndex(int currentIndex, List> openedTemplate, String type) { - if (currentIndex < 0 || currentIndex > openedTemplate.size() - 1) { - return -1; - } - int result = getShowJTemplateTab(currentIndex, openedTemplate, template -> showJTemplateTab(type, template)); - if (result != -1) return result; - return getShowJTemplateTab(currentIndex, openedTemplate, template -> !showJTemplateTab(type, template)); - } - - /** - * 先从左找,再从右找离得最近的满足条件的模板 - * - * @param currentIndex 当前index - * @param openedTemplate 模板list - * @param predicate - * @return - */ - private static int getShowJTemplateTab(int currentIndex, List> openedTemplate, Predicate> predicate) { - for (int i = currentIndex; i >= 0; i--) { - if (predicate.test(openedTemplate.get(i))) { - return i; - } - } - for (int i = currentIndex + 1; i < openedTemplate.size(); i++) { - if (predicate.test(openedTemplate.get(i))) { - return i; - } - } - return -1; - } - - /** - * 是否显示模板 - * - * @param type 模板类型 - * @param jTemplate 模板 - * @return - */ - private static boolean showJTemplateTab(String type, JTemplate jTemplate) { - return ComparatorUtils.equals(type, jTemplate.getTemplateTabOperatorType()); - } -} diff --git a/designer-base/src/main/java/com/fr/design/file/SaveSomeTemplatePane.java b/designer-base/src/main/java/com/fr/design/file/SaveSomeTemplatePane.java index 1517309ef1..de8ca831d9 100644 --- a/designer-base/src/main/java/com/fr/design/file/SaveSomeTemplatePane.java +++ b/designer-base/src/main/java/com/fr/design/file/SaveSomeTemplatePane.java @@ -3,7 +3,6 @@ package com.fr.design.file; import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.BasicPane; import com.fr.design.dialog.DialogActionAdapter; -import com.fr.design.dialog.FineJOptionPane; import com.fr.design.event.StateChangeListener; import com.fr.design.gui.icheckbox.UICheckBox; import com.fr.design.gui.icontainer.UIScrollPane; @@ -15,14 +14,19 @@ import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.JTemplate; import com.fr.general.ComparatorUtils; - import com.fr.log.FineLoggerFactory; import org.jetbrains.annotations.Nullable; -import javax.swing.*; -import javax.swing.border.EmptyBorder; -import java.awt.*; -import java.awt.event.*; +import javax.swing.AbstractListModel; +import javax.swing.BorderFactory; +import javax.swing.DefaultListCellRenderer; +import javax.swing.JList; +import javax.swing.JPanel; +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Window; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; import java.util.ArrayList; /** @@ -215,7 +219,7 @@ public class SaveSomeTemplatePane extends BasicPane { int currentIndex = opendedTemplate.indexOf(currentTemplate); for (int i = 0; i < opendedTemplate.size(); i++) { //满足关闭条件的才继续判断文件是否发生了改动 - boolean needClose = option == null || option.shouldClose(opendedTemplate.get(i), currentIndex, i); + boolean needClose = option == null || option.shouldClose(currentIndex, i); if (judgeSameTabType) { needClose &= ComparatorUtils.equals(opendedTemplate.get(i).getTemplateTabOperatorType(), currentTemplate.getTemplateTabOperatorType()); } diff --git a/designer-base/src/test/java/com/fr/design/file/MultiTemplateTabPaneTest.java b/designer-base/src/test/java/com/fr/design/file/MultiTemplateTabPaneTest.java index c00976abb3..bae2b8ebdf 100644 --- a/designer-base/src/test/java/com/fr/design/file/MultiTemplateTabPaneTest.java +++ b/designer-base/src/test/java/com/fr/design/file/MultiTemplateTabPaneTest.java @@ -14,13 +14,10 @@ import com.fr.design.menu.ShortCut; import com.fr.design.menu.ToolBarDef; import com.fr.plugin.injectable.PluginModule; import junit.framework.TestCase; -import org.junit.Assert; import javax.swing.Icon; import javax.swing.JComponent; import javax.swing.JPanel; -import java.util.ArrayList; -import java.util.List; public class MultiTemplateTabPaneTest extends TestCase { @Override @@ -28,61 +25,61 @@ public class MultiTemplateTabPaneTest extends TestCase { PluginModule.registerAgent(PluginModule.ExtraDesign, new ExtraDesignClassManager()); } - /** - * 当前显示模式A,传入index左边(含当前)或右边有模式A的模板,返回最近的模式A模板index(优先左边) - */ - public void test_index_left_has_same_mode_temp() { - //当前显示模式A,传入index左边(含当前)有模式A的模板,返回左边最近的模式A模板index - List> openedTemplateList = new ArrayList<>(); - openedTemplateList.add(new A_Mode()); - Assert.assertEquals(0, MultiTemplateTabUtils.calShowTemplateIndex(0, openedTemplateList, "A_Mode")); - openedTemplateList.add(new A_Mode()); - Assert.assertEquals(1, MultiTemplateTabUtils.calShowTemplateIndex(1, openedTemplateList, "A_Mode")); - openedTemplateList.add(new B_Mode()); - Assert.assertEquals(1, MultiTemplateTabUtils.calShowTemplateIndex(1, openedTemplateList, "A_Mode")); - } - - public void test_index_left_has_not_but_right_has_same_mode_temp() { - //当前显示模式A,传入index左边没有但是右边有模式A的模板,返回右边最近的模式A模板index - List> openedTemplateList = new ArrayList<>(); - openedTemplateList.add(new B_Mode()); - openedTemplateList.add(new A_Mode()); - Assert.assertEquals(1, MultiTemplateTabUtils.calShowTemplateIndex(0, openedTemplateList, "A_Mode")); - openedTemplateList.add(1, new B_Mode()); - openedTemplateList.add(new A_Mode()); - Assert.assertEquals(2, MultiTemplateTabUtils.calShowTemplateIndex(0, openedTemplateList, "A_Mode")); - openedTemplateList.add(new A_Mode()); - Assert.assertEquals(2, MultiTemplateTabUtils.calShowTemplateIndex(0, openedTemplateList, "A_Mode")); - } - - /** - * 当前显示模式A,没有模式A的模板,左边(含当前)或者右边有其他模式的模板,返回最近的其他模式模式模板index(优先左边) - */ - public void test_no_same_mode_temp_but_index_left_has_other_mode_temp() { - //当前显示模式A,没有模式A的模板,左边(含当前)有其他模式模板,返回左边最近的其他模式模板index - List> openedTemplateList = new ArrayList<>(); - openedTemplateList.add(new B_Mode()); - Assert.assertEquals(0, MultiTemplateTabUtils.calShowTemplateIndex(0, openedTemplateList, "A_Mode")); - openedTemplateList.add(new B_Mode()); - Assert.assertEquals(1, MultiTemplateTabUtils.calShowTemplateIndex(1, openedTemplateList, "A_Mode")); - } - - - public void test_has_no_temp() { - //当前显示模式A,没有模式A的模板,也没有其他模式的模板,返回-1 - List> openedTemplateList = new ArrayList<>(); - Assert.assertEquals(-1, MultiTemplateTabUtils.calShowTemplateIndex(0, openedTemplateList, "A_Mode")); - } - - - public void test_if_index_less_than_zero_or_more_than_open_temp_size() { - //index<0 或者超出openTemplateList.size时,返回-1 - List> openedTemplateList = new ArrayList<>(); - Assert.assertEquals(-1, MultiTemplateTabUtils.calShowTemplateIndex(-1, openedTemplateList, "A_Mode")); - Assert.assertEquals(-1, MultiTemplateTabUtils.calShowTemplateIndex(0, openedTemplateList, "A_Mode")); - openedTemplateList.add(new A_Mode()); - Assert.assertEquals(-1, MultiTemplateTabUtils.calShowTemplateIndex(1, openedTemplateList, "A_Mode")); - } +// /** +// * 当前显示模式A,传入index左边(含当前)或右边有模式A的模板,返回最近的模式A模板index(优先左边) +// */ +// public void test_index_left_has_same_mode_temp() { +// //当前显示模式A,传入index左边(含当前)有模式A的模板,返回左边最近的模式A模板index +// List> openedTemplateList = new ArrayList<>(); +// openedTemplateList.add(new A_Mode()); +// Assert.assertEquals(0, MultiTemplateTabUtils.calShowTemplateIndex(0, openedTemplateList, "A_Mode")); +// openedTemplateList.add(new A_Mode()); +// Assert.assertEquals(1, MultiTemplateTabUtils.calShowTemplateIndex(1, openedTemplateList, "A_Mode")); +// openedTemplateList.add(new B_Mode()); +// Assert.assertEquals(1, MultiTemplateTabUtils.calShowTemplateIndex(1, openedTemplateList, "A_Mode")); +// } +// +// public void test_index_left_has_not_but_right_has_same_mode_temp() { +// //当前显示模式A,传入index左边没有但是右边有模式A的模板,返回右边最近的模式A模板index +// List> openedTemplateList = new ArrayList<>(); +// openedTemplateList.add(new B_Mode()); +// openedTemplateList.add(new A_Mode()); +// Assert.assertEquals(1, MultiTemplateTabUtils.calShowTemplateIndex(0, openedTemplateList, "A_Mode")); +// openedTemplateList.add(1, new B_Mode()); +// openedTemplateList.add(new A_Mode()); +// Assert.assertEquals(2, MultiTemplateTabUtils.calShowTemplateIndex(0, openedTemplateList, "A_Mode")); +// openedTemplateList.add(new A_Mode()); +// Assert.assertEquals(2, MultiTemplateTabUtils.calShowTemplateIndex(0, openedTemplateList, "A_Mode")); +// } +// +// /** +// * 当前显示模式A,没有模式A的模板,左边(含当前)或者右边有其他模式的模板,返回最近的其他模式模式模板index(优先左边) +// */ +// public void test_no_same_mode_temp_but_index_left_has_other_mode_temp() { +// //当前显示模式A,没有模式A的模板,左边(含当前)有其他模式模板,返回左边最近的其他模式模板index +// List> openedTemplateList = new ArrayList<>(); +// openedTemplateList.add(new B_Mode()); +// Assert.assertEquals(0, MultiTemplateTabUtils.calShowTemplateIndex(0, openedTemplateList, "A_Mode")); +// openedTemplateList.add(new B_Mode()); +// Assert.assertEquals(1, MultiTemplateTabUtils.calShowTemplateIndex(1, openedTemplateList, "A_Mode")); +// } + + +// public void test_has_no_temp() { +// //当前显示模式A,没有模式A的模板,也没有其他模式的模板,返回-1 +// List> openedTemplateList = new ArrayList<>(); +// Assert.assertEquals(-1, MultiTemplateTabUtils.calShowTemplateIndex(0, openedTemplateList, "A_Mode")); +// } +// +// +// public void test_if_index_less_than_zero_or_more_than_open_temp_size() { +// //index<0 或者超出openTemplateList.size时,返回-1 +// List> openedTemplateList = new ArrayList<>(); +// Assert.assertEquals(-1, MultiTemplateTabUtils.calShowTemplateIndex(-1, openedTemplateList, "A_Mode")); +// Assert.assertEquals(-1, MultiTemplateTabUtils.calShowTemplateIndex(0, openedTemplateList, "A_Mode")); +// openedTemplateList.add(new A_Mode()); +// Assert.assertEquals(-1, MultiTemplateTabUtils.calShowTemplateIndex(1, openedTemplateList, "A_Mode")); +// } private class A_Mode extends AbstractTestMode { public String getTemplateTabOperatorType() {