├── .gitignore ├── LICENSE ├── README.md ├── dest ├── ant │ ├── build-antScriptAutoBuild.xml │ ├── build.properties │ ├── build_generateJar.xml │ └── build_project.properties ├── antScriptAutoBuild-1.2.zip ├── common_gui_tools-1.1.zip ├── common_gui_tools-1.2.zip ├── common_gui_tools-1.21.zip ├── common_gui_tools-1.3.zip ├── common_gui_tools-1.4.zip └── common_gui_tools-1.5.zip ├── documention └── images │ ├── Ant Script Auto Build.png │ ├── Character Converter-1.png │ ├── Character Converter-2.png │ ├── Class Finder.png │ ├── Code Formatter.png │ ├── Color Tool.png │ ├── Encrypt And Decrypt.png │ ├── Escape Character Tool.png │ ├── File Digital Signature.png │ ├── Folder And File Operate.png │ ├── Interest Calculator.jpg │ ├── JNotify Visual.png │ ├── JODConverter Visual.png │ ├── JUniversal Chardet.png │ ├── Password Generator.jpg │ ├── QrCode Converter.png │ ├── Regex Tester-help.png │ ├── Regex Tester.png │ ├── Run Script.png │ ├── Simple Webview.png │ ├── System Information.png │ ├── Text File Split.png │ ├── Time Tool.png │ ├── ZHConverter Visual.png │ └── donate │ ├── alipay.jpg │ └── weixin.png ├── notice.txt ├── pom.xml ├── release-notes.txt └── src └── main ├── MANIFEST.MF ├── java └── bs │ ├── tool │ ├── ant │ │ └── AntScriptAutoBuild.java │ ├── commongui │ │ ├── AbstractGuiJPanel.java │ │ ├── GuiImagePanel.java │ │ ├── GuiMain.java │ │ ├── GuiUtils.java │ │ ├── code │ │ │ └── QrCodeUtil.java │ │ ├── plugins │ │ │ ├── AntScriptAutoBuild.java │ │ │ ├── CharacterConverter.java │ │ │ ├── ClassFinder.java │ │ │ ├── ColorTool.java │ │ │ ├── EncryptAndDecrypt.java │ │ │ ├── FileDigitalSignature.java │ │ │ ├── FolderAndFileOperate.java │ │ │ ├── InterestCalculator.java │ │ │ ├── RegexTester.java │ │ │ ├── RunScript.java │ │ │ ├── SystemInformation.java │ │ │ ├── TimeTool.java │ │ │ └── more │ │ │ │ ├── CodeFormatter.java │ │ │ │ ├── EscapeCharacterTool.java │ │ │ │ ├── JNotifyVisual.java │ │ │ │ ├── JODConverterVisual.java │ │ │ │ ├── JUniversalChardet.java │ │ │ │ ├── PasswordGenerator.java │ │ │ │ ├── QrCodeConverter.java │ │ │ │ ├── SimpleWebview.java │ │ │ │ ├── TextFileSplit.java │ │ │ │ └── ZHConverterVisual.java │ │ └── utils │ │ │ ├── CollectionUtils.java │ │ │ ├── EscapeUtils.java │ │ │ ├── ExcelUtils.java │ │ │ ├── FileUtils.java │ │ │ ├── LanguageUtils.java │ │ │ ├── MacUtils.java │ │ │ ├── NumberUtils.java │ │ │ ├── RadixUtils.java │ │ │ ├── SearchFileAndFolderNamePathParams.java │ │ │ ├── SearchFileNameParams.java │ │ │ ├── SimpleMouseListener.java │ │ │ ├── TimeUtils.java │ │ │ └── interest │ │ │ ├── InterestUtils.java │ │ │ ├── LendType.java │ │ │ ├── LoanInterestBean.java │ │ │ └── LoanInterestUtils.java │ └── eclipse │ │ ├── ProjectPropertiesDeal.java │ │ └── ProjectPropertiesDealInterface.java │ └── util │ ├── common │ └── CodecUtil.java │ └── io │ ├── LinkedProperties.java │ └── PropertiesUtils.java ├── resources └── simplelogger.properties ├── sources ├── bin │ ├── start.bat │ └── start.sh ├── conf │ ├── AntScriptAutoBuild │ │ ├── conf.properties │ │ ├── properties │ │ │ ├── base │ │ │ ├── checkstyle │ │ │ ├── findbugs │ │ │ ├── jar │ │ │ ├── java2html │ │ │ ├── jsch │ │ │ ├── junit │ │ │ ├── mail │ │ │ ├── pmd │ │ │ ├── tomcat │ │ │ ├── war │ │ │ └── yuicompressor │ │ ├── readme.txt │ │ └── script │ │ │ ├── base │ │ │ ├── checkstyle │ │ │ ├── findbugs │ │ │ ├── jar │ │ │ ├── jautodoc │ │ │ ├── java2html │ │ │ ├── javadoc │ │ │ ├── jsch │ │ │ ├── junit │ │ │ ├── mail │ │ │ ├── pmd │ │ │ ├── tomcat │ │ │ ├── war │ │ │ └── yuicompressor │ ├── ClassFinder │ │ └── conf.properties │ ├── FolderAndFileOperate │ │ └── filetype.properties │ ├── JODConverterVisual │ │ └── converter.properties │ ├── JUniversalChardet │ │ └── searchFiletypes.properties │ ├── RegexTester │ │ ├── expression.properties │ │ └── help.txt │ ├── SimpleWebview │ │ └── index.html │ ├── TextFileSplit │ │ └── searchFiletypes.properties │ ├── common_gui_tools.properties │ └── tools.properties ├── img │ ├── cgt_blank.png │ ├── donate │ │ ├── alipay.jpg │ │ └── weixin.png │ └── icon │ │ ├── cgt_About.png │ │ ├── cgt_AntScriptAutoBuild.png │ │ ├── cgt_CharacterConverter.png │ │ ├── cgt_ClassFinder.png │ │ ├── cgt_Close.png │ │ ├── cgt_CodeFormatter.png │ │ ├── cgt_ColorTool.png │ │ ├── cgt_Donate.png │ │ ├── cgt_EncryptAndDecrypt.png │ │ ├── cgt_EscapeCharacterTool.png │ │ ├── cgt_Exit.png │ │ ├── cgt_FileDigitalSignature.png │ │ ├── cgt_FolderAndFileOperate.png │ │ ├── cgt_Font.png │ │ ├── cgt_HttpClient.png │ │ ├── cgt_Icon.png │ │ ├── cgt_InterestCalculator.png │ │ ├── cgt_JNotifyVisual.png │ │ ├── cgt_JODConverterVisual.png │ │ ├── cgt_JUniversalChardet.png │ │ ├── cgt_PasswordGenerator.png │ │ ├── cgt_QrCodeConverter.png │ │ ├── cgt_RegexTester.png │ │ ├── cgt_RunScript.png │ │ ├── cgt_SimpleWebview.png │ │ ├── cgt_SystemInformation.png │ │ ├── cgt_TextFileSplit.png │ │ ├── cgt_TimeTool.png │ │ ├── cgt_ZHConverterVisual.png │ │ └── readme └── lib │ ├── DJNativeSwing-1.0.3-20140708.jar │ ├── DJNativeSwing-SWT-1.0.3-20140708.jar │ ├── ZHConverter.jar │ └── jnotify-0.94_improve-1.0.jar └── zip.xml /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | 3 | .idea 4 | *.iml 5 | *.ipr 6 | *.iws 7 | .DS_Store 8 | dest/.DS_Store 9 | common_gui_tools.log -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Java GUI实用小工具集 Common Gui Tools 2 | ===================================== 3 | 4 | ### 简介 ### 5 | Common Gui Tools 是用java编写,GUI界面的实用小工具集,1.5版分六个类别22个小工具。 6 | 7 | ### 安装 ### 8 | 1. Require Java 6.0+ 9 | 2. 下载压缩包common_gui_tools-1.5.zip,解压,Windows下双击start.bat运行,Mac或Linux下双击start.sh运行 10 | 3. 软件打开后通过菜单栏Character Tools、File Tools等选择要打开的工具 11 | 12 | ### 工具集索引 ### 13 | #### 字符集工具集 #### 14 | 1. 编码转换:Character Converter 15 | 2. 加密解密:Encrypt And Decrypt 16 | 3. 字符转义工具:Escape Character Tool 17 | 4. 文本编码识别:JUniversal Chardet 18 | #### 文件工具集 #### 19 | 1. 计算文件数字签名:File Digital Signature 20 | 2. 文件(夹)查找操作:Folder And File Operate 21 | 3. 文件(夹)变化监控:JNotify Visual 22 | 4. OpenOffice文档转换:JODConverter Visual 23 | 5. 文本文件切分:Text File Split 24 | #### 常用工具集 #### 25 | 1. Code格式化:Code Formatter 26 | 2. 随机密码生成:Password Generator 27 | 3. 二维码转换:QrCode Converter 28 | 4. 正则表达式验证:Regex Tester 29 | 5. 执行Script脚本:Run Script 30 | 6. 时间工具:Time Tool 31 | 7. 中文简体繁体互转:ZHConverter Visual 32 | #### 金融工具集 #### 33 | 1. 利息利率计算器:Interest Calculator 34 | #### 其他工具集 #### 35 | 1. 颜色工具:Color Tool 36 | 2. 运行环境信息:System Information 37 | #### 过时工具集 #### 38 | 1. Ant脚本自动build:Ant Script Auto Build 39 | 2. Java类查找:Class Finder 40 | 3. 简易Webview:Simple Webview 41 | 42 | ### 配置说明 ### 43 | ``` 44 | 1,本软件采用插件方式,22个小工具即是22个插件,插件配置文件夹conf, 45 | 配置文件有:common_gui_tools.properties、tools.properties以及多个插件的配置; 46 | 2,相关配置说明参看各配置文件,可通过修改文件common_gui_tools.properties中属性CommonUseTools修改常用插件; 47 | 默认加载插件Encrypt And Decrypt、Folder And File Operate、Time Tool、Code Formatter; 48 | 3,可通过GUISkin属性修改软件皮肤,fontStyles系列属性修改显示字体。 49 | ``` 50 | 51 | ### 开发说明 ### 52 | ``` 53 | 1,启动类:bs.tool.commongui.GuiMain,参见:src/main/MANIFEST.MF; 54 | 2,本地开发运行前先执行mvn clean package,以将src/main/sources下资源拷贝到target,否则运行时会找不到配置文件及图片; 55 | ``` 56 | 57 | ### 捐助本项目 ### 58 | 支持长远发展,感谢您的认可! 59 |
微信 60 | ![Donate weixin](./documention/images/donate/weixin.png) 61 |
支付宝 62 | ![Donate alipay](./documention/images/donate/alipay.jpg) 63 | 64 | ### 详细介绍 ### 65 | 以下详细简绍每个小工具: 66 | #### 字符集工具集 #### 67 | 1. 编码转换:Character Converter 68 | (1),编码:Encode String表单输入字符,点击右侧对应的Encode按钮,对输入字符进行编码,注意此时的编码类别是“二进制”、“八进制”、“十进制”、“十六进制”,对应的可以使用下面的Decode进行解码 69 | ![Character Converter](./documention/images/Character%20Converter-1.png) 70 | (2),乱码解码:选择编码类别“乱码解码”,比如在Big5表单中输入“趼睫”,点击右侧对应Decode按钮,GBK表单中解码出字符“字符” 71 | ![Character Converter](./documention/images/Character%20Converter-2.png) 72 | 73 | 2. 加密解密:Encrypt And Decrypt 74 | 加密解密:默认字符集UTF-8,另可选其他常用字符集,前五种算法可解密,后五种算法不可逆 75 | ![Encrypt And Decrypt](./documention/images/Encrypt%20And%20Decrypt.png) 76 | 77 | 3. 字符转义工具:Escape Character Tool 78 | HTML、XML、JAVA、JavaScript、CSV字符转义字符及还原,使用Apache Commons-lang的StringEscapeUtils类 79 | ![Escape Character Tool](./documention/images/Escape%20Character%20Tool.png) 80 | 81 | 4. 文本编码识别:JUniversal Chardet 82 | 检测文件编码,识别准确率高(有一定的误差) 83 | ![JUniversal Chardet](./documention/images/JUniversal%20Chardet.png) 84 | 项目:juniversalchardet 85 | 文档:Mozilla UniversalCharsetDetection 86 | 其他编码识别项目:jchardet  cpdetector  Charset Detect Stream Reader 87 | 88 | #### 文件工具集 #### 89 | 1. 计算文件数字签名:File Digital Signature 90 | 计算文件/文件夹子文件的MD5、SHA1值,支持计算大文件,支持对文件名的正则过滤,对满足条件的文件进行计算 91 | ![File Digital Signature](./documention/images/File%20Digital%20Signature.png) 92 | 93 | 2. 文件(夹)查找操作Folder And File Operate 94 | (1)此工具功能丰富,可通过多种条件(名称,类型,时间,大小,其中名称包括后缀名且不区分大小写)查找文件(夹) 95 | (2)不仅包括文件(夹)查找,也包括复制、剪切、删除文件及删除空文件夹 96 | (3)通过工具界面可了解其详细功能,注意操作类型非“默认查找”时,需谨慎操作,以防误删除文件 97 | (4)文件类型配置文件conf\FolderAndFileOperate\filetype.properties 98 | ![Folder And File Operate](./documention/images/Folder%20And%20File%20Operate.png) 99 | 100 | 3. 文件(夹)变化监控:JNotify Visual 101 | 使用JNotify监控文件(夹)增删改及重命名 102 | ![JNotify Visual](./documention/images/JNotify%20Visual.png) 103 | 关于JNotify Visual使用的类包jnotify-0.94_improve-1.0.jar,改进自jnotify-0.94,项目地址:http://code.google.com/p/improve-lgpl-jars/ 104 | 105 | 4. OpenOffice文档转换:JODConverter Visual 106 | 可视化文档转换,支持常见文档的相互转换,如doc/docx转pdf、rtf、text、html,xls/xlsx转pdf、csv、tsv、html,支持的详细转换类型具体参见插件,需Openoffice后台服务支持 107 | ![JODConverter Visual](./documention/images/JODConverter%20Visual.png) 108 | 测试OpenOffice版本:3.4 109 | 配置文件:conf/JODConverterVisual/converter.properties 110 | 转换文档:Supported Formats  Document Conversion with OpenOffice 111 | 112 | 5. 文本文件切分:Text File Split 113 | 按大小或行数切分文件 114 | ![Text File Split](./documention/images/Text%20File%20Split.png) 115 | 116 | #### 常用工具集 #### 117 | 1. Code格式化:Code Formatter 118 | 代码格式化,目前仅支持Json 119 | ![Code Formatter](./documention/images/Code%20Formatter.png) 120 | 项目:gson 121 | 122 | 2. 随机密码生成:Password Generator 123 | 使用类库:https://github.com/vt-middleware/passay 124 | ![Password Generator](./documention/images/Password%20Generator.jpg) 125 | 126 | 3. 二维码转换:QrCode Converter 127 | 二维码生成、解析 128 | ![QrCode Converter](./documention/images/QrCode%20Converter.png) 129 | 项目:zxing 130 | 131 | 4. 正则表达式验证:Regex Tester 132 | 常用正则表达式文件conf\RegexTester\expression.properties 133 | ![Regex Tester](./documention/images/Regex%20Tester.png) 134 | ![Regex Tester help](./documention/images/Regex%20Tester-help.png) 135 | 136 | 5. 执行Script脚本:Run Script 137 | 此工具简单目前仅可进行简单的计算 138 | ![Run Script](./documention/images/Run%20Script.png) 139 | 140 | 6. 时间工具:Time Tool 141 | 时间字符串与时间戳的相互转换 142 | ![Time Tool](./documention/images/Time%20Tool.png) 143 | 144 | 7. 中文简体繁体互转:ZHConverter Visual 145 | ![ZHConverter Visual](./documention/images/ZHConverter%20Visual.png) 146 | 项目:java-zhconverter 147 | 148 | #### 金融工具集 #### 149 | 1. 利息利率计算器:Interest Calculator 150 | 包括:贷款利率计算、等额本金与等额本息比较计算、提前还款计算、分期名义利率真实利率计算 151 | ![Interest Calculator](./documention/images/Interest%20Calculator.jpg) 152 | 153 | #### 其他工具集 #### 154 | 1. 颜色工具:Color Tool 155 | 此工具可进行颜色RGB码与HTML码的相互转换,调色板显示所填写颜色的效果以及选择颜色 156 | ![Color Tool](./documention/images/Color%20Tool.png) 157 | 158 | 2. 运行环境信息:System Information 159 | 此工具可查看运行机器的Overview(基础信息)、Running Status、System Properties、支持的字符集、字体 160 | ![System Information](./documention/images/System%20Information.png) 161 | 162 | #### 过时工具集 #### 163 | 1. Ant脚本自动build: Ant Script Auto Build 164 | 通过解析Eclipse的Java Project、Dynamic Web Project或者MyEclipse的Web Project的相关配置文件,自动构建者这三类Project的Ant脚本 165 | ![Ant Script Auto Build](./documention/images/Ant%20Script%20Auto%20Build.png) 166 | Ant Script Auto Build也提供独立版本,下载文件:antScriptAutoBuild-1.21.zip 167 | 168 | 2. Java类查找:Class Finder 169 | 查找文件夹下的.class及.java文件,或者文件夹下压缩文件jar,war,aar,ear,zip内的.class及.java文件 170 | ![Class Finder](./documention/images/Class%20Finder.png) 171 | 可配置查找的文件类型(不限于.class及.java文件,可通过配置扩展用于查找其他类型的文件),压缩文件限于java.util.zip.ZipEntry类可解析的类型,配置文件参见conf\ClassFinder\conf.properties 172 | 173 | 3. 简易Webview:Simple Webview 174 | 说明:Windows系统下可用,Mac及Linux系统下暂不可用 175 | ![Simple Webview](./documention/images/Simple%20Webview.png) 176 | 项目:The DJ Project -------------------------------------------------------------------------------- /dest/ant/build-antScriptAutoBuild.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | antScriptAutoBuild 9 | 10 | 1.2 11 | 12 | bs.util.tool.ant.AntScriptAutoBuild 13 | 14 | bs/util/web/tool/eclipse/*,bs/util/tool/ant/* 15 | 16 | **/package-info.java 17 | 18 | 19 | 20 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | WebContent/WEB-INF/conf/AntScriptAutoBuild/ 38 | 39 | ${project.name}-${project.version}.jar 40 | 41 | ${project.name}-${project.version}.zip 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /dest/ant/build.properties: -------------------------------------------------------------------------------- 1 | ############基本任务properties属性配置############ 2 | 3 | #properties 构建者信息 4 | build.author.name=baishui2004 5 | build.author.email=bs2004@163.com 6 | 7 | #properties 项目信息 8 | project.compile.source=1.6 9 | project.compile.target=1.6 10 | 11 | #产出物目录(JAR, WAR, Java Doc, 测试报告等等) 12 | dir.dest=dest 13 | #Java源码目录 14 | dir.src=src 15 | #编译好的字节码目录 16 | dir.classes=${dir.dest}/output 17 | 18 | #filter替换属性配置文件 19 | properties.filter.file=${dir.dest}/ant/build_project.properties 20 | #filter替换好的属性配置文件 21 | properties.replaced.file=${dir.dest}/ant/build_project-replace.properties 22 | -------------------------------------------------------------------------------- /dest/ant/build_generateJar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 |
43 | 44 | 45 | 46 | 47 |
48 |
49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 |
60 |
61 |
62 | 63 |
64 |
65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 |
-------------------------------------------------------------------------------- /dest/ant/build_project.properties: -------------------------------------------------------------------------------- 1 | ############以下属性配置用于被Ant Filter任务替换############ 2 | 3 | #Project名称 4 | project.name=@project.name@ 5 | #Project版本 6 | project.version=@project.version@ 7 | #Project入口程序 8 | project.main.class=@project.main.class@ 9 | #编译打包包括的源文件 10 | project.includes.java.sources=@project.includes.java.sources@ 11 | #打包排除的源文件 12 | project.excludes.java.sources=@project.excludes.java.sources@ 13 | 14 | #打包源码的jar 15 | file.sourceJarfile=${project.name}-${project.version}-sources.jar 16 | #打包字节码的jar 17 | file.jarfile=${project.name}-${project.version}.jar -------------------------------------------------------------------------------- /dest/antScriptAutoBuild-1.2.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baishui2004/common_gui_tools/2da4ea20df590b50a66129e640165aea87e13b6e/dest/antScriptAutoBuild-1.2.zip -------------------------------------------------------------------------------- /dest/common_gui_tools-1.1.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baishui2004/common_gui_tools/2da4ea20df590b50a66129e640165aea87e13b6e/dest/common_gui_tools-1.1.zip -------------------------------------------------------------------------------- /dest/common_gui_tools-1.2.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baishui2004/common_gui_tools/2da4ea20df590b50a66129e640165aea87e13b6e/dest/common_gui_tools-1.2.zip -------------------------------------------------------------------------------- /dest/common_gui_tools-1.21.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baishui2004/common_gui_tools/2da4ea20df590b50a66129e640165aea87e13b6e/dest/common_gui_tools-1.21.zip -------------------------------------------------------------------------------- /dest/common_gui_tools-1.3.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baishui2004/common_gui_tools/2da4ea20df590b50a66129e640165aea87e13b6e/dest/common_gui_tools-1.3.zip -------------------------------------------------------------------------------- /dest/common_gui_tools-1.4.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baishui2004/common_gui_tools/2da4ea20df590b50a66129e640165aea87e13b6e/dest/common_gui_tools-1.4.zip -------------------------------------------------------------------------------- /dest/common_gui_tools-1.5.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baishui2004/common_gui_tools/2da4ea20df590b50a66129e640165aea87e13b6e/dest/common_gui_tools-1.5.zip -------------------------------------------------------------------------------- /documention/images/Ant Script Auto Build.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baishui2004/common_gui_tools/2da4ea20df590b50a66129e640165aea87e13b6e/documention/images/Ant Script Auto Build.png -------------------------------------------------------------------------------- /documention/images/Character Converter-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baishui2004/common_gui_tools/2da4ea20df590b50a66129e640165aea87e13b6e/documention/images/Character Converter-1.png -------------------------------------------------------------------------------- /documention/images/Character Converter-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baishui2004/common_gui_tools/2da4ea20df590b50a66129e640165aea87e13b6e/documention/images/Character Converter-2.png -------------------------------------------------------------------------------- /documention/images/Class Finder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baishui2004/common_gui_tools/2da4ea20df590b50a66129e640165aea87e13b6e/documention/images/Class Finder.png -------------------------------------------------------------------------------- /documention/images/Code Formatter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baishui2004/common_gui_tools/2da4ea20df590b50a66129e640165aea87e13b6e/documention/images/Code Formatter.png -------------------------------------------------------------------------------- /documention/images/Color Tool.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baishui2004/common_gui_tools/2da4ea20df590b50a66129e640165aea87e13b6e/documention/images/Color Tool.png -------------------------------------------------------------------------------- /documention/images/Encrypt And Decrypt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baishui2004/common_gui_tools/2da4ea20df590b50a66129e640165aea87e13b6e/documention/images/Encrypt And Decrypt.png -------------------------------------------------------------------------------- /documention/images/Escape Character Tool.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baishui2004/common_gui_tools/2da4ea20df590b50a66129e640165aea87e13b6e/documention/images/Escape Character Tool.png -------------------------------------------------------------------------------- /documention/images/File Digital Signature.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baishui2004/common_gui_tools/2da4ea20df590b50a66129e640165aea87e13b6e/documention/images/File Digital Signature.png -------------------------------------------------------------------------------- /documention/images/Folder And File Operate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baishui2004/common_gui_tools/2da4ea20df590b50a66129e640165aea87e13b6e/documention/images/Folder And File Operate.png -------------------------------------------------------------------------------- /documention/images/Interest Calculator.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baishui2004/common_gui_tools/2da4ea20df590b50a66129e640165aea87e13b6e/documention/images/Interest Calculator.jpg -------------------------------------------------------------------------------- /documention/images/JNotify Visual.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baishui2004/common_gui_tools/2da4ea20df590b50a66129e640165aea87e13b6e/documention/images/JNotify Visual.png -------------------------------------------------------------------------------- /documention/images/JODConverter Visual.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baishui2004/common_gui_tools/2da4ea20df590b50a66129e640165aea87e13b6e/documention/images/JODConverter Visual.png -------------------------------------------------------------------------------- /documention/images/JUniversal Chardet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baishui2004/common_gui_tools/2da4ea20df590b50a66129e640165aea87e13b6e/documention/images/JUniversal Chardet.png -------------------------------------------------------------------------------- /documention/images/Password Generator.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baishui2004/common_gui_tools/2da4ea20df590b50a66129e640165aea87e13b6e/documention/images/Password Generator.jpg -------------------------------------------------------------------------------- /documention/images/QrCode Converter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baishui2004/common_gui_tools/2da4ea20df590b50a66129e640165aea87e13b6e/documention/images/QrCode Converter.png -------------------------------------------------------------------------------- /documention/images/Regex Tester-help.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baishui2004/common_gui_tools/2da4ea20df590b50a66129e640165aea87e13b6e/documention/images/Regex Tester-help.png -------------------------------------------------------------------------------- /documention/images/Regex Tester.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baishui2004/common_gui_tools/2da4ea20df590b50a66129e640165aea87e13b6e/documention/images/Regex Tester.png -------------------------------------------------------------------------------- /documention/images/Run Script.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baishui2004/common_gui_tools/2da4ea20df590b50a66129e640165aea87e13b6e/documention/images/Run Script.png -------------------------------------------------------------------------------- /documention/images/Simple Webview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baishui2004/common_gui_tools/2da4ea20df590b50a66129e640165aea87e13b6e/documention/images/Simple Webview.png -------------------------------------------------------------------------------- /documention/images/System Information.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baishui2004/common_gui_tools/2da4ea20df590b50a66129e640165aea87e13b6e/documention/images/System Information.png -------------------------------------------------------------------------------- /documention/images/Text File Split.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baishui2004/common_gui_tools/2da4ea20df590b50a66129e640165aea87e13b6e/documention/images/Text File Split.png -------------------------------------------------------------------------------- /documention/images/Time Tool.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baishui2004/common_gui_tools/2da4ea20df590b50a66129e640165aea87e13b6e/documention/images/Time Tool.png -------------------------------------------------------------------------------- /documention/images/ZHConverter Visual.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baishui2004/common_gui_tools/2da4ea20df590b50a66129e640165aea87e13b6e/documention/images/ZHConverter Visual.png -------------------------------------------------------------------------------- /documention/images/donate/alipay.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baishui2004/common_gui_tools/2da4ea20df590b50a66129e640165aea87e13b6e/documention/images/donate/alipay.jpg -------------------------------------------------------------------------------- /documention/images/donate/weixin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baishui2004/common_gui_tools/2da4ea20df590b50a66129e640165aea87e13b6e/documention/images/donate/weixin.png -------------------------------------------------------------------------------- /notice.txt: -------------------------------------------------------------------------------- 1 | 1,文件(夹)查找操作:Folder And File Operate 2 | 优化方案:2013-9-25,取出有相同大小的所有文件,比较文件大小以及前2048Byte的内容的MD5值是否一样,如果两者相同,则认为重复,否则认为不重复,有较小的误差率。 3 | 旧版方案:2013-3-9,没使用Md5值,考虑是速度会比较慢。用比较文件后缀名及文件大小,如果两者相同,则认为重复,否则认为不重复,有一定的误差率。 4 | Map<"type:后缀名,size:文件大小", List>,判断List.size()>1,则加入List<"type:后缀名,size:文件大小">中。 5 | 2,bs.tool.commongui.plugins.more中的插件,需要依赖第三方类包,插件加载配置在配置文件conf/tools.properties中,如不需使用某个插件,则可依照如下操作进行精简: 6 | (1),注释或删掉配置文件conf/tools.properties中的插件加载配置; 7 | (2),对照以下的Java依赖包说明删掉上一步插件的对应类包。 8 | 9 | 10 | 11 | Java依赖包说明: 12 | 1, commons-codec-*.jar 类bs.util.common.CodecUtil.java 13 | 插件Character Converter类bs.util.tool.commongui.plugins.CharacterConverter.java 14 | 插件Encrypt And Decrypt类bs.util.tool.commongui.plugins.EncryptAndDecrypt.java 15 | 2, commons-io-*.jar 多个插件使用此类包中类 16 | 类包来源:http://commons.apache.org/proper/commons-io/index.html 17 | 3, commons-lang-*.jar 类bs.tool.commongui.utils.EscapeUtils.java 18 | 插件Escape Character Tool类bs.util.tool.commongui.plugins.more.EscapeCharacterTool.java 19 | 类包来源:http://commons.apache.org/proper/commons-lang/index.html 20 | 4, jnotify-0.94_improve-1.0.jar 插件JNotify Visual类bs.util.tool.commongui.plugins.more.JNotifyVisual.java 21 | 类包来源:http://code.google.com/p/improve-lgpl-jars/ 22 | 5, juniversalchardet-1.0.3.jar 插件JUniversal Chardet类bs.util.tool.commongui.plugins.more.JUniversalChardet.java 23 | 类包来源:https://code.google.com/p/juniversalchardet/ 24 | https://github.com/thkoch2001/juniversalchardet 25 | Mozilla Project: https://www-archive.mozilla.org/projects/intl/chardet.html 26 | 6, ZHConverter.jar 插件ZHConverter Visual类bs.util.tool.commongui.plugins.more.ZHConverterVisual.java 27 | 类包来源:https://code.google.com/p/java-zhconverter/ 28 | 7, zxing-*.jar 插件QrCode Converter类bs.tool.commongui.plugins.more.QrCodeConverter.java 29 | 包含:javase-*.jar, core-2.2.jar 30 | 8, gson-*.jar 插件Code Formatter类bs.tool.commongui.plugins.more.CodeFormatter.java 31 | 9, passay-*.jar 插件Password Generator类bs.tool.commongui.plugins.more.PasswordGenerator.java 32 | 10, jxl-*.jar 插件Interest Calculator类bs.tool.commongui.plugins.InterestCalculator.java导出Excel使用 33 | 11, slf4j-api-*.jar, slf4j-simple-*.jar slf4j日志依赖类包 34 | 35 | @Deprecated 36 | 1, jodconverter/*.jar 插件JODConverter Visual类bs.util.tool.commongui.plugins.more.JODConverterVisual.java 37 | 包括:jodconverter-*.jar, juh-*.jar, jurt-*.jar, ridl-*.jar, unoil-*.jar 38 | 类包来源:http://www.artofsolving.com/opensource/jodconverter/ 39 | https://sourceforge.net/projects/jodconverter/files/JODConverter/ 40 | http://mvnrepository.com/artifact/com.artofsolving/jodconverter/ 41 | New: https://github.com/mirkonasato/jodconverter/ 42 | 2, DJNativeSwing, swt.win32.x86_64 插件Simple Webview类bs.util.tool.commongui.plugins.more.SimpleWebview.java 43 | 包括:DJNativeSwing-*.jar, DJNativeSwing-SWT-*.jar, org.eclipse.swt.win32.win32.x86_64-*.jar 44 | 类包来源:https://sourceforge.net/projects/djproject/files/DJ Native Swing/ 45 | https://mvnrepository.com/artifact/org.eclipse.swt/org.eclipse.swt.win32.win32.x86_64/4.3 46 | other platform: https://mvnrepository.com/artifact/org.eclipse.swt Standard Widget Toolkit 47 | -------------------------------------------------------------------------------- /release-notes.txt: -------------------------------------------------------------------------------- 1 | Version 1.5 2021-3-10 2 | 1,完善插件:文件(夹)查找操作(Folder And File Operate),增加只遍历X级设置;同名文件查询,可选择是否相同后缀名; 3 | 优化重复文件查找速度; 4 | 2,完善插件:Code格式化Code Formatter,增加去除json的value,用来对比schema(字符型改空"",数字型改0,换行符统一为\n); 5 | 3,增加插件:利息利率计算器Interest Calculator,包括:贷款利率计算、等额本金与等额本息比较计算、提前还款计算、分期名义利率真实利率计算; 6 | 4,增加插件:随机密码生成Password Generator,使用类库:https://github.com/vt-middleware/passay; 7 | 5,优化内容:Mac系统上展示程序名称;Mac系统上暂改使用Monaco字体; 8 | 9 | 10 | 11 | Version 1.4 2018-4-22 12 | 1,改为Maven项目; 13 | 2,删除插件:短网址转换Short URL; 2018-2-14 14 | 3,增加插件:二维码转换QrCode Converter; 2018-2-26 15 | 4,增加插件:Code格式化Code Formatter; 2018-2-27 16 | 5,增加插件:文本文件切分Text File Split; 2018-3-14 17 | 6,增加插件:简易Webview Simple Webview; 2018-3-24 18 | 7,插件编码转换:Character Converter支持Decode的字符中含有非编码字符; 2018-4-22 19 | 20 | 21 | 22 | Version 1.3 2015-4-22 23 | 1,增加插件:时间工具Time Tool; 2015-4-22 24 | 25 | 26 | 27 | Version 1.21 2014-11-27 28 | 1,完善插件:文件(夹)查找操作(Folder And File Operate),增加同名文件查找(比较文件名,不比较后缀名,查找相同文件名称的文件); 2014-11-27 29 | 30 | 31 | 32 | Version 1.2 2014-8-28 33 | 1,增加插件:短网址转换Short URL; 2014-8-28 34 | 2,增加插件:颜色工具Color Tool; 2014-8-29 35 | 3,增加插件:字符转义工具Escape Character Tool; 2014-8-29 36 | 37 | 38 | 39 | Version 1.1 2013-12-6 40 | 1,改善错误日志输出,增加Console日志输出域; 2013-11-22 41 | 2,修改插件:OpenOffice文档转换JODConverter Visual,增加“目标文件名是否保留原始文件类型”及“是否作为文本处理”; 2013-11-24 42 | 3,增加插件:Java类查找Class Finder,可查找文件夹下的.class及.java文件,以及文件夹下jar、zip中的.class及.java; 2013-12-2 43 | 4,修复BUG:在Windows下对无权限访问文件夹进行listFiles()出现NullPointer异常,此时listFiles()==null,解决方法即对此做判断; 2013-12-4 44 | 5,修复BUG:Ant脚本自动build插件Ant Script Auto Build,Project的Java Compiler未设置“Enable project specific settings”找不到文件“.settings/org.eclipse.jdt.core.prefs”; 2013-12-6 45 | 6,完善插件:Java类查找Class Finder,可配置查找的文件类型(不限于.class及.java文件),压缩文件限于java.util.zip.ZipEntry类可解析的类型; 2013-12-26 46 | 47 | 48 | 49 | Version 1.03 2013-10-1 50 | 1,修改JTextArea为自动换行,setLineWrap(true); 2013-4-28 51 | 2,完善插件文件(夹)查找操作(Folder And File Operate)的结果输出统计; 2013-4-30 52 | 3,增加插件:中文简体繁体互转ZHConverter Visual; 2013-5-1 53 | 4,将需要依赖第三方类包(除commons-codec-*.jar)的插件规划分配到类包bs.util.tool.commongui.plugins.more下。 2013-5-1 54 | 5,URL.getPath()处理不了中文或带空格的路径,修改为URLDecoder.decode(path, "UTF-8")("+"号decode后为空格" ",所以decode前使用"%2b"替换"+"号); 2013-5-10 55 | 6,插件编码转换Character Converter增加手动输入编码转换; 2013-8-8 56 | 7,简化精炼属性配置及属性读取; 2013-8-8 57 | 9,增加插件的关闭图标,位于插件title栏右侧,左侧是插件图标; 2013-8-8 58 | 10,增加插件:文本编码识别JUniversal Chardet; 2013-8-9 59 | 11,增加插件:计算文件数字签名File Digital Signature,支持计算大文件; 2013-8-10 60 | 12,修改插件:文件(夹)查找操作(Folder And File Operate),2013-9-25 61 | 操作类型选择非查找操作的提示框需点击两次才关闭,改为点击一次确定即关闭,代码jComboBox.transferFocus(); 62 | 文件显示大小由显示M改增加选择项G、KB、Byte,默认M; 63 | 重复文件查找方案优化为:取出有相同大小的所有文件,比较文件大小以及前2048Byte的内容的MD5值是否一样,如果两者相同,则认为重复,否则认为不重复,有较小的误差率; 64 | 增加查找条件:文件/夹路径包含字符,文件/夹路径不包含字符;2013-9-29 65 | 13,优化Windows下的启动,使用“start javaw”代替“java”命令以关闭悬停的CMD窗口,增加VM参数“-Xms48m”加快程序的启动; 66 | 14,修改插件:编码转换:Character Converter,增加MD5加密的16位值输出(算法:取MD5值32位的第9到24个字符);2013-9-26 67 | 15,修改插件:Ant脚本自动build: Ant Script Auto Build,优化原jar任务为base + jar任务,base及jar任务默认选中(base任务为必选);2013-9-26 68 | 16,优化插件的异常输出以及提炼文件查找的重复代码;2013-9-30 69 | 17,将插件文件(夹)变化监控JNotify Visual使用的类包由jnotify-0.93_improve-1.0.jar升级为jnotify-0.94_improve-1.0.jar;2013-9-30 70 | 18,增加插件:OpenOffice文档转换JODConverter Visual;2013-10-1 71 | 72 | 73 | 74 | Version 1.02 2013-4-5 75 | 76 | 1,将配置从类路径下移到与lib同级的conf目录下,将图标从类路径下移到与lib同级的img/icon目录下,方便修改; 77 | 2,增加插件:Ant脚本自动build: Ant Script Auto Build,通过解析Eclipse的Java Project、Dynamic Web Project或者MyEclipse的Web Project的相关配置文件, 78 | 自动构建者这三类Project的Ant脚本。 79 | 80 | 81 | 82 | Version 1.01 2013-3-26 83 | 84 | 1,解决插件“编码转换:Character Converter”的二进制转换错误BUG,并增加八进制、十进制编码转换。 2013-3-23 85 | 2,增加插件:文件(夹)变化监控:JNotify Visual,使用JNotify监控文件(夹)增删改及重命名。 86 | 注意:文件的剪切(move)操作,Windows下JNotify识别为删除操作,而Deepin 12.06(Linux其他版本待测试)却不识别。 87 | 88 | 89 | 90 | Version 1.0 2013-3-20 91 | 92 | Common Gui Tools是用java编写,GUI界面的实用小工具集,暂有6个小工具: 93 | 94 | 1,编码转换:Character Converter 95 | 2,加密解密:Encrypt And Decrypt 96 | 3,正则表达式验证:Regex Tester 97 | 4,执行Script脚本:Run Script 98 | 5,文件(夹)查找操作:Folder And File Operate 99 | 6,运行环境信息:System Information 100 | -------------------------------------------------------------------------------- /src/main/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Main-Class: bs.tool.commongui.GuiMain 3 | 4 | Name: Built 5 | Built-By: Baishui2004 6 | Email: bs2004@163.com 7 | -------------------------------------------------------------------------------- /src/main/java/bs/tool/commongui/GuiImagePanel.java: -------------------------------------------------------------------------------- 1 | package bs.tool.commongui; 2 | 3 | import javax.imageio.ImageIO; 4 | import javax.swing.*; 5 | import java.awt.*; 6 | import java.awt.image.BufferedImage; 7 | import java.io.File; 8 | import java.io.IOException; 9 | 10 | /** 11 | * How to add an image to a JPanel? 12 | * https://stackoverflow.com/questions/299495/how-to-add-an-image-to-a-jpanel 13 | */ 14 | public class GuiImagePanel extends JPanel { 15 | 16 | private BufferedImage image; 17 | private int imageWidth; 18 | private int imageHeight; 19 | 20 | public GuiImagePanel() { 21 | } 22 | 23 | public GuiImagePanel(String imagePath) { 24 | setImage(imagePath); 25 | } 26 | 27 | public GuiImagePanel(int imageWidth, int imageHeight) { 28 | setImageWidth(imageWidth); 29 | setImageHeight(imageHeight); 30 | } 31 | 32 | public GuiImagePanel(String imagePath, int imageWidth, int imageHeight) { 33 | this(imageWidth, imageHeight); 34 | setImage(imagePath); 35 | } 36 | 37 | private void readImage(String imagePath) { 38 | try { 39 | image = ImageIO.read(new File(imagePath)); 40 | } catch (IOException e) { 41 | GuiUtils.log(e); 42 | } 43 | } 44 | 45 | public void setImage(String imagePath) { 46 | readImage(imagePath); 47 | } 48 | 49 | public void setImageWidth(int imageWidth) { 50 | this.imageWidth = imageWidth; 51 | } 52 | 53 | public void setImageHeight(int imageHeight) { 54 | this.imageHeight = imageHeight; 55 | } 56 | 57 | @Override 58 | protected void paintComponent(Graphics g) { 59 | super.paintComponent(g); 60 | if (image != null) { 61 | g.drawImage(image, 0, 0, imageWidth, imageHeight, this); 62 | } 63 | } 64 | 65 | public void repaint(String imagePath) { 66 | setImage(imagePath); 67 | super.repaint(); 68 | } 69 | 70 | } -------------------------------------------------------------------------------- /src/main/java/bs/tool/commongui/code/QrCodeUtil.java: -------------------------------------------------------------------------------- 1 | package bs.tool.commongui.code; 2 | 3 | import com.google.zxing.*; 4 | import com.google.zxing.client.j2se.BufferedImageLuminanceSource; 5 | import com.google.zxing.client.j2se.MatrixToImageWriter; 6 | import com.google.zxing.common.BitMatrix; 7 | import com.google.zxing.common.HybridBinarizer; 8 | import org.apache.commons.codec.binary.Base64; 9 | 10 | import javax.imageio.ImageIO; 11 | import java.awt.image.BufferedImage; 12 | import java.io.ByteArrayOutputStream; 13 | import java.io.File; 14 | import java.io.IOException; 15 | import java.util.HashMap; 16 | import java.util.Map; 17 | 18 | public class QrCodeUtil { 19 | 20 | public static final String FORMAT_JPG = "jpg"; 21 | public static final String FORMAT_PNG = "png"; 22 | public static final String FORMAT_BMP = "bmp"; 23 | 24 | public static void genQrCodeJpgFile(String content, String filePath, int width, int height) throws WriterException, IOException { 25 | genQrCodeFile(content, filePath, QrCodeUtil.FORMAT_JPG, width, height); 26 | } 27 | 28 | public static void genQrCodeFile(String content, String filePath, String format, int width, int height) throws WriterException, IOException { 29 | MultiFormatWriter multiFormatWriter = new MultiFormatWriter(); 30 | Map hints = new HashMap(); 31 | hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); 32 | hints.put(EncodeHintType.MARGIN, 2); 33 | BitMatrix bitMatrix = multiFormatWriter.encode(content, BarcodeFormat.QR_CODE, width, height, hints); 34 | File file = new File(filePath); 35 | MatrixToImageWriter.writeToFile(bitMatrix, format, file); 36 | } 37 | 38 | public static String genQrCodeBase64String(String content, String format, int width, int height) throws WriterException, IOException { 39 | MultiFormatWriter multiFormatWriter = new MultiFormatWriter(); 40 | Map hints = new HashMap(); 41 | hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); 42 | hints.put(EncodeHintType.MARGIN, 2); 43 | BitMatrix bitMatrix = multiFormatWriter.encode(content, BarcodeFormat.QR_CODE, width, height, hints); 44 | ByteArrayOutputStream bos = new ByteArrayOutputStream(); 45 | MatrixToImageWriter.writeToStream(bitMatrix, format, bos); 46 | return new String(Base64.encodeBase64(bos.toByteArray()), "utf-8"); 47 | } 48 | 49 | public static Result decodeQrCodeFile(String filePath) throws IOException, NotFoundException { 50 | MultiFormatReader formatReader = new MultiFormatReader(); 51 | File file = new File(filePath); 52 | BufferedImage image = ImageIO.read(file); 53 | LuminanceSource source = new BufferedImageLuminanceSource(image); 54 | Binarizer binarizer = new HybridBinarizer(source); 55 | BinaryBitmap binaryBitmap = new BinaryBitmap(binarizer); 56 | Map hints = new HashMap(); 57 | hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); 58 | return formatReader.decode(binaryBitmap, hints); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/bs/tool/commongui/plugins/AntScriptAutoBuild.java: -------------------------------------------------------------------------------- 1 | package bs.tool.commongui.plugins; 2 | 3 | import bs.tool.commongui.AbstractGuiJPanel; 4 | import bs.tool.commongui.GuiUtils; 5 | import bs.tool.commongui.utils.SimpleMouseListener; 6 | import bs.tool.eclipse.ProjectPropertiesDeal; 7 | import bs.tool.eclipse.ProjectPropertiesDealInterface; 8 | import bs.util.io.PropertiesUtils; 9 | 10 | import javax.swing.*; 11 | import java.awt.*; 12 | import java.awt.event.ActionEvent; 13 | import java.awt.event.ActionListener; 14 | import java.awt.event.MouseEvent; 15 | import java.io.File; 16 | import java.io.IOException; 17 | import java.net.URISyntaxException; 18 | import java.util.Properties; 19 | 20 | /** 21 | * Auto Build Ant构建脚本. 22 | */ 23 | public class AntScriptAutoBuild extends AbstractGuiJPanel { 24 | 25 | private static final long serialVersionUID = 1L; 26 | 27 | /** 28 | * Project路径表单. 29 | */ 30 | private JTextField projectPathTextField = new JTextField(); 31 | /** 32 | * Project路径选择. 33 | */ 34 | private JFileChooser projectPathChooser = new JFileChooser(); 35 | 36 | /** 37 | * 是否备份已存在的同名构建属性脚本及脚本. 38 | */ 39 | private boolean isBak = true; 40 | 41 | /** 42 | * Ant 任务. 43 | */ 44 | private String taskNames = ""; 45 | 46 | /** 47 | * 运行日志输出文本域. 48 | */ 49 | private JTextArea runLogTextArea = createJTextArea(GuiUtils.font14_un); 50 | 51 | public AntScriptAutoBuild() { 52 | 53 | // 主面板:边界布局,分North、Center两部分,North用于放置条件控件,Center放置运行日志输出 54 | setLayout(new BorderLayout()); 55 | 56 | // 输入条件/操作 57 | JPanel inputPanel = new JPanel(new BorderLayout()); 58 | // Project路径选择/填写 59 | JPanel fileChooPanel = new JPanel(new BorderLayout()); 60 | addJLabel(fileChooPanel, " Project路径: ", GuiUtils.font14_cn, BorderLayout.WEST); 61 | JPanel pathPanel = new JPanel(new BorderLayout()); 62 | pathPanel.add(new JPanel(), BorderLayout.NORTH); 63 | addJTextField(pathPanel, projectPathTextField, GuiUtils.font14_un, BorderLayout.CENTER); 64 | pathPanel.add(new JPanel(), BorderLayout.SOUTH); 65 | fileChooPanel.add(pathPanel, BorderLayout.CENTER); 66 | JPanel buttonFlowPanel = new JPanel(new FlowLayout(FlowLayout.LEADING)); 67 | addJButton(buttonFlowPanel, "浏览", "", GuiUtils.font12_cn, 68 | buttonBrowseListener(projectPathChooser, projectPathTextField)); 69 | addJCheckBox(buttonFlowPanel, "备份已存在脚本", true, GuiUtils.font12_cn, new ActionListener() { 70 | @Override 71 | public void actionPerformed(ActionEvent event) { 72 | isBak = ((JCheckBox) event.getSource()).isSelected(); 73 | } 74 | }); 75 | // 按钮 76 | addJButton(buttonFlowPanel, "Build", "", GuiUtils.font14b_cn, new SimpleMouseListener() { 77 | @Override 78 | public void mouseReleased(MouseEvent event) { 79 | String projectPath = projectPathTextField.getText().trim(); 80 | if (!new File(projectPath).exists()) { 81 | showMessage("Project路径不存在!", "警告", JOptionPane.WARNING_MESSAGE); 82 | return; 83 | } 84 | try { 85 | bs.tool.ant.AntScriptAutoBuild build = new bs.tool.ant.AntScriptAutoBuild(); 86 | build.setIsBak(isBak); 87 | ProjectPropertiesDealInterface propertiesDeal = new ProjectPropertiesDeal(); 88 | if (!propertiesDeal.isJavaOrJavaWebEclipseProject(projectPath)) { 89 | runLogTextArea.append("Error: The Path \'" + projectPath 90 | + "\' not has a Eclipse Java Project, Dynamic Web Project or MyEclipse Web Project."); 91 | return; 92 | } 93 | propertiesDeal.setRunLogTextArea(runLogTextArea); 94 | propertiesDeal.deal(projectPath); 95 | build.setRunLogTextArea(runLogTextArea); 96 | build.autoBuild(projectPath, propertiesDeal, taskNames); 97 | } catch (IOException e) { 98 | showExceptionMessage(e); 99 | } catch (URISyntaxException e) { 100 | showExceptionMessage(e); 101 | } 102 | } 103 | 104 | @Override 105 | public void mousePressed(MouseEvent e) { 106 | runLogTextArea.setText(""); 107 | } 108 | }); 109 | // Project路径选择控件,仅可选择文件夹 110 | projectPathChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 111 | fileChooPanel.add(buttonFlowPanel, BorderLayout.EAST); 112 | inputPanel.add(fileChooPanel, BorderLayout.NORTH); 113 | 114 | int gridRow = 5; 115 | int gridCol = 6; 116 | // Ant Task任务JPanel 117 | JPanel taskGridPanel = new JPanel(new GridLayout(gridRow, gridCol)); 118 | String antTaskPropsFile = "conf/AntScriptAutoBuild/conf.properties"; 119 | try { 120 | Properties taskConfProperties = PropertiesUtils.getProperties(GuiUtils.getActualPath(antTaskPropsFile)); 121 | 122 | String baseTask = taskConfProperties.getProperty("baseTask").trim(); 123 | String javaTask = taskConfProperties.getProperty("javaTask").trim(); 124 | String javaWebTask = taskConfProperties.getProperty("javaWebTask").trim(); 125 | String generalTask = taskConfProperties.getProperty("generalTask").trim(); 126 | String specialTask = taskConfProperties.getProperty("specialTask").trim(); 127 | 128 | addTaskCheckBox(taskGridPanel, " Java Base", baseTask + "," + javaTask, baseTask, gridCol); 129 | addTaskCheckBox(taskGridPanel, " Java Web ", javaWebTask, baseTask, gridCol); 130 | addTaskCheckBox(taskGridPanel, " General ", generalTask, baseTask, gridCol); 131 | addTaskCheckBox(taskGridPanel, " Special ", specialTask, baseTask, gridCol); 132 | } catch (IOException e) { 133 | logLoadPropertiesException(antTaskPropsFile, e); 134 | } 135 | inputPanel.add(taskGridPanel, BorderLayout.CENTER); 136 | 137 | add(inputPanel, BorderLayout.NORTH); 138 | 139 | add(new JScrollPane(runLogTextArea), BorderLayout.CENTER); 140 | } 141 | 142 | /** 143 | * 添加Ant Task JCheckBox选择框. 144 | */ 145 | private void addTaskCheckBox(JPanel taskGridPanel, String labelName, String taskNames, String baseTask, int gridCol) { 146 | addJLabel(taskGridPanel, labelName + " 任务:", GuiUtils.font14_cn); 147 | String[] tasks = taskNames.split(","); 148 | int row = tasks.length / (gridCol - 1); 149 | row = row * (gridCol - 1) == tasks.length ? row : row + 1; 150 | int num = row * gridCol - 1; 151 | 152 | for (int i = 0; i < num; i++) { 153 | String title = ""; 154 | if (i < tasks.length + i / (gridCol - 1) && !(i % (gridCol - 1) == 0 && i != 0)) { 155 | title = tasks[i - i / (gridCol - 1)]; 156 | } 157 | if ("".equals(title)) { 158 | addJLabel(taskGridPanel, title, GuiUtils.font14_cn); 159 | } else { 160 | boolean isSelected = false; 161 | if (("," + baseTask + ",").contains("," + title + ",") || "jar".equals(title)) { 162 | isSelected = true; 163 | } 164 | JCheckBox taskBox = createJCheckBox(title, isSelected, GuiUtils.font16, new ActionListener() { 165 | @Override 166 | public void actionPerformed(ActionEvent event) { 167 | JCheckBox checkBox = (JCheckBox) event.getSource(); 168 | setTaskNames(checkBox.getText(), checkBox.isSelected()); 169 | } 170 | }); 171 | if (isSelected) { 172 | if ("base".equals(title)) { 173 | taskBox.setEnabled(false); 174 | } 175 | this.taskNames += "," + title; 176 | } 177 | taskGridPanel.add(taskBox); 178 | } 179 | } 180 | 181 | } 182 | 183 | /** 184 | * 设置被选择的Ant任务. 185 | */ 186 | private void setTaskNames(String taskName, boolean add) { 187 | if (("," + this.taskNames + ",").contains("," + taskName + ",")) { 188 | if (!add) { 189 | this.taskNames = ("," + this.taskNames + ",").replace("," + taskName + ",", ""); 190 | } 191 | } else { 192 | if (add) { 193 | this.taskNames = this.taskNames + "," + taskName; 194 | } 195 | } 196 | if (this.taskNames.startsWith(",")) { 197 | this.taskNames = this.taskNames.substring(1); 198 | } 199 | } 200 | 201 | } 202 | -------------------------------------------------------------------------------- /src/main/java/bs/tool/commongui/plugins/ColorTool.java: -------------------------------------------------------------------------------- 1 | package bs.tool.commongui.plugins; 2 | 3 | import bs.tool.commongui.AbstractGuiJPanel; 4 | import bs.tool.commongui.GuiUtils; 5 | 6 | import javax.swing.*; 7 | import java.awt.*; 8 | import java.awt.event.ActionEvent; 9 | import java.awt.event.ActionListener; 10 | 11 | /** 12 | * 颜色工具. 13 | */ 14 | public class ColorTool extends AbstractGuiJPanel { 15 | 16 | private static final long serialVersionUID = 1L; 17 | 18 | /** 19 | * R表单. 20 | */ 21 | private JTextField rTextField = new JTextField(3); 22 | /** 23 | * G表单. 24 | */ 25 | private JTextField gTextField = new JTextField(3); 26 | /** 27 | * B表单. 28 | */ 29 | private JTextField bTextField = new JTextField(3); 30 | 31 | /** 32 | * HTML表单. 33 | */ 34 | private JTextField htmlTextField = new JTextField(6); 35 | 36 | public ColorTool() { 37 | 38 | // 主面板:边界布局,分North、Center两部分,North用于放置输入及条件控件,Center是放置空面面板 39 | setLayout(new BorderLayout()); 40 | 41 | // 输入及条件Panel 42 | JPanel colorPanel = new JPanel(new BorderLayout()); 43 | 44 | JPanel flowPanel = new JPanel(new FlowLayout()); 45 | 46 | addJLabel(flowPanel, " R:", GuiUtils.font13); 47 | flowPanel.add(rTextField); 48 | addJLabel(flowPanel, "G:", GuiUtils.font13); 49 | flowPanel.add(gTextField); 50 | addJLabel(flowPanel, "B:", GuiUtils.font13); 51 | flowPanel.add(bTextField); 52 | addJLabel(flowPanel, " HTML: ", GuiUtils.font13); 53 | 54 | addJButton(flowPanel, "<-", "", GuiUtils.font14b_cn, new ActionListener() { 55 | @Override 56 | public void actionPerformed(ActionEvent event) { 57 | Color color = getHTMLFillColor(); 58 | if (color != null) { 59 | rTextField.setText(Integer.toString(color.getRed())); 60 | gTextField.setText(Integer.toString(color.getGreen())); 61 | bTextField.setText(Integer.toString(color.getBlue())); 62 | } else { 63 | showMessage("未输入正确的颜色值!", "警告", JOptionPane.WARNING_MESSAGE); 64 | } 65 | } 66 | }); 67 | 68 | addJButton(flowPanel, "->", "", GuiUtils.font14b_cn, new ActionListener() { 69 | @Override 70 | public void actionPerformed(ActionEvent event) { 71 | Color color = getRGBFillColor(); 72 | if (color != null) { 73 | htmlTextField.setText("#" + hex(color.getRed()) + hex(color.getGreen()) + hex(color.getBlue())); 74 | } else { 75 | showMessage("未输入正确的颜色值!", "警告", JOptionPane.WARNING_MESSAGE); 76 | } 77 | } 78 | }); 79 | 80 | flowPanel.add(htmlTextField); 81 | colorPanel.add(flowPanel, BorderLayout.CENTER); 82 | colorPanel.add(new JPanel(), BorderLayout.EAST); 83 | 84 | JButton paletteButton = createJButton("显示调色板", "", GuiUtils.font14_cn); 85 | paletteButton.addActionListener(new ActionListener() { 86 | @Override 87 | public void actionPerformed(ActionEvent event) { 88 | Color fillColor = getRGBFillColor(); 89 | fillColor = fillColor == null ? getHTMLFillColor() : fillColor; 90 | Color chooseColor = fillColor == null ? Color.black : fillColor; 91 | Color color = JColorChooser.showDialog(ColorTool.this, "调色板", chooseColor); 92 | if (color != null) { 93 | int r = color.getRed(); 94 | int g = color.getGreen(); 95 | int b = color.getBlue(); 96 | rTextField.setText(Integer.toString(r)); 97 | gTextField.setText(Integer.toString(g)); 98 | bTextField.setText(Integer.toString(b)); 99 | htmlTextField.setText("#" + hex(r) + hex(g) + hex(b)); 100 | } 101 | } 102 | }); 103 | flowPanel.add(paletteButton); 104 | 105 | add(colorPanel, BorderLayout.NORTH); 106 | 107 | // 空面面板 108 | JPanel resultPanel = new JPanel(new BorderLayout()); 109 | // 空白文本域 110 | JTextArea resultTextArea = createJTextArea(GuiUtils.font14_un); 111 | resultTextArea.setEditable(false); 112 | resultTextArea.setText("说明:" + "\n1,R、G、B的范围0-255" + "\n2,HTML颜色码可识别3位或6位,且可带或不带井号#,不区分大小写" 113 | + "\n3,调色板颜色选择说明,如果RGB有正确的值则选择其值,否则选择HTML颜色码正确的值,若两者都无正确的值,则选择黑色"); 114 | resultPanel.add(new JScrollPane(resultTextArea)); 115 | add(resultPanel, BorderLayout.CENTER); 116 | } 117 | 118 | /** 119 | * 将0-255转为双位数字的16进制. 120 | */ 121 | private String hex(int code) { 122 | String hex = Integer.toHexString(code); 123 | return hex.length() == 1 ? "0" + hex : hex; 124 | } 125 | 126 | /** 127 | * 获取RGB表单设置的颜色. 128 | */ 129 | private Color getRGBFillColor() { 130 | Color color = null; 131 | String r = rTextField.getText().trim(); 132 | String g = gTextField.getText().trim(); 133 | String b = bTextField.getText().trim(); 134 | try { 135 | if (!"".equals(r) && !"".equals(g) && !"".equals(b)) { 136 | color = new Color(Integer.parseInt(r), Integer.parseInt(g), Integer.parseInt(b)); 137 | } 138 | } catch (Exception e) { 139 | GuiUtils.log(e); 140 | } 141 | return color; 142 | } 143 | 144 | /** 145 | * 获取HTML颜色表单设置的颜色. 146 | */ 147 | private Color getHTMLFillColor() { 148 | Color color = null; 149 | String r = ""; 150 | String g = ""; 151 | String b = ""; 152 | String html = htmlTextField.getText().trim(); 153 | try { 154 | if (!"".equals(html)) { 155 | if (html.startsWith("#")) { 156 | html = html.substring(1); 157 | } 158 | if (html.length() == 3) { 159 | r = html.substring(0, 1) + html.substring(0, 1); 160 | g = html.substring(1, 2) + html.substring(1, 2); 161 | b = html.substring(2, 3) + html.substring(2, 3); 162 | } else if (html.length() == 6) { 163 | r = html.substring(0, 2); 164 | g = html.substring(2, 4); 165 | b = html.substring(4, 6); 166 | } 167 | color = new Color(Integer.parseInt(r, 16), Integer.parseInt(g, 16), Integer.parseInt(b, 16)); 168 | } 169 | } catch (Exception e) { 170 | GuiUtils.log(e); 171 | } 172 | return color; 173 | } 174 | 175 | } 176 | -------------------------------------------------------------------------------- /src/main/java/bs/tool/commongui/plugins/EncryptAndDecrypt.java: -------------------------------------------------------------------------------- 1 | package bs.tool.commongui.plugins; 2 | 3 | import bs.tool.commongui.AbstractGuiJPanel; 4 | import bs.tool.commongui.GuiUtils; 5 | import bs.tool.commongui.utils.SimpleMouseListener; 6 | import bs.util.common.CodecUtil; 7 | import org.apache.commons.codec.DecoderException; 8 | 9 | import javax.swing.*; 10 | import java.awt.*; 11 | import java.awt.event.*; 12 | import java.io.UnsupportedEncodingException; 13 | 14 | /** 15 | * 加密解密. 16 | */ 17 | public class EncryptAndDecrypt extends AbstractGuiJPanel { 18 | 19 | private static final long serialVersionUID = 1L; 20 | 21 | /** 22 | * 明文文本域. 23 | */ 24 | private JTextArea encrptyTextArea = createJTextArea(GuiUtils.font14_un); 25 | /** 26 | * 密文文本域. 27 | */ 28 | private JTextArea decrptyTextArea = createJTextArea(GuiUtils.font14_un); 29 | 30 | /** 31 | * 字符集. 32 | */ 33 | private String[] charsets = new String[]{GuiUtils.CHARSET_UTF_8, GuiUtils.CHARSET_UTF_16BE, 34 | GuiUtils.CHARSET_UTF_16LE, GuiUtils.CHARSET_UTF_16, GuiUtils.CHARSET_GBK, GuiUtils.CHARSET_Big5, 35 | GuiUtils.CHARSET_ISO_8859_1}; 36 | 37 | /** 38 | * 当前字符集. 39 | */ 40 | private String curCharset = charsets[0]; 41 | 42 | /** 43 | * 加密算法. 空""用于填充一个空位. 44 | */ 45 | private String[] cryptos = new String[]{GuiUtils.CRYPTO_ASCII, GuiUtils.CRYPTO_HEX, GuiUtils.CRYPTO_BASE64, 46 | GuiUtils.CRYPTO_BASE32, GuiUtils.CRYPTO_URL, "", "", "", GuiUtils.CRYPTO_MD5, "", 47 | GuiUtils.CRYPTO_SHA, GuiUtils.CRYPTO_SHA256, GuiUtils.CRYPTO_SHA384, GuiUtils.CRYPTO_SHA512}; 48 | 49 | /** 50 | * 当前加密算法. 51 | */ 52 | private String curCrypto = cryptos[0]; 53 | 54 | public EncryptAndDecrypt() { 55 | 56 | // 边界布局 57 | setLayout(new BorderLayout()); 58 | // Center,加密解密输入输出域,使用2行1列的Grid布局,使其平均显示 59 | JPanel textAreaPanel = new JPanel(new GridLayout(2, 1)); 60 | add(textAreaPanel, BorderLayout.CENTER); 61 | 62 | JPanel encrptyPanel = new JPanel(new BorderLayout()); 63 | addJLabel(encrptyPanel, " 明文: ", GuiUtils.font14b_cn, BorderLayout.WEST); 64 | encrptyPanel.add(new JScrollPane(encrptyTextArea), BorderLayout.CENTER); 65 | textAreaPanel.add(encrptyPanel); 66 | 67 | JPanel decrptyPanel = new JPanel(new BorderLayout()); 68 | addJLabel(decrptyPanel, " 密文: ", GuiUtils.font14b_cn, BorderLayout.WEST); 69 | decrptyPanel.add(new JScrollPane(decrptyTextArea), BorderLayout.CENTER); 70 | textAreaPanel.add(decrptyPanel); 71 | 72 | // East,操作区域,使用BorderLayout布局 73 | JPanel actionPanel = new JPanel(new BorderLayout()); 74 | add(actionPanel, BorderLayout.EAST); 75 | // 放置下拉框、单选框等 76 | JPanel actionGridPanel = new JPanel(new GridLayout(10, 1)); 77 | actionPanel.add(actionGridPanel, BorderLayout.NORTH); 78 | 79 | // 字符集下拉框 80 | JPanel charsetsPanel = new JPanel(new FlowLayout()); 81 | addJLabel(charsetsPanel, "字符集:", GuiUtils.font14b_cn); 82 | addJComboBox(charsetsPanel, charsets, GuiUtils.font13, new ActionListener() { 83 | @Override 84 | public void actionPerformed(ActionEvent event) { 85 | curCharset = ((JComboBox) event.getSource()).getSelectedItem().toString(); 86 | } 87 | }); 88 | actionGridPanel.add(charsetsPanel); 89 | 90 | // 仅作填充 91 | addJLabel(actionGridPanel, " ", GuiUtils.font13); 92 | // 算法单选框 93 | ButtonGroup buttonGroup = new ButtonGroup(); 94 | int cryptosLen = cryptos.length; 95 | int cryptosLoop = cryptosLen / 2; 96 | cryptosLoop = cryptosLoop * 2 == cryptosLen ? cryptosLoop : (cryptosLoop + 1); 97 | for (int i = 0; i < cryptosLoop; i++) { 98 | // FlowLayout.LEADING,此值指示每一行组件都应该与容器方向的开始边对齐,例如,对于从左到右的方向,则与左边对齐 99 | JPanel cryptoPanel = new JPanel(new FlowLayout(FlowLayout.LEADING)); 100 | String crypto = cryptos[i * 2]; 101 | if (crypto.trim().length() != 0) { 102 | JRadioButton firstRadio = new JRadioButton(GuiUtils.getFillUpString(crypto, 6)); 103 | firstRadio.setFont(GuiUtils.font13_cn); 104 | firstRadio.addItemListener(new ItemListener() { 105 | @Override 106 | public void itemStateChanged(ItemEvent event) { 107 | JRadioButton radio = (JRadioButton) event.getSource(); 108 | if (radio.isSelected()) { 109 | curCrypto = radio.getText().trim(); 110 | } 111 | } 112 | }); 113 | if (GuiUtils.CRYPTO_MD5.equals(firstRadio.getText().trim())) { 114 | firstRadio.setSelected(true); 115 | } 116 | buttonGroup.add(firstRadio); 117 | cryptoPanel.add(firstRadio); 118 | } 119 | if (!(cryptosLen % 2 == 1 && i * 2 + 1 == cryptosLen)) { 120 | crypto = GuiUtils.getFillUpString(cryptos[i * 2 + 1], 6); 121 | if (crypto.trim().length() != 0) { 122 | JRadioButton secondRadio = new JRadioButton(crypto); 123 | secondRadio.setFont(GuiUtils.font13_cn); 124 | secondRadio.addItemListener(new ItemListener() { 125 | @Override 126 | public void itemStateChanged(ItemEvent event) { 127 | JRadioButton radio = (JRadioButton) event.getSource(); 128 | if (radio.isSelected()) { 129 | curCrypto = radio.getText().trim(); 130 | } 131 | } 132 | }); 133 | if (GuiUtils.CRYPTO_MD5.equals(secondRadio.getText().trim())) { 134 | secondRadio.setSelected(true); 135 | } 136 | buttonGroup.add(secondRadio); 137 | cryptoPanel.add(secondRadio); 138 | } 139 | } 140 | actionGridPanel.add(cryptoPanel); 141 | } 142 | 143 | // 仅作填充 144 | actionPanel.add(new Panel(), BorderLayout.CENTER); 145 | 146 | // 放置加密解密按钮 147 | JPanel buttonPanel = new JPanel(new GridLayout(3, 1)); 148 | actionPanel.add(buttonPanel, BorderLayout.SOUTH); 149 | // 加密按钮 150 | addJButton(buttonPanel, "加密", "", GuiUtils.font14b_cn, new SimpleMouseListener() { 151 | @Override 152 | public void mouseReleased(MouseEvent event) { 153 | String input = encrptyTextArea.getText(); 154 | try { 155 | if (GuiUtils.CRYPTO_ASCII.equals(curCrypto)) { 156 | decrptyTextArea.setText(CodecUtil.encodeAscii(input, curCharset)); 157 | } else if (GuiUtils.CRYPTO_HEX.equals(curCrypto)) { 158 | decrptyTextArea.setText(CodecUtil.encodeHex(input, curCharset)); 159 | } else if (GuiUtils.CRYPTO_BASE64.equals(curCrypto)) { 160 | decrptyTextArea.setText(CodecUtil.encodeBase64(input, curCharset)); 161 | } else if (GuiUtils.CRYPTO_BASE32.equals(curCrypto)) { 162 | decrptyTextArea.setText(CodecUtil.encodeBase32(input, curCharset)); 163 | } else if (GuiUtils.CRYPTO_URL.equals(curCrypto)) { 164 | decrptyTextArea.setText(CodecUtil.encodeURL(input, curCharset)); 165 | } else if (GuiUtils.CRYPTO_MD5.equals(curCrypto)) { 166 | String md5Val = CodecUtil.encryptMd5(input, curCharset); 167 | decrptyTextArea.setText("16Bit:" + md5Val.substring(8, 24) + "\n32Bit:" + md5Val); 168 | } else if (GuiUtils.CRYPTO_SHA.equals(curCrypto)) { 169 | decrptyTextArea.setText(CodecUtil.encryptSha(input, curCharset)); 170 | } else if (GuiUtils.CRYPTO_SHA256.equals(curCrypto)) { 171 | decrptyTextArea.setText(CodecUtil.encryptSha256(input, curCharset)); 172 | } else if (GuiUtils.CRYPTO_SHA384.equals(curCrypto)) { 173 | decrptyTextArea.setText(CodecUtil.encryptSha384(input, curCharset)); 174 | } else if (GuiUtils.CRYPTO_SHA512.equals(curCrypto)) { 175 | decrptyTextArea.setText(CodecUtil.encryptSha512(input, curCharset)); 176 | } 177 | } catch (UnsupportedEncodingException e) { 178 | showExceptionMessage(e); 179 | } 180 | } 181 | 182 | @Override 183 | public void mousePressed(MouseEvent e) { 184 | decrptyTextArea.setText(""); 185 | } 186 | }); 187 | // 解密按钮 188 | addJButton(buttonPanel, "解密", "", GuiUtils.font14b_cn, new SimpleMouseListener() { 189 | @Override 190 | public void mouseReleased(MouseEvent event) { 191 | String input = decrptyTextArea.getText(); 192 | try { 193 | if (GuiUtils.CRYPTO_ASCII.equals(curCrypto)) { 194 | encrptyTextArea.setText(CodecUtil.decodeAscii(input, curCharset)); 195 | } else if (GuiUtils.CRYPTO_HEX.equals(curCrypto)) { 196 | encrptyTextArea.setText(CodecUtil.decodeHex(input, curCharset)); 197 | } else if (GuiUtils.CRYPTO_BASE64.equals(curCrypto)) { 198 | encrptyTextArea.setText(CodecUtil.decodeBase64(input, curCharset)); 199 | } else if (GuiUtils.CRYPTO_BASE32.equals(curCrypto)) { 200 | encrptyTextArea.setText(CodecUtil.decodeBase32(input, curCharset)); 201 | } else if (GuiUtils.CRYPTO_URL.equals(curCrypto)) { 202 | encrptyTextArea.setText(CodecUtil.decodeURL(input, curCharset)); 203 | } else { 204 | encrptyTextArea.setText("不支持此种加密算法的解密!"); 205 | } 206 | } catch (UnsupportedEncodingException e) { 207 | showExceptionMessage(e); 208 | } catch (DecoderException e) { 209 | showExceptionMessage(e); 210 | } 211 | } 212 | 213 | @Override 214 | public void mousePressed(MouseEvent e) { 215 | encrptyTextArea.setText(""); 216 | } 217 | }); 218 | } 219 | } 220 | -------------------------------------------------------------------------------- /src/main/java/bs/tool/commongui/plugins/FileDigitalSignature.java: -------------------------------------------------------------------------------- 1 | package bs.tool.commongui.plugins; 2 | 3 | import bs.tool.commongui.AbstractGuiJPanel; 4 | import bs.tool.commongui.GuiUtils; 5 | import bs.tool.commongui.utils.FileUtils; 6 | import bs.tool.commongui.utils.SearchFileNameParams; 7 | import bs.tool.commongui.utils.SimpleMouseListener; 8 | import org.apache.commons.codec.digest.DigestUtils; 9 | 10 | import javax.swing.*; 11 | import java.awt.*; 12 | import java.awt.event.ActionEvent; 13 | import java.awt.event.ActionListener; 14 | import java.awt.event.MouseEvent; 15 | import java.io.File; 16 | import java.io.FileInputStream; 17 | import java.io.IOException; 18 | import java.util.ArrayList; 19 | import java.util.HashMap; 20 | import java.util.List; 21 | import java.util.Map; 22 | 23 | /** 24 | * 计算文件数字签名. 25 | */ 26 | public class FileDigitalSignature extends AbstractGuiJPanel { 27 | 28 | private static final long serialVersionUID = 1L; 29 | 30 | /** 31 | * 文本/文件夹路径表单. 32 | */ 33 | private JTextField digitalPathTextField = new JTextField(); 34 | /** 35 | * 文本/文件夹路径选择. 36 | */ 37 | private JFileChooser digitalPathChooser = new JFileChooser(); 38 | 39 | /** 40 | * 是否计算MD5. 41 | */ 42 | private boolean ifDigitalMd5 = true; 43 | 44 | /** 45 | * 是否计算SHA1. 46 | */ 47 | private boolean ifDigitalSha1 = false; 48 | 49 | /** 50 | * 计算按钮. 51 | */ 52 | private JButton digitalButton; 53 | 54 | /** 55 | * 文件名包含字符表单. 56 | */ 57 | private JTextField fileNameContainsTextField; 58 | /** 59 | * 文件名不包含字符表单. 60 | */ 61 | private JTextField fileNameNotContainsTextField; 62 | /** 63 | * 文件名是否支持正则. 64 | */ 65 | private boolean fileNameSupportRegex = false; 66 | 67 | /** 68 | * 计算结果文本域. 69 | */ 70 | private JTextArea resultTextArea = createJTextArea(GuiUtils.font14_un); 71 | 72 | public FileDigitalSignature() { 73 | 74 | // 主面板:边界布局,分North、Center两部分,North用于放置输入及条件控件,Center是放置计算结果输出 75 | setLayout(new BorderLayout()); 76 | 77 | // 输入及条件Panel 78 | JPanel inputPanel = new JPanel(new GridLayout(2, 1)); 79 | 80 | // 文本/文件夹表单、计算按钮Panel 81 | JPanel fileChooAndDetectPanel = new JPanel(new BorderLayout()); 82 | // 文本/文件夹表单 83 | addJLabel(fileChooAndDetectPanel, " 文件/文件夹: ", GuiUtils.font14_cn, BorderLayout.WEST); 84 | JPanel fileChooPanel = new JPanel(new BorderLayout()); 85 | fileChooPanel.add(new JPanel(), BorderLayout.NORTH); 86 | addJTextField(fileChooPanel, digitalPathTextField, GuiUtils.font14_un, BorderLayout.CENTER); 87 | fileChooPanel.add(new JPanel(), BorderLayout.SOUTH); 88 | fileChooAndDetectPanel.add(fileChooPanel, BorderLayout.CENTER); 89 | 90 | JPanel buttonFlowPanel = new JPanel(new FlowLayout(FlowLayout.LEADING)); 91 | addJButton(buttonFlowPanel, "浏览", "", GuiUtils.font12_cn, 92 | buttonBrowseListener(digitalPathChooser, digitalPathTextField)); 93 | // 计算按钮 94 | digitalButton = createJButton("计算", "", GuiUtils.font14b_cn); 95 | digitalButton.addMouseListener(new SimpleMouseListener() { 96 | @Override 97 | public void mouseReleased(MouseEvent event) { 98 | String path = digitalPathTextField.getText().trim(); 99 | File file = new File(path); 100 | if (!file.exists()) { 101 | showMessage("文件/文件夹不存在!", "警告", JOptionPane.WARNING_MESSAGE); 102 | return; 103 | } 104 | Map paramsMap = new HashMap(); 105 | paramsMap.put("fileNameContainsText", fileNameContainsTextField.getText().trim()); 106 | paramsMap.put("fileNameNotContainsText", fileNameNotContainsTextField.getText().trim()); 107 | paramsMap.put("fileNameSupportRegex", fileNameSupportRegex); 108 | digitalButton.setEnabled(false); 109 | 110 | resultTextArea.setText(""); 111 | try { 112 | if (!file.isDirectory()) { 113 | appendDigitalResult(resultTextArea, file, ifDigitalMd5, ifDigitalSha1); 114 | } else { 115 | List files = new ArrayList(); 116 | FileUtils.loopDirectory(file, files, new SearchFileNameParams(paramsMap)); 117 | for (File fFile : files) { 118 | appendDigitalResult(resultTextArea, fFile, ifDigitalMd5, ifDigitalSha1); 119 | } 120 | resultTextArea.append("\nDigital files: " + files.size()); 121 | } 122 | } catch (NumberFormatException e) { 123 | showMessage("取样大小必须是正整数!", "警告", JOptionPane.WARNING_MESSAGE); 124 | } catch (IOException e) { 125 | showExceptionMessage(e); 126 | } 127 | digitalButton.setEnabled(true); 128 | } 129 | 130 | @Override 131 | public void mousePressed(MouseEvent e) { 132 | resultTextArea.setText(""); 133 | } 134 | }); 135 | buttonFlowPanel.add(digitalButton); 136 | // 路径选择控件,可选择文件/文件夹 137 | digitalPathChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); 138 | fileChooAndDetectPanel.add(buttonFlowPanel, BorderLayout.EAST); 139 | inputPanel.add(fileChooAndDetectPanel); 140 | 141 | // 高级条件Panel 142 | JPanel advancePanel = new JPanel(new FlowLayout(FlowLayout.LEADING)); 143 | addJLabel(advancePanel, " ", GuiUtils.font12_cn); 144 | // 是否计算MD5 145 | addJCheckBox(advancePanel, "MD5 ", true, GuiUtils.font14_cn, new ActionListener() { 146 | @Override 147 | public void actionPerformed(ActionEvent event) { 148 | ifDigitalMd5 = ((JCheckBox) event.getSource()).isSelected(); 149 | } 150 | }); 151 | // 是否计算SHA1 152 | addJCheckBox(advancePanel, "SHA1 ", false, GuiUtils.font14_cn, new ActionListener() { 153 | @Override 154 | public void actionPerformed(ActionEvent event) { 155 | ifDigitalSha1 = ((JCheckBox) event.getSource()).isSelected(); 156 | } 157 | }); 158 | // 文件名包含(不包含)字符 159 | addJLabel(advancePanel, " 文件名包含字符: ", GuiUtils.font14_cn); 160 | fileNameContainsTextField = new JTextField(16); 161 | addJTextField(advancePanel, fileNameContainsTextField, GuiUtils.font14_un); 162 | addJLabel(advancePanel, " 文件名不包含字符: ", GuiUtils.font14_cn); 163 | fileNameNotContainsTextField = new JTextField(16); 164 | addJTextField(advancePanel, fileNameNotContainsTextField, GuiUtils.font14_un); 165 | // 是否支持正则 166 | addJCheckBox(advancePanel, "支持正则", false, GuiUtils.font14_cn, new ActionListener() { 167 | @Override 168 | public void actionPerformed(ActionEvent event) { 169 | fileNameSupportRegex = ((JCheckBox) event.getSource()).isSelected(); 170 | } 171 | }); 172 | inputPanel.add(advancePanel); 173 | 174 | add(inputPanel, BorderLayout.NORTH); 175 | 176 | // 计算结果输出 177 | JPanel detectLogPanel = new JPanel(new BorderLayout()); 178 | detectLogPanel.add(new JScrollPane(resultTextArea)); 179 | add(detectLogPanel, BorderLayout.CENTER); 180 | } 181 | 182 | /** 183 | * append计算文件数字签名结果. 184 | */ 185 | private void appendDigitalResult(JTextArea resultTextArea, File file, boolean ifDigitalMd5, boolean ifDigitalSha1) 186 | throws IOException { 187 | resultTextArea.append(file.getAbsolutePath()); 188 | if (ifDigitalMd5) { 189 | resultTextArea.append(" MD5: " + digitalFileMd5(file)); 190 | } 191 | if (ifDigitalSha1) { 192 | resultTextArea.append(" SHA1: " + digitalFileSha1(file)); 193 | } 194 | resultTextArea.append("\n"); 195 | } 196 | 197 | /** 198 | * 计算文件数字签名-MD5. 199 | */ 200 | public static String digitalFileMd5(File file) throws IOException { 201 | return DigestUtils.md5Hex(new FileInputStream(file)); 202 | } 203 | 204 | /** 205 | * 计算文件数字签名-SHA1. 206 | */ 207 | public static String digitalFileSha1(File file) throws IOException { 208 | return DigestUtils.shaHex(new FileInputStream(file)); 209 | } 210 | 211 | } 212 | -------------------------------------------------------------------------------- /src/main/java/bs/tool/commongui/plugins/RunScript.java: -------------------------------------------------------------------------------- 1 | package bs.tool.commongui.plugins; 2 | 3 | import bs.tool.commongui.AbstractGuiJPanel; 4 | import bs.tool.commongui.GuiUtils; 5 | import bs.tool.commongui.utils.SimpleMouseListener; 6 | 7 | import javax.script.ScriptEngine; 8 | import javax.script.ScriptEngineFactory; 9 | import javax.script.ScriptEngineManager; 10 | import javax.script.ScriptException; 11 | import javax.swing.*; 12 | import java.awt.*; 13 | import java.awt.event.ActionEvent; 14 | import java.awt.event.ActionListener; 15 | import java.awt.event.MouseEvent; 16 | import java.util.LinkedHashSet; 17 | import java.util.List; 18 | import java.util.Set; 19 | 20 | /** 21 | * 执行Script脚本. 22 | */ 23 | public class RunScript extends AbstractGuiJPanel { 24 | 25 | private static final long serialVersionUID = 1L; 26 | 27 | /** 28 | * 脚本文本域. 29 | */ 30 | private JTextArea scriptTextArea = createJTextArea(GuiUtils.font14_un); 31 | /** 32 | * 结果文本域. 33 | */ 34 | private JTextArea resultTextArea = createJTextArea(GuiUtils.font14_un); 35 | 36 | /** 37 | * 脚本类型. 38 | */ 39 | private String[] scriptTypes = getScriptTypes(); 40 | /** 41 | * 当前脚本类型. 42 | */ 43 | private String curScriptType = scriptTypes[0]; 44 | 45 | public RunScript() { 46 | // 边界布局 47 | setLayout(new BorderLayout()); 48 | // Center,脚本及结果输入输出域,使用2行1列的Grid布局,使其平均显示 49 | JPanel textAreaPanel = new JPanel(new GridLayout(2, 1)); 50 | add(textAreaPanel, BorderLayout.CENTER); 51 | 52 | JPanel scriptPanel = new JPanel(new BorderLayout()); 53 | addJLabel(scriptPanel, " 执行脚本: ", GuiUtils.font14b_cn, BorderLayout.WEST); 54 | scriptPanel.add(new JScrollPane(scriptTextArea), BorderLayout.CENTER); 55 | textAreaPanel.add(scriptPanel); 56 | 57 | JPanel resultPanel = new JPanel(new BorderLayout()); 58 | addJLabel(resultPanel, " 执行结果: ", GuiUtils.font14b_cn, BorderLayout.WEST); 59 | resultPanel.add(new JScrollPane(resultTextArea), BorderLayout.CENTER); 60 | textAreaPanel.add(resultPanel); 61 | 62 | // East,操作区域,使用BorderLayout布局 63 | JPanel actionPanel = new JPanel(new BorderLayout()); 64 | add(actionPanel, BorderLayout.EAST); 65 | // 放置下拉框等 66 | JPanel actionGridPanel = new JPanel(new GridLayout(5, 1)); 67 | actionPanel.add(actionGridPanel, BorderLayout.NORTH); 68 | 69 | // 脚本类型下拉框 70 | JPanel scriptTypesPanel = new JPanel(new FlowLayout()); 71 | addJLabel(scriptTypesPanel, "脚本类型:", GuiUtils.font14b_cn); 72 | addJComboBox(scriptTypesPanel, scriptTypes, GuiUtils.font13, new ActionListener() { 73 | @Override 74 | public void actionPerformed(ActionEvent event) { 75 | curScriptType = ((JComboBox) event.getSource()).getSelectedItem().toString(); 76 | } 77 | }); 78 | actionGridPanel.add(scriptTypesPanel); 79 | 80 | // 放置执行按钮 81 | JPanel buttonPanel = new JPanel(new GridLayout(2, 1)); 82 | actionPanel.add(buttonPanel, BorderLayout.SOUTH); 83 | // 执行按钮 84 | addJButton(buttonPanel, "执行", "", GuiUtils.font14b_cn, new SimpleMouseListener() { 85 | @Override 86 | public void mouseReleased(MouseEvent event) { 87 | String input = scriptTextArea.getText(); 88 | 89 | ScriptEngineManager sem = new ScriptEngineManager(); 90 | ScriptEngine se = sem.getEngineByName(curScriptType); 91 | try { 92 | resultTextArea.setText(String.valueOf(se.eval(input))); 93 | } catch (ScriptException e) { 94 | showExceptionMessage(e); 95 | } 96 | } 97 | 98 | @Override 99 | public void mousePressed(MouseEvent e) { 100 | resultTextArea.setText(""); 101 | } 102 | }); 103 | } 104 | 105 | /** 106 | * 支持的脚本类型. 107 | */ 108 | private String[] getScriptTypes() { 109 | ScriptEngineManager sem = new ScriptEngineManager(); 110 | List factorys = sem.getEngineFactories(); 111 | Set languages = new LinkedHashSet(); 112 | for (ScriptEngineFactory factory : factorys) { 113 | languages.add(factory.getLanguageName()); 114 | } 115 | String[] types = new String[languages.size()]; 116 | int i = 0; 117 | for (String name : languages) { 118 | types[i] = name; 119 | i++; 120 | } 121 | return types; 122 | } 123 | 124 | } 125 | -------------------------------------------------------------------------------- /src/main/java/bs/tool/commongui/plugins/TimeTool.java: -------------------------------------------------------------------------------- 1 | package bs.tool.commongui.plugins; 2 | 3 | import bs.tool.commongui.AbstractGuiJPanel; 4 | import bs.tool.commongui.GuiUtils; 5 | import bs.tool.commongui.utils.SimpleMouseListener; 6 | import bs.tool.commongui.utils.TimeUtils; 7 | 8 | import javax.swing.*; 9 | import java.awt.*; 10 | import java.awt.datatransfer.StringSelection; 11 | import java.awt.event.ActionEvent; 12 | import java.awt.event.ActionListener; 13 | import java.awt.event.MouseEvent; 14 | import java.text.SimpleDateFormat; 15 | import java.util.Date; 16 | 17 | /** 18 | * 时间工具. 19 | */ 20 | public class TimeTool extends AbstractGuiJPanel { 21 | 22 | private static final long serialVersionUID = 1L; 23 | 24 | /** 25 | * 时间格式. 26 | */ 27 | private String[] timeFormatter = new String[]{TimeUtils.FORMATTER, TimeUtils.FORMATTER_MILLISECOND, TimeUtils.FORMATTER_ZH, TimeUtils.FORMATTER_YEAR, TimeUtils.FORMATTER_ZH_YEAR}; 28 | 29 | /** 30 | * 当前时间格式. 31 | */ 32 | private String curTimeFormatter = timeFormatter[0]; 33 | 34 | /** 35 | * 时间字符表单. 36 | */ 37 | private JTextField timeStrTextField = new JTextField(new SimpleDateFormat(curTimeFormatter).format(new Date())); 38 | 39 | /** 40 | * 转换. 41 | */ 42 | private JButton convertButton; 43 | 44 | /** 45 | * 时间戳表单. 46 | */ 47 | private JTextField timestampTextField = new JTextField(Long.toString(System.currentTimeMillis())); 48 | 49 | /** 50 | * 还原. 51 | */ 52 | private JButton revertButton; 53 | 54 | public TimeTool() { 55 | 56 | // 主面板:边界布局,分North、Center两部分,North用于放置输入及条件控件,Center是放置空面面板 57 | setLayout(new BorderLayout()); 58 | 59 | // 输入及条件Panel 60 | JPanel inputPanel = new JPanel(new GridLayout(2, 1)); 61 | 62 | // 时间字符表单、时间格式、转换按钮Panel 63 | JPanel convertPanel = new JPanel(new BorderLayout()); 64 | addJLabel(convertPanel, " 时间字符: ", GuiUtils.font14_cn, BorderLayout.WEST); 65 | // 时间字符表单 66 | addJTextField(convertPanel, timeStrTextField, GuiUtils.font14_un, BorderLayout.CENTER); 67 | 68 | JPanel convertFlowPanel = new JPanel(new FlowLayout(FlowLayout.LEADING)); 69 | // 时间格式 70 | addJComboBox(convertFlowPanel, timeFormatter, GuiUtils.font13_cn, new ActionListener() { 71 | @Override 72 | public void actionPerformed(ActionEvent event) { 73 | curTimeFormatter = ((JComboBox) event.getSource()).getSelectedItem().toString(); 74 | } 75 | }); 76 | // 当前时间 77 | addJButton(convertFlowPanel, "当前时间", "", GuiUtils.font13_cn, new ActionListener() { 78 | @Override 79 | public void actionPerformed(ActionEvent event) { 80 | Date curDate = new Date(); 81 | timeStrTextField.setText(new SimpleDateFormat(curTimeFormatter).format(curDate)); 82 | timestampTextField.setText(Long.toString(curDate.getTime())); 83 | } 84 | }); 85 | // 复制 86 | addJButton(convertFlowPanel, "复制", "", GuiUtils.font13_cn, new ActionListener() { 87 | @Override 88 | public void actionPerformed(ActionEvent event) { 89 | StringSelection selection = new StringSelection(timeStrTextField.getText()); 90 | // 获取系统剪切板,复制时间字符 91 | Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection, selection); 92 | } 93 | }); 94 | // 转换按钮 95 | convertButton = createJButton("转换", "", GuiUtils.font14b_cn); 96 | convertButton.addMouseListener(new SimpleMouseListener() { 97 | @Override 98 | public void mouseReleased(MouseEvent event) { 99 | String timeStr = timeStrTextField.getText().trim(); 100 | if (timeStr.length() == 0) { 101 | showMessage("没有输入时间字符!", "警告", JOptionPane.WARNING_MESSAGE); 102 | return; 103 | } 104 | timestampTextField.setText(""); 105 | convertButton.setEnabled(false); 106 | try { 107 | timestampTextField.setText(Long.toString(new SimpleDateFormat(curTimeFormatter).parse(timeStr).getTime())); 108 | } catch (Exception e) { 109 | showExceptionMessage(e); 110 | } 111 | convertButton.setEnabled(true); 112 | } 113 | 114 | @Override 115 | public void mousePressed(MouseEvent e) { 116 | timestampTextField.setText(""); 117 | } 118 | }); 119 | convertFlowPanel.add(convertButton); 120 | convertPanel.add(convertFlowPanel, BorderLayout.EAST); 121 | 122 | // 时间戳表单、还原按钮Panel 123 | JPanel revertPanel = new JPanel(new BorderLayout()); 124 | addJLabel(revertPanel, " 时 间 戳: ", GuiUtils.font14_cn, BorderLayout.WEST); 125 | // 时间戳表单 126 | addJTextField(revertPanel, timestampTextField, GuiUtils.font14_un, BorderLayout.CENTER); 127 | 128 | JPanel revertFlowPanel = new JPanel(new FlowLayout(FlowLayout.LEADING)); 129 | // 复制 130 | addJButton(revertFlowPanel, "复制", "", GuiUtils.font13_cn, new ActionListener() { 131 | @Override 132 | public void actionPerformed(ActionEvent event) { 133 | StringSelection selection = new StringSelection(timestampTextField.getText()); 134 | // 获取系统剪切板,复制时间戳 135 | Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection, selection); 136 | } 137 | }); 138 | 139 | revertButton = createJButton("还原", "", GuiUtils.font14b_cn); 140 | revertButton.addMouseListener(new SimpleMouseListener() { 141 | @Override 142 | public void mouseReleased(MouseEvent event) { 143 | String timestamp = timestampTextField.getText().trim(); 144 | if (timestamp.length() == 0) { 145 | showMessage("没有输入时间戳!", "警告", JOptionPane.WARNING_MESSAGE); 146 | return; 147 | } 148 | timeStrTextField.setText(""); 149 | revertButton.setEnabled(false); 150 | try { 151 | timeStrTextField.setText(new SimpleDateFormat(curTimeFormatter).format(new Date(Long.parseLong(timestamp)))); 152 | } catch (Exception e) { 153 | showExceptionMessage(e); 154 | } 155 | revertButton.setEnabled(true); 156 | } 157 | 158 | @Override 159 | public void mousePressed(MouseEvent e) { 160 | timeStrTextField.setText(""); 161 | } 162 | }); 163 | revertFlowPanel.add(revertButton); 164 | revertPanel.add(revertFlowPanel, BorderLayout.EAST); 165 | 166 | inputPanel.add(convertPanel); 167 | inputPanel.add(revertPanel); 168 | 169 | add(inputPanel, BorderLayout.NORTH); 170 | 171 | // 空面面板 172 | JPanel resultPanel = new JPanel(new BorderLayout()); 173 | // 空白文本域 174 | JTextArea resultTextArea = createJTextArea(GuiUtils.font14_un); 175 | resultTextArea.setEditable(false); 176 | resultTextArea.setText(""); 177 | resultPanel.add(new JScrollPane(resultTextArea)); 178 | add(resultPanel, BorderLayout.CENTER); 179 | } 180 | 181 | } 182 | -------------------------------------------------------------------------------- /src/main/java/bs/tool/commongui/plugins/more/CodeFormatter.java: -------------------------------------------------------------------------------- 1 | package bs.tool.commongui.plugins.more; 2 | 3 | import bs.tool.commongui.AbstractGuiJPanel; 4 | import bs.tool.commongui.GuiUtils; 5 | import bs.tool.commongui.utils.CollectionUtils; 6 | import bs.tool.commongui.utils.SimpleMouseListener; 7 | import com.google.gson.*; 8 | 9 | import javax.swing.*; 10 | import java.awt.*; 11 | import java.awt.event.ActionEvent; 12 | import java.awt.event.ActionListener; 13 | import java.awt.event.MouseEvent; 14 | import java.lang.reflect.Type; 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | 18 | /** 19 | * Code格式化. 20 | */ 21 | public class CodeFormatter extends AbstractGuiJPanel { 22 | 23 | private static final long serialVersionUID = 1L; 24 | 25 | /** 26 | * 文本域. 27 | */ 28 | private JTextArea textArea = createJTextArea(GuiUtils.font14_un); 29 | 30 | /** 31 | * Code类型. 32 | */ 33 | private String[] codeTypes = new String[]{GuiUtils.CODE_TYPE_JSON, GuiUtils.CODE_TYPE_PROPERTIES, GuiUtils.CODE_TYPE_YML, 34 | GuiUtils.CODE_TYPE_XML, GuiUtils.CODE_TYPE_JAVA, GuiUtils.CODE_TYPE_JS, GuiUtils.CODE_TYPE_PYTHON, GuiUtils.CODE_TYPE_SQL}; 35 | 36 | /** 37 | * 当前Code类型. 38 | */ 39 | private String curCodeType = codeTypes[0]; 40 | 41 | public CodeFormatter() { 42 | // 边界布局 43 | setLayout(new BorderLayout()); 44 | JPanel textAreaPanel = new JPanel(new GridLayout(1, 1)); 45 | add(textAreaPanel, BorderLayout.CENTER); 46 | 47 | JPanel textPanel = new JPanel(new BorderLayout()); 48 | addJLabel(textPanel, " Code: ", GuiUtils.font14b_cn, BorderLayout.WEST); 49 | textPanel.add(new JScrollPane(textArea), BorderLayout.CENTER); 50 | textAreaPanel.add(textPanel); 51 | 52 | // East,操作区域,使用BorderLayout布局 53 | JPanel actionPanel = new JPanel(new BorderLayout()); 54 | add(actionPanel, BorderLayout.EAST); 55 | 56 | // 填充 57 | actionPanel.add(new JPanel(), BorderLayout.CENTER); 58 | 59 | // 放置按钮 60 | JPanel buttonPanel = new JPanel(new GridLayout(6, 1)); 61 | actionPanel.add(buttonPanel, BorderLayout.SOUTH); 62 | 63 | JPanel codeTypePanel = new JPanel(new FlowLayout()); 64 | addJLabel(codeTypePanel, "类型:", GuiUtils.font14b_cn); 65 | // 类型下拉框 66 | addJComboBox(codeTypePanel, codeTypes, GuiUtils.font13, new ActionListener() { 67 | @Override 68 | public void actionPerformed(ActionEvent event) { 69 | curCodeType = ((JComboBox) event.getSource()).getSelectedItem().toString(); 70 | } 71 | }); 72 | buttonPanel.add(codeTypePanel); 73 | // 仅做填充 74 | buttonPanel.add(new JPanel()); 75 | 76 | // 格式化 77 | addJButton(buttonPanel, " 格式化 ", "", GuiUtils.font14b_cn, new SimpleMouseListener() { 78 | @Override 79 | public void mouseReleased(MouseEvent event) { 80 | String input = textArea.getText(); 81 | if (curCodeType.equals(GuiUtils.CODE_TYPE_JSON)) { 82 | textArea.setText(prettyJson(input, false)); 83 | } else if (curCodeType.equals(GuiUtils.CODE_TYPE_PROPERTIES)) { 84 | textArea.setText(prettyProperties(input, false)); 85 | } else { 86 | showMessage("当前仅支持JSON, Properties格式化!", "提示", JOptionPane.INFORMATION_MESSAGE); 87 | } 88 | } 89 | }); 90 | 91 | // 反格式化 92 | addJButton(buttonPanel, " 反格式化 ", "", GuiUtils.font14b_cn, new SimpleMouseListener() { 93 | @Override 94 | public void mouseReleased(MouseEvent event) { 95 | String input = textArea.getText(); 96 | if (curCodeType.equals(GuiUtils.CODE_TYPE_JSON)) { 97 | textArea.setText(unPrettyJson(input)); 98 | } else { 99 | showMessage("当前仅支持JSON反格式化!", "提示", JOptionPane.INFORMATION_MESSAGE); 100 | } 101 | } 102 | }); 103 | 104 | // 初始化元素值 105 | addJButton(buttonPanel, " 初始化元素值 ", "", GuiUtils.font14b_cn, new SimpleMouseListener() { 106 | @Override 107 | public void mouseReleased(MouseEvent event) { 108 | String input = textArea.getText(); 109 | if (curCodeType.equals(GuiUtils.CODE_TYPE_JSON)) { 110 | textArea.setText(prettyJson(input, true)); 111 | } else if (curCodeType.equals(GuiUtils.CODE_TYPE_PROPERTIES)) { 112 | textArea.setText(prettyProperties(input, true)); 113 | } else { 114 | showMessage("当前仅支持JSON, Properties初始化元素值!", "提示", JOptionPane.INFORMATION_MESSAGE); 115 | } 116 | } 117 | }); 118 | 119 | // 清空 120 | addJButton(buttonPanel, " 清 空 ", "", GuiUtils.font14_cn, new ActionListener() { 121 | @Override 122 | public void actionPerformed(ActionEvent event) { 123 | textArea.setText(""); 124 | } 125 | }); 126 | } 127 | 128 | /** 129 | * 格式化json. 130 | * 131 | * @param jsonStr 132 | * @param reInitItem 133 | * @return 134 | */ 135 | public String prettyJson(String jsonStr, boolean reInitItem) { 136 | try { 137 | Gson gson = getGsonBuilder() 138 | .setPrettyPrinting() 139 | .create(); 140 | Object o = gson.fromJson(jsonStr, Object.class); 141 | if (reInitItem) { 142 | CollectionUtils.reInitItemValue(o); 143 | } 144 | return gson.toJson(o); 145 | } catch (Exception e) { 146 | showExceptionMessage(e); 147 | return jsonStr; 148 | } 149 | } 150 | 151 | /** 152 | * 格式化properties. 153 | * 154 | * @param propertiesStr 155 | * @param reInitItem 156 | * @return 157 | */ 158 | public String prettyProperties(String propertiesStr, boolean reInitItem) { 159 | try { 160 | StringBuilder rps = new StringBuilder(); 161 | 162 | List l = new ArrayList(); 163 | String[] f = propertiesStr.split("\r\n"); 164 | for (String fi : f) { 165 | String[] s = fi.split("\n"); 166 | for (String si : s) { 167 | String[] t = si.split("\r"); 168 | for (String ti : t) { 169 | if (GuiUtils.trim(ti).startsWith("#")) { 170 | rps.append(GuiUtils.trim(ti)).append("\n"); 171 | } else { 172 | int idx = ti.indexOf("="); 173 | if (idx > 0) { 174 | rps.append(GuiUtils.trim(ti.substring(0, idx))).append("="); 175 | if (!reInitItem) { 176 | rps.append(GuiUtils.trim(ti.substring(idx + 1))); 177 | } 178 | rps.append("\n"); 179 | } else { 180 | rps.append(GuiUtils.trim(ti)).append("\n"); 181 | } 182 | } 183 | } 184 | } 185 | } 186 | return rps.toString(); 187 | } catch (Exception e) { 188 | showExceptionMessage(e); 189 | return propertiesStr; 190 | } 191 | } 192 | 193 | /** 194 | * 反格式化json. 195 | * 196 | * @param jsonStr 197 | * @return 198 | */ 199 | public String unPrettyJson(String jsonStr) { 200 | try { 201 | Gson gson = getGsonBuilder() 202 | .create(); 203 | return gson.toJson(gson.fromJson(jsonStr, Object.class)); 204 | } catch (Exception e) { 205 | showExceptionMessage(e); 206 | return jsonStr; 207 | } 208 | } 209 | 210 | /** 211 | * How to prevent Gson from expressing integers as floats. 212 | * https://stackoverflow.com/questions/15507997/how-to-prevent-gson-from-expressing-integers-as-floats 213 | * 214 | * @return 215 | */ 216 | private GsonBuilder getGsonBuilder() { 217 | return new GsonBuilder(). 218 | registerTypeAdapter(Double.class, new JsonSerializer() { 219 | @Override 220 | public JsonElement serialize(Double src, Type typeOfSrc, JsonSerializationContext context) { 221 | if (src == src.longValue()) { 222 | return new JsonPrimitive(src.longValue()); 223 | } 224 | return new JsonPrimitive(src); 225 | } 226 | }); 227 | } 228 | 229 | } 230 | -------------------------------------------------------------------------------- /src/main/java/bs/tool/commongui/plugins/more/EscapeCharacterTool.java: -------------------------------------------------------------------------------- 1 | package bs.tool.commongui.plugins.more; 2 | 3 | import bs.tool.commongui.AbstractGuiJPanel; 4 | import bs.tool.commongui.GuiUtils; 5 | import bs.tool.commongui.utils.EscapeUtils; 6 | import bs.tool.commongui.utils.LanguageUtils; 7 | import bs.tool.commongui.utils.SimpleMouseListener; 8 | 9 | import javax.swing.*; 10 | import java.awt.*; 11 | import java.awt.event.ActionEvent; 12 | import java.awt.event.ActionListener; 13 | import java.awt.event.MouseEvent; 14 | 15 | /** 16 | * 字符转义工具. 17 | */ 18 | public class EscapeCharacterTool extends AbstractGuiJPanel { 19 | 20 | private static final long serialVersionUID = 1L; 21 | 22 | /** 23 | * 字符文本域. 24 | */ 25 | private JTextArea unescapeTextArea = createJTextArea(GuiUtils.font14_un); 26 | /** 27 | * 转义文本域. 28 | */ 29 | private JTextArea escapeTextArea = createJTextArea(GuiUtils.font14_un); 30 | /** 31 | * 帮助文本域. 32 | */ 33 | private JTextArea helpTextArea = createJTextArea(GuiUtils.font14_un); 34 | 35 | /** 36 | * 字符类型. 37 | */ 38 | private String[] characterTypes = new String[]{LanguageUtils.CONST_HTML, LanguageUtils.CONST_XML, 39 | LanguageUtils.CONST_JAVA, LanguageUtils.CONST_JAVASCRIPT, LanguageUtils.CONST_CSV}; 40 | /** 41 | * 字符类型. 42 | */ 43 | private String curCharacterType = characterTypes[0]; 44 | 45 | /** 46 | * HTML转义说明. 47 | */ 48 | private static final String ESCAPE_HELP_HTML = "HTML See: http://www.w3.org/TR/html4/sgml/entities.html" 49 | + "\n" 50 | + "\n < > & \" no-break space em space en space ® © ™" 51 | + "\n< > & "       ® © ™"; 52 | /** 53 | * XML转义说明. 54 | */ 55 | private static final String ESCAPE_HELP_XML = "XML See: http://www.xmlnews.org/docs/xml-basics.html" 56 | + "\n" + "\n < > & \" '" 57 | + "\n< > & " '"; 58 | /** 59 | * JAVA转义说明. 60 | */ 61 | private static final String ESCAPE_HELP_JAVA = "JAVA See: http://docs.oracle.com/javase/tutorial/java/data/characters.html" 62 | + "\n" 63 | + "\n回车符 换行符 制表符 单引号 双引号 反斜杠 退格符 换页符" 64 | + "\n \\r \\n \\t \\' \\\" \\\\ \\b \\f"; 65 | /** 66 | * JavaScript转义说明. 67 | */ 68 | private static final String ESCAPE_HELP_JAVA_SCRIPT = "JavaScript See: http://www.w3schools.com/js/js_strings.asp" 69 | + "\n" 70 | + "\n回车符 换行符 制表符 单引号 双引号 反斜杠 退格符 换页符" 71 | + "\n \\r \\n \\t \\' \\\" \\\\ \\b \\f"; 72 | /** 73 | * CSV转义说明. 74 | */ 75 | private static final String ESCAPE_HELP_CSV = ""; 76 | 77 | public EscapeCharacterTool() { 78 | // 边界布局 79 | setLayout(new BorderLayout()); 80 | // Center,字符及转义结果输入输出域,使用3行1列的Grid布局,使其平均显示 81 | JPanel textAreaPanel = new JPanel(new GridLayout(3, 1)); 82 | add(textAreaPanel, BorderLayout.CENTER); 83 | 84 | JPanel scriptPanel = new JPanel(new BorderLayout()); 85 | addJLabel(scriptPanel, " 原 字 符: ", GuiUtils.font14b_cn, BorderLayout.WEST); 86 | scriptPanel.add(new JScrollPane(unescapeTextArea), BorderLayout.CENTER); 87 | textAreaPanel.add(scriptPanel); 88 | 89 | JPanel resultPanel = new JPanel(new BorderLayout()); 90 | addJLabel(resultPanel, " 转义字符: ", GuiUtils.font14b_cn, BorderLayout.WEST); 91 | resultPanel.add(new JScrollPane(escapeTextArea), BorderLayout.CENTER); 92 | textAreaPanel.add(resultPanel); 93 | 94 | JPanel helpTextPanel = new JPanel(new BorderLayout()); 95 | addJLabel(helpTextPanel, " 常用转义: ", GuiUtils.font14b_cn, BorderLayout.WEST); 96 | helpTextPanel.add(new JScrollPane(helpTextArea), BorderLayout.CENTER); 97 | textAreaPanel.add(helpTextPanel); 98 | 99 | setHelpTextArea(); 100 | 101 | // East,操作区域,使用BorderLayout布局 102 | JPanel actionPanel = new JPanel(new BorderLayout()); 103 | add(actionPanel, BorderLayout.EAST); 104 | 105 | // 帮助面板 106 | JPanel helpPanel = new JPanel(new BorderLayout()); 107 | JPanel helpButtonPanel = new JPanel(new BorderLayout()); 108 | helpPanel.add(helpButtonPanel, BorderLayout.EAST); 109 | addJButton(helpButtonPanel, "帮助", "", GuiUtils.font13_cn, new ActionListener() { 110 | @Override 111 | public void actionPerformed(ActionEvent event) { 112 | showTextAreaMessage("常用转义字符" + "\n\n" + ESCAPE_HELP_HTML + "\n\n\n" + ESCAPE_HELP_XML + "\n\n\n" 113 | + ESCAPE_HELP_JAVA + "\n\n\n" + ESCAPE_HELP_JAVA_SCRIPT + "\n\n\n" + ESCAPE_HELP_CSV, "帮助", 114 | JOptionPane.INFORMATION_MESSAGE, null, null); 115 | } 116 | }); 117 | 118 | actionPanel.add(helpPanel, BorderLayout.NORTH); 119 | // 填充 120 | actionPanel.add(new JPanel(), BorderLayout.CENTER); 121 | 122 | // 放置按钮 123 | JPanel buttonPanel = new JPanel(new GridLayout(9, 1)); 124 | actionPanel.add(buttonPanel, BorderLayout.SOUTH); 125 | addJComboBox(buttonPanel, characterTypes, GuiUtils.font13, new ActionListener() { 126 | @Override 127 | public void actionPerformed(ActionEvent event) { 128 | curCharacterType = ((JComboBox) event.getSource()).getSelectedItem().toString(); 129 | setHelpTextArea(); 130 | } 131 | }); 132 | // 仅做填充 133 | buttonPanel.add(new JPanel()); 134 | // 转换 135 | addJButton(buttonPanel, " 转换 ", "", GuiUtils.font14b_cn, new SimpleMouseListener() { 136 | @Override 137 | public void mouseReleased(MouseEvent event) { 138 | String input = unescapeTextArea.getText(); 139 | escapeTextArea.append(EscapeUtils.escape(input, curCharacterType)); 140 | } 141 | 142 | @Override 143 | public void mousePressed(MouseEvent e) { 144 | escapeTextArea.setText(""); 145 | } 146 | }); 147 | // 仅做填充 148 | buttonPanel.add(new JPanel()); 149 | // 还原 150 | addJButton(buttonPanel, " 还原 ", "", GuiUtils.font14b_cn, new SimpleMouseListener() { 151 | @Override 152 | public void mouseReleased(MouseEvent event) { 153 | String input = escapeTextArea.getText(); 154 | unescapeTextArea.append(EscapeUtils.unescape(input, curCharacterType)); 155 | } 156 | 157 | @Override 158 | public void mousePressed(MouseEvent e) { 159 | unescapeTextArea.setText(""); 160 | } 161 | }); 162 | // 仅做填充 163 | buttonPanel.add(new JPanel()); 164 | // 全部清空 165 | addJButton(buttonPanel, " 全部清空 ", "", GuiUtils.font14_cn, new ActionListener() { 166 | @Override 167 | public void actionPerformed(ActionEvent event) { 168 | unescapeTextArea.setText(""); 169 | escapeTextArea.setText(""); 170 | } 171 | }); 172 | } 173 | 174 | /** 175 | * 设置帮助文本域显示文字. 176 | */ 177 | private void setHelpTextArea() { 178 | if (curCharacterType.equals(LanguageUtils.CONST_HTML)) { 179 | helpTextArea.setText(ESCAPE_HELP_HTML); 180 | } else if (curCharacterType.equals(LanguageUtils.CONST_XML)) { 181 | helpTextArea.setText(ESCAPE_HELP_XML); 182 | } else if (curCharacterType.equals(LanguageUtils.CONST_JAVA)) { 183 | helpTextArea.setText(ESCAPE_HELP_JAVA); 184 | } else if (curCharacterType.equals(LanguageUtils.CONST_JAVASCRIPT)) { 185 | helpTextArea.setText(ESCAPE_HELP_JAVA_SCRIPT); 186 | } else if (curCharacterType.equals(LanguageUtils.CONST_CSV)) { 187 | helpTextArea.setText(ESCAPE_HELP_CSV); 188 | } 189 | } 190 | 191 | } 192 | -------------------------------------------------------------------------------- /src/main/java/bs/tool/commongui/plugins/more/JUniversalChardet.java: -------------------------------------------------------------------------------- 1 | package bs.tool.commongui.plugins.more; 2 | 3 | import bs.tool.commongui.AbstractGuiJPanel; 4 | import bs.tool.commongui.GuiUtils; 5 | import bs.tool.commongui.utils.FileUtils; 6 | import bs.tool.commongui.utils.SearchFileNameParams; 7 | import bs.tool.commongui.utils.SimpleMouseListener; 8 | import bs.util.io.PropertiesUtils; 9 | import org.mozilla.universalchardet.UniversalDetector; 10 | 11 | import javax.swing.*; 12 | import java.awt.*; 13 | import java.awt.event.ActionEvent; 14 | import java.awt.event.ActionListener; 15 | import java.awt.event.MouseEvent; 16 | import java.io.File; 17 | import java.io.FileInputStream; 18 | import java.io.IOException; 19 | import java.net.URL; 20 | import java.util.List; 21 | import java.util.*; 22 | 23 | /** 24 | * 文本编码识别. 25 | */ 26 | public class JUniversalChardet extends AbstractGuiJPanel { 27 | 28 | private static final long serialVersionUID = 1L; 29 | 30 | /** 31 | * 探测文本/文件夹路径表单. 32 | */ 33 | private JTextField detectPathTextField = new JTextField(); 34 | /** 35 | * 探测文本/文件夹路径选择. 36 | */ 37 | private JFileChooser detectPathChooser = new JFileChooser(); 38 | 39 | /** 40 | * 探测按钮. 41 | */ 42 | private JButton detectButton; 43 | 44 | /** 45 | * 取样大小表单. 46 | */ 47 | private JTextField detectSizeTextField = new JTextField("51200", 7); 48 | 49 | /** 50 | * 文件名包含字符表单. 51 | */ 52 | private JTextField fileNameContainsTextField; 53 | /** 54 | * 文件名不包含字符表单. 55 | */ 56 | private JTextField fileNameNotContainsTextField; 57 | /** 58 | * 文件名是否支持正则. 59 | */ 60 | private boolean fileNameSupportRegex = true; 61 | 62 | /** 63 | * 探测结果文本域. 64 | */ 65 | private JTextArea resultTextArea = createJTextArea(GuiUtils.font14_un); 66 | 67 | public JUniversalChardet() { 68 | 69 | // 主面板:边界布局,分North、Center两部分,North用于放置输入及条件控件,Center是放置探测结果输出 70 | setLayout(new BorderLayout()); 71 | 72 | // 输入及条件Panel 73 | JPanel inputPanel = new JPanel(new GridLayout(2, 1)); 74 | 75 | // 探测文本/文件夹表单、探测按钮Panel 76 | JPanel fileChooAndDetectPanel = new JPanel(new BorderLayout()); 77 | // 探测文本/文件夹表单 78 | addJLabel(fileChooAndDetectPanel, " 探测文本/文件夹/URL: ", GuiUtils.font14_cn, BorderLayout.WEST); 79 | JPanel fileChooPanel = new JPanel(new BorderLayout()); 80 | fileChooPanel.add(new JPanel(), BorderLayout.NORTH); 81 | addJTextField(fileChooPanel, detectPathTextField, GuiUtils.font14_un, BorderLayout.CENTER); 82 | fileChooPanel.add(new JPanel(), BorderLayout.SOUTH); 83 | fileChooAndDetectPanel.add(fileChooPanel, BorderLayout.CENTER); 84 | 85 | JPanel buttonFlowPanel = new JPanel(new FlowLayout(FlowLayout.LEADING)); 86 | addJButton(buttonFlowPanel, "浏览", "", GuiUtils.font12_cn, 87 | buttonBrowseListener(detectPathChooser, detectPathTextField)); 88 | // 探测按钮 89 | detectButton = createJButton("探测", "", GuiUtils.font14b_cn); 90 | detectButton.addMouseListener(new SimpleMouseListener() { 91 | @Override 92 | public void mouseReleased(MouseEvent event) { 93 | String path = detectPathTextField.getText().trim(); 94 | File file = new File(path); 95 | boolean exists = true; 96 | if (!file.exists()) { 97 | try { 98 | file = new File(FileUtils.JAVA_IO_TMPDIR + "/" + "detect-" + System.currentTimeMillis()); 99 | org.apache.commons.io.FileUtils.copyURLToFile(new URL(path), file); 100 | } catch (IOException e) { 101 | GuiUtils.log(e); 102 | exists = false; 103 | } 104 | } 105 | if (!exists || file == null || !file.exists()) { 106 | showMessage("探测文本/文件夹/URL不存在或错误!", "警告", JOptionPane.WARNING_MESSAGE); 107 | return; 108 | } 109 | Map paramsMap = new HashMap(); 110 | paramsMap.put("fileNameContainsText", fileNameContainsTextField.getText().trim()); 111 | paramsMap.put("fileNameNotContainsText", fileNameNotContainsTextField.getText().trim()); 112 | paramsMap.put("fileNameSupportRegex", fileNameSupportRegex); 113 | detectButton.setEnabled(false); 114 | 115 | resultTextArea.setText(""); 116 | try { 117 | int detectLength = Integer.parseInt(detectSizeTextField.getText().trim()); 118 | if (!file.isDirectory()) { 119 | appendDetectResult(resultTextArea, file, detectLength); 120 | } else { 121 | List files = new ArrayList(); 122 | FileUtils.loopDirectory(file, files, new SearchFileNameParams(paramsMap)); 123 | for (File fFile : files) { 124 | appendDetectResult(resultTextArea, fFile, detectLength); 125 | } 126 | resultTextArea.append("\nCount files: " + files.size()); 127 | } 128 | } catch (NumberFormatException e) { 129 | showMessage("取样大小必须是正整数!", "警告", JOptionPane.WARNING_MESSAGE); 130 | } catch (IOException e) { 131 | showExceptionMessage(e); 132 | } 133 | detectButton.setEnabled(true); 134 | } 135 | 136 | @Override 137 | public void mousePressed(MouseEvent e) { 138 | resultTextArea.setText(""); 139 | } 140 | }); 141 | buttonFlowPanel.add(detectButton); 142 | // 探测路径选择控件,可选择文件/文件夹 143 | detectPathChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); 144 | fileChooAndDetectPanel.add(buttonFlowPanel, BorderLayout.EAST); 145 | inputPanel.add(fileChooAndDetectPanel); 146 | 147 | // 高级条件Panel 148 | JPanel advancePanel = new JPanel(new FlowLayout(FlowLayout.LEADING)); 149 | // 取样大小 150 | addJLabel(advancePanel, " ", GuiUtils.font12_cn); 151 | addJLabel(advancePanel, "取样大小: ", GuiUtils.font14_cn); 152 | addJTextField(advancePanel, detectSizeTextField, GuiUtils.font14_cn); 153 | addJLabel(advancePanel, "Byte", GuiUtils.font14_cn); 154 | 155 | // 文件名包含(不包含)字符 156 | String confPropsFile = "conf/JUniversalChardet/searchFiletypes.properties"; 157 | String containsFiletypes = ""; 158 | String notContainsFiletypes = ""; 159 | try { 160 | Properties confProperties = PropertiesUtils.getProperties(GuiUtils.getActualPath(confPropsFile)); 161 | containsFiletypes = confProperties.getProperty("ContainsFiletypes").trim(); 162 | notContainsFiletypes = confProperties.getProperty("NotContainsFiletypes").trim(); 163 | } catch (IOException e) { 164 | logLoadPropertiesException(confPropsFile, e); 165 | } 166 | addJLabel(advancePanel, " 文件名包含字符: ", GuiUtils.font14_cn); 167 | String fileNameContains = containsFiletypes.length() > 0 ? "\\.(" + containsFiletypes.replace(",", "|") + ")$" 168 | : ""; 169 | fileNameContainsTextField = new JTextField(fileNameContains, 15); 170 | addJTextField(advancePanel, fileNameContainsTextField, GuiUtils.font14_un); 171 | addJLabel(advancePanel, " 文件名不包含字符: ", GuiUtils.font14_cn); 172 | String fileNameNotContains = notContainsFiletypes.length() > 0 ? "\\.(" 173 | + notContainsFiletypes.replace(",", "|") + ")$" : ""; 174 | fileNameNotContainsTextField = new JTextField(fileNameNotContains, 15); 175 | addJTextField(advancePanel, fileNameNotContainsTextField, GuiUtils.font14_un); 176 | // 是否支持正则 177 | addJCheckBox(advancePanel, "支持正则", true, GuiUtils.font14_cn, new ActionListener() { 178 | @Override 179 | public void actionPerformed(ActionEvent event) { 180 | fileNameSupportRegex = ((JCheckBox) event.getSource()).isSelected(); 181 | } 182 | }); 183 | inputPanel.add(advancePanel); 184 | 185 | add(inputPanel, BorderLayout.NORTH); 186 | 187 | // 探测结果输出 188 | JPanel detectLogPanel = new JPanel(new BorderLayout()); 189 | detectLogPanel.add(new JScrollPane(resultTextArea)); 190 | add(detectLogPanel, BorderLayout.CENTER); 191 | } 192 | 193 | /** 194 | * append探测文本编码结果. 195 | */ 196 | private void appendDetectResult(JTextArea resultTextArea, File file, int detectLength) throws IOException { 197 | resultTextArea.append(file.getAbsolutePath() + " Charset: " + detectFileCharset(file, detectLength) 198 | + "\n"); 199 | } 200 | 201 | /** 202 | * 探测文本编码. 203 | */ 204 | public static String detectFileCharset(File file, int detectLength) throws IOException { 205 | String charset = null; 206 | FileInputStream fis = null; 207 | try { 208 | byte[] buf = new byte[detectLength]; 209 | fis = new FileInputStream(file); 210 | UniversalDetector detector = new UniversalDetector(null); 211 | int nread; 212 | while ((nread = fis.read(buf)) > 0 && !detector.isDone()) { 213 | detector.handleData(buf, 0, nread); 214 | } 215 | detector.dataEnd(); 216 | charset = detector.getDetectedCharset(); 217 | detector.reset(); 218 | } finally { 219 | if (fis != null) { 220 | fis.close(); 221 | } 222 | } 223 | return charset; 224 | } 225 | 226 | } 227 | -------------------------------------------------------------------------------- /src/main/java/bs/tool/commongui/plugins/more/PasswordGenerator.java: -------------------------------------------------------------------------------- 1 | package bs.tool.commongui.plugins.more; 2 | 3 | import bs.tool.commongui.AbstractGuiJPanel; 4 | import bs.tool.commongui.GuiUtils; 5 | import bs.tool.commongui.utils.SimpleMouseListener; 6 | import org.passay.CharacterRule; 7 | import org.passay.EnglishCharacterData; 8 | 9 | import javax.swing.*; 10 | import java.awt.*; 11 | import java.awt.event.ActionEvent; 12 | import java.awt.event.ActionListener; 13 | import java.awt.event.MouseEvent; 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | 17 | /** 18 | * 随机密码生成. 19 | */ 20 | public class PasswordGenerator extends AbstractGuiJPanel { 21 | 22 | private static final long serialVersionUID = 1L; 23 | 24 | /** 25 | * 密码文本域. 26 | */ 27 | private JTextArea passwordTextArea = createJTextArea(GuiUtils.font14_un); 28 | /** 29 | * 规则校验文本域. 30 | */ 31 | private JTextArea ruleCheckTextArea = createJTextArea(GuiUtils.font14_un); 32 | 33 | /** 34 | * 常见密码组合. 35 | */ 36 | private String[] passwordCombinations = new String[]{GuiUtils.PASSWORD_COMBINATION_8_CHAR_NUM_SIMPLE, 37 | GuiUtils.PASSWORD_COMBINATION_8_CHAR_NUM_POPULAR}; 38 | private String curPasswordCombination = passwordCombinations[0]; 39 | 40 | /** 41 | * 生成数量输入框. 42 | */ 43 | private JTextField passwordNumberTextField = new JTextField("10", 5); 44 | /** 45 | * 数字位数输入框. 46 | */ 47 | private JTextField numberCharacterRuleTextField = new JTextField("6", 5); 48 | /** 49 | * 字母位数输入框. 50 | */ 51 | private JTextField englishCharacterRuleTextField = new JTextField("2", 5); 52 | /** 53 | * 特殊字符位数输入框. 54 | */ 55 | private JTextField specialCharacterRuleTextField = new JTextField("0", 5); 56 | /** 57 | * 大小字母位数输入框. 58 | */ 59 | private JTextField upperCaseCharacterRuleTextField = new JTextField(5); 60 | /** 61 | * 小写字母位数输入框. 62 | */ 63 | private JTextField lowerCaseCharacterRuleTextField = new JTextField(5); 64 | 65 | public PasswordGenerator() { 66 | 67 | // 边界布局 68 | setLayout(new BorderLayout()); 69 | // Center,加密解密输入输出域,使用2行1列的Grid布局,使其平均显示 70 | JPanel textAreaPanel = new JPanel(new GridLayout(2, 1)); 71 | add(textAreaPanel, BorderLayout.CENTER); 72 | 73 | JPanel encrptyPanel = new JPanel(new BorderLayout()); 74 | addJLabel(encrptyPanel, " 密码: ", GuiUtils.font14b_cn, BorderLayout.WEST); 75 | encrptyPanel.add(new JScrollPane(passwordTextArea), BorderLayout.CENTER); 76 | textAreaPanel.add(encrptyPanel); 77 | 78 | JPanel decrptyPanel = new JPanel(new BorderLayout()); 79 | addJLabel(decrptyPanel, " 校验: ", GuiUtils.font14b_cn, BorderLayout.WEST); 80 | decrptyPanel.add(new JScrollPane(ruleCheckTextArea), BorderLayout.CENTER); 81 | textAreaPanel.add(decrptyPanel); 82 | 83 | // East,操作区域,使用BorderLayout布局 84 | JPanel actionPanel = new JPanel(new BorderLayout()); 85 | add(actionPanel, BorderLayout.EAST); 86 | // 放置下拉框、单选框等 87 | JPanel actionGridPanel = new JPanel(new GridLayout(10, 1)); 88 | actionPanel.add(actionGridPanel, BorderLayout.NORTH); 89 | 90 | // 密码组合下拉框 91 | JPanel passwordCombinationsPanel = new JPanel(new FlowLayout()); 92 | addJLabel(passwordCombinationsPanel, "密码组合:", GuiUtils.font14b_cn); 93 | addJComboBox(passwordCombinationsPanel, passwordCombinations, GuiUtils.font13_cn, new ActionListener() { 94 | @Override 95 | public void actionPerformed(ActionEvent event) { 96 | curPasswordCombination = ((JComboBox) event.getSource()).getSelectedItem().toString(); 97 | if (curPasswordCombination.equals(GuiUtils.PASSWORD_COMBINATION_8_CHAR_NUM_SIMPLE)) { 98 | numberCharacterRuleTextField.setText("6"); 99 | englishCharacterRuleTextField.setText("2"); 100 | specialCharacterRuleTextField.setText("0"); 101 | upperCaseCharacterRuleTextField.setText(""); 102 | lowerCaseCharacterRuleTextField.setText(""); 103 | } else if (curPasswordCombination.equals(GuiUtils.PASSWORD_COMBINATION_8_CHAR_NUM_POPULAR)) { 104 | numberCharacterRuleTextField.setText("2"); 105 | englishCharacterRuleTextField.setText("3"); 106 | specialCharacterRuleTextField.setText("1"); 107 | upperCaseCharacterRuleTextField.setText("1"); 108 | lowerCaseCharacterRuleTextField.setText("1"); 109 | } 110 | } 111 | }); 112 | actionGridPanel.add(passwordCombinationsPanel); 113 | 114 | JPanel numPanel = new JPanel(new FlowLayout(FlowLayout.LEADING)); 115 | addJLabel(numPanel, "生成数量:", GuiUtils.font14b_cn); 116 | numPanel.add(passwordNumberTextField); 117 | actionGridPanel.add(numPanel); 118 | 119 | // 仅作填充 120 | addJLabel(actionGridPanel, " ", GuiUtils.font13); 121 | 122 | addJLabel(actionGridPanel, " 密码规则:", GuiUtils.font14b_cn); 123 | 124 | // FlowLayout.LEADING,此值指示每一行组件都应该与容器方向的开始边对齐,例如,对于从左到右的方向,则与左边对齐 125 | JPanel rfPanel = new JPanel(new FlowLayout(FlowLayout.LEADING)); 126 | addJLabel(rfPanel, " 数字位数:", GuiUtils.font13_cn); 127 | rfPanel.add(numberCharacterRuleTextField); 128 | actionGridPanel.add(rfPanel); 129 | 130 | JPanel rsPanel = new JPanel(new FlowLayout(FlowLayout.LEADING)); 131 | addJLabel(rsPanel, " 字母位数:", GuiUtils.font13_cn); 132 | rsPanel.add(englishCharacterRuleTextField); 133 | actionGridPanel.add(rsPanel); 134 | 135 | JPanel rtPanel = new JPanel(new FlowLayout(FlowLayout.LEADING)); 136 | addJLabel(rtPanel, " 特殊字符:", GuiUtils.font13_cn); 137 | rtPanel.add(specialCharacterRuleTextField); 138 | actionGridPanel.add(rtPanel); 139 | 140 | JPanel rfoPanel = new JPanel(new FlowLayout(FlowLayout.LEADING)); 141 | addJLabel(rfoPanel, " 大写字母:", GuiUtils.font13_cn); 142 | rfoPanel.add(upperCaseCharacterRuleTextField); 143 | actionGridPanel.add(rfoPanel); 144 | 145 | JPanel rfiPanel = new JPanel(new FlowLayout(FlowLayout.LEADING)); 146 | addJLabel(rfiPanel, " 小写字母:", GuiUtils.font13_cn); 147 | rfiPanel.add(lowerCaseCharacterRuleTextField); 148 | actionGridPanel.add(rfiPanel); 149 | 150 | // 仅作填充 151 | actionPanel.add(new Panel(), BorderLayout.CENTER); 152 | 153 | // 放置生成校验按钮 154 | JPanel buttonPanel = new JPanel(new GridLayout(3, 1)); 155 | actionPanel.add(buttonPanel, BorderLayout.SOUTH); 156 | // 生成按钮 157 | addJButton(buttonPanel, "生成", "", GuiUtils.font14b_cn, new SimpleMouseListener() { 158 | @Override 159 | public void mouseReleased(MouseEvent event) { 160 | try { 161 | // https://github.com/vt-middleware/passay/blob/master/src/test/java/org/passay/PasswordGeneratorTest.java 162 | List rules = new ArrayList(); 163 | int pt = 0; 164 | pt += addRuleIfNotNull(numberCharacterRuleTextField.getText(), EnglishCharacterData.Digit, rules); 165 | pt += addRuleIfNotNull(englishCharacterRuleTextField.getText(), EnglishCharacterData.Alphabetical, rules); 166 | pt += addRuleIfNotNull(specialCharacterRuleTextField.getText(), EnglishCharacterData.Special, rules); 167 | pt += addRuleIfNotNull(upperCaseCharacterRuleTextField.getText(), EnglishCharacterData.UpperCase, rules); 168 | pt += addRuleIfNotNull(lowerCaseCharacterRuleTextField.getText(), EnglishCharacterData.LowerCase, rules); 169 | 170 | org.passay.PasswordGenerator generator = new org.passay.PasswordGenerator(); 171 | int number = Integer.parseInt(passwordNumberTextField.getText().trim()); 172 | StringBuilder sb = new StringBuilder(); 173 | for (int i = 0; i < number; i++) { 174 | sb.append("\n").append(generator.generatePassword(pt, rules)); 175 | } 176 | passwordTextArea.setText(sb.length() > 0 ? sb.substring(1) : ""); 177 | } catch (Exception e) { 178 | showExceptionMessage(e); 179 | } 180 | } 181 | 182 | @Override 183 | public void mousePressed(MouseEvent e) { 184 | ruleCheckTextArea.setText(""); 185 | } 186 | }); 187 | // 校验按钮 188 | addJButton(buttonPanel, "校验", "", GuiUtils.font14b_cn, new SimpleMouseListener() { 189 | @Override 190 | public void mouseReleased(MouseEvent event) { 191 | String input = passwordTextArea.getText(); 192 | try { 193 | showMessage("暂未实现!", "提示", JOptionPane.INFORMATION_MESSAGE); 194 | } catch (Exception e) { 195 | showExceptionMessage(e); 196 | } 197 | } 198 | 199 | @Override 200 | public void mousePressed(MouseEvent e) { 201 | passwordTextArea.setText(""); 202 | } 203 | }); 204 | } 205 | 206 | private int addRuleIfNotNull(String value, EnglishCharacterData cData, List rules) { 207 | int n = 0; 208 | String v = GuiUtils.trim(value); 209 | if (v.length() != 0) { 210 | n = Integer.parseInt(v); 211 | if (n > 0) { 212 | rules.add(new CharacterRule(cData, n)); 213 | } else { 214 | n = 0; 215 | } 216 | } 217 | return n; 218 | } 219 | } 220 | -------------------------------------------------------------------------------- /src/main/java/bs/tool/commongui/plugins/more/QrCodeConverter.java: -------------------------------------------------------------------------------- 1 | package bs.tool.commongui.plugins.more; 2 | 3 | import bs.tool.commongui.AbstractGuiJPanel; 4 | import bs.tool.commongui.GuiImagePanel; 5 | import bs.tool.commongui.GuiUtils; 6 | import bs.tool.commongui.code.QrCodeUtil; 7 | import bs.tool.commongui.utils.FileUtils; 8 | import bs.tool.commongui.utils.SimpleMouseListener; 9 | 10 | import javax.swing.*; 11 | import java.awt.*; 12 | import java.awt.event.ActionEvent; 13 | import java.awt.event.ActionListener; 14 | import java.awt.event.MouseEvent; 15 | import java.io.File; 16 | import java.io.IOException; 17 | 18 | /** 19 | * 二维码转换. 20 | */ 21 | public class QrCodeConverter extends AbstractGuiJPanel { 22 | 23 | private static final long serialVersionUID = 1L; 24 | 25 | /** 26 | * 文本域. 27 | */ 28 | private JTextArea textArea = createJTextArea(GuiUtils.font14_un, System.getProperty("QrCodeConverter.defaultText")); 29 | private int imageWidth = 420; 30 | private int imageHeight = 420; 31 | private String qrCodeImageFile = FileUtils.JAVA_IO_TMPDIR + "/" + "$QrCodeConverter$.jpg"; 32 | private String blankImageFile = GuiUtils.getActualPath("img/cgt_blank.png"); 33 | private String currentQrCodeImageFile = blankImageFile; 34 | /** 35 | * 二维码图片域. 36 | */ 37 | private GuiImagePanel qrCodeImagePanel = new GuiImagePanel(imageWidth, imageHeight); 38 | /** 39 | * 图片路径选择. 40 | */ 41 | private JFileChooser imageChooser = createImageChooser(); 42 | 43 | public QrCodeConverter() { 44 | 45 | // 主面板:边界布局,分North、Center、East三部分,North用于放置文本,Center是放置二维码图片,East是按钮 46 | setLayout(new BorderLayout()); 47 | 48 | // 文本 49 | JPanel textAreaPanel = new JPanel(new BorderLayout()); 50 | add(textAreaPanel, BorderLayout.NORTH); 51 | addJLabel(textAreaPanel, " 字 符: ", GuiUtils.font14b_cn, BorderLayout.WEST); 52 | textArea.setRows(4); 53 | textAreaPanel.add(new JScrollPane(textArea), BorderLayout.CENTER); 54 | // 填充 55 | addJLabel(textAreaPanel, " ", GuiUtils.font14b_cn, BorderLayout.EAST); 56 | 57 | // Center,二维码图片域 58 | JPanel imagePanel = new JPanel(new BorderLayout()); 59 | add(imagePanel, BorderLayout.CENTER); 60 | addJLabel(imagePanel, " 二维码: ", GuiUtils.font14b_cn, BorderLayout.WEST); 61 | imagePanel.add(new JScrollPane(qrCodeImagePanel), BorderLayout.CENTER); 62 | 63 | // East,操作区域,使用BorderLayout布局 64 | JPanel actionPanel = new JPanel(new BorderLayout()); 65 | add(actionPanel, BorderLayout.EAST); 66 | 67 | // 填充 68 | actionPanel.add(new JPanel(), BorderLayout.CENTER); 69 | 70 | // 放置按钮 71 | JPanel buttonPanel = new JPanel(new GridLayout(6, 1)); 72 | actionPanel.add(buttonPanel, BorderLayout.SOUTH); 73 | // 生成 74 | addJButton(buttonPanel, " 生成二维码 ", "", GuiUtils.font14b_cn, new SimpleMouseListener() { 75 | @Override 76 | public void mouseReleased(MouseEvent event) { 77 | String input = textArea.getText(); 78 | if (input.length() != 0) { 79 | currentQrCodeImageFile = qrCodeImageFile; 80 | genQrCodeImage(input); 81 | } 82 | } 83 | 84 | @Override 85 | public void mousePressed(MouseEvent e) { 86 | currentQrCodeImageFile = blankImageFile; 87 | qrCodeImagePanel.repaint(currentQrCodeImageFile); 88 | } 89 | }); 90 | 91 | // 另存图片 92 | addJButton(buttonPanel, " 另存图片 ", "", GuiUtils.font14_cn, 93 | new ActionListener() { 94 | @Override 95 | public void actionPerformed(ActionEvent event) { 96 | int option = imageChooser.showSaveDialog(null); 97 | if (option == JFileChooser.APPROVE_OPTION) { 98 | try { 99 | // 补后缀名 100 | File selectedFile = imageChooser.getSelectedFile(); 101 | if (selectedFile.getName().indexOf(".") < 0) { 102 | imageChooser.setSelectedFile(new File(selectedFile.getAbsolutePath() + ".png")); 103 | } 104 | // 复制图片 105 | org.apache.commons.io.FileUtils.copyFile(new File(currentQrCodeImageFile), imageChooser.getSelectedFile()); 106 | } catch (IOException e) { 107 | showExceptionMessage(e); 108 | } 109 | } 110 | } 111 | }); 112 | 113 | // 仅做填充 114 | buttonPanel.add(new JPanel()); 115 | 116 | // 选择图片 117 | addJButton(buttonPanel, " 选择图片 ", "", GuiUtils.font14_cn, 118 | new ActionListener() { 119 | @Override 120 | public void actionPerformed(ActionEvent event) { 121 | if (imageChooser.showDialog(getContextPanel(), "确定") != JFileChooser.CANCEL_OPTION) { 122 | textArea.setText(""); 123 | File selectFile = imageChooser.getSelectedFile(); 124 | if (selectFile != null) { 125 | currentQrCodeImageFile = selectFile.getAbsolutePath(); 126 | decodeQrCodeImage(currentQrCodeImageFile); 127 | qrCodeImagePanel.repaint(currentQrCodeImageFile); 128 | } 129 | } 130 | } 131 | }); 132 | 133 | // 解析 134 | addJButton(buttonPanel, " 解析二维码 ", "", GuiUtils.font14b_cn, new SimpleMouseListener() { 135 | @Override 136 | public void mouseReleased(MouseEvent event) { 137 | decodeQrCodeImage(currentQrCodeImageFile); 138 | } 139 | 140 | @Override 141 | public void mousePressed(MouseEvent e) { 142 | textArea.setText(""); 143 | } 144 | }); 145 | } 146 | 147 | private void genQrCodeImage(String code) { 148 | try { 149 | QrCodeUtil.genQrCodeFile(code, currentQrCodeImageFile, QrCodeUtil.FORMAT_PNG, imageWidth, imageHeight); 150 | qrCodeImagePanel.repaint(currentQrCodeImageFile); 151 | } catch (Exception e) { 152 | showExceptionMessage(e, "generate qrCode image error."); 153 | } 154 | } 155 | 156 | private void decodeQrCodeImage(String imagePath) { 157 | if (!blankImageFile.equals(imagePath)) { 158 | try { 159 | textArea.setText(QrCodeUtil.decodeQrCodeFile(imagePath).getText()); 160 | } catch (Exception e) { 161 | showExceptionMessage(e, "decode qrCode image error."); 162 | } 163 | } 164 | } 165 | 166 | } 167 | -------------------------------------------------------------------------------- /src/main/java/bs/tool/commongui/plugins/more/SimpleWebview.java: -------------------------------------------------------------------------------- 1 | package bs.tool.commongui.plugins.more; 2 | 3 | import bs.tool.commongui.AbstractGuiJPanel; 4 | import bs.tool.commongui.GuiUtils; 5 | import chrriis.dj.nativeswing.swtimpl.NativeInterface; 6 | import chrriis.dj.nativeswing.swtimpl.components.JWebBrowser; 7 | 8 | import javax.swing.*; 9 | import java.awt.*; 10 | 11 | /** 12 | * Simple Webview. 13 | */ 14 | public class SimpleWebview extends AbstractGuiJPanel { 15 | 16 | public SimpleWebview() { 17 | setLayout(new BorderLayout()); 18 | 19 | NativeInterface.open(); 20 | JWebBrowser webBrowser = new JWebBrowser(); 21 | webBrowser.navigate("file://" + GuiUtils.getActualPath("conf/SimpleWebview/index.html")); 22 | 23 | JPanel webBrowserPanel = new JPanel(new BorderLayout()); 24 | webBrowserPanel.add(webBrowser, BorderLayout.CENTER); 25 | 26 | add(webBrowserPanel, BorderLayout.CENTER); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/bs/tool/commongui/plugins/more/ZHConverterVisual.java: -------------------------------------------------------------------------------- 1 | package bs.tool.commongui.plugins.more; 2 | 3 | import bs.tool.commongui.AbstractGuiJPanel; 4 | import bs.tool.commongui.GuiUtils; 5 | import bs.tool.commongui.utils.SimpleMouseListener; 6 | import com.spreada.utils.chinese.ZHConverter; 7 | 8 | import javax.swing.*; 9 | import java.awt.*; 10 | import java.awt.event.ActionEvent; 11 | import java.awt.event.ActionListener; 12 | import java.awt.event.MouseEvent; 13 | 14 | /** 15 | * 中文简繁体转换. 16 | */ 17 | public class ZHConverterVisual extends AbstractGuiJPanel { 18 | 19 | private static final long serialVersionUID = 1L; 20 | 21 | /** 22 | * 简体文本域. 23 | */ 24 | private JTextArea simplifiedTextArea = createJTextArea(GuiUtils.font14_un); 25 | /** 26 | * 繁体文本域. 27 | */ 28 | private JTextArea traditionalTextArea = createJTextArea(GuiUtils.font14_un); 29 | 30 | public ZHConverterVisual() { 31 | // 边界布局 32 | setLayout(new BorderLayout()); 33 | // Center,文字及转换结果输入输出域,使用2行1列的Grid布局,使其平均显示 34 | JPanel textAreaPanel = new JPanel(new GridLayout(2, 1)); 35 | add(textAreaPanel, BorderLayout.CENTER); 36 | 37 | JPanel scriptPanel = new JPanel(new BorderLayout()); 38 | addJLabel(scriptPanel, " 简体文本: ", GuiUtils.font14b_cn, BorderLayout.WEST); 39 | scriptPanel.add(new JScrollPane(simplifiedTextArea), BorderLayout.CENTER); 40 | textAreaPanel.add(scriptPanel); 41 | 42 | JPanel resultPanel = new JPanel(new BorderLayout()); 43 | addJLabel(resultPanel, " 繁体文本: ", GuiUtils.font14b_cn, BorderLayout.WEST); 44 | resultPanel.add(new JScrollPane(traditionalTextArea), BorderLayout.CENTER); 45 | textAreaPanel.add(resultPanel); 46 | 47 | // East,操作区域,使用BorderLayout布局 48 | JPanel actionPanel = new JPanel(new BorderLayout()); 49 | add(actionPanel, BorderLayout.EAST); 50 | 51 | // 填充 52 | actionPanel.add(new JPanel(), BorderLayout.CENTER); 53 | 54 | // 放置按钮 55 | JPanel buttonPanel = new JPanel(new GridLayout(7, 1)); 56 | actionPanel.add(buttonPanel, BorderLayout.SOUTH); 57 | // 简->繁 58 | addJButton(buttonPanel, " 简 -> 繁 ", "", GuiUtils.font14b_cn, new SimpleMouseListener() { 59 | @Override 60 | public void mouseReleased(MouseEvent event) { 61 | String input = simplifiedTextArea.getText(); 62 | traditionalTextArea.append(ZHConverter.convert(input, ZHConverter.TRADITIONAL)); 63 | } 64 | 65 | @Override 66 | public void mousePressed(MouseEvent e) { 67 | traditionalTextArea.setText(""); 68 | } 69 | }); 70 | // 仅做填充 71 | buttonPanel.add(new JPanel()); 72 | // 繁->简 73 | addJButton(buttonPanel, " 繁 -> 简 ", "", GuiUtils.font14b_cn, new SimpleMouseListener() { 74 | @Override 75 | public void mouseReleased(MouseEvent event) { 76 | String input = traditionalTextArea.getText(); 77 | simplifiedTextArea.append(ZHConverter.convert(input, ZHConverter.SIMPLIFIED)); 78 | } 79 | 80 | @Override 81 | public void mousePressed(MouseEvent e) { 82 | simplifiedTextArea.setText(""); 83 | } 84 | }); 85 | // 仅做填充 86 | buttonPanel.add(new JPanel()); 87 | // 全部清空 88 | addJButton(buttonPanel, " 全部清空 ", "", GuiUtils.font14_cn, new ActionListener() { 89 | @Override 90 | public void actionPerformed(ActionEvent event) { 91 | simplifiedTextArea.setText(""); 92 | traditionalTextArea.setText(""); 93 | } 94 | }); 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /src/main/java/bs/tool/commongui/utils/CollectionUtils.java: -------------------------------------------------------------------------------- 1 | package bs.tool.commongui.utils; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | public class CollectionUtils { 8 | 9 | /** 10 | * 仅支持List及Map. 11 | * 12 | * @param t 13 | * @param 14 | * @return 15 | */ 16 | public static T reInitItemValue(T t) { 17 | if (t instanceof List) { 18 | List list = (List) t; 19 | int lSize = list.size(); 20 | List nList = new ArrayList(); 21 | for (int i = 0; i < lSize; i++) { 22 | Object item = list.get(i); 23 | if (item instanceof List || item instanceof Map) { 24 | reInitItemValue(item); 25 | nList.add(item); 26 | } else { 27 | nList.add(reInitValue(item)); 28 | } 29 | } 30 | return (T) nList; 31 | } else if (t instanceof Map) { 32 | Map map = (Map) t; 33 | for (Object m : map.keySet()) { 34 | Object item = map.get(m); 35 | if (item instanceof List || item instanceof Map) { 36 | reInitItemValue(item); 37 | map.put(m, item); 38 | } else { 39 | map.put(m, reInitValue(item)); 40 | } 41 | } 42 | return t; 43 | } 44 | return t; 45 | } 46 | 47 | public static Object reInitValue(T t) { 48 | Object v = null; 49 | if (t instanceof Integer) { 50 | v = 0; 51 | } else if (t instanceof Float || t instanceof Double) { 52 | v = 0.0; 53 | } else if (t instanceof String) { 54 | v = ""; 55 | } 56 | return v; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/bs/tool/commongui/utils/EscapeUtils.java: -------------------------------------------------------------------------------- 1 | package bs.tool.commongui.utils; 2 | 3 | import org.apache.commons.lang.StringEscapeUtils; 4 | 5 | public class EscapeUtils { 6 | 7 | /** 8 | * 转义字符. 9 | * 10 | * @param string 字符 11 | * @param type 字符类型 12 | */ 13 | public static String escape(String string, String type) { 14 | String unescape = "不支持对" + type + "字符的转义"; 15 | if (type.equals(LanguageUtils.CONST_HTML)) { 16 | unescape = StringEscapeUtils.escapeHtml(string); 17 | } else if (type.equals(LanguageUtils.CONST_XML)) { 18 | unescape = StringEscapeUtils.escapeXml(string); 19 | } else if (type.equals(LanguageUtils.CONST_SQL)) { 20 | unescape = StringEscapeUtils.escapeSql(string); 21 | } else if (type.equals(LanguageUtils.CONST_JAVA)) { 22 | unescape = StringEscapeUtils.escapeJava(string); 23 | } else if (type.equals(LanguageUtils.CONST_JAVASCRIPT)) { 24 | unescape = StringEscapeUtils.escapeJavaScript(string); 25 | } else if (type.equals(LanguageUtils.CONST_CSV)) { 26 | unescape = StringEscapeUtils.escapeCsv(string); 27 | } 28 | return unescape; 29 | } 30 | 31 | /** 32 | * 还原转义字符. 33 | * 34 | * @param string 转义字符 35 | * @param type 字符类型 36 | */ 37 | public static String unescape(String string, String type) { 38 | String escape = "转义字符还原遇到错误"; 39 | if (type.equals(LanguageUtils.CONST_HTML)) { 40 | escape = StringEscapeUtils.unescapeHtml(string); 41 | } else if (type.equals(LanguageUtils.CONST_XML)) { 42 | escape = StringEscapeUtils.unescapeXml(string); 43 | } else if (type.equals(LanguageUtils.CONST_SQL)) { 44 | escape = type + "转义字符不能进行还原"; 45 | } else if (type.equals(LanguageUtils.CONST_JAVA)) { 46 | escape = StringEscapeUtils.unescapeJava(string); 47 | } else if (type.equals(LanguageUtils.CONST_JAVASCRIPT)) { 48 | escape = StringEscapeUtils.unescapeJavaScript(string); 49 | } else if (type.equals(LanguageUtils.CONST_CSV)) { 50 | escape = StringEscapeUtils.unescapeCsv(string); 51 | } 52 | return escape; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/bs/tool/commongui/utils/ExcelUtils.java: -------------------------------------------------------------------------------- 1 | package bs.tool.commongui.utils; 2 | 3 | 4 | import jxl.format.*; 5 | import jxl.write.WritableCellFormat; 6 | import jxl.write.WritableFont; 7 | import jxl.write.WriteException; 8 | 9 | public class ExcelUtils { 10 | 11 | public static WritableCellFormat getHeaderCellFormat() throws WriteException { 12 | return getCellFormat(Alignment.CENTRE, Colour.GRAY_25); 13 | } 14 | 15 | public static WritableCellFormat getBodyCellFormat() throws WriteException { 16 | return getCellFormat(Alignment.LEFT, Colour.WHITE); 17 | } 18 | 19 | private static WritableCellFormat getCellFormat(Alignment alignment, Colour colour) throws WriteException { 20 | WritableFont arial10font = new WritableFont(WritableFont.ARIAL, 10); 21 | WritableCellFormat arial10format = new WritableCellFormat(arial10font); 22 | arial10format.setAlignment(alignment); 23 | arial10format.setVerticalAlignment(VerticalAlignment.CENTRE); 24 | arial10format.setBackground(colour); 25 | arial10format.setWrap(true); 26 | arial10format.setBorder(Border.ALL, BorderLineStyle.THIN, Colour.BLACK); 27 | return arial10format; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/bs/tool/commongui/utils/LanguageUtils.java: -------------------------------------------------------------------------------- 1 | package bs.tool.commongui.utils; 2 | 3 | public class LanguageUtils { 4 | 5 | /** 6 | * JAVA. 7 | */ 8 | public static final String CONST_JAVA = "JAVA"; 9 | 10 | /** 11 | * SQL. 12 | */ 13 | public static final String CONST_SQL = "SQL"; 14 | 15 | /** 16 | * HTML. 17 | */ 18 | public static final String CONST_HTML = "HTML"; 19 | 20 | /** 21 | * XML. 22 | */ 23 | public static final String CONST_XML = "XML"; 24 | 25 | /** 26 | * JavaScript. 27 | */ 28 | public static final String CONST_JAVASCRIPT = "JavaScript"; 29 | 30 | /** 31 | * URI. 32 | */ 33 | public static final String CONST_URI = "URI"; 34 | 35 | /** 36 | * JSON. 37 | */ 38 | public static final String CONST_JSON = "JSON"; 39 | 40 | /** 41 | * CSS. 42 | */ 43 | public static final String CONST_CSS = "CSS"; 44 | 45 | /** 46 | * CSV. 47 | */ 48 | public static final String CONST_CSV = "CSV"; 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/bs/tool/commongui/utils/MacUtils.java: -------------------------------------------------------------------------------- 1 | package bs.tool.commongui.utils; 2 | 3 | import bs.tool.commongui.GuiUtils; 4 | 5 | import javax.swing.*; 6 | import java.awt.*; 7 | import java.util.Map; 8 | 9 | public class MacUtils { 10 | 11 | public static void showAboutMessage(final Toolkit kit, final JPanel contextPanel, Image icon, final Map 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 keys = new LinkedHashSet(); 10 | 11 | public LinkedProperties() { 12 | } 13 | 14 | public Iterable orderedKeys() { 15 | return Collections.list(keys()); 16 | } 17 | 18 | @Override 19 | public Enumeration keys() { 20 | return Collections.enumeration(keys); 21 | } 22 | 23 | @Override 24 | public Object put(Object key, Object value) { 25 | keys.add(key); 26 | return super.put(key, value); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/bs/util/io/PropertiesUtils.java: -------------------------------------------------------------------------------- 1 | package bs.util.io; 2 | 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | import java.util.Enumeration; 8 | import java.util.LinkedHashMap; 9 | 10 | /** 11 | * 读取属性文件属性. 12 | * 13 | * @author Baishui2004 14 | * @version 1.0 15 | */ 16 | public class PropertiesUtils { 17 | 18 | /** 19 | * 获取.properties属性文件所有属性. 20 | * 21 | * @param path 属性文件路径 22 | * @return Properties 属性 23 | * @throws IOException IO Exception 24 | */ 25 | public static LinkedProperties getProperties(String path) throws IOException { 26 | LinkedProperties properties = new LinkedProperties(); 27 | InputStream in = null; 28 | try { 29 | in = new FileInputStream(new File(path)); 30 | properties = getProperties(in); 31 | } finally { 32 | if (in != null) { 33 | in.close(); 34 | } 35 | } 36 | return properties; 37 | } 38 | 39 | /** 40 | * 获取所有属性. 41 | * 42 | * @param in InputStream 43 | * @return Properties 属性 44 | * @throws IOException IO Exception 45 | */ 46 | public static LinkedProperties getProperties(InputStream in) throws IOException { 47 | LinkedProperties properties = new LinkedProperties(); 48 | properties.load(in); 49 | return properties; 50 | } 51 | 52 | /** 53 | * 获取.properties属性文件所有属性的Map集合. 54 | * 55 | * @param path 属性文件路径 56 | * @return Map 属性的Map集合 57 | * @throws IOException IO Exception 58 | */ 59 | public static LinkedHashMap getPropertiesMap(String path) throws IOException { 60 | LinkedProperties properties = getProperties(path); 61 | return getPropertiesMap(properties); 62 | } 63 | 64 | /** 65 | * 获取所有属性. 66 | * 67 | * @param in InputStream 68 | * @return Map 属性的Map集合 69 | * @throws IOException IO Exception 70 | */ 71 | public static LinkedHashMap getPropertiesMap(InputStream in) throws IOException { 72 | LinkedProperties properties = getProperties(in); 73 | return getPropertiesMap(properties); 74 | } 75 | 76 | /** 77 | * 获取properties属性的Map集合. 78 | * 79 | * @param properties 属性 80 | * @return Map 属性的Map集合 81 | */ 82 | public static LinkedHashMap getPropertiesMap(LinkedProperties properties) { 83 | Enumeration keys = properties.keys(); 84 | LinkedHashMap map = new LinkedHashMap(); 85 | while (keys.hasMoreElements()) { 86 | String key = (String) keys.nextElement(); 87 | map.put(key, properties.getProperty(key)); 88 | } 89 | return map; 90 | } 91 | 92 | /** 93 | * 获取.properties属性单个属性的方法,获取两个或两个以上属性值使用getPropertiesMap(path)方法. 94 | * 95 | * @param path 属性文件路径 96 | * @param property 属性key 97 | * @return String 属性值 98 | * @throws IOException IO Exception 99 | * @see #getPropertiesMap(String) 100 | */ 101 | public static String getProperty(String path, String property) throws IOException { 102 | return getPropertiesMap(path).get(property); 103 | } 104 | 105 | } 106 | -------------------------------------------------------------------------------- /src/main/resources/simplelogger.properties: -------------------------------------------------------------------------------- 1 | org.slf4j.simpleLogger.defaultLogLevel=info 2 | org.slf4j.simpleLogger.showDateTime=true 3 | org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss.SSS 4 | org.slf4j.simpleLogger.logFile=System.err -------------------------------------------------------------------------------- /src/main/sources/bin/start.bat: -------------------------------------------------------------------------------- 1 | start javaw -Xms64m -Xmx256m -cp "%CD%\lib\*" bs.tool.commongui.GuiMain -------------------------------------------------------------------------------- /src/main/sources/bin/start.sh: -------------------------------------------------------------------------------- 1 | java -Xms64m -Xmx256m -Dapple.awt.application.name="Common Gui Tools" -Dcom.apple.mrj.application.apple.menu.about.name="Common Gui Tools" -cp "./lib/*" bs.tool.commongui.GuiMain -------------------------------------------------------------------------------- /src/main/sources/conf/AntScriptAutoBuild/conf.properties: -------------------------------------------------------------------------------- 1 | #AntScriptAutoBuild配置 2 | #baseTask、javaTask、javaWebTask、generalTask、specialTask,五个属性值中的任务不可重复 3 | #Base任务 4 | baseTask=base 5 | #Java任务 6 | javaTask=jar,javadoc,junit,findbugs,pmd,checkstyle,java2html 7 | #Java Web任务 8 | javaWebTask=yuicompressor,war,tomcat 9 | #通用任务 10 | generalTask=mail,jsch 11 | #特殊任务,此类任务每个任务单独生成一个构建脚本build-taskName.xml 12 | specialTask=jautodoc 13 | 14 | -------------------------------------------------------------------------------- /src/main/sources/conf/AntScriptAutoBuild/properties/base: -------------------------------------------------------------------------------- 1 | ############基本任务properties属性配置############ 2 | 3 | #构建者信息 4 | build.author.name=baishui2004 5 | build.author.email=bs2004@163.com 6 | 7 | #项目信息 8 | project.name= 9 | project.version=1.0 10 | project.compile.source= 11 | project.compile.target= 12 | #编译打包包括的源文件 13 | project.includes.java.sources=**/* 14 | #打包排除的源文件 15 | project.excludes.java.sources=**/package-info.java 16 | 17 | #properties 项目结构 18 | #Java源码目录 19 | dir.src= 20 | #类包目录 21 | dir.lib= 22 | #产出物目录(Jar, War, Java Doc, 测试报告等等) 23 | dir.dest=dest 24 | #编译好的字节码目录 25 | dir.classes=${dir.dest}/classes 26 | 27 | #Web项目属性配置 28 | #Web资源目录 29 | dir.web= -------------------------------------------------------------------------------- /src/main/sources/conf/AntScriptAutoBuild/properties/checkstyle: -------------------------------------------------------------------------------- 1 | 2 | #CheckStyle任务需要下载完整包而不是使用Eclipse下的CheckStyle插件 3 | checkstyle.home=C:/Java/Lib/checkstyle 4 | checkstyle.all.jar=${checkstyle.home}/checkstyle-5.5-all.jar 5 | checkstyle.convert.xsl=${checkstyle.home}/contrib/checkstyle-noframes.xsl -------------------------------------------------------------------------------- /src/main/sources/conf/AntScriptAutoBuild/properties/findbugs: -------------------------------------------------------------------------------- 1 | 2 | #FindBugs任务需要下载完整包而不是使用Eclipse下的FindBugs插件 3 | findbugs.home=C:/Java/Lib/findbugs -------------------------------------------------------------------------------- /src/main/sources/conf/AntScriptAutoBuild/properties/jar: -------------------------------------------------------------------------------- 1 | 2 | #Jar打包 3 | #Main程序 4 | project.main.class= 5 | #Soureces Jar 6 | file.sourceJarfile=${project.name}-${project.version}-sources.jar 7 | #Classes Jar 8 | file.jarfile=${project.name}-${project.version}.jar -------------------------------------------------------------------------------- /src/main/sources/conf/AntScriptAutoBuild/properties/java2html: -------------------------------------------------------------------------------- 1 | 2 | #Java2Html 3 | java2html.location=C:/Java/ThinSoft/Java2Html/java2html.jar -------------------------------------------------------------------------------- /src/main/sources/conf/AntScriptAutoBuild/properties/jsch: -------------------------------------------------------------------------------- 1 | 2 | ############JSch SSH(远程Linux)任务properties属性配置############ 3 | #注意:依赖类包jsch-*.jar,需要将其放在目录ANT_HOME/lib下, 4 | # Eclipse下运行还需要重设Preferences->Ant->Runtime->Ant home 5 | ssh.host=192.168.149.131 6 | ssh.port=22 7 | ssh.user=root 8 | ssh.password=linux 9 | ssh.command=pwd && uname -a 10 | ssh.send.local.file=${dir.dest}/${project.name}-${project.version}.war 11 | ssh.send.remote.dir=/home/user -------------------------------------------------------------------------------- /src/main/sources/conf/AntScriptAutoBuild/properties/junit: -------------------------------------------------------------------------------- 1 | 2 | ############JUnit单元测试属性配置############ 3 | junit.jar=C:/Java/Eclipse/plugins/org.junit_4.8.2.v4_8_2_v20110321-1705/junit.jar 4 | hamcrest.jar=C:/Java/Eclipse/plugins/org.hamcrest.core_1.1.0.v20090501071000.jar 5 | 6 | dir.junit.src=junit 7 | dir.junit.classes=${dir.dest}/junit/classes 8 | dir.junit.reports=${dir.dest}/junit/reports 9 | dir.junit.reports.testcases=${dir.junit.reports}/testcases -------------------------------------------------------------------------------- /src/main/sources/conf/AntScriptAutoBuild/properties/mail: -------------------------------------------------------------------------------- 1 | 2 | ############邮件任务properties属性配置############ 3 | #注意:依赖类包activation-*.jar及mail-.*jar,需要将其放在目录ANT_HOME/lib下, 4 | # Eclipse下运行还需要重设Preferences->Ant->Runtime->Ant home 5 | #replyto 回复mail地址 6 | #tolist 收件地址列表 可用子标签替代 7 | #cclist 抄送地址列表 可用子标签替代 8 | #bcclist 暗送地址列表 可用子标签替代 9 | mail.mailhost=smtp.qq.com 10 | mail.subject=Test build 11 | mail.user=860495914 12 | mail.password= 13 | mail.from.address=860495914@qq.com 14 | mail.to.address=weijinmaozi@qq.com 15 | mail.message=The Test nightly build has completed. 16 | #产出物目录下的文件 17 | mail.attachments=junit/reports/*.html,findbugs/*.html,pmd/*.html,checkstyle/*.html -------------------------------------------------------------------------------- /src/main/sources/conf/AntScriptAutoBuild/properties/pmd: -------------------------------------------------------------------------------- 1 | 2 | #PMD任务使用Eclipse下的插件或者使用下载的完整包都可以 3 | pmd.home=C:/Java/Eclipse/plugins/net.sourceforge.pmd.eclipse.plugin_3.2.6.v200903300643 -------------------------------------------------------------------------------- /src/main/sources/conf/AntScriptAutoBuild/properties/tomcat: -------------------------------------------------------------------------------- 1 | 2 | #Tomcat Server 3 | tomcat.home=C:/Java/Tomcat/Tomcat-6.0.32 -------------------------------------------------------------------------------- /src/main/sources/conf/AntScriptAutoBuild/properties/war: -------------------------------------------------------------------------------- 1 | 2 | #War打包 3 | file.warfile=${project.name}-${project.version}.war -------------------------------------------------------------------------------- /src/main/sources/conf/AntScriptAutoBuild/properties/yuicompressor: -------------------------------------------------------------------------------- 1 | 2 | #YUICompressor 3 | yuicompressor.jar=C:/Java/Lib/yuicompressor/build/yuicompressor-2.4.7.jar 4 | #${dir.web}下需要压缩的js 5 | dir.webapp.compress.js=${dir.web}/js 6 | #${dir.web}下需要压缩的css 7 | dir.webapp.compress.css=${dir.web}/css 8 | dir.yuicompressor.compress=${dir.dest}/yuicompressor 9 | #压缩后的js存储目录 10 | dir.yuicompressor.compress.js=${dir.yuicompressor.compress}/js 11 | #压缩后的css存储目录 12 | dir.yuicompressor.compress.css=${dir.yuicompressor.compress}/css -------------------------------------------------------------------------------- /src/main/sources/conf/AntScriptAutoBuild/readme.txt: -------------------------------------------------------------------------------- 1 | 更新:优化原jar任务为base + jar任务,base及jar任务默认选中(base任务为必选);2013-9-26 2 | 3 | 4 | 5 | Version: 1.1 2013-4-4 6 | 7 | 8 | 程序作用: 9 | 传入Eclipse的Java Project、Dynamic Web Project或者MyEclipse的Web Project绝对路径地址, 10 | 在此路径下自动生成Ant构建属性文件build.properties及构建脚本build.xml。 11 | 12 | 13 | 14 | 独立版本(antScriptAutoBuild-1.1.zip)启动说明: java -jar antScriptAutoBuild-1.1.jar 参数1 参数2 15 | 1,只接受传入两个参数: 16 | 第一个是Eclipse的Java Project、Dynamic Web Project或者MyEclipse的Web Project绝对路径地址, 17 | 第二个是Ant Task任务名称串(以半角逗号分隔),任务名称即目录conf/AntScriptAutoBuild/script/下的文件名称,可以额外增加更多Ant构建脚本片段文件。 18 | 19 | 20 | 21 | 其他说明: 22 | 1,自动生成的Ant构建属性文件build.properties从文件夹conf/AntScriptAutoBuild/properties/中的属性文件拼接而成,文件编码UTF-8, 23 | 根据项目属性替换掉以下六个属性的值: project.name、project.compile.source、project.compile.target、dir.web、dir.src、dir.classes,其他属性及值原样不变; 24 | 2,自动生成的Ant构建脚本build.xml从文件夹conf/AntScriptAutoBuild/script/中的任务文件拼接而成,文件编码UTF-8; 25 | 3,Ant Task任务对应conf/AntScriptAutoBuild/script/下的文件名称,增加一个文件即增加一个Ant构建脚本,而../../properties/文件夹下并不要求有对应属性文件。 26 | 27 | 28 | 29 | 30 | 从Project的配置文件中读取相关属性:Eclipse的Java Project、Dynamic Web Project、MyEclipse的Web Project 31 | 1,解析文件'.project'以获取Project Name; 32 | 2,解析文件'.settings/org.eclipse.jdt.core.prefs'以获取Project Compile Source以及Project Compile Target; 33 | 如果没有'.settings/org.eclipse.jdt.core.prefs'文件,则解析文件'.settings/org.eclipse.wst.common.project.facet.core.xml'以获取"installed java facet version"; 34 | 3,解析文件'.classpath'以获取Java Sources Path以及Compile Output Path; 35 | 4,解析文件'.settings/.jsdtscope'以获取Webapp Path。 36 | 其中Java Project没有第4个文件'.settings/.jsdtscope'解析以获取Webapp Path。 37 | 38 | -------------------------------------------------------------------------------- /src/main/sources/conf/AntScriptAutoBuild/script/base: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /src/main/sources/conf/AntScriptAutoBuild/script/checkstyle: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |