2023年6月2日18:28:13
parent
39c6185b3a
commit
d3c2ef1400
13
README.md
13
README.md
|
|
@ -110,6 +110,19 @@
|
|||

|
||||
|
||||
|
||||
### 3.15 文本编辑器
|
||||
|
||||

|
||||
|
||||
|
||||
### 3.16 批量修改文件名
|
||||
|
||||

|
||||
|
||||
### 3.16 截图
|
||||
|
||||

|
||||
|
||||
### 4. 编解码工具
|
||||
|
||||
> 编解码工具也是对开源组件 Hutool 简单封装展示
|
||||
|
|
|
|||
|
|
@ -10,12 +10,15 @@ import com.zaxxer.hikari.util.FastList;
|
|||
import javafx.application.Platform;
|
||||
import javafx.beans.property.SimpleIntegerProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.TreeCell;
|
||||
import javafx.scene.control.TreeItem;
|
||||
import javafx.scene.control.TreeView;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.input.MouseButton;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.text.Font;
|
||||
import javafx.scene.text.Text;
|
||||
|
|
@ -30,8 +33,6 @@ public class RecursiveFileList extends TreeView<File> {
|
|||
|
||||
private final SimpleObjectProperty<File> index_file = new SimpleObjectProperty<>(null);
|
||||
|
||||
private final SimpleIntegerProperty text_size = new SimpleIntegerProperty(15);
|
||||
private final SimpleIntegerProperty icon_size = new SimpleIntegerProperty(15);
|
||||
|
||||
public RecursiveFileList(File root) {
|
||||
super(new TreeItem<>(root));
|
||||
|
|
@ -50,79 +51,6 @@ public class RecursiveFileList extends TreeView<File> {
|
|||
index_file.setValue(newValue.getValue());
|
||||
}
|
||||
});
|
||||
this.setCellFactory(new Callback<TreeView<File>, TreeCell<File>>() {
|
||||
@Override
|
||||
public TreeCell<File> call(TreeView<File> param) {
|
||||
return new TreeCell<File>(){
|
||||
@Override
|
||||
protected void updateItem(File item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
if (!empty){
|
||||
HBox hBox = new HBox(10);
|
||||
ImageView iv = null;
|
||||
if (this.getTreeItem().isExpanded()){
|
||||
iv = new ImageView(new Image("image/向下.png"));
|
||||
}else {
|
||||
iv = new ImageView(new Image("image/向右.png"));
|
||||
}
|
||||
iv.setPreserveRatio(true);
|
||||
iv.setFitWidth(icon_size.get());
|
||||
this.setDisclosureNode(iv);
|
||||
|
||||
Label label = new Label(item.getName());
|
||||
label.setFont(new Font(text_size.get()));
|
||||
|
||||
//判断是否是文件
|
||||
boolean directory = item.isDirectory();
|
||||
if (directory){
|
||||
ImageView dir = new ImageView(new Image("image/dir.png"));
|
||||
dir.setPreserveRatio(true);
|
||||
dir.setFitWidth(icon_size.get());
|
||||
hBox.getChildren().add(dir);
|
||||
}else {
|
||||
if (item.isFile()){
|
||||
ImageView file = null;
|
||||
|
||||
String extension = FilenameUtils.getExtension(item.getName());
|
||||
if (extension.equals("java")){
|
||||
file = new ImageView(new Image("image/java.png"));
|
||||
}
|
||||
if (extension.equals("html")){
|
||||
file = new ImageView(new Image("image/html.png"));
|
||||
}
|
||||
if (extension.equals("jar")){
|
||||
file = new ImageView(new Image("image/jar.png"));
|
||||
}
|
||||
if (extension.equals("json")){
|
||||
file = new ImageView(new Image("image/json.png"));
|
||||
}
|
||||
|
||||
if (extension.equals("jpg")){
|
||||
file = new ImageView(new Image("image/jpg.png"));
|
||||
}
|
||||
|
||||
if (extension.equals("png")){
|
||||
file = new ImageView(new Image("image/png.png"));
|
||||
}
|
||||
|
||||
if (file != null){
|
||||
file.setPreserveRatio(true);
|
||||
file.setFitWidth(icon_size.get());
|
||||
hBox.getChildren().add(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hBox.getChildren().add(label);
|
||||
this.setGraphic(hBox);
|
||||
}else {
|
||||
this.setGraphic(null);
|
||||
this.setDisclosureNode(null);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private TreeItem<File> getTreeItem(File file) {
|
||||
|
|
|
|||
|
|
@ -13,15 +13,20 @@ import javafx.collections.FXCollections;
|
|||
import javafx.collections.ListChangeListener;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.SplitPane;
|
||||
import javafx.scene.control.Tab;
|
||||
import javafx.scene.control.TabPane;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.input.MouseButton;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.text.Font;
|
||||
import javafx.stage.DirectoryChooser;
|
||||
import javafx.stage.FileChooser;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.util.Callback;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.fxmisc.flowless.VirtualizedScrollPane;
|
||||
|
|
@ -32,6 +37,7 @@ import org.fxmisc.richtext.model.StyleSpansBuilder;
|
|||
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
|
@ -69,6 +75,9 @@ public class FileEditController {
|
|||
private static String path = null;
|
||||
private final ObservableList<Path> filePaths_list = FXCollections.observableArrayList();
|
||||
private final SimpleIntegerProperty index = new SimpleIntegerProperty(0);
|
||||
|
||||
private final SimpleIntegerProperty text_size = new SimpleIntegerProperty(15);
|
||||
private final SimpleIntegerProperty icon_size = new SimpleIntegerProperty(15);
|
||||
private static final Map<Integer,Tab> map = new HashMap<>();
|
||||
|
||||
@FXML
|
||||
|
|
@ -76,6 +85,7 @@ public class FileEditController {
|
|||
//读取本地加载记录
|
||||
Properties s = config_path(false);
|
||||
recursiveFileList = new RecursiveFileList(null);
|
||||
init_file_list();
|
||||
tabPane = new TabPane();
|
||||
splitPane.getItems().add(0, recursiveFileList);
|
||||
splitPane.getItems().add(1, tabPane);
|
||||
|
|
@ -85,8 +95,10 @@ public class FileEditController {
|
|||
tabPane.getTabs().addListener(new ListChangeListener<Tab>() {
|
||||
@Override
|
||||
public void onChanged(Change<? extends Tab> c) {
|
||||
if (c.wasRemoved()){
|
||||
filePaths_list.remove(c);
|
||||
if (c.next()){
|
||||
if (c.wasRemoved()){
|
||||
filePaths_list.remove(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -129,6 +141,92 @@ public class FileEditController {
|
|||
}
|
||||
}
|
||||
|
||||
public void init_file_list(){
|
||||
this.recursiveFileList.setCellFactory(new Callback<TreeView<File>, TreeCell<File>>() {
|
||||
@Override
|
||||
public TreeCell<File> call(TreeView<File> param) {
|
||||
return new TreeCell<File>(){
|
||||
@Override
|
||||
protected void updateItem(File item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
if (!empty){
|
||||
HBox hBox = new HBox(10);
|
||||
ImageView iv = null;
|
||||
if (this.getTreeItem().isExpanded()){
|
||||
iv = new ImageView(new Image("image/向下.png"));
|
||||
}else {
|
||||
iv = new ImageView(new Image("image/向右.png"));
|
||||
}
|
||||
iv.setPreserveRatio(true);
|
||||
iv.setFitWidth(icon_size.get());
|
||||
this.setDisclosureNode(iv);
|
||||
|
||||
Label label = new Label(item.getName());
|
||||
label.setFont(new Font(text_size.get()));
|
||||
|
||||
//判断是否是文件
|
||||
boolean directory = item.isDirectory();
|
||||
if (directory){
|
||||
ImageView dir = new ImageView(new Image("image/dir.png"));
|
||||
dir.setPreserveRatio(true);
|
||||
dir.setFitWidth(icon_size.get());
|
||||
hBox.getChildren().add(dir);
|
||||
}else {
|
||||
if (item.isFile()){
|
||||
ImageView file = null;
|
||||
|
||||
String extension = FilenameUtils.getExtension(item.getName());
|
||||
if (extension.equals("java")){
|
||||
file = new ImageView(new Image("image/java.png"));
|
||||
}
|
||||
if (extension.equals("html")){
|
||||
file = new ImageView(new Image("image/html.png"));
|
||||
}
|
||||
if (extension.equals("jar")){
|
||||
file = new ImageView(new Image("image/jar.png"));
|
||||
}
|
||||
if (extension.equals("json")){
|
||||
file = new ImageView(new Image("image/json.png"));
|
||||
}
|
||||
|
||||
if (extension.equals("jpg")){
|
||||
file = new ImageView(new Image("image/jpg.png"));
|
||||
}
|
||||
|
||||
if (extension.equals("png")){
|
||||
file = new ImageView(new Image("image/png.png"));
|
||||
}
|
||||
|
||||
if (file != null){
|
||||
file.setPreserveRatio(true);
|
||||
file.setFitWidth(icon_size.get());
|
||||
hBox.getChildren().add(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hBox.getChildren().add(label);
|
||||
|
||||
hBox.setOnMouseClicked(new EventHandler<MouseEvent>() {
|
||||
@Override
|
||||
public void handle(MouseEvent event) {
|
||||
if (event.getButton() == MouseButton.PRIMARY && event.getClickCount() == 2) {
|
||||
// 双击左键的操作
|
||||
file_checked(item);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this.setGraphic(hBox);
|
||||
}else {
|
||||
this.setGraphic(null);
|
||||
this.setDisclosureNode(null);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void open_file_dir_menu(ActionEvent event) {
|
||||
|
|
@ -157,7 +255,11 @@ public class FileEditController {
|
|||
try {
|
||||
file_content = Files.readString(file.toPath(), StandardCharsets.UTF_8);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
try {
|
||||
file_content = Files.readString(file.toPath(), Charset.forName("GBK"));
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
codeArea.textProperty().addListener((obs, oldText, newText) -> {
|
||||
|
|
@ -192,12 +294,12 @@ public class FileEditController {
|
|||
public void refresh(File file, boolean is_open_file) {
|
||||
splitPane.getItems().clear();
|
||||
recursiveFileList = new RecursiveFileList(file);
|
||||
init_file_list();
|
||||
recursiveFileList.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
|
||||
if (newValue.getValue().isFile()) {
|
||||
file_checked(newValue.getValue());
|
||||
}
|
||||
});
|
||||
|
||||
splitPane.getItems().add(0, recursiveFileList);
|
||||
splitPane.getItems().add(1, tabPane);
|
||||
splitPane.setDividerPosition(0, 0.20);
|
||||
|
|
|
|||
Binary file not shown.
|
After Width: | Height: | Size: 121 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 61 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 358 KiB |
Loading…
Reference in New Issue