diff --git a/README.md b/README.md index d87d61d..abdbf2d 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,15 @@ ![](./src/main/resources/static/redame/img_34.png) +#### 3.10 json工具 + +![](./src/main/resources/static/redame/img_39.png) + +#### 3.11 mvn本地安装jar(windows) + +![](./src/main/resources/static/redame/img_35.png) +![](./src/main/resources/static/redame/img_38.png) + ### 4. 编解码工具 > 编解码工具也是对开源组件 Hutool 简单封装展示 diff --git a/pom.xml b/pom.xml index 4a00d34..0528c27 100644 --- a/pom.xml +++ b/pom.xml @@ -313,6 +313,17 @@ 3.5.2 + + com.google.code.gson + gson + 2.10 + + + com.googlecode.json-simple + json-simple + 1.1.1 + + diff --git a/src/main/java/com/zhangmeng/tools/controller/HomeController.java b/src/main/java/com/zhangmeng/tools/controller/HomeController.java index b0b192d..615393e 100644 --- a/src/main/java/com/zhangmeng/tools/controller/HomeController.java +++ b/src/main/java/com/zhangmeng/tools/controller/HomeController.java @@ -479,4 +479,13 @@ public class HomeController implements Serializable { public void mybatis_plus_gen_menu_item(ActionEvent event) { load_sql_tools(1); } + + public void JsonView_menu_item(ActionEvent event) { + + load_small_tools(9); + } + + public void maven_jar_install_menu_item(ActionEvent event) { + load_small_tools(10); + } } \ No newline at end of file diff --git a/src/main/java/com/zhangmeng/tools/controller/JSONViewController.java b/src/main/java/com/zhangmeng/tools/controller/JSONViewController.java new file mode 100644 index 0000000..c8c0ac4 --- /dev/null +++ b/src/main/java/com/zhangmeng/tools/controller/JSONViewController.java @@ -0,0 +1,136 @@ +package com.zhangmeng.tools.controller; + + +import com.zhangmeng.tools.utils.AlertUtils; +import com.zhangmeng.tools.utils.ImagePath; +import javafx.beans.property.SimpleObjectProperty; +import javafx.fxml.FXML; +import javafx.scene.control.*; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; +import javafx.stage.DirectoryChooser; +import javafx.stage.FileChooser; +import javafx.stage.Stage; +import lombok.extern.slf4j.Slf4j; + +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.Map; +import java.util.Set; + +/** + * @author : 芊芊墨客 + * @version : 1.0 + * @date : 2023-03-28 09:19 + */ +@Slf4j +public class JSONViewController { + + @FXML + public TextArea json_str; + + @FXML + public Button choose_file; + + @FXML + public Button cover; + + @FXML + public TextField path; + + @FXML + private TreeView json_view; + + @FXML + private SimpleObjectProperty obj = new SimpleObjectProperty<>(); + + @FXML + public void initialize() { + + choose_file.setText(null); + ImageView iv = new ImageView(new Image(ImagePath.path(ImagePath.ImagePathType.IMAGE_FILE))); + iv.setPreserveRatio(true); + iv.setFitWidth(18); + choose_file.setGraphic(iv); + + choose_file.setOnAction(event -> { + choose_file(); + }); + + cover.setOnAction(event -> { + + if (json_str.getText().length() == 0) { + AlertUtils.alert_warning("请选择json"); + } + + try { + JSONParser parser = new JSONParser(); + JSONObject root = (JSONObject) parser.parse(json_str.getText()); + json_view.setRoot(parseJSON("root_object", root)); + json_view.setId("json_view"); + json_view.setShowRoot(false); + } catch (ParseException e) { + e.printStackTrace(); + } + + }); + } + + public void choose_file() { + Stage stage = new Stage(); + FileChooser fc = new FileChooser(); + fc.setTitle("单选文件"); + fc.getExtensionFilters().addAll( + new FileChooser.ExtensionFilter("json文件", "*.json") + ); + File file = fc.showOpenDialog(stage); + if (file == null) { + return; + } + path.setText(file.getPath()); + try { + JSONParser parser = new JSONParser(); + JSONObject root = (JSONObject) parser.parse(new FileReader(new File(path.getText()), StandardCharsets.UTF_8)); + obj.setValue(root); + json_str.setText(JSONObject.toJSONString(root)); + } catch (IOException | ParseException e) { + e.printStackTrace(); + } + } + + + @SuppressWarnings("unchecked") + private static TreeItem parseJSON(String name, Object json) { + TreeItem item = new TreeItem<>(); + item.setExpanded(true); + if (json instanceof JSONObject object) { + item.setValue(name); + ((Set) object.entrySet()).forEach(entry -> { + String childName = (String) entry.getKey(); + Object childJson = entry.getValue(); + TreeItem child = parseJSON(childName, childJson); + child.setExpanded(true); + item.getChildren().add(child); + }); + } else if (json instanceof JSONArray array) { + item.setValue(name); + for (int i = 0; i < array.size(); i++) { + String childName = String.valueOf(i); + Object childJson = array.get(i); + TreeItem child = parseJSON(childName, childJson); + child.setExpanded(true); + item.getChildren().add(child); + } + } else { + item.setValue(name + " : " + json); + } + return item; + } +} \ No newline at end of file diff --git a/src/main/java/com/zhangmeng/tools/controller/MavenInstallJarController.java b/src/main/java/com/zhangmeng/tools/controller/MavenInstallJarController.java new file mode 100644 index 0000000..31cbaca --- /dev/null +++ b/src/main/java/com/zhangmeng/tools/controller/MavenInstallJarController.java @@ -0,0 +1,131 @@ +package com.zhangmeng.tools.controller; + +import cn.hutool.core.text.StrFormatter; +import com.zhangmeng.tools.utils.AlertUtils; +import com.zhangmeng.tools.utils.ImagePath; +import javafx.fxml.FXML; +import javafx.scene.control.Button; +import javafx.scene.control.TextArea; +import javafx.scene.control.TextField; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; +import javafx.stage.FileChooser; +import javafx.stage.Stage; +import lombok.extern.slf4j.Slf4j; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; + +import java.io.*; +import java.nio.charset.StandardCharsets; + + +/** + * @author : 芊芊墨客 + * @version : 1.0 + * @date : 2023-03-28 17:07 + */ +@Slf4j +public class MavenInstallJarController { + + @FXML + public TextField jar_path; + + @FXML + public TextField group_id; + + @FXML + public TextField artifact_id; + + @FXML + public TextField version; + + @FXML + public Button install; + + @FXML + public TextArea textArea; + + @FXML + public Button choose_file; + + public static final String cmd = "cmd /c mvn install:install-file -Dfile={} -DgroupId={} -DartifactId={} -Dversion={} -Dpackaging=jar"; + + @FXML + public void initialize() { + + choose_file.setText(null); + ImageView iv = new ImageView(new Image(ImagePath.path(ImagePath.ImagePathType.IMAGE_FILE))); + iv.setPreserveRatio(true); + iv.setFitWidth(18); + choose_file.setGraphic(iv); + + choose_file.setOnAction(event -> { + choose_file(); + }); + + install.setOnAction(event -> { + if (jar_path.getText().length() == 0){ + AlertUtils.alert_warning("安装jar包路径不能为空!"); + return; + } + + if (group_id.getText().length() == 0){ + AlertUtils.alert_warning("group_id不能为空!"); + return; + } + + if (artifact_id.getText().length() == 0){ + AlertUtils.alert_warning("artifact_id不能为空!"); + return; + } + + if (version.getText().length() == 0){ + AlertUtils.alert_warning("version不能为空!"); + return; + } + String format = StrFormatter.format(cmd, jar_path.getText(), group_id.getText(), artifact_id.getText(), version.getText()); + log.info(format); + exec(format); + }); + } + + public void choose_file() { + Stage stage = new Stage(); + FileChooser fc = new FileChooser(); + fc.setTitle("单选文件"); + fc.getExtensionFilters().addAll( + new FileChooser.ExtensionFilter("jar文件", "*.jar") + ); + File file = fc.showOpenDialog(stage); + if (file == null) { + return; + } + jar_path.setText(file.getPath()); + } + + public void exec(String cmd) { + textArea.setText(null); + // Java调用 dos命令 + try { + Process process = Runtime.getRuntime().exec(cmd); + InputStream is = process.getInputStream(); + InputStreamReader isr = new InputStreamReader(is,"GBK"); + BufferedReader br = new BufferedReader(isr); + String content = br.readLine(); + while (content != null) { + add_msg(content); + content = br.readLine(); + } + + } catch (IOException e) { + e.printStackTrace(); + } + } + + public void add_msg(String content){ + textArea.appendText(System.lineSeparator()); + textArea.appendText(content); + textArea.appendText(System.lineSeparator()); + } +} diff --git a/src/main/java/com/zhangmeng/tools/controller/SmallToolsController.java b/src/main/java/com/zhangmeng/tools/controller/SmallToolsController.java index faffd5f..5dda26a 100644 --- a/src/main/java/com/zhangmeng/tools/controller/SmallToolsController.java +++ b/src/main/java/com/zhangmeng/tools/controller/SmallToolsController.java @@ -52,6 +52,7 @@ import javafx.util.Callback; import lombok.extern.slf4j.Slf4j; import java.io.IOException; +import java.net.URL; import java.util.Arrays; /** @@ -75,6 +76,8 @@ public class SmallToolsController { private AnchorPane cron; private AnchorPane mail; private AnchorPane telephone; + private AnchorPane json_view; + private AnchorPane maven_install_jar; @FXML private ListView listView; @@ -348,12 +351,24 @@ public class SmallToolsController { } mail(flag); } - if (newValue.getIndex() == 7) { + if (newValue.getIndex() == 8) { if (telephone != null) { flag = true; } telephone(flag); } + if (newValue.getIndex() == 9) { + if (json_view != null) { + flag = true; + } + json_view(flag); + } + if (newValue.getIndex() == 10) { + if (maven_install_jar != null) { + flag = true; + } + maven_install_jar(flag); + } } }); } @@ -369,6 +384,8 @@ public class SmallToolsController { case Cron -> new Image(ImagePath.path(ImagePath.ImagePathType.Qr_CODE)); case Mail -> new Image(ImagePath.path(ImagePath.ImagePathType.Qr_CODE)); case TelePhone -> new Image(ImagePath.path(ImagePath.ImagePathType.Qr_CODE)); + case JSONView -> new Image(ImagePath.path(ImagePath.ImagePathType.Qr_CODE)); + case Maven_Install_Jar -> new Image(ImagePath.path(ImagePath.ImagePathType.Qr_CODE)); }; } @@ -569,6 +586,42 @@ public class SmallToolsController { } + private void json_view(boolean flag) { + URL resource = this.getClass().getClassLoader().getResource("css/tree_item.css"); + splitPane.getScene().getStylesheets().add(resource.toExternalForm()); + //默认选择第一个 + listView.getSelectionModel().select(9); + + if (!flag) { + try { + root = FXMLLoader.load(ResourcesUtils.getResource("json_view")); + } catch (IOException e) { + e.printStackTrace(); + } + json_view = root; + } else { + root = json_view; + } + common_method(); + } + + private void maven_install_jar(boolean flag) { + //默认选择第一个 + listView.getSelectionModel().select(10); + + if (!flag) { + try { + root = FXMLLoader.load(ResourcesUtils.getResource("maven-install-jar")); + } catch (IOException e) { + e.printStackTrace(); + } + maven_install_jar = root; + } else { + root = maven_install_jar; + } + common_method(); + } + private void common_method() { splitPane.getItems().remove(1); splitPane.getItems().add(1, root); diff --git a/src/main/java/com/zhangmeng/tools/utils/ResourcesUtils.java b/src/main/java/com/zhangmeng/tools/utils/ResourcesUtils.java index c931e85..1612d2c 100644 --- a/src/main/java/com/zhangmeng/tools/utils/ResourcesUtils.java +++ b/src/main/java/com/zhangmeng/tools/utils/ResourcesUtils.java @@ -119,6 +119,8 @@ public class ResourcesUtils { Cron("cron表达式",6), Mail("发送邮件",7), TelePhone("手机号工具",8), + JSONView("json工具",9), + Maven_Install_Jar("maven安装jar",10), ; SmallTools(String title, int index) { diff --git a/src/main/resources/css/tree_item.css b/src/main/resources/css/tree_item.css new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/fxml/home.fxml b/src/main/resources/fxml/home.fxml index c86b839..6e456b3 100644 --- a/src/main/resources/fxml/home.fxml +++ b/src/main/resources/fxml/home.fxml @@ -39,6 +39,8 @@ + + diff --git a/src/main/resources/fxml/json_view.fxml b/src/main/resources/fxml/json_view.fxml new file mode 100644 index 0000000..b1f633d --- /dev/null +++ b/src/main/resources/fxml/json_view.fxml @@ -0,0 +1,20 @@ + + + + + + + + + + + + +