添加JSON , maven 工具 2023年3月28日17:59:17

master
zhangmeng 2023-03-28 17:59:34 +08:00
parent 3c28681835
commit feac865349
14 changed files with 398 additions and 1 deletions

View File

@ -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 简单封装展示

11
pom.xml
View File

@ -313,6 +313,17 @@
<version>3.5.2</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
<build>

View File

@ -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);
}
}

View File

@ -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<String> json_view;
@FXML
private SimpleObjectProperty<JSONObject> 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<String> parseJSON(String name, Object json) {
TreeItem<String> item = new TreeItem<>();
item.setExpanded(true);
if (json instanceof JSONObject object) {
item.setValue(name);
((Set<Map.Entry>) object.entrySet()).forEach(entry -> {
String childName = (String) entry.getKey();
Object childJson = entry.getValue();
TreeItem<String> 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<String> child = parseJSON(childName, childJson);
child.setExpanded(true);
item.getChildren().add(child);
}
} else {
item.setValue(name + " : " + json);
}
return item;
}
}

View File

@ -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());
}
}

View File

@ -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<ResourcesUtils.SmallTools> 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);

View File

@ -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) {

View File

View File

@ -39,6 +39,8 @@
<MenuItem mnemonicParsing="false" text="cron表达式" onAction="#cron_menu_item"/>
<MenuItem mnemonicParsing="false" text="邮件发送" onAction="#mail_menu_item"/>
<MenuItem mnemonicParsing="false" text="手机号工具" onAction="#telephone_menu_item"/>
<MenuItem mnemonicParsing="false" text="JsonView" onAction="#JsonView_menu_item"/>
<MenuItem mnemonicParsing="false" text="maven-jar-install" onAction="#maven_jar_install_menu_item"/>
</items>
</Menu>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.TreeView?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane prefHeight="649.0" prefWidth="1200.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.zhangmeng.tools.controller.JSONViewController">
<children>
<TreeView fx:id="json_view" layoutX="129.0" layoutY="393.0" prefHeight="256.0" prefWidth="1071.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="129.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="393.0" />
<TextArea fx:id="json_str" layoutX="129.0" layoutY="104.0" prefHeight="234.0" prefWidth="1071.0" AnchorPane.leftAnchor="129.0" AnchorPane.rightAnchor="0.0" />
<TextField fx:id="path" layoutX="204.0" layoutY="58.0" prefHeight="25.0" prefWidth="350.0" />
<Label layoutX="30.0" layoutY="62.0" text="请选择json文件:" />
<Button fx:id="choose_file" layoutX="132.0" layoutY="58.0" mnemonicParsing="false" text="Button" />
<Label layoutX="48.0" layoutY="102.0" text="json字符串:" />
<Button fx:id="cover" layoutX="74.0" layoutY="353.0" mnemonicParsing="false" text="转换" />
</children>
</AnchorPane>

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane prefHeight="649.0" prefWidth="1200.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.zhangmeng.tools.controller.MavenInstallJarController">
<children>
<Label layoutX="280.0" layoutY="104.0" text="jar包的路径:" />
<TextField fx:id="jar_path" layoutX="400.0" layoutY="100.0" prefHeight="25.0" prefWidth="568.0" />
<TextField fx:id="group_id" layoutX="400.0" layoutY="164.0" prefHeight="25.0" prefWidth="568.0" />
<Label layoutX="292.0" layoutY="168.0" text="group-id:" />
<Label layoutX="283.0" layoutY="225.0" text="artifact-id:" />
<TextField fx:id="artifact_id" layoutX="400.0" layoutY="221.0" prefHeight="25.0" prefWidth="568.0" />
<Label layoutX="291.0" layoutY="283.0" text="version:" />
<TextField fx:id="version" layoutX="400.0" layoutY="279.0" prefHeight="25.0" prefWidth="568.0" />
<Button fx:id="install" layoutX="594.0" layoutY="341.0" mnemonicParsing="false" text="安装" />
<Label layoutX="298.0" layoutY="406.0" text="console-log" />
<TextArea fx:id="textArea" layoutX="400.0" layoutY="415.0" prefHeight="200.0" prefWidth="568.0" AnchorPane.bottomAnchor="34.0" AnchorPane.leftAnchor="400.0" AnchorPane.rightAnchor="232.0" AnchorPane.topAnchor="415.0" />
<Button fx:id="choose_file" layoutX="992.0" layoutY="100.0" mnemonicParsing="false" text="Button" />
</children>
</AnchorPane>

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB