propsMap) {
12 | try {
13 | com.apple.eawt.Application app = com.apple.eawt.Application.getApplication();
14 | app.setDockIconImage(icon);
15 | app.setDockIconBadge("");
16 | app.setAboutHandler(new com.apple.eawt.AboutHandler() {
17 | @Override
18 | public void handleAbout(com.apple.eawt.AppEvent.AboutEvent aboutEvent) {
19 | GuiUtils.showAboutMessage(kit, contextPanel, propsMap);
20 | }
21 | });
22 | } catch (Error e) {
23 | e.printStackTrace();
24 | }
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/bs/tool/commongui/utils/NumberUtils.java:
--------------------------------------------------------------------------------
1 | package bs.tool.commongui.utils;
2 |
3 | import java.math.BigDecimal;
4 | import java.text.DecimalFormat;
5 |
6 | public class NumberUtils {
7 |
8 | /**
9 | * 转化为百分比展示,百分比后精确到2位小数.
10 | *
11 | * @param obj
12 | * @return
13 | */
14 | public static String convertPercentageStr(Object obj) {
15 | return convertPrecision(obj, 100) + "%";
16 | }
17 |
18 | /**
19 | * 精确到3位精度.
20 | *
21 | * @param obj
22 | * @return
23 | */
24 | public static String convertPrecision(Object obj) {
25 | return convertPrecision(obj, 1);
26 | }
27 |
28 | /**
29 | * 精确到3位精度.
30 | *
31 | * @param obj
32 | * @param multi
33 | * @return
34 | */
35 | public static String convertPrecision(Object obj, int multi) {
36 | if (obj instanceof Double) {
37 | return String.format("%.3f", ((Double) obj) * multi);
38 | } else if (obj instanceof BigDecimal) {
39 | DecimalFormat format = new DecimalFormat("0.000");
40 | BigDecimal decimal = (BigDecimal) obj;
41 | if (decimal != null) {
42 | return format.format(decimal.multiply(new BigDecimal(multi)));
43 | } else {
44 | return "0.000";
45 | }
46 | } else {
47 | throw new RuntimeException("Convert precision string error, not support object type.");
48 | }
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/bs/tool/commongui/utils/RadixUtils.java:
--------------------------------------------------------------------------------
1 | package bs.tool.commongui.utils;
2 |
3 | /**
4 | * 进制转换类.
5 | *
6 | *
7 | * 特别说明:此处的字符皆为1个字节8位为1个转换单位,因此:
8 | * 1,1个字节转16进制为2位16进制,不足前面补零;
9 | * 2,1个字节转10进制为3位10进制,不足前面补零;
10 | * 3,1个字节转8进制为3位8进制,不足前面补零;
11 | * 这个类中的所有进制字符转换方法都是依据以上条件而定,当不满足以上条件时,程序会发生异常或不能得到预期结果!
12 | *
13 | */
14 | public class RadixUtils {
15 |
16 | /**
17 | * 字符串前填充以满足固定长度.
18 | */
19 | public static String fillStringBefore(String string, String fill, int size) {
20 | StringBuilder sb = new StringBuilder();
21 | int len = string.length();
22 | for (int i = 0; i < size - len; i++) {
23 | sb.append(fill);
24 | }
25 | return sb.append(string).toString();
26 | }
27 |
28 | /**
29 | * 将16进制字符转为10进制字符.
30 | */
31 | public static String convertRadixString16To10(String radix16) {
32 | StringBuilder sb = new StringBuilder();
33 | for (int i = 0; i < radix16.length() / 2; i++) {
34 | sb.append(fillStringBefore(Integer.toString(Integer.valueOf(radix16.substring(i * 2, (i + 1) * 2), 16)),
35 | "0", 3));
36 | }
37 | return sb.toString();
38 | }
39 |
40 | /**
41 | * 将10进制字符转为16进制字符.
42 | */
43 | public static String convertRadixString10To16(String radix10) {
44 | StringBuilder sb = new StringBuilder();
45 | for (int i = 0; i < radix10.length() / 3; i++) {
46 | sb.append(Integer.toHexString(Integer.valueOf(radix10.substring(i * 3, (i + 1) * 3))));
47 | }
48 | return sb.toString();
49 | }
50 |
51 | /**
52 | * 将16进制字符转为8进制字符.
53 | */
54 | public static String convertRadixString16To8(String radix16) {
55 | StringBuilder sb = new StringBuilder();
56 | for (int i = 0; i < radix16.length() / 2; i++) {
57 | sb.append(fillStringBefore(
58 | Integer.toOctalString(Integer.valueOf(radix16.substring(i * 2, (i + 1) * 2), 16)), "0", 3));
59 | }
60 | return sb.toString();
61 | }
62 |
63 | /**
64 | * 将8进制字符转为16进制字符.
65 | */
66 | public static String convertRadixString8To16(String radix8) {
67 | StringBuilder sb = new StringBuilder();
68 | for (int i = 0; i < radix8.length() / 3; i++) {
69 | sb.append(Integer.toHexString(Integer.valueOf(radix8.substring(i * 3, (i + 1) * 3), 8)));
70 | }
71 | return sb.toString();
72 | }
73 |
74 | /**
75 | * 将16进制字符转为2进制字符.
76 | */
77 | public static String convertRadixString16To2(String radix16) {
78 | StringBuilder sb = new StringBuilder();
79 | for (int i = 0; i < radix16.length(); i++) {
80 | sb.append(fillStringBefore(Integer.toBinaryString(Integer.valueOf(radix16.substring(i, i + 1), 16)), "0", 4));
81 | }
82 | return sb.toString();
83 | }
84 |
85 | /**
86 | * 将2进制字符转为16进制字符.
87 | */
88 | public static String convertRadixString2To16(String radix2) {
89 | StringBuilder sb = new StringBuilder();
90 | for (int i = 0; i < radix2.length() / 4; i++) {
91 | sb.append(Integer.toHexString(Integer.valueOf(radix2.substring(i * 4, (i + 1) * 4), 2)));
92 | }
93 | return sb.toString();
94 | }
95 |
96 | }
97 |
--------------------------------------------------------------------------------
/src/main/java/bs/tool/commongui/utils/SearchFileAndFolderNamePathParams.java:
--------------------------------------------------------------------------------
1 | package bs.tool.commongui.utils;
2 |
3 | import bs.tool.commongui.GuiUtils;
4 |
5 | import java.util.Map;
6 | import java.util.regex.Pattern;
7 |
8 | public class SearchFileAndFolderNamePathParams {
9 |
10 | public Boolean typeRepeatSearch;
11 | public Boolean typeSameNameSearch;
12 | public Boolean typeBlankSearch;
13 | public String fileType;
14 | public boolean containsFile;
15 | public boolean containsFolder;
16 | public boolean containsHidden;
17 | public boolean containsNotHidden;
18 | public boolean repeatSameSuffix;
19 | public Double sizeFrom;
20 | public Double sizeTo;
21 | public Long modifyTimeFrom;
22 | public Long modifyTimeTo;
23 | public String filePathCsText;
24 | public String filePathNCsText;
25 | public boolean filePathSRegex;
26 | public String fileNameCsText;
27 | public String fileNameNCsText;
28 | public boolean fileNameSRegex;
29 | public String folderPathCsText;
30 | public String folderPathNCsText;
31 | public boolean folderPathSRegex;
32 |
33 | public Pattern filePathCsPattern;
34 | public Pattern filePathNCsPattern;
35 | public Pattern fileNameCsPattern;
36 | public Pattern fileNameNCsPattern;
37 | public Pattern folderPathCsPattern;
38 | public Pattern folderPathNCsPattern;
39 | // 0表示不限制
40 | public int folderHierarchy;
41 |
42 | public SearchFileAndFolderNamePathParams(Map paramsMap) {
43 | typeRepeatSearch = Boolean.parseBoolean(GuiUtils.toString(paramsMap.get("type_repeatSearch")));
44 | typeSameNameSearch = Boolean.parseBoolean(GuiUtils.toString(paramsMap.get("type_sameNameSearch")));
45 | typeBlankSearch = Boolean.parseBoolean(GuiUtils.toString(paramsMap.get("type_blankSearch")));
46 | fileType = GuiUtils.toString(paramsMap.get("searchFileType"));
47 | containsFile = GuiUtils.parseFalse(paramsMap.get("containsFile"));
48 | containsFolder = GuiUtils.parseFalse(paramsMap.get("containsFolder"));
49 | containsHidden = GuiUtils.parseFalse(paramsMap.get("containsHidden"));
50 | containsNotHidden = GuiUtils.parseFalse(paramsMap.get("containsNotHidden"));
51 | repeatSameSuffix = GuiUtils.parseFalse(paramsMap.get("repeatSameSuffix"));
52 | sizeFrom = (Double) paramsMap.get("fileSizeFrom");
53 | sizeTo = (Double) paramsMap.get("fileSizeTo");
54 | modifyTimeFrom = (Long) paramsMap.get("modifyTimeFrom");
55 | modifyTimeTo = (Long) paramsMap.get("modifyTimeTo");
56 | filePathCsText = GuiUtils.toString(paramsMap.get("filePathContainsText"));
57 | filePathNCsText = GuiUtils.toString(paramsMap.get("filePathNotContainsText"));
58 | filePathSRegex = Boolean.parseBoolean(GuiUtils.toString(paramsMap.get("filePathSupportRegex")));
59 | fileNameCsText = GuiUtils.toString(paramsMap.get("fileNameContainsText"));
60 | fileNameNCsText = GuiUtils.toString(paramsMap.get("fileNameNotContainsText"));
61 | fileNameSRegex = Boolean.parseBoolean(GuiUtils.toString(paramsMap.get("fileNameSupportRegex")));
62 | folderPathCsText = GuiUtils.toString(paramsMap.get("folderPathContainsText"));
63 | folderPathNCsText = GuiUtils.toString(paramsMap.get("folderPathNotContainsText"));
64 | folderPathSRegex = Boolean.parseBoolean(GuiUtils.toString(paramsMap.get("folderPathSupportRegex")));
65 | if (GuiUtils.toString(paramsMap.get("folderHierarchyText")).length() != 0) {
66 | folderHierarchy = Integer.parseInt(GuiUtils.toString(paramsMap.get("folderHierarchyText")));
67 | } else {
68 | folderHierarchy = 0;
69 | }
70 |
71 | if (filePathSRegex) {
72 | filePathCsPattern = Pattern.compile(filePathCsText, Pattern.CASE_INSENSITIVE);
73 | filePathNCsPattern = Pattern.compile(filePathNCsText, Pattern.CASE_INSENSITIVE);
74 | }
75 | if (fileNameSRegex) {
76 | fileNameCsPattern = Pattern.compile(fileNameCsText, Pattern.CASE_INSENSITIVE);
77 | fileNameNCsPattern = Pattern.compile(fileNameNCsText, Pattern.CASE_INSENSITIVE);
78 | }
79 | if (folderPathSRegex) {
80 | folderPathCsPattern = Pattern.compile(folderPathCsText, Pattern.CASE_INSENSITIVE);
81 | folderPathNCsPattern = Pattern.compile(folderPathNCsText, Pattern.CASE_INSENSITIVE);
82 | }
83 | }
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/src/main/java/bs/tool/commongui/utils/SearchFileNameParams.java:
--------------------------------------------------------------------------------
1 | package bs.tool.commongui.utils;
2 |
3 | import bs.tool.commongui.GuiUtils;
4 |
5 | import java.util.Map;
6 | import java.util.regex.Pattern;
7 |
8 | public class SearchFileNameParams {
9 |
10 | public String fileNameCsText;
11 | public String fileNameNCsText;
12 | public boolean fileNameSRegex;
13 |
14 | public Pattern fileNameCsPattern;
15 | public Pattern fileNameNCsPattern;
16 |
17 | public SearchFileNameParams(Map paramsMap) {
18 | fileNameCsText = GuiUtils.toString(paramsMap.get("fileNameContainsText"));
19 | fileNameNCsText = GuiUtils.toString(paramsMap.get("fileNameNotContainsText"));
20 | fileNameSRegex = Boolean.parseBoolean(GuiUtils.toString(paramsMap.get("fileNameSupportRegex")));
21 | if (fileNameSRegex) {
22 | fileNameCsPattern = Pattern.compile(fileNameCsText, Pattern.CASE_INSENSITIVE);
23 | fileNameNCsPattern = Pattern.compile(fileNameNCsText, Pattern.CASE_INSENSITIVE);
24 | }
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/bs/tool/commongui/utils/SimpleMouseListener.java:
--------------------------------------------------------------------------------
1 | package bs.tool.commongui.utils;
2 |
3 | import java.awt.event.MouseEvent;
4 | import java.awt.event.MouseListener;
5 |
6 | public class SimpleMouseListener implements MouseListener {
7 |
8 | @Override
9 | public void mouseClicked(MouseEvent e) {
10 |
11 | }
12 |
13 | @Override
14 | public void mousePressed(MouseEvent e) {
15 |
16 | }
17 |
18 | @Override
19 | public void mouseReleased(MouseEvent e) {
20 |
21 | }
22 |
23 | @Override
24 | public void mouseEntered(MouseEvent e) {
25 |
26 | }
27 |
28 | @Override
29 | public void mouseExited(MouseEvent e) {
30 |
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/bs/tool/commongui/utils/TimeUtils.java:
--------------------------------------------------------------------------------
1 | package bs.tool.commongui.utils;
2 |
3 | /**
4 | * 时间工具类.
5 | */
6 | public class TimeUtils {
7 |
8 | /**
9 | * yyyy-MM-dd HH:mm:ss.
10 | */
11 | public static final String FORMATTER = "yyyy-MM-dd HH:mm:ss";
12 |
13 | /**
14 | * yyyy-MM-dd HH:mm:ss.SSS.
15 | */
16 | public static final String FORMATTER_MILLISECOND = "yyyy-MM-dd HH:mm:ss.SSS";
17 |
18 | /**
19 | * yyyy年MM月dd日HH时mm分ss秒.
20 | */
21 | public static final String FORMATTER_ZH = "yyyy年MM月dd日HH时mm分ss秒";
22 |
23 | /**
24 | * yyyy-MM-dd.
25 | */
26 | public static final String FORMATTER_YEAR = "yyyy-MM-dd";
27 |
28 | /**
29 | * yyyy年MM月dd日.
30 | */
31 | public static final String FORMATTER_ZH_YEAR = "yyyy年MM月dd日";
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/bs/tool/commongui/utils/interest/InterestUtils.java:
--------------------------------------------------------------------------------
1 | package bs.tool.commongui.utils.interest;
2 |
3 | import java.math.BigDecimal;
4 | import java.math.RoundingMode;
5 |
6 | public class InterestUtils {
7 |
8 | /**
9 | * 精度.
10 | */
11 | public final static int SCALE = 20;
12 |
13 | /**
14 | * 每月存款变化计算复利.
15 | *
16 | * @param principal 初始本金
17 | * @param amount 初始月存金额
18 | * @param monthDiff 每月差额
19 | * @param rate 月利率
20 | * @param months 存款月数
21 | */
22 | public static BigDecimal compoundInterest(BigDecimal principal, BigDecimal amount, BigDecimal monthDiff, BigDecimal rate, int months) {
23 | BigDecimal all = new BigDecimal(0);
24 | for (int m = 0; m < months; m++) {
25 | // 每月本金金额逐月递减
26 | all = all.add(fixedPrincipalCompoundInterest(amount.subtract(monthDiff.multiply(new BigDecimal(m))), rate, months - m));
27 | }
28 | return all.add(fixedPrincipalCompoundInterest(principal, rate, months));
29 | }
30 |
31 | /**
32 | * 固定本金计算复利.
33 | *
34 | * @param principal 本金
35 | * @param rate 月利率
36 | * @param months 存款月数
37 | */
38 | public static BigDecimal fixedPrincipalCompoundInterest(BigDecimal principal, BigDecimal rate, int months) {
39 | for (int s = 0; s < months; s++) {
40 | principal = principal.multiply(rate.add(new BigDecimal(1)));
41 | }
42 | return principal;
43 | }
44 |
45 | /**
46 | * 分期真实年化利率计算.
47 | * 二分最大次数100次进行计算,总本金差值精度精确到0.001.
48 | *
49 | * @param declaredPeriodRate 名义每期费率
50 | * @param periods 期数
51 | * @return
52 | */
53 | public static BigDecimal calculatePeriodActualRate(String declaredPeriodRate, int periods) {
54 | // 假定本金10000
55 | BigDecimal principal = new BigDecimal(10000);
56 | // 平均每期本金
57 | BigDecimal avgPrincipal = principal.divide(new BigDecimal(periods), InterestUtils.SCALE, RoundingMode.HALF_UP);
58 | // 利息总额
59 | BigDecimal interest = principal.multiply(new BigDecimal(declaredPeriodRate)).multiply(new BigDecimal(periods));
60 | // 每期还款额
61 | BigDecimal periodAmount = (interest.add(principal)).divide(new BigDecimal(periods), InterestUtils.SCALE, RoundingMode.HALF_UP);
62 | BigDecimal assumeRate = new BigDecimal(0);
63 | BigDecimal head = new BigDecimal(0);
64 | BigDecimal tail = avgPrincipal;
65 | // 使用二分推测首期本金
66 | BigDecimal firstPeriodPrincipal;
67 | // 二分最大次数100次进行计算,总本金差值精度精确到0.001
68 | for (int i = 0; i < 100; i++) {
69 | firstPeriodPrincipal = (head.add(tail)).divide(new BigDecimal(2));
70 | // 以首期还款额 = 总本金 * 实际月利率 + 首期本金 计算月利率
71 | assumeRate = (periodAmount.subtract(firstPeriodPrincipal)).divide(principal, InterestUtils.SCALE, RoundingMode.HALF_UP);
72 | BigDecimal assumePrincipal = new BigDecimal(0);
73 | BigDecimal assumePeriodPrincipal = firstPeriodPrincipal;
74 | for (int p = 0; p < periods; p++) {
75 | assumePrincipal = assumePrincipal.add(assumePeriodPrincipal);
76 | assumePeriodPrincipal = periodAmount.subtract(principal.subtract(assumePrincipal).multiply(assumeRate));
77 | }
78 | double s = principal.subtract(assumePrincipal).doubleValue();
79 | if (s >= -0.001 && s <= 0.001) {
80 | // System.out.println("calculateActualRate success times: " + i + ", head: " + head + ", tail: " + tail);
81 | break;
82 | } else if (s > 0.001) {
83 | head = firstPeriodPrincipal;
84 | } else if (s < -0.001) {
85 | tail = firstPeriodPrincipal;
86 | }
87 |
88 | }
89 | return assumeRate;
90 | }
91 |
92 | }
93 |
--------------------------------------------------------------------------------
/src/main/java/bs/tool/commongui/utils/interest/LendType.java:
--------------------------------------------------------------------------------
1 | package bs.tool.commongui.utils.interest;
2 |
3 | /**
4 | * 还款计息方式.
5 | */
6 | public enum LendType {
7 | /**
8 | * 等额本息.
9 | */
10 | Interest("等额本息"),
11 | /**
12 | * 等额本金.
13 | */
14 | Principal("等额本金");
15 |
16 | LendType(String desc) {
17 | this.desc = desc;
18 | }
19 |
20 | private String desc;
21 |
22 | public String getDesc() {
23 | return desc;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/bs/tool/eclipse/ProjectPropertiesDealInterface.java:
--------------------------------------------------------------------------------
1 | package bs.tool.eclipse;
2 |
3 | import javax.swing.*;
4 | import java.io.IOException;
5 |
6 | /**
7 | * Eclipse Project Properties Deal Interface.
8 | *
9 | * @author Baishui2004
10 | * @version 1.1
11 | * @date 2013-4-5
12 | */
13 | public interface ProjectPropertiesDealInterface {
14 |
15 | /**
16 | * 解析属性文件获得Project相关属性.
17 | */
18 | public void deal(String projectPath) throws IOException;
19 |
20 | /**
21 | * 是否是Eclipse 的Java Project、Dynamic Web Project或者MyEclipse的Web Project.
22 | */
23 | public boolean isJavaOrJavaWebEclipseProject(String projectPath);
24 |
25 | /**
26 | * 是否是Java Web Project.
27 | */
28 | public boolean isJavaWebProject();
29 |
30 | /**
31 | * 设置项目绝对路径.
32 | */
33 | public void setProjectPath(String projectPath);
34 |
35 | public void setRunLogTextArea(JTextArea runLogTextArea);
36 |
37 | /**
38 | * 获取项目绝对路径.
39 | */
40 | public String getProjectPath();
41 |
42 | /**
43 | * Java Compile Source.
44 | */
45 | public String getCompileSource();
46 |
47 | /**
48 | * Java Compile Target.
49 | */
50 | public String getCompileTarget();
51 |
52 | /**
53 | * 获取项目名称.
54 | */
55 | public String getProjectName();
56 |
57 | /**
58 | * 获取项目Java源码目录(可能多个).
59 | */
60 | public String[] getJavaSourcesPath();
61 |
62 | /**
63 | * 获取项目Java源码编译目录.
64 | */
65 | public String getOutputPath();
66 |
67 | /**
68 | * 获取项目Webapp目录.
69 | */
70 | public String getWebappPath();
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/src/main/java/bs/util/io/LinkedProperties.java:
--------------------------------------------------------------------------------
1 | package bs.util.io;
2 |
3 | import java.util.*;
4 |
5 | /**
6 | * copyright: https://stackoverflow.com/questions/1312383/pulling-values-from-a-java-properties-file-in-order
7 | */
8 | public class LinkedProperties extends Properties {
9 | private final HashSet