字符串 操作 2023年2月18日15:48:03

master
zhangmeng 2023-02-18 15:48:15 +08:00
parent f617ce1f3f
commit e9ff569837
12 changed files with 489 additions and 7 deletions

View File

@ -27,6 +27,15 @@ public class Hex16Controller {
@FXML @FXML
private TextArea hex_16; private TextArea hex_16;
@FXML
private Button button1;
@FXML
private TextField text_filed1;
@FXML
private TextArea hex_161;
@FXML @FXML
public void initialize() { public void initialize() {
button.setOnAction(event -> { button.setOnAction(event -> {
@ -37,5 +46,14 @@ public class Hex16Controller {
} }
hex_16.setText(Convert.toHex(text, CharsetUtil.CHARSET_UTF_8)); hex_16.setText(Convert.toHex(text, CharsetUtil.CHARSET_UTF_8));
}); });
button1.setOnAction(event -> {
String text = text_filed1.getText();
if (text.length() == 0) {
AlertUtils.alert_warning("请输入将要转换的字符!");
return;
}
hex_161.setText(Convert.hexToStr(text, CharsetUtil.CHARSET_UTF_8));
});
} }
} }

View File

@ -84,6 +84,27 @@ public class HomeController implements Serializable {
load_player(2); load_player(2);
} }
@FXML
public void hex_16(){
load_small_tools(0);
}
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) { public void load_player(int index) {
AnchorPane fx = null; AnchorPane fx = null;
try { try {

View File

@ -0,0 +1,264 @@
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-18 14:43
*/
@Slf4j
public class SmallToolsController {
private SimpleDoubleProperty width = new SimpleDoubleProperty(0.0);
private SimpleDoubleProperty height = new SimpleDoubleProperty(0.0);
private AnchorPane root;
private AnchorPane hex_16;
private AnchorPane unicode;
@FXML
private ListView<ResourcesUtils.SmallTools> 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() {
}
@FXML
public void music_menu_item() {
}
@FXML
public void vip_parser_menu_item() {
}
@FXML
public void unicode_menu_item(){
boolean flag = false;
if (unicode != null){
flag = true;
}
unicode(flag);
}
@FXML
public void hex_16_menu_item(){
boolean flag = false;
if (hex_16 != null){
flag = true;
}
hex_16(flag);
}
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 (hex_16 != null) {
flag = true;
}
hex_16(flag);
}
if (newValue.getIndex() == 1) {
if (unicode != null) {
flag = true;
}
unicode(flag);
}
}
});
}
public static Image getImage(ResourcesUtils.SmallTools SmallTools) {
return switch (SmallTools) {
case Hex_16 -> new Image(ImagePath.path(ImagePath.ImagePathType.Hex_16));
case Unicode -> new Image(ImagePath.path(ImagePath.ImagePathType.Unicode));
};
}
public void init() {
ResourcesUtils.SmallTools[] values = ResourcesUtils.SmallTools.values();
ObservableList<ResourcesUtils.SmallTools> 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.SmallTools> call(ListView<ResourcesUtils.SmallTools> SmallToolsListView) {
Label label = new Label();
label.setPrefWidth(100);
ListCell<ResourcesUtils.SmallTools> listCell = new ListCell<>() {
@Override
protected void updateItem(ResourcesUtils.SmallTools SmallTools, boolean b) {
super.updateItem(SmallTools, b);
if (!b) {
HBox hBox = new HBox(30);
hBox.setAlignment(Pos.CENTER);
label.setText(SmallTools.getTitle());
label.setTextFill(Paint.valueOf("#000000"));
Image im = getImage(SmallTools);
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(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> observableValue, Boolean aBoolean, Boolean 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;
}
});
hex_16(false);
}
private void hex_16(boolean flag) {
//默认选择第一个
listView.getSelectionModel().select(0);
if (!flag) {
try {
root = FXMLLoader.load(ResourcesUtils.getResource("hex_16"));
} catch (IOException e) {
e.printStackTrace();
}
hex_16 = root;
} else {
root = hex_16;
}
common_method();
}
private void unicode(boolean flag) {
//默认选择第一个
listView.getSelectionModel().select(1);
if (!flag) {
try {
root = FXMLLoader.load(ResourcesUtils.getResource("unicode"));
} catch (IOException e) {
e.printStackTrace();
}
unicode = root;
} else {
root = unicode;
}
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();
SmallToolsController.this.width.set(width);
log.info("SmallTools:--->width:{}", width);
}
});
root.heightProperty().addListener((observable, oldValue, newValue) -> {
if (newValue != null) {
double height = splitPane.getHeight();
SmallToolsController.this.height.set(height);
log.info("SmallTools:--->height:{}", height);
}
});
this.width.addListener((observable, oldValue, newValue) -> {
SmallToolsController.this.root.setPrefWidth(newValue.doubleValue() - listView.getWidth());
log.info("newValue.doubleValue():{}", newValue.doubleValue());
});
this.height.addListener((observable, oldValue, newValue) -> {
SmallToolsController.this.root.setPrefHeight(newValue.doubleValue() - listView.getHeight());
log.info("newValue.doubleValue():{}", newValue.doubleValue());
});
}
}

