From af9fde79d761c0e762b6e59279188a907ddc9567 Mon Sep 17 00:00:00 2001 From: zhangmeng <1334717033@qq.com> Date: Tue, 21 Feb 2023 12:02:04 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=96=E8=A7=A3=E7=A0=81=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tools/controller/Base32Controller.java | 58 +++ .../tools/controller/Base62Controller.java | 58 +++ .../tools/controller/Base64Controller.java | 114 +++++ .../controller/CodecToolsController.java | 389 ++++++++++++++++++ .../tools/controller/HomeController.java | 36 ++ .../controller/MorseCoderController.java | 61 +++ .../zhangmeng/tools/utils/ResourcesUtils.java | 33 ++ src/main/resources/fxml/base-32.fxml | 25 ++ src/main/resources/fxml/base-62.fxml | 24 ++ src/main/resources/fxml/base-64.fxml | 38 ++ src/main/resources/fxml/codec-tools.fxml | 58 +++ src/main/resources/fxml/home.fxml | 11 +- src/main/resources/fxml/morse-coder.fxml | 26 ++ src/main/resources/fxml/player.fxml | 4 +- src/main/resources/fxml/small-tools.fxml | 4 +- 15 files changed, 932 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/zhangmeng/tools/controller/Base32Controller.java create mode 100644 src/main/java/com/zhangmeng/tools/controller/Base62Controller.java create mode 100644 src/main/java/com/zhangmeng/tools/controller/Base64Controller.java create mode 100644 src/main/java/com/zhangmeng/tools/controller/CodecToolsController.java create mode 100644 src/main/java/com/zhangmeng/tools/controller/MorseCoderController.java create mode 100644 src/main/resources/fxml/base-32.fxml create mode 100644 src/main/resources/fxml/base-62.fxml create mode 100644 src/main/resources/fxml/base-64.fxml create mode 100644 src/main/resources/fxml/codec-tools.fxml create mode 100644 src/main/resources/fxml/morse-coder.fxml diff --git a/src/main/java/com/zhangmeng/tools/controller/Base32Controller.java b/src/main/java/com/zhangmeng/tools/controller/Base32Controller.java new file mode 100644 index 0000000..296f094 --- /dev/null +++ b/src/main/java/com/zhangmeng/tools/controller/Base32Controller.java @@ -0,0 +1,58 @@ +package com.zhangmeng.tools.controller; + +import cn.hutool.core.codec.Base32; +import cn.hutool.core.codec.Base62; +import com.zhangmeng.tools.utils.AlertUtils; +import javafx.fxml.FXML; +import javafx.scene.control.Button; +import javafx.scene.control.TextArea; +import javafx.scene.control.TextField; +import lombok.extern.slf4j.Slf4j; + +/** + * @author : 芊芊墨客 + * @version : 1.0 + * @date : 2023-02-21 11:50 + */ +@Slf4j +public class Base32Controller { + + @FXML + private Button button; + + @FXML + private TextField text_filed; + + @FXML + private TextArea textArea1; + + @FXML + private Button button1; + + @FXML + private TextField text_filed1; + + @FXML + private TextArea textArea2; + + @FXML + public void initialize() { + button.setOnAction(event -> { + String text = text_filed.getText(); + if (text.length() == 0) { + AlertUtils.alert_warning("请输入将要转换的字符!"); + return; + } + textArea1.setText(Base32.encode(text)); + }); + + button1.setOnAction(event -> { + String text = text_filed1.getText(); + if (text.length() == 0) { + AlertUtils.alert_warning("请输入将要转换的字符!"); + return; + } + textArea2.setText(Base32.decodeStr(text)); + }); + } +} diff --git a/src/main/java/com/zhangmeng/tools/controller/Base62Controller.java b/src/main/java/com/zhangmeng/tools/controller/Base62Controller.java new file mode 100644 index 0000000..ac84701 --- /dev/null +++ b/src/main/java/com/zhangmeng/tools/controller/Base62Controller.java @@ -0,0 +1,58 @@ +package com.zhangmeng.tools.controller; + +import cn.hutool.core.codec.Base62; +import cn.hutool.core.convert.Convert; +import com.zhangmeng.tools.utils.AlertUtils; +import javafx.fxml.FXML; +import javafx.scene.control.Button; +import javafx.scene.control.TextArea; +import javafx.scene.control.TextField; +import lombok.extern.slf4j.Slf4j; + +/** + * @author : 芊芊墨客 + * @version : 1.0 + * @date : 2023-02-21 11:02 + */ +@Slf4j +public class Base62Controller { + + @FXML + private Button button; + + @FXML + private TextField text_filed; + + @FXML + private TextArea textArea1; + + @FXML + private Button button1; + + @FXML + private TextField text_filed1; + + @FXML + private TextArea textArea2; + + @FXML + public void initialize() { + button.setOnAction(event -> { + String text = text_filed.getText(); + if (text.length() == 0) { + AlertUtils.alert_warning("请输入将要转换的字符!"); + return; + } + textArea1.setText(Base62.encode(text)); + }); + + button1.setOnAction(event -> { + String text = text_filed1.getText(); + if (text.length() == 0) { + AlertUtils.alert_warning("请输入将要转换的字符!"); + return; + } + textArea2.setText(Base62.decodeStr(text)); + }); + } +} diff --git a/src/main/java/com/zhangmeng/tools/controller/Base64Controller.java b/src/main/java/com/zhangmeng/tools/controller/Base64Controller.java new file mode 100644 index 0000000..3c3e6de --- /dev/null +++ b/src/main/java/com/zhangmeng/tools/controller/Base64Controller.java @@ -0,0 +1,114 @@ +package com.zhangmeng.tools.controller; + +import cn.hutool.captcha.CaptchaUtil; +import cn.hutool.captcha.CircleCaptcha; +import cn.hutool.core.codec.Base62; +import cn.hutool.core.codec.Base64; +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.Button; +import javafx.scene.control.TextArea; +import javafx.scene.control.TextField; +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 java.io.File; + +/** + * @author : 芊芊墨客 + * @version : 1.0 + * @date : 2023-02-21 11:02 + */ +@Slf4j +public class Base64Controller { + + @FXML + private Button button; + + @FXML + private TextField text_filed; + + @FXML + private TextArea textArea1; + + @FXML + private Button button1; + + @FXML + private TextField text_filed1; + + @FXML + private TextArea textArea2; + + @FXML + private Button file_choose_button; + + @FXML + private TextField text_file; + + private SimpleObjectProperty choose_file = new SimpleObjectProperty<>(); + + @FXML + public void initialize() { + + textArea1.setWrapText(true); + textArea2.setWrapText(true); + + file_choose_button.setText(null); + ImageView iv = new ImageView(new Image(ImagePath.path(ImagePath.ImagePathType.IMAGE_FILE))); + iv.setPreserveRatio(true); + iv.setFitWidth(18); + file_choose_button.setGraphic(iv); + + button.setOnAction(event -> { + String text = text_filed.getText(); + if (text.length() == 0) { + AlertUtils.alert_warning("请输入将要转换的字符!"); + return; + } + textArea1.setText(Base64.encode(text)); + }); + + button1.setOnAction(event -> { + String text = text_filed1.getText(); + if (text.length() == 0) { + AlertUtils.alert_warning("请输入将要转换的字符!"); + return; + } + textArea2.setText(Base64.decodeStr(text)); + }); + } + + @FXML + public void choose_file(){ + Stage stage = (Stage) file_choose_button.getScene().getWindow(); + FileChooser dc = new FileChooser(); + dc.setTitle("文件选择"); + dc.getExtensionFilters().addAll( + new FileChooser.ExtensionFilter("图片类型", "*.jpg", "*.png") + ); + File file = dc.showOpenDialog(stage); + if (file != null){ + String path = file.getAbsolutePath(); + text_file.setText(path); + log.info("base64---file:{}" ,path); + choose_file.set(file); + } + } + + @FXML + private void convert_to_base64(){ + File file = choose_file.getValue(); + if (file == null){ + AlertUtils.alert_warning("请选择图片文件!"); + } + String encode = Base64.encode(file); + textArea1.setText(Base64.encode(encode)); + } +} diff --git a/src/main/java/com/zhangmeng/tools/controller/CodecToolsController.java b/src/main/java/com/zhangmeng/tools/controller/CodecToolsController.java new file mode 100644 index 0000000..01ef3df --- /dev/null +++ b/src/main/java/com/zhangmeng/tools/controller/CodecToolsController.java @@ -0,0 +1,389 @@ +package com.zhangmeng.tools.controller; + +import com.zhangmeng.tools.utils.ImagePath; +import com.zhangmeng.tools.utils.ResourcesUtils; +import javafx.beans.property.SimpleDoubleProperty; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +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-02-21 10:29 + */ +@Slf4j +public class CodecToolsController { + + private SimpleDoubleProperty width = new SimpleDoubleProperty(0.0); + private SimpleDoubleProperty height = new SimpleDoubleProperty(0.0); + private AnchorPane root; + + private AnchorPane hex_16; + private AnchorPane unicode; + private AnchorPane jwt_web; + private AnchorPane color_choose; + private AnchorPane base_62; + private AnchorPane base_64; + private AnchorPane base_32; + private AnchorPane morse_coder; + + @FXML + private ListView listView; + + @FXML + private SplitPane splitPane; + + public static final String color_cell = "#f4f4f4"; + + @FXML + public void md5_menu_item() { + load_encrypt(); + } + + @FXML + public void spring_security_menu_item() { + load_encrypt(); + } + + @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 unicode_menu_item(){ + load_small_tools(1); + } + + @FXML + public void jwt_menu_item(){ + load_small_tools(2); + } + + @FXML + public void hex_16_menu_item(){ + load_small_tools(0); + } + + @FXML + public void color_choose_menu_item(){ + + load_small_tools(3); + } + + + @FXML + public void base_62_menu_item(){ + + boolean flag = false; + if (base_62 != null){ + flag = true; + } + base_62(flag); + } + + @FXML + public void base_64_menu_item(){ + + boolean flag = false; + if (base_64 != null){ + flag = true; + } + base_64(flag); + } + + @FXML + public void base_32_menu_item(){ + + boolean flag = false; + if (base_32 != null){ + flag = true; + } + base_32(flag); + } + + @FXML + public void morse_coder_menu_item(){ + + boolean flag = false; + if (morse_coder != null){ + flag = true; + } + morse_coder(flag); + } + + 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); + } + + public void load_encrypt() { + + Stage stage = (Stage) splitPane.getScene().getWindow(); + + AnchorPane fx = null; + try { + fx = FXMLLoader.load(ResourcesUtils.getResource("home")); + } catch (IOException e) { + e.printStackTrace(); + } + Scene scene = new Scene(fx); + stage.setScene(scene); + } + + @FXML + public void initialize() { + init(); + listView.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> { + if (newValue != null) { + boolean flag = false; + if (newValue.getIndex() == 0) { + if (base_62 != null) { + flag = true; + } + base_62(flag); + } + if (newValue.getIndex() == 1) { + if (base_64 != null) { + flag = true; + } + base_64(flag); + } + + if (newValue.getIndex() == 2) { + if (base_32 != null) { + flag = true; + } + base_32(flag); + } + + if (newValue.getIndex() == 3) { + if (morse_coder != null) { + flag = true; + } + morse_coder(flag); + } + } + }); + } + + public static Image getImage(ResourcesUtils.CodecTools codecTools) { + return switch (codecTools) { + case Base62 -> new Image(ImagePath.path(ImagePath.ImagePathType.Hex_16)); + case Base64 -> new Image(ImagePath.path(ImagePath.ImagePathType.Unicode)); + case Base32 -> new Image(ImagePath.path(ImagePath.ImagePathType.JWT_WEB)); + case MorseCoder -> new Image(ImagePath.path(ImagePath.ImagePathType.COLOR_CHOOSE)); + }; + } + + public void init() { + ResourcesUtils.CodecTools[] values = ResourcesUtils.CodecTools.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 SmallToolsListView) { + + Label label = new Label(); + label.setPrefWidth(200); + ListCell listCell = new ListCell<>() { + @Override + protected void updateItem(ResourcesUtils.CodecTools codecTools, boolean b) { + super.updateItem(codecTools, b); + if (!b) { + HBox hBox = new HBox(30); + hBox.setAlignment(Pos.CENTER); + label.setText(codecTools.getTitle()); + label.setTextFill(Paint.valueOf("#000000")); + Image im = getImage(codecTools); + 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 = SmallToolsListView.getItems().indexOf(label.getText()); + label.setFont(new Font(16)); + SmallToolsListView.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; + } + }); + base_62(false); + } + + public void base_62(boolean flag){ + //默认选择第一个 + listView.getSelectionModel().select(0); + + if (!flag) { + try { + root = FXMLLoader.load(ResourcesUtils.getResource("base-62")); + } catch (IOException e) { + e.printStackTrace(); + } + base_62 = root; + } else { + root = base_62; + } + common_method(); + } + + public void base_64(boolean flag){ + //默认选择第一个 + listView.getSelectionModel().select(1); + + if (!flag) { + try { + root = FXMLLoader.load(ResourcesUtils.getResource("base-64")); + } catch (IOException e) { + e.printStackTrace(); + } + base_64 = root; + } else { + root = base_64; + } + common_method(); + } + + public void base_32(boolean flag){ + //默认选择第一个 + listView.getSelectionModel().select(2); + + if (!flag) { + try { + root = FXMLLoader.load(ResourcesUtils.getResource("base-32")); + } catch (IOException e) { + e.printStackTrace(); + } + base_32 = root; + } else { + root = base_32; + } + common_method(); + } + + public void morse_coder(boolean flag){ + //默认选择第一个 + listView.getSelectionModel().select(3); + + if (!flag) { + try { + root = FXMLLoader.load(ResourcesUtils.getResource("morse-coder")); + } catch (IOException e) { + e.printStackTrace(); + } + morse_coder = root; + } else { + root = morse_coder; + } + common_method(); + } + + 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(); + CodecToolsController.this.width.set(width); + log.info("SmallTools:--->width:{}", width); + } + }); + root.heightProperty().addListener((observable, oldValue, newValue) -> { + if (newValue != null) { + double height = splitPane.getHeight(); + CodecToolsController.this.height.set(height); + log.info("SmallTools:--->height:{}", height); + } + }); + + this.width.addListener((observable, oldValue, newValue) -> { + CodecToolsController.this.root.setPrefWidth(newValue.doubleValue() - listView.getWidth()); + log.info("newValue.doubleValue():{}", newValue.doubleValue()); + }); + + this.height.addListener((observable, oldValue, newValue) -> { + CodecToolsController.this.root.setPrefHeight(newValue.doubleValue() - listView.getHeight()); + log.info("newValue.doubleValue():{}", newValue.doubleValue()); + }); + } +} diff --git a/src/main/java/com/zhangmeng/tools/controller/HomeController.java b/src/main/java/com/zhangmeng/tools/controller/HomeController.java index 56197d2..3a553fb 100644 --- a/src/main/java/com/zhangmeng/tools/controller/HomeController.java +++ b/src/main/java/com/zhangmeng/tools/controller/HomeController.java @@ -109,6 +109,42 @@ public class HomeController implements Serializable { load_small_tools(3); } + @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); + } + + 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 { diff --git a/src/main/java/com/zhangmeng/tools/controller/MorseCoderController.java b/src/main/java/com/zhangmeng/tools/controller/MorseCoderController.java new file mode 100644 index 0000000..fecb547 --- /dev/null +++ b/src/main/java/com/zhangmeng/tools/controller/MorseCoderController.java @@ -0,0 +1,61 @@ +package com.zhangmeng.tools.controller; + +import cn.hutool.core.codec.Base32; +import cn.hutool.core.codec.Morse; +import com.zhangmeng.tools.utils.AlertUtils; +import javafx.fxml.FXML; +import javafx.scene.control.Button; +import javafx.scene.control.TextArea; +import javafx.scene.control.TextField; +import lombok.extern.slf4j.Slf4j; +import org.apache.ibatis.annotations.Select; + +/** + * @author : 芊芊墨客 + * @version : 1.0 + * @date : 2023-02-21 11:57 + */ +@Slf4j +public class MorseCoderController { + + @FXML + private Button button; + + @FXML + private TextField text_filed; + + @FXML + private TextArea textArea1; + + @FXML + private Button button1; + + @FXML + private TextField text_filed1; + + @FXML + private TextArea textArea2; + + private final Morse morseCoder = new Morse(); + + @FXML + public void initialize() { + button.setOnAction(event -> { + String text = text_filed.getText(); + if (text.length() == 0) { + AlertUtils.alert_warning("请输入将要转换的字符!"); + return; + } + textArea1.setText(morseCoder.encode(text)); + }); + + button1.setOnAction(event -> { + String text = text_filed1.getText(); + if (text.length() == 0) { + AlertUtils.alert_warning("请输入将要转换的字符!"); + return; + } + textArea2.setText(morseCoder.decode(text)); + }); + } +} diff --git a/src/main/java/com/zhangmeng/tools/utils/ResourcesUtils.java b/src/main/java/com/zhangmeng/tools/utils/ResourcesUtils.java index 1c7bc3d..7203779 100644 --- a/src/main/java/com/zhangmeng/tools/utils/ResourcesUtils.java +++ b/src/main/java/com/zhangmeng/tools/utils/ResourcesUtils.java @@ -110,4 +110,37 @@ public class ResourcesUtils { private String title; private int index; } + + public enum CodecTools{ + + Base62("Base62编码解码",0), + Base64("Base64编码解码",1), + Base32("Base32编码解码",2), + MorseCoder ("摩尔斯电码",3), + ; + + CodecTools(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/base-32.fxml b/src/main/resources/fxml/base-32.fxml new file mode 100644 index 0000000..64a8211 --- /dev/null +++ b/src/main/resources/fxml/base-32.fxml @@ -0,0 +1,25 @@ + + + + + + + + + + + +