From 88a216ba80ddbd663a68dc51f7f14c01f44cb487 Mon Sep 17 00:00:00 2001 From: Alan473 <1109658180@qq.com> Date: Mon, 20 Nov 2023 23:00:09 +0800 Subject: [PATCH 1/2] bug fix --- main/src/operations/createFileOperations.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/src/operations/createFileOperations.java b/main/src/operations/createFileOperations.java index 1cfadd4..62cc9bc 100644 --- a/main/src/operations/createFileOperations.java +++ b/main/src/operations/createFileOperations.java @@ -28,7 +28,7 @@ public class createFileOperations { public static File createFile(FlowPane flowPane, Map icons, ContextMenu actionContextMenu){ String rdStr = RandomStr.getRandomString(5); // Path newPath = new Path(currentFile.getAbsolutePath()+"新建文件"+rdStr,currentFile.getPath()); - File file = new File(true,false,true,false,"新建文件"+rdStr,currentFile); + File file = new File(false,false,true,false,"新建文件"+rdStr,currentFile); System.out.println("创建文件"); Label icon = new Label(file.getFileName(),new ImageView("icon/文本文件.png")); icon.setContentDisplay(ContentDisplay.TOP); -- Gitee From add9a1af6ba6921fc8037d42b2f97145d847760c Mon Sep 17 00:00:00 2001 From: Alan473 <1109658180@qq.com> Date: Tue, 21 Nov 2023 01:50:46 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=A8=A1=E6=8B=9F=E7=A3=81=E7=9B=98?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96=E5=86=99=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Disk.sfs | Bin 0 -> 808 bytes main/src/controller/FileController.java | 6 ++- main/src/controller/MainController.java | 53 ++++++++++++++++++++-- main/src/controller/RenameController.java | 6 ++- main/src/util/FileConvertToIcon.java | 32 ++++++++++--- main/src/util/FileRW.java | 24 ++++++++++ 6 files changed, 109 insertions(+), 12 deletions(-) create mode 100644 Disk.sfs create mode 100644 main/src/util/FileRW.java diff --git a/Disk.sfs b/Disk.sfs new file mode 100644 index 0000000000000000000000000000000000000000..37dae150cebfae5f34df3dc6ae29ad3ec504dda5 GIT binary patch literal 808 zcmbtRy-(Xf6n`;s_-K$CU|^vV|3Ff}l`5D(2ocpJ&{V4G?XWM&(X)N{ULavWVq)!t z#K6Ybp;M)nKY*Q)xv+KY-g{2?a=Y<#XP@uA-^Y9Y`WtMW!00MNR$dd5hp)a|&sP7$ z7K~S+7zq8jfh@sVC-h)M=(Sh|Jn^6?bS+LoCJEy~LFl^Tkq2W!zvnEdN3xd|HF_F( zNJUjBNFKGYU4^_B2i%3C-xe}RctmN0m+lVRW0ejHS#gENB^QSMI6@vF!bCqQS=6dD zFcDG9q(_93qgUhGv<{z1U%?k8jnR7;M&v)L&q*i)fv+cQ0^{qZnchFUK f9v`=u{AaFD9TRdo("C:",new ImageView("icon/disk.png")); fileView.setRoot(rootNode); rootNode.setExpanded(true); @@ -165,6 +168,18 @@ public class MainController { fileExplorer.setHgap(15); fileExplorer.setVgap(20); fileExplorer.setPadding(new Insets(0,10,0,10)); + openOperations.openFolder(fileExplorer, currentFile, icons); + TreeViewIterator treeViewIterator = new TreeViewIterator(); + treeViewIterator.iterator(fileView); + ArrayList tmpFiles = new FileIterator().iterator(rootFile); + for (File file : tmpFiles) { + if (file.isFolder()) { + LabelMouseEventForFolder(icons.get(file)); + } else { + LabelMouseEventForFile(icons.get(file)); + } + } + // writeDisk(); } private void contextMenuInit() { @@ -258,6 +273,11 @@ public class MainController { treeViewIterator.Clear(); treeViewIterator.iterator(fileView); LabelMouseEventForFile(icons.get(file)); + try { + writeDisk(); + } catch (IOException | ClassNotFoundException e) { + throw new RuntimeException(e); + } }); createFolderItem.setOnAction(ActionEvent -> { @@ -266,6 +286,11 @@ public class MainController { treeViewIterator.Clear(); treeViewIterator.iterator(fileView); LabelMouseEventForFolder(icons.get(folder)); + try { + writeDisk(); + } catch (IOException | ClassNotFoundException e) { + throw new RuntimeException(e); + } }); } @@ -278,7 +303,7 @@ public class MainController { } } - void LabelMouseEventForFile(Label icon){ + void LabelMouseEventForFile(Label icon){ icon.setOnMouseEntered(new EventHandler() { @Override @@ -330,13 +355,18 @@ public class MainController { openOperations.openFolder(fileExplorer, currentFile, icons); } deleteOperations.deleteFile(fileExplorer, icons, deleteFile); + try { + writeDisk(); + } catch (IOException | ClassNotFoundException e) { + throw new RuntimeException(e); + } }); //右键重命名文件 actionContextMenu.getItems().get(2).setOnAction(ActionEvent -> { currentFile = FindLabelToFile.findFile(icons, src); try { + sentParam(fileView); renameFile(); - } catch (Exception e) { throw new RuntimeException(e); } @@ -348,6 +378,11 @@ public class MainController { } else { currentFile.setReadOnly(true); } + try { + writeDisk(); + } catch (IOException | ClassNotFoundException e) { + throw new RuntimeException(e); + } }); actionContextMenu.show(src, event.getScreenX(), event.getScreenY()); } else if (event.getButton() == MouseButton.PRIMARY && event.getClickCount() == 2) { @@ -430,6 +465,11 @@ public class MainController { TreeViewIterator treeViewIterator = new TreeViewIterator(); treeViewIterator.Clear(); treeViewIterator.iterator(fileView); + try { + writeDisk(); + } catch (IOException | ClassNotFoundException e) { + throw new RuntimeException(e); + } }); //右键重命名文件 actionContextMenu.getItems().get(2).setOnAction(ActionEvent -> { @@ -448,6 +488,11 @@ public class MainController { } else { currentFile.setReadOnly(true); } + try { + writeDisk(); + } catch (IOException | ClassNotFoundException e) { + throw new RuntimeException(e); + } }); actionContextMenu.show(src, event.getScreenX(), event.getScreenY()); } else if (event.getButton() == MouseButton.PRIMARY && event.getClickCount() == 2) { diff --git a/main/src/controller/RenameController.java b/main/src/controller/RenameController.java index d9c51fe..5780ab0 100644 --- a/main/src/controller/RenameController.java +++ b/main/src/controller/RenameController.java @@ -13,8 +13,11 @@ import javafx.scene.layout.Pane; import javafx.stage.Stage; import util.TreeViewIterator; +import java.io.IOException; + import static controller.MainController.*; import static operations.renameOperations.isAbleToRename; +import static util.FileRW.writeDisk; public class RenameController { @@ -41,7 +44,7 @@ public class RenameController { } @FXML - void renameConfirm(ActionEvent event) { + void renameConfirm(ActionEvent event) throws IOException, ClassNotFoundException { if (isAbleToRename(currentFile, renameField.getText())) { currentFile.setFileName(renameField.getText()); icons.get(currentFile).setText(currentFile.getFileName()); @@ -55,6 +58,7 @@ public class RenameController { treeViewIterator.iterator(tmpFileView); Stage stage = (Stage) renameField.getScene().getWindow(); stage.close(); + writeDisk(); } else { AnchorPane anchorPane = new AnchorPane(); Scene scene = new Scene(anchorPane, 200, 20); diff --git a/main/src/util/FileConvertToIcon.java b/main/src/util/FileConvertToIcon.java index 666c0a7..bac5e0e 100644 --- a/main/src/util/FileConvertToIcon.java +++ b/main/src/util/FileConvertToIcon.java @@ -1,22 +1,42 @@ package util; import Data.File; +import javafx.geometry.Pos; +import javafx.scene.control.ContentDisplay; import javafx.scene.control.Label; +import javafx.scene.image.ImageView; +import java.util.ArrayList; import java.util.HashMap; import java.util.Map; +import static controller.MainController.icons; -public class FileConvertToIcon { +public class FileConvertToIcon { //递归 void deepConvert(File file) { - + ArrayList folders = new ArrayList<>(); + for (File file1 : file.getChildrenFile()) { + Label icon; + if(file1.isFolder()) { + folders.add(file1); + icon = new Label(file1.getFileName(),new ImageView("icon/文件夹.png")); + } else { + icon = new Label(file1.getFileName(),new ImageView("icon/文本文件.png")); + } + icon.setContentDisplay(ContentDisplay.TOP); + icon.setWrapText(false); + icon.setPrefWidth(100); + icon.setAlignment(Pos.CENTER); + icons.put(file1,icon); + } + for (File file1 : folders) { + deepConvert(file1); + } } - public static Map convert(File rootFile) { - Map icon = new HashMap<>(); - - return icon; + public void convert(File rootFile) { + deepConvert(rootFile); } } diff --git a/main/src/util/FileRW.java b/main/src/util/FileRW.java new file mode 100644 index 0000000..841e066 --- /dev/null +++ b/main/src/util/FileRW.java @@ -0,0 +1,24 @@ +package util; + +import java.io.*; + +import static controller.MainController.icons; +import static controller.MainController.rootFile; + +public class FileRW { + public static void readDisk() throws IOException, ClassNotFoundException { + ObjectInputStream oi = new ObjectInputStream(new FileInputStream(new File("Disk.sfs"))); + + rootFile = (Data.File) oi.readObject(); + FileConvertToIcon fileConvertToIcon = new FileConvertToIcon(); + fileConvertToIcon.convert(rootFile); + oi.close(); + } + + public static void writeDisk() throws IOException, ClassNotFoundException { + ObjectOutputStream oo = new ObjectOutputStream(new FileOutputStream(new File("Disk.sfs"))); + + oo.writeObject(rootFile); + oo.close(); + } +} -- Gitee