435 lines
13 KiB
Java
435 lines
13 KiB
Java
/*
|
|
* MIT License
|
|
*
|
|
* Copyright (c) 2023 芊芊墨客
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* in the Software without restriction, including without limitation the rights
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
* copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
* SOFTWARE.
|
|
*
|
|
*/
|
|
|
|
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<ResourcesUtils.CodecTools> 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 sql_code_gen_menu_item(){
|
|
load_sql_tools(0);
|
|
}
|
|
@FXML
|
|
public void morse_coder_menu_item(){
|
|
|
|
boolean flag = false;
|
|
if (morse_coder != null){
|
|
flag = true;
|
|
}
|
|
morse_coder(flag);
|
|
}
|
|
|
|
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<ResourcesUtils.Player> 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<ResourcesUtils.Player> 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<ResourcesUtils.Player> 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<ResourcesUtils.CodecTools> list = FXCollections.observableArrayList();
|
|
list.addAll(Arrays.asList(values));
|
|
listView.setItems(list);
|
|
listView.setFixedCellSize(40);
|
|
listView.setCellFactory(new Callback<>() {
|
|
|
|
private int position;
|
|
|
|
@Override
|
|
public ListCell<ResourcesUtils.CodecTools> call(ListView<ResourcesUtils.CodecTools> SmallToolsListView) {
|
|
|
|
Label label = new Label();
|
|
label.setPrefWidth(200);
|
|
ListCell<ResourcesUtils.CodecTools> 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());
|
|
});
|
|
}
|
|
}
|