View File

@ -0,0 +1,55 @@
package com.zhangmeng.tools.controller;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.CharsetUtil;
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;
/**
* @author :
* @version : 1.0
* @date : 2023-02-18 15:45
*/
public class UnicodeController {
@FXML
private Button button;
@FXML
private TextField text_filed;
@FXML
private TextArea hex_16;
@FXML
private Button button1;
@FXML
private TextField text_filed1;
@FXML
private TextArea hex_161;
@FXML
public void initialize() {
button.setOnAction(event -> {
String text = text_filed.getText();
if (text.length() == 0) {
AlertUtils.alert_warning("请输入将要转换的字符!");
return;
}
hex_16.setText(Convert.strToUnicode(text));
});
button1.setOnAction(event -> {
String text = text_filed1.getText();
if (text.length() == 0) {
AlertUtils.alert_warning("请输入将要转换的字符!");
return;
}
hex_161.setText(Convert.unicodeToStr(text));
});
}
}

View File

@ -55,6 +55,9 @@ public class ImagePath {
MD5("md5 加密"), MD5("md5 加密"),
SPRING_SECURITY("SPRING_SECURITY 加密"), SPRING_SECURITY("SPRING_SECURITY 加密"),
Hex_16("16 进制"),
Unicode("Unicode"),
ICON_NULL_COVER(""); ICON_NULL_COVER("");
private String desc; private String desc;
@ -233,6 +236,8 @@ public class ImagePath {
public static String MUSIC_PLAYER = "svg/music-player.png"; public static String MUSIC_PLAYER = "svg/music-player.png";
public static String MD5 = "svg/md5.png"; public static String MD5 = "svg/md5.png";
public static String SPRING_SECURITY = "svg/spring-security.png"; public static String SPRING_SECURITY = "svg/spring-security.png";
public static String Hex_16 = "svg/hex_16.png";
public static String Unicode = "svg/unicode.png";
public static String path(ImagePathType type) { public static String path(ImagePathType type) {
@ -375,6 +380,12 @@ public class ImagePath {
case SPRING_SECURITY: case SPRING_SECURITY:
path = ImagePath.SPRING_SECURITY; path = ImagePath.SPRING_SECURITY;
break; break;
case Hex_16:
path = ImagePath.Hex_16;
break;
case Unicode:
path = ImagePath.Unicode;
break;
} }
return "static/" + path; return "static/" + path;
} }

View File

@ -77,4 +77,36 @@ public class ResourcesUtils {
private String title; private String title;
private int index; private int index;
} }
public enum SmallTools{
Hex_16("16进制Hex",0),
Unicode("Unicode和字符串转换",1),
;
SmallTools(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;
}
} }

View File

