2023年9月2日11:14:42
parent
104244886b
commit
adc4040cc8
|
|
@ -606,4 +606,8 @@ public class HomeController implements Serializable {
|
||||||
public void layui_form_gen_menu_item(ActionEvent actionEvent) {
|
public void layui_form_gen_menu_item(ActionEvent actionEvent) {
|
||||||
load_small_tools(17);
|
load_small_tools(17);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void log_console_menu_item(ActionEvent actionEvent) {
|
||||||
|
load_small_tools(18);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,130 @@
|
||||||
|
package com.zhangmeng.tools.controller;
|
||||||
|
|
||||||
|
import cn.hutool.core.io.FileUtil;
|
||||||
|
import cn.hutool.core.io.LineHandler;
|
||||||
|
import cn.hutool.core.io.file.Tailer;
|
||||||
|
import cn.hutool.core.lang.Console;
|
||||||
|
import com.sun.javafx.PlatformUtil;
|
||||||
|
import com.zhangmeng.tools.utils.AlertUtils;
|
||||||
|
import javafx.application.Platform;
|
||||||
|
import javafx.beans.property.SimpleListProperty;
|
||||||
|
import javafx.beans.value.ChangeListener;
|
||||||
|
import javafx.beans.value.ObservableValue;
|
||||||
|
import javafx.collections.FXCollections;
|
||||||
|
import javafx.collections.ListChangeListener;
|
||||||
|
import javafx.collections.ObservableList;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.TextArea;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
|
import javafx.scene.text.Font;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class LogConsoleController {
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public TextArea console_show;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private TextField log_path;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Button start_read;
|
||||||
|
|
||||||
|
private Tailer tailer;
|
||||||
|
|
||||||
|
private static final ObservableList<String> list = FXCollections.observableArrayList();
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void initialize() {
|
||||||
|
|
||||||
|
console_show.setFont(Font.font("微软雅黑",14));
|
||||||
|
new Thread(()->{
|
||||||
|
list.addListener(new ListChangeListener<String>() {
|
||||||
|
@Override
|
||||||
|
public void onChanged(Change<? extends String> c) {
|
||||||
|
while (c.next()){
|
||||||
|
if (c.wasAdded()){
|
||||||
|
List<? extends String> addedSubList = c.getAddedSubList();
|
||||||
|
if (addedSubList.size()>0){
|
||||||
|
String line = addedSubList.get(0);
|
||||||
|
Platform.runLater(()->{
|
||||||
|
console_show.appendText(System.lineSeparator());
|
||||||
|
console_show.appendText(line);
|
||||||
|
console_show.setScrollLeft(0);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}).start();
|
||||||
|
|
||||||
|
|
||||||
|
log_path.textProperty().addListener(new ChangeListener<String>() {
|
||||||
|
@Override
|
||||||
|
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
|
||||||
|
if (newValue != null && !newValue.equals("")){
|
||||||
|
log.info("log_path ==" + log_path.getText());
|
||||||
|
//重新加载日志
|
||||||
|
if (tailer != null){
|
||||||
|
tailer.stop();
|
||||||
|
start_read();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
start_read.setOnAction(event -> {
|
||||||
|
start_read();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void start_read(){
|
||||||
|
if (log_path.getText().length() == 0){
|
||||||
|
AlertUtils.alert_warning("日志路径不能为空!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
File file = FileUtil.file(log_path.getText());
|
||||||
|
|
||||||
|
String file_content = null;
|
||||||
|
try {
|
||||||
|
file_content = Files.readString(file.toPath(), StandardCharsets.UTF_8);
|
||||||
|
} catch (IOException e) {
|
||||||
|
try {
|
||||||
|
file_content = Files.readString(file.toPath(), Charset.forName("GBK"));
|
||||||
|
} catch (IOException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console_show.setText(file_content);
|
||||||
|
console_show.appendText(System.lineSeparator());
|
||||||
|
console_show.setScrollLeft(0);
|
||||||
|
new Thread(()->{
|
||||||
|
LineHandler CONSOLE_HANDLER = new ConsoleLineHandler();
|
||||||
|
tailer = new Tailer(file, CONSOLE_HANDLER, 2);
|
||||||
|
tailer.start();
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 命令行打印的行处理器
|
||||||
|
*
|
||||||
|
* @author looly
|
||||||
|
* @since 4.5.2
|
||||||
|
*/
|
||||||
|
public static class ConsoleLineHandler implements LineHandler {
|
||||||
|
@Override
|
||||||
|
public void handle(String line) {
|
||||||
|
list.add(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -85,6 +85,7 @@ public class SmallToolsController {
|
||||||
private AnchorPane capter_screen;
|
private AnchorPane capter_screen;
|
||||||
private AnchorPane file_edit;
|
private AnchorPane file_edit;
|
||||||
private AnchorPane layui_form_gen;
|
private AnchorPane layui_form_gen;
|
||||||
|
private AnchorPane log_console;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private ListView<ResourcesUtils.SmallTools> listView;
|
private ListView<ResourcesUtils.SmallTools> listView;
|
||||||
|
|
@ -424,10 +425,32 @@ public class SmallToolsController {
|
||||||
}
|
}
|
||||||
layui_form_gen(flag);
|
layui_form_gen(flag);
|
||||||
}
|
}
|
||||||
|
if (newValue.getIndex() == 18) {
|
||||||
|
if (log_console != null) {
|
||||||
|
flag = true;
|
||||||
|
}
|
||||||
|
log_console(flag);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void log_console(boolean flag) {
|
||||||
|
//默认选择第一个
|
||||||
|
listView.getSelectionModel().select(18);
|
||||||
|
if (!flag) {
|
||||||
|
try {
|
||||||
|
root = FXMLLoader.load(ResourcesUtils.getResource("log-console"));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
log_console = root;
|
||||||
|
} else {
|
||||||
|
root = log_console;
|
||||||
|
}
|
||||||
|
common_method();
|
||||||
|
}
|
||||||
|
|
||||||
private void layui_form_gen(boolean flag) {
|
private void layui_form_gen(boolean flag) {
|
||||||
//默认选择第一个
|
//默认选择第一个
|
||||||
listView.getSelectionModel().select(17);
|
listView.getSelectionModel().select(17);
|
||||||
|
|
@ -482,6 +505,7 @@ public class SmallToolsController {
|
||||||
case Capter_Screent -> new Image("image/截图.png");
|
case Capter_Screent -> new Image("image/截图.png");
|
||||||
case File_Edit -> new Image("image/编辑.png");
|
case File_Edit -> new Image("image/编辑.png");
|
||||||
case LayUI_Form_Gen -> new Image("image/layui.png");
|
case LayUI_Form_Gen -> new Image("image/layui.png");
|
||||||
|
case LogConsole -> new Image("image/layui.png");
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,6 @@
|
||||||
package com.zhangmeng.tools.utils;
|
package com.zhangmeng.tools.utils;
|
||||||
|
|
||||||
import javafx.scene.image.Image;
|
import javafx.scene.image.Image;
|
||||||
import javafx.scene.layout.AnchorPane;
|
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
|
|
@ -134,6 +133,7 @@ public class ResourcesUtils {
|
||||||
Capter_Screent("截图", 15),
|
Capter_Screent("截图", 15),
|
||||||
File_Edit("文件编辑器", 16),
|
File_Edit("文件编辑器", 16),
|
||||||
LayUI_Form_Gen("layui-from 表单生成", 17),
|
LayUI_Form_Gen("layui-from 表单生成", 17),
|
||||||
|
LogConsole("日志输出", 18),
|
||||||
;
|
;
|
||||||
|
|
||||||
SmallTools(String title, int index) {
|
SmallTools(String title, int index) {
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,7 @@
|
||||||
<MenuItem mnemonicParsing="false" text="截图工具" onAction="#capter_screen_menu_item"/>
|
<MenuItem mnemonicParsing="false" text="截图工具" onAction="#capter_screen_menu_item"/>
|
||||||
<MenuItem mnemonicParsing="false" text="文件编辑器" onAction="#file_edit_menu_item"/>
|
<MenuItem mnemonicParsing="false" text="文件编辑器" onAction="#file_edit_menu_item"/>
|
||||||
<MenuItem mnemonicParsing="false" text="LayUI表单代码生成" onAction="#layui_form_gen_menu_item"/>
|
<MenuItem mnemonicParsing="false" text="LayUI表单代码生成" onAction="#layui_form_gen_menu_item"/>
|
||||||
|
<MenuItem mnemonicParsing="false" text="日志输出" onAction="#log_console_menu_item"/>
|
||||||
</items>
|
</items>
|
||||||
</Menu>
|
</Menu>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
<?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.LogConsoleController">
|
||||||
|
<children>
|
||||||
|
<Label layoutX="114.0" layoutY="79.0" text="日志文件位置:" />
|
||||||
|
<TextField fx:id="log_path" layoutX="207.0" layoutY="75.0" prefHeight="22.0" prefWidth="850.0" />
|
||||||
|
<TextArea fx:id="console_show" layoutX="207.0" layoutY="136.0" prefHeight="425.0" prefWidth="954.0" AnchorPane.bottomAnchor="88.0" AnchorPane.leftAnchor="207.0" AnchorPane.rightAnchor="39.0" AnchorPane.topAnchor="136.0" />
|
||||||
|
<Label layoutX="114.0" layoutY="136.0" text="日志内容:" />
|
||||||
|
<Button layoutX="1073.0" layoutY="75.0" mnemonicParsing="false" text="读取日志文件" fx:id="start_read" />
|
||||||
|
</children>
|
||||||
|
</AnchorPane>
|
||||||
Loading…
Reference in New Issue