From 31e49d3fa6256d1d18510d7f7544f3cca43061f0 Mon Sep 17 00:00:00 2001 From: zhangmeng <1334717033@qq.com> Date: Wed, 8 Mar 2023 10:16:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0http=E5=B7=A5=E5=85=B7=202023?= =?UTF-8?q?=E5=B9=B43=E6=9C=888=E6=97=A510:16:37?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tools/controller/HttpToolsController.java | 446 ++++++++++++++++++ .../zhangmeng/tools/utils/ResourcesUtils.java | 32 ++ src/main/resources/fxml/http-download.fxml | 11 + src/main/resources/fxml/http-request.fxml | 14 + src/main/resources/fxml/http-tools.fxml | 82 ++++ src/main/resources/fxml/http-upload.fxml | 14 + 6 files changed, 599 insertions(+) create mode 100644 src/main/java/com/zhangmeng/tools/controller/HttpToolsController.java create mode 100644 src/main/resources/fxml/http-download.fxml create mode 100644 src/main/resources/fxml/http-request.fxml create mode 100644 src/main/resources/fxml/http-tools.fxml create mode 100644 src/main/resources/fxml/http-upload.fxml diff --git a/src/main/java/com/zhangmeng/tools/controller/HttpToolsController.java b/src/main/java/com/zhangmeng/tools/controller/HttpToolsController.java new file mode 100644 index 0000000..9d98cd4 --- /dev/null +++ b/src/main/java/com/zhangmeng/tools/controller/HttpToolsController.java @@ -0,0 +1,446 @@ +package com.zhangmeng.tools.controller; + +import com.zhangmeng.tools.utils.ImagePath; +import com.zhangmeng.tools.utils.ResourcesUtils; +import javafx.beans.property.SimpleDoubleProperty; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.geometry.Pos; +import javafx.scene.Scene; +import javafx.scene.control.Label; +import javafx.scene.control.ListCell; +import javafx.scene.control.ListView; +import javafx.scene.control.SplitPane; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; +import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.HBox; +import javafx.scene.paint.Paint; +import javafx.scene.text.Font; +import javafx.stage.Stage; +import javafx.util.Callback; +import lombok.extern.slf4j.Slf4j; + +import java.io.IOException; +import java.util.Arrays; + +/** + * @author : 芊芊墨客 + * @version : 1.0 + * @date : 2023-03-08 09:41 + */ +@Slf4j +public class HttpToolsController { + + + private SimpleDoubleProperty width = new SimpleDoubleProperty(0.0); + private SimpleDoubleProperty height = new SimpleDoubleProperty(0.0); + private AnchorPane root; + + private AnchorPane http_request; + private AnchorPane http_upload; + private AnchorPane http_download; + + + public static final String color_cell = "#f4f4f4"; + + @FXML + private ListView listView; + + @FXML + private SplitPane splitPane; + + @FXML + public void date_query_menu_item(){ + load_small_tools(5); + } + + @FXML + public void cron_menu_item(){ + load_small_tools(6); + } + + @FXML + public void md5_menu_item() { + load_encrypt(0); + } + + @FXML + public void spring_security_menu_item() { + load_encrypt(1); + } + + @FXML + public void video_menu_item() { + load_player(0); + } + + @FXML + public void music_menu_item() { + load_player(1); + } + + @FXML + public void vip_parser_menu_item() { + load_player(2); + } + + @FXML + public void hex_16(){ + load_small_tools(0); + } + + @FXML + private void hex_16_menu_item(){ + load_small_tools(0); + } + + @FXML + private void unicode_menu_item(){ + load_small_tools(1); + } + + @FXML + private void jwt_menu_item(){ + load_small_tools(2); + } + + @FXML + private void color_choose_menu_item(){ + load_small_tools(3); + } + + @FXML + public void qr_code_menu_item(){ + load_small_tools(4); + } + + @FXML + public void base_62_menu_item(){ + load_codec_tools(0); + } + + @FXML + public void base_64_menu_item(){ + load_codec_tools(1); + } + + @FXML + public void base_32_menu_item(){ + load_codec_tools(2); + } + + @FXML + public void morse_coder_menu_item(){ + load_codec_tools(3); + } + + @FXML + private void sql_code_gen_menu_item(){ + load_sql_tools(0); + } + + @FXML + public void netty_client_menu_item(){ + load_network_tools(0); + } + + public void load_network_tools(int index){ + AnchorPane fx = null; + try { + fx = FXMLLoader.load(ResourcesUtils.getResource("network-tools")); + } catch (IOException e) { + e.printStackTrace(); + } + + Scene scene = new Scene(fx); + Stage stage = (Stage) splitPane.getScene().getWindow(); + stage.setScene(scene); + + ListView listView = (ListView) fx.lookup("#listView"); + listView.getSelectionModel().select(index); + } + + public void load_sql_tools(int index){ + AnchorPane fx = null; + try { + fx = FXMLLoader.load(ResourcesUtils.getResource("sql-tools")); + } catch (IOException e) { + e.printStackTrace(); + } + + Scene scene = new Scene(fx); + Stage stage = (Stage) splitPane.getScene().getWindow(); + stage.setScene(scene); + + ListView listView = (ListView) fx.lookup("#listView"); + listView.getSelectionModel().select(index); + } + + public void load_codec_tools(int index){ + AnchorPane fx = null; + try { + fx = FXMLLoader.load(ResourcesUtils.getResource("codec-tools")); + } catch (IOException e) { + e.printStackTrace(); + } + + Scene scene = new Scene(fx); + Stage stage = (Stage) splitPane.getScene().getWindow(); + stage.setScene(scene); + + ListView listView = (ListView) fx.lookup("#listView"); + listView.getSelectionModel().select(index); + } + + public void load_small_tools(int index){ + AnchorPane fx = null; + try { + fx = FXMLLoader.load(ResourcesUtils.getResource("small-tools")); + } catch (IOException e) { + e.printStackTrace(); + } + + Scene scene = new Scene(fx); + Stage stage = (Stage) splitPane.getScene().getWindow(); + stage.setScene(scene); + + ListView listView = (ListView) fx.lookup("#listView"); + listView.getSelectionModel().select(index); + } + + public void load_player(int index) { + AnchorPane fx = null; + try { + fx = FXMLLoader.load(ResourcesUtils.getResource("player")); + } catch (IOException e) { + e.printStackTrace(); + } + + Scene scene = new Scene(fx); + Stage stage = (Stage) splitPane.getScene().getWindow(); + stage.setScene(scene); + + ListView listView = (ListView) fx.lookup("#listView"); + listView.getSelectionModel().select(index); + } + + @FXML + public void initialize() { + init(); + listView.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> { + if (newValue != null) { + boolean flag = false; + + if (newValue.getIndex() == 0) { + if (http_request != null){ + flag = true; + } + http_request(flag); + } + + if (newValue.getIndex() == 1) { + if (http_request != null){ + flag = true; + } + http_upload(flag); + } + + if (newValue.getIndex() == 2) { + if (http_request != null){ + flag = true; + } + http_download(flag); + } + + } + }); + } + + public static Image getImage(ResourcesUtils.HttpTools player){ + return switch (player){ + case Http_Request -> new Image(ImagePath.path(ImagePath.ImagePathType.MD5)); + case Http_Upload -> new Image(ImagePath.path(ImagePath.ImagePathType.MD5)); + case Http_DownLoad -> new Image(ImagePath.path(ImagePath.ImagePathType.SPRING_SECURITY)); + }; + } + + public void init() { + ResourcesUtils.HttpTools[] values = ResourcesUtils.HttpTools.values(); + ObservableList list = FXCollections.observableArrayList(); + list.addAll(Arrays.asList(values)); + listView.setItems(list); + listView.setFixedCellSize(40); + listView.setCellFactory(new Callback<>() { + private int position; + @Override + public ListCell call(ListView playerListView) { + Label label = new Label(); + label.setPrefWidth(200); + ListCell listCell = new ListCell<>() { + @Override + protected void updateItem(ResourcesUtils.HttpTools player, boolean b) { + super.updateItem(player, b); + if (!b) { + HBox hBox = new HBox(25); + hBox.setAlignment(Pos.CENTER); + label.setText(player.getTitle()); + label.setTextFill(Paint.valueOf("#000000")); + Image im = getImage(player); + ImageView iv = new ImageView(im); + iv.setPreserveRatio(true); + iv.setFitWidth(15); + hBox.getChildren().add(iv); + + hBox.getChildren().add(label); + this.setGraphic(hBox); + } + this.setStyle("-fx-background-color: " + color_cell); + } + }; + + listCell.hoverProperty().addListener((observableValue, aBoolean, t1) -> { + if (t1 && !label.getText().equals("")) { + position = playerListView.getItems().indexOf(label.getText()); + label.setFont(new Font(16)); + playerListView.getFocusModel().focus(position); + listCell.setStyle("-fx-background-color: #369e7d"); + } else { + label.setPrefHeight(20); + label.setFont(new Font(13)); + listCell.setStyle("-fx-background-color: " + color_cell); + } + }); + + return listCell; + } + }); + + http_request(false); + } + + private void http_request(boolean flag){ + //默认选择第一个 + listView.getSelectionModel().select(0); + + if (!flag){ + try { + root = FXMLLoader.load(ResourcesUtils.getResource("http-request")); + } catch (IOException e) { + e.printStackTrace(); + } + http_request = root; + }else { + root = http_request; + } + common_method(); + } + + private void http_upload(boolean flag){ + //默认选择第一个 + listView.getSelectionModel().select(1); + + if (!flag){ + try { + root = FXMLLoader.load(ResourcesUtils.getResource("http-upload")); + } catch (IOException e) { + e.printStackTrace(); + } + http_request = root; + }else { + root = http_request; + } + common_method(); + } + + private void http_download(boolean flag){ + //默认选择第一个 + listView.getSelectionModel().select(2); + + if (!flag){ + try { + root = FXMLLoader.load(ResourcesUtils.getResource("http-download")); + } catch (IOException e) { + e.printStackTrace(); + } + http_request = root; + }else { + root = http_request; + } + common_method(); + } + + //加载加密 + private void load_encrypt(int index) { + AnchorPane fx = null; + try { + fx = FXMLLoader.load(ResourcesUtils.getResource("http-tools")); + } catch (IOException e) { + e.printStackTrace(); + } + + Scene scene = new Scene(fx); + Stage stage = (Stage) splitPane.getScene().getWindow(); + stage.setScene(scene); + + ListView listView = (ListView) fx.lookup("#listView"); + listView.getSelectionModel().select(index); + } + + private void common_method() { + splitPane.getItems().remove(1); + splitPane.getItems().add(1, root); + root.widthProperty().addListener((observable, oldValue, newValue) -> { + if (newValue != null) { + double width = splitPane.getWidth(); + HttpToolsController.this.width.set(width); + log.info("home:--->width:{}", width); + } + }); + root.heightProperty().addListener((observable, oldValue, newValue) -> { + if (newValue != null) { + double height = splitPane.getHeight(); + HttpToolsController.this.height.set(height); + log.info("home:--->height:{}", height); + } + }); + + this.width.addListener((observable, oldValue, newValue) -> { + HttpToolsController.this.root.setPrefWidth(newValue.doubleValue() - listView.getWidth()); + }); + + this.height.addListener((observable, oldValue, newValue) -> { + HttpToolsController.this.root.setPrefHeight(newValue.doubleValue() - listView.getHeight()); + }); + } + + @FXML + public void http_request_menu_item(ActionEvent event) { + boolean flag = false; + if (http_request != null){ + flag = true; + } + http_request(flag); + } + + @FXML + public void http_upload_menu_item(ActionEvent event) { + boolean flag = false; + if (http_upload != null){ + flag = true; + } + http_upload(flag); + } + + @FXML + public void http_download_menu_item(ActionEvent event) { + boolean flag = false; + if (http_download != null){ + flag = true; + } + http_download(flag); + } +} diff --git a/src/main/java/com/zhangmeng/tools/utils/ResourcesUtils.java b/src/main/java/com/zhangmeng/tools/utils/ResourcesUtils.java index 5a4e79b..20f1e15 100644 --- a/src/main/java/com/zhangmeng/tools/utils/ResourcesUtils.java +++ b/src/main/java/com/zhangmeng/tools/utils/ResourcesUtils.java @@ -231,4 +231,36 @@ public class ResourcesUtils { private String title; private int index; } + + public enum HttpTools{ + + Http_Request("http 请求工具",0), + Http_Upload("http 上传工具",1), + Http_DownLoad("http 下载工具",2), + ; + + HttpTools(String title, int index) { + this.title = title; + this.index = index; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public int getIndex() { + return index; + } + + public void setIndex(int index) { + this.index = index; + } + + private String title; + private int index; + } } diff --git a/src/main/resources/fxml/http-download.fxml b/src/main/resources/fxml/http-download.fxml new file mode 100644 index 0000000..1a871e3 --- /dev/null +++ b/src/main/resources/fxml/http-download.fxml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/src/main/resources/fxml/http-request.fxml b/src/main/resources/fxml/http-request.fxml new file mode 100644 index 0000000..6d9c75c --- /dev/null +++ b/src/main/resources/fxml/http-request.fxml @@ -0,0 +1,14 @@ + + + + + + + + + + + diff --git a/src/main/resources/fxml/http-tools.fxml b/src/main/resources/fxml/http-tools.fxml new file mode 100644 index 0000000..bdabb55 --- /dev/null +++ b/src/main/resources/fxml/http-tools.fxml @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/fxml/http-upload.fxml b/src/main/resources/fxml/http-upload.fxml new file mode 100644 index 0000000..cfca0f2 --- /dev/null +++ b/src/main/resources/fxml/http-upload.fxml @@ -0,0 +1,14 @@ + + + + + + + + + + +