From 823755386c9bf2ab880ab853218e49e1b3af7537 Mon Sep 17 00:00:00 2001 From: shine Date: Fri, 7 May 2021 15:54:14 +0800 Subject: [PATCH 1/2] CHART-18790 design new template name --- .../fr/design/mainframe/DesignerFrame.java | 3 + .../com/fr/design/mainframe/JTemplate.java | 43 +-------------- .../design/mainframe/JTemplateNameHelper.java | 55 +++++++++++++++++++ 3 files changed, 59 insertions(+), 42 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/design/mainframe/JTemplateNameHelper.java diff --git a/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java b/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java index 76a0e3ad3d..0c6d0d7cfa 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/DesignerFrame.java @@ -829,6 +829,9 @@ public class DesignerFrame extends JFrame implements JTemplateActionListener, Ta if (east != null) { basePane.add(east, BorderLayout.EAST); } + + layeredPane.repaint(); + layeredPane.revalidate(); } /** diff --git a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java index 5ecf4ae82b..4e026a859d 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/JTemplate.java @@ -24,7 +24,6 @@ import com.fr.design.dialog.FineJOptionPane; import com.fr.design.dialog.InformationWarnPane; import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.file.TemplateResourceManager; -import com.fr.design.file.TemplateTreePane; import com.fr.design.fun.DesignerFrameUpButtonProvider; import com.fr.design.fun.MenuHandler; import com.fr.design.fun.PreviewProvider; @@ -34,7 +33,6 @@ import com.fr.design.gui.frpane.HyperlinkGroupPane; import com.fr.design.gui.frpane.HyperlinkGroupPaneActionProvider; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.imenu.UIMenuItem; -import com.fr.design.gui.itree.filetree.TemplateFileTree; import com.fr.design.i18n.Toolkit; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.mainframe.chart.info.ChartInfoCollector; @@ -80,20 +78,15 @@ import javax.swing.BorderFactory; import javax.swing.Icon; import javax.swing.JComponent; import javax.swing.JOptionPane; -import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.undo.UndoManager; import java.awt.BorderLayout; -import java.util.ArrayList; -import java.util.Arrays; import java.util.Set; -import java.util.regex.Pattern; /** * 报表设计和表单设计的编辑区域(设计器编辑的IO文件) */ public abstract class JTemplate> extends TargetComponent implements ToolBarMenuDockPlus, DesignerProxy { // TODO ALEX_SEP editingFILE这个属性一定要吗?如果非要不可,有没有可能保证不为null - private static final int PREFIX_NUM = 3000; private FILE editingFILE = null; // alex:初始状态为saved,这样不管是新建模板,还是打开模板,如果未做任何操作直接关闭,不提示保存 private boolean saved = true; @@ -105,7 +98,6 @@ public abstract class JTemplate> protected T template; // 当前模板 protected TemplateProcessInfo processInfo; // 模板过程的相关信息 private JComponent centerPane; - private static short currentIndex = 0;// 此变量用于多次新建模板时,让名字不重复 private DesignModelAdapter designModel; private PreviewProvider previewType; protected TimeConsumeTimer consumeTimer = new TimeConsumeTimer(); @@ -117,7 +109,7 @@ public abstract class JTemplate> } public JTemplate(T t, String defaultFileName) { - this(t, new MemFILE(newTemplateNameByIndex(defaultFileName)), true); + this(t, new MemFILE(JTemplateNameHelper.newTemplateNameByIndex(defaultFileName)), true); } public JTemplate(T t, FILE file) { @@ -840,39 +832,6 @@ public abstract class JTemplate> return true; } - private static String newTemplateNameByIndex(String prefix) { - // 用于获取左侧模板的文件名,如左侧已包含"WorkBook1.cpt, WorkBook12.cpt, WorkBook177.cpt" - // 那么新建的文件名将被命名为"WorkBook178.cpt",即取最大数+1 - TemplateFileTree tt = TemplateTreePane.getInstance().getTemplateFileTree(); - DefaultMutableTreeNode gen = (DefaultMutableTreeNode) tt.getModel().getRoot(); - String[] str = new String[gen.getChildCount()]; - ArrayList al = new ArrayList(); - for (int j = 0; j < gen.getChildCount(); j++) { - str[j] = gen.getChildAt(j).toString(); - if (str[j].contains(prefix) && str[j].contains(".")) { - for (int i = 0; i < PREFIX_NUM; i++) { - if (ComparatorUtils.equals(str[j].split("[.]")[0], (prefix + i))) { - al.add(str[j]); - } - - } - } - } - - int[] reportNum = new int[al.size()]; - for (int i = 0; i < al.size(); i++) { - Pattern pattern = Pattern.compile("[" + prefix + ".]+"); - String[] strs = pattern.split(al.get(i).toString()); - reportNum[i] = Integer.parseInt(strs[1]); - } - - Arrays.sort(reportNum); - int idx = reportNum.length > 0 ? reportNum[reportNum.length - 1] + 1 : 1; - idx = idx + currentIndex; - currentIndex++; - return prefix + idx; - } - // /////////////////////////////toolbarMenuDock////////////////////////////////// /** diff --git a/designer-base/src/main/java/com/fr/design/mainframe/JTemplateNameHelper.java b/designer-base/src/main/java/com/fr/design/mainframe/JTemplateNameHelper.java new file mode 100644 index 0000000000..bd1b869b08 --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/mainframe/JTemplateNameHelper.java @@ -0,0 +1,55 @@ +package com.fr.design.mainframe; + +import com.fr.design.file.TemplateTreePane; +import com.fr.design.gui.itree.filetree.TemplateFileTree; +import com.fr.general.ComparatorUtils; + +import javax.swing.tree.DefaultMutableTreeNode; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.regex.Pattern; + +/** + * @author shine + * @version 10.0 + * Created by shine on 2021/5/7 + */ +public class JTemplateNameHelper { + + private static final int PREFIX_NUM = 3000; + + private static short currentIndex = 0;// 此变量用于多次新建模板时,让名字不重复 + + public static String newTemplateNameByIndex(String prefix) { + // 用于获取左侧模板的文件名,如左侧已包含"WorkBook1.cpt, WorkBook12.cpt, WorkBook177.cpt" + // 那么新建的文件名将被命名为"WorkBook178.cpt",即取最大数+1 + TemplateFileTree tt = TemplateTreePane.getInstance().getTemplateFileTree(); + DefaultMutableTreeNode gen = (DefaultMutableTreeNode) tt.getModel().getRoot(); + String[] str = new String[gen.getChildCount()]; + ArrayList al = new ArrayList(); + for (int j = 0; j < gen.getChildCount(); j++) { + str[j] = gen.getChildAt(j).toString(); + if (str[j].contains(prefix) && str[j].contains(".")) { + for (int i = 0; i < PREFIX_NUM; i++) { + if (ComparatorUtils.equals(str[j].split("[.]")[0], (prefix + i))) { + al.add(str[j]); + } + + } + } + } + + int[] reportNum = new int[al.size()]; + for (int i = 0; i < al.size(); i++) { + Pattern pattern = Pattern.compile("[" + prefix + ".]+"); + String[] strs = pattern.split(al.get(i).toString()); + reportNum[i] = Integer.parseInt(strs[1]); + } + + Arrays.sort(reportNum); + int idx = reportNum.length > 0 ? reportNum[reportNum.length - 1] + 1 : 1; + idx = idx + currentIndex; + currentIndex++; + return prefix + idx; + } +} From 752e500a649ad3b10633acd4ffdf6d3dd2402943 Mon Sep 17 00:00:00 2001 From: shine Date: Sat, 8 May 2021 10:05:01 +0800 Subject: [PATCH 2/2] test --- .../mainframe/JTemplateNameHelperTest.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 designer-base/src/test/java/com/fr/design/mainframe/JTemplateNameHelperTest.java diff --git a/designer-base/src/test/java/com/fr/design/mainframe/JTemplateNameHelperTest.java b/designer-base/src/test/java/com/fr/design/mainframe/JTemplateNameHelperTest.java new file mode 100644 index 0000000000..032e715f60 --- /dev/null +++ b/designer-base/src/test/java/com/fr/design/mainframe/JTemplateNameHelperTest.java @@ -0,0 +1,23 @@ +package com.fr.design.mainframe; + +import junit.framework.TestCase; + +/** + * @author shine + * @version 10.0 + * Created by shine on 2021/5/8 + */ +public class JTemplateNameHelperTest extends TestCase { + + public void testNewTemplateNameByIndex() { + + String name = JTemplateNameHelper.newTemplateNameByIndex("TEST"); + + assertEquals("TEST1", name); + + String name1 = JTemplateNameHelper.newTemplateNameByIndex("TEST"); + + assertEquals("TEST2", name1); + + } +}