@ -2,17 +2,23 @@
<?import javafx.scene.control.Button?> <?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?> <?import javafx.scene.control.Label?>
<?import javafx.scene.control.Separator?>
<?import javafx.scene.control.TextArea?> <?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.TextField?> <?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?> <?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.Hex16Controller"> <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.Hex16Controller">
<children> <children>
<Label layoutX="169.0" layoutY="102.0" text="将要加密的字符:" AnchorPane.leftAnchor="169.0" /> <Label layoutX="169.0" layoutY="102.0" text="普通字符串:" AnchorPane.leftAnchor="169.0" />
<TextField fx:id="text_filed" layoutX="300.0" layoutY="98.0" prefHeight="25.0" prefWidth="619.0" AnchorPane.leftAnchor="300.0" AnchorPane.rightAnchor="281.0" AnchorPane.topAnchor="98.0" /> <TextField fx:id="text_filed" layoutX="300.0" layoutY="98.0" prefHeight="25.0" prefWidth="619.0" AnchorPane.leftAnchor="300.0" AnchorPane.rightAnchor="281.0" AnchorPane.topAnchor="98.0" />
<Button fx:id="button" layoutX="934.0" layoutY="98.0" mnemonicParsing="false" text="加密" AnchorPane.rightAnchor="226.0" /> <Button fx:id="button" layoutX="930.0" layoutY="98.0" mnemonicParsing="false" text="转换" AnchorPane.rightAnchor="230.0" />
<Label layoutX="169.0" layoutY="160.0" text="加密后的字符 32位:" /> <Label layoutX="169.0" layoutY="160.0" text="16进制字符:" />
<TextArea fx:id="hex_16" layoutX="300.0" layoutY="160.0" prefHeight="200.0" prefWidth="619.0" AnchorPane.leftAnchor="300.0" AnchorPane.rightAnchor="281.0" AnchorPane.topAnchor="160.0" /> <TextArea fx:id="hex_16" layoutX="300.0" layoutY="160.0" prefHeight="121.0" prefWidth="619.0" AnchorPane.leftAnchor="300.0" AnchorPane.rightAnchor="281.0" AnchorPane.topAnchor="160.0" />
<Label layoutX="169.0" layoutY="377.0" text="将要转换的字符 16位:" /> <Label layoutX="169.0" layoutY="369.0" text="将要转换的16位字符:" AnchorPane.leftAnchor="169.0" AnchorPane.rightAnchor="918.0" />
<Separator layoutX="56.0" layoutY="317.0" prefHeight="5.0" prefWidth="1200.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
<TextField fx:id="text_filed1" layoutX="300.0" layoutY="365.0" prefHeight="25.0" prefWidth="619.0" AnchorPane.leftAnchor="300.0" AnchorPane.rightAnchor="281.0" />
<Button fx:id="button1" layoutX="930.0" layoutY="365.0" mnemonicParsing="false" text="转换" AnchorPane.rightAnchor="230.0" />
<TextArea fx:id="hex_161" layoutX="300.0" layoutY="429.0" prefHeight="121.0" prefWidth="619.0" AnchorPane.leftAnchor="300.0" AnchorPane.rightAnchor="281.0" />
<Label layoutX="169.0" layoutY="429.0" text="普通字符串:" AnchorPane.leftAnchor="169.0" AnchorPane.rightAnchor="918.0" />
</children> </children>
</AnchorPane> </AnchorPane>

View File

@ -30,7 +30,7 @@
</Menu> </Menu>
<Menu mnemonicParsing="false" text="常用小工具"> <Menu mnemonicParsing="false" text="常用小工具">
<items> <items>
<MenuItem mnemonicParsing="false" text="16进制Hex"/> <MenuItem mnemonicParsing="false" text="16进制Hex" onAction="#hex_16"/>
<MenuItem mnemonicParsing="false" text="Unicode和字符串转换"/> <MenuItem mnemonicParsing="false" text="Unicode和字符串转换"/>
<MenuItem mnemonicParsing="false" text="时间单位转换"/> <MenuItem mnemonicParsing="false" text="时间单位转换"/>
<MenuItem mnemonicParsing="false" text="颜色选择工具"/> <MenuItem mnemonicParsing="false" text="颜色选择工具"/>

View File

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="800.0"
prefWidth="1661.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="com.zhangmeng.tools.controller.SmallToolsController">
<children>
<MenuBar layoutX="14.0" layoutY="27.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
AnchorPane.topAnchor="0.0">
<menus>
<Menu mnemonicParsing="false" text="加密工具">
<items>
<MenuItem mnemonicParsing="false" onAction="#md5_menu_item" text="md5 加密"/>
<MenuItem mnemonicParsing="false" onAction="#spring_security_menu_item"
text="spring security 加密"/>
</items>
</Menu>
<Menu mnemonicParsing="false" text="影音工具">
<items>
<MenuItem mnemonicParsing="false" text="视频播放" onAction="#video_menu_item"/>
<MenuItem mnemonicParsing="false" text="音乐播放" onAction="#music_menu_item"/>
<MenuItem mnemonicParsing="false" text="vip 视频解析" onAction="#vip_parser_menu_item"/>
</items>
</Menu>
<Menu mnemonicParsing="false" text="常用小工具">
<items>
<MenuItem mnemonicParsing="false" text="16进制Hex" onAction="#hex_16_menu_item"/>
<MenuItem mnemonicParsing="false" text="Unicode和字符串转换" onAction="#unicode_menu_item"/>
<MenuItem mnemonicParsing="false" text="时间单位转换"/>
<MenuItem mnemonicParsing="false" text="颜色选择工具"/>
</items>
</Menu>
</menus>
</MenuBar>
<SplitPane fx:id="splitPane" dividerPositions="0.5" layoutY="25.0" prefHeight="575.0" prefWidth="1200.0"
AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0"
AnchorPane.topAnchor="25.0">
<items>
<ListView fx:id="listView" maxWidth="300.0" minWidth="200.0" prefHeight="200.0" prefWidth="200.0"/>
<AnchorPane prefHeight="200.0" prefWidth="200.0"/>
</items>
</SplitPane>
</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.Separator?>
<?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.UnicodeController">
<children>
<Label layoutX="169.0" layoutY="102.0" text="普通字符串:" AnchorPane.leftAnchor="169.0" />
<TextField fx:id="text_filed" layoutX="300.0" layoutY="98.0" prefHeight="25.0" prefWidth="619.0" AnchorPane.leftAnchor="300.0" AnchorPane.rightAnchor="281.0" AnchorPane.topAnchor="98.0" />
<Button fx:id="button" layoutX="930.0" layoutY="98.0" mnemonicParsing="false" text="转换" AnchorPane.rightAnchor="230.0" />
<Label layoutX="169.0" layoutY="160.0" text="unicode字符:" />
<TextArea fx:id="hex_16" layoutX="300.0" layoutY="160.0" prefHeight="121.0" prefWidth="619.0" AnchorPane.leftAnchor="300.0" AnchorPane.rightAnchor="281.0" AnchorPane.topAnchor="160.0" />
<Label layoutX="169.0" layoutY="369.0" text="将要转换的unicode字符:" AnchorPane.leftAnchor="169.0" AnchorPane.rightAnchor="918.0" />
<Separator layoutX="56.0" layoutY="317.0" prefHeight="5.0" prefWidth="1200.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
<TextField fx:id="text_filed1" layoutX="300.0" layoutY="365.0" prefHeight="25.0" prefWidth="619.0" AnchorPane.leftAnchor="300.0" AnchorPane.rightAnchor="281.0" />
<Button fx:id="button1" layoutX="930.0" layoutY="365.0" mnemonicParsing="false" text="转换" AnchorPane.rightAnchor="230.0" />
<TextArea fx:id="hex_161" layoutX="300.0" layoutY="429.0" prefHeight="121.0" prefWidth="619.0" AnchorPane.leftAnchor="300.0" AnchorPane.rightAnchor="281.0" />
<Label layoutX="169.0" layoutY="429.0" text="普通字符串:" AnchorPane.leftAnchor="169.0" AnchorPane.rightAnchor="918.0" />
</children>
</AnchorPane>

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB