|
|
|
@ -2,12 +2,12 @@ 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 com.fr.stable.StringUtils; |
|
|
|
|
|
|
|
|
|
import javax.swing.tree.DefaultMutableTreeNode; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.Arrays; |
|
|
|
|
import java.util.regex.Pattern; |
|
|
|
|
import java.util.Collections; |
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @author shine |
|
|
|
@ -26,30 +26,58 @@ public class JTemplateNameHelper {
|
|
|
|
|
TemplateFileTree tt = TemplateTreePane.getInstance().getTemplateFileTree(); |
|
|
|
|
DefaultMutableTreeNode gen = (DefaultMutableTreeNode) tt.getModel().getRoot(); |
|
|
|
|
String[] str = new String[gen.getChildCount()]; |
|
|
|
|
ArrayList<String> al = new ArrayList<String>(); |
|
|
|
|
|
|
|
|
|
List<Integer> reportNum = 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]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
//返回文件名中的index(算法中没有再匹配文件后缀了,因为DefaultMutableTreeNode中已经匹配过了)
|
|
|
|
|
Integer index = getFileNameIndex(prefix, str[j]); |
|
|
|
|
if (index != null) { |
|
|
|
|
reportNum.add(index); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Collections.sort(reportNum); |
|
|
|
|
int idx = reportNum.size() > 0 ? reportNum.get(reportNum.size() - 1) + 1 : 1; |
|
|
|
|
|
|
|
|
|
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; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @return java.lang.Integer WorkBook11.cpt则返回11,如果没有找到index返回null |
|
|
|
|
* @Description 返回文件名中的index |
|
|
|
|
* @param: prefix 前缀 |
|
|
|
|
* @param: fileName 文件名称全名 |
|
|
|
|
* @Author Henry.Wang |
|
|
|
|
* @Date 2021/4/9 11:13 |
|
|
|
|
**/ |
|
|
|
|
private static Integer getFileNameIndex(String prefix, String fileName) { |
|
|
|
|
char[] chars = new char[fileName.length()]; |
|
|
|
|
int i = 0; |
|
|
|
|
for (; i < fileName.length(); i++) { |
|
|
|
|
char c = fileName.charAt(i); |
|
|
|
|
//匹配前缀
|
|
|
|
|
if (i < prefix.length()) { |
|
|
|
|
if (c != prefix.charAt(i)) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
if (c == '.') { |
|
|
|
|
break; |
|
|
|
|
} else { |
|
|
|
|
//匹配0~9
|
|
|
|
|
if (c < 48 || c > 57) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
chars[i - prefix.length()] = c; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
String s = new String(chars).substring(0, i - prefix.length()); |
|
|
|
|
if (StringUtils.isBlank(s)) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
return Integer.valueOf(s); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|