diff --git a/main/src/Data/DiskBlock.java b/main/src/Data/DiskBlock.java index 24ac95bee5c20140be69ef8100ae65b9d4345dc1..88c684a904c15a1daa7b218922cb491c989aeff7 100644 --- a/main/src/Data/DiskBlock.java +++ b/main/src/Data/DiskBlock.java @@ -26,14 +26,7 @@ public class DiskBlock implements Serializable { setFileProperty(); } - /* private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { - s.defaultReadObject(); - numberProperty = new SimpleStringProperty(String.valueOf(number)); - nextDiskNumProperty = new SimpleStringProperty(String.valueOf(nextDiskNum)); - typeProperty = new SimpleStringProperty(type); - fileProperty = new SimpleStringProperty(file == null ? "" : file.toString()); - setObject(file); - }*/ + public transient StringProperty numberProperty = new SimpleStringProperty(); public transient StringProperty nextDiskNumProperty = new SimpleStringProperty(); diff --git a/main/src/Data/FAT.java b/main/src/Data/FAT.java index ef79cbcf12e50fe11e25002c4f10c2f8a8d829e6..e4b8d4dd02ba9f2bdc3a17c2722fd95de00a951b 100644 --- a/main/src/Data/FAT.java +++ b/main/src/Data/FAT.java @@ -46,7 +46,7 @@ public class FAT implements Serializable { if(file.isFolder){ fileType = "文件夹"; }else { - fileType = "文件文本"; + fileType = "普通文件"; } if(file.getDiskStartNum() == 0){ for(int i = 0; i < 128; i++){ diff --git a/main/src/Data/Path.java b/main/src/Data/Path.java deleted file mode 100644 index 490724b161f65eb36085ca0fc6bb578699053c74..0000000000000000000000000000000000000000 --- a/main/src/Data/Path.java +++ /dev/null @@ -1,41 +0,0 @@ -package Data; - -import java.util.ArrayList; -import java.util.List; - -public class Path { - - private String pathName; - private Path parent; - private List children; - - public Path(String pathName, Path parent) { - this.pathName = pathName; - this.parent = parent; - children = new ArrayList<>(); - } - - public String getPathName() { - return pathName; - } - - public void setPathName(String pathName) { - this.pathName = pathName; - } - - public Path getParent() { - return parent; - } - - public void setParent(Path parent) { - this.parent = parent; - } - - public List getChildren() { - return children; - } - - public void setChildren(List children) { - this.children = children; - } -} diff --git a/main/src/controller/FileController.java b/main/src/controller/FileController.java index 41e2af05525e07b980dd875b7ab6a2049460efc9..97e519412a2de82b6e08093bf9c645b985d9e2f3 100644 --- a/main/src/controller/FileController.java +++ b/main/src/controller/FileController.java @@ -44,8 +44,8 @@ public class FileController { fileName.setText(currentFile.getFileName()); contentField.setText(currentFile.getContent()); if (currentFile.isReadOnly()) { -// contentField.setDisable(true); - contentField.setEditable(false); + contentField.setDisable(true); + // contentField.setEditable(false); } } diff --git a/main/src/controller/MainController.java b/main/src/controller/MainController.java index 98be3d88316e47786b4483dfaa8c8b99e49cce46..a1fe573eeff2fc13bdc26f062c04157836455696 100644 --- a/main/src/controller/MainController.java +++ b/main/src/controller/MainController.java @@ -155,14 +155,8 @@ public class MainController { public static File currentFile; public static TreeItem recentNode; public static Map> treeMap = new HashMap<>(); - public static Stack frontStack = new Stack<>() ; public static Stack backStack = new Stack<>(); - - - Path rootPath; - Path currentPath; - public static Map icons = new HashMap<>(); Label selectIcon = null; diff --git a/main/src/operations/createFileOperations.java b/main/src/operations/createFileOperations.java index 62cc9bcdb49c9976f486c2826ec4eb2a36ce6307..127119edd4db4bdde97abd5e15a91bc75893b5df 100644 --- a/main/src/operations/createFileOperations.java +++ b/main/src/operations/createFileOperations.java @@ -1,20 +1,12 @@ package operations; import Data.File; -import Data.Path; -import controller.MainController; -import javafx.event.ActionEvent; -import javafx.event.EventHandler; import javafx.geometry.Pos; import javafx.scene.control.ContentDisplay; import javafx.scene.control.ContextMenu; import javafx.scene.control.Label; import javafx.scene.image.ImageView; -import javafx.scene.input.MouseButton; -import javafx.scene.input.MouseEvent; import javafx.scene.layout.FlowPane; -import util.FindLabelToFile; -import util.GetFileAbsolutePath; import util.RandomStr; @@ -22,12 +14,10 @@ import java.util.Map; import java.util.Vector; import static controller.MainController.currentFile; -import static controller.MainController.rootFile; 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(false,false,true,false,"新建文件"+rdStr,currentFile); System.out.println("创建文件"); Label icon = new Label(file.getFileName(),new ImageView("icon/文本文件.png")); @@ -58,73 +48,12 @@ public class createFileOperations { flowPane.getChildren().add(icon); currentFile.getChildrenFile().add(file); -// currentFile.getPath().getChildren().add(newPath); - /* icon.setOnMouseEntered(new EventHandler() { - - @Override - public void handle(MouseEvent event) { - ((Label) event.getSource()).setStyle("-fx-background-color: rgba(116,194,238,0.35);"); - } - }); - - icon.setOnMouseExited(new EventHandler() { - - @Override - public void handle(MouseEvent event) { - ((Label) event.getSource()).setStyle("-fx-background-color: transparent;"); - } - }); - - icon.setOnMouseClicked(new EventHandler() { - - @Override - public void handle(MouseEvent event) { - Label src = (Label) event.getSource(); - if (event.getButton() == MouseButton.SECONDARY && event.getClickCount() == 1) { - actionContextMenu.getItems().get(0).setOnAction(ActionEvent -> { - currentFile = FindLabelToFile.findFile(icons, src); - if(currentFile != null) { - if (currentFile.isFolder()) { - System.out.println(1); - System.out.println(src); - openOperations.openFolder(flowPane, currentFile, icons); - } else { - openOperations.openFile(); - } - } - }); - actionContextMenu.getItems().get(1).setOnAction(ActionEvent -> { - currentFile = FindLabelToFile.findFile(icons, src); - File deleteFile = currentFile; - currentFile = currentFile.getParent(); - if (currentFile != rootFile && currentFile.isFolder()) { - openOperations.openFolder(flowPane, currentFile, icons); - } - deleteOperations.deleteFile(flowPane, icons, deleteFile); - }); - actionContextMenu.getItems().get(2).setOnAction(ActionEvent -> { - currentFile = FindLabelToFile.findFile(icons, src); - - }); - actionContextMenu.show(src, event.getScreenX(), event.getScreenY()); - } else if (event.getButton() == MouseButton.PRIMARY && event.getClickCount() == 2) { - System.out.println("打开文件"); - } else if (event.getButton() == MouseButton.PRIMARY && event.getClickCount() == 1) { - System.out.println("选择"); - File file = FindLabelToFile.findFile(icons, icon); - MainController.selectAction(file); - } else { - actionContextMenu.hide(); - } - } - });*/ return file; } public static File createFolder(FlowPane flowPane, /*File currentFile,*/ Map icons, ContextMenu actionContextMenu){ String rdStr = RandomStr.getRandomString(5); -// Path newPath = new Path(currentFile.getAbsolutePath()+"新建文件夹" + rdStr,currentFile.getPath()); File file = new File(false,false,true,true,"新建文件夹"+rdStr,currentFile); System.out.println("创建文件夹"); Label icon = new Label(file.getFileName(),new ImageView("icon/文件夹.png")); @@ -144,7 +73,6 @@ public class createFileOperations { flowPane.getChildren().remove(icons.get(file1)); } } - for(File folder1 : folders){ if(folder1 != null) { flowPane.getChildren().add(icons.get(folder1)); diff --git a/main/src/util/FileRW.java b/main/src/util/FileRW.java index 3ada573919662b9925f50ea020f986e8a5280701..b3e4b36dc881cc403c918a38a09f945881a0c375 100644 --- a/main/src/util/FileRW.java +++ b/main/src/util/FileRW.java @@ -4,30 +4,46 @@ import Data.StoreDiskBlock; import Data.StoreFileToDiskBlock; import java.io.*; +import java.nio.file.Path; +import java.nio.file.Paths; import static controller.MainController.*; public class FileRW { public static void readDisk() throws IOException, ClassNotFoundException { - try { - ObjectInputStream oi = new ObjectInputStream(new FileInputStream(new File("Disk.sfs"))); - rootFile = (Data.File) oi.readObject(); - FileConvertToIcon fileConvertToIcon = new FileConvertToIcon(); - fileConvertToIcon.convert(rootFile); - oi.close(); - }catch (EOFException e){ - rootFile = new Data.File(false,true,false,true,"c:",null); + Path currentPath = Paths.get(""); + String filePath = currentPath.toAbsolutePath() + "\\Disk.sfs"; + File file = new File(filePath); + if(!file.exists()){ + file.createNewFile(); + rootFile = new Data.File(false, true, false, true, "c:", null); + }else { + try { + ObjectInputStream oi = new ObjectInputStream(new FileInputStream(file)); + rootFile = (Data.File) oi.readObject(); + FileConvertToIcon fileConvertToIcon = new FileConvertToIcon(); + fileConvertToIcon.convert(rootFile); + oi.close(); + } catch (EOFException e) { + throw new RuntimeException(e); + } } - try { - ObjectInputStream bi = new ObjectInputStream(new FileInputStream(new File("DiskBlock.sfs"))); - StoreDiskBlock[] t = (StoreDiskBlock[])bi.readObject() ; - StoreFileToDiskBlock d = new StoreFileToDiskBlock(); - d.setStoreDiskBlocks(t); - d.convert(rootFile, fat.getDiskBlocks()); - bi.close(); - }catch (EOFException e){ - System.out.println("没有文件读取"); + filePath = currentPath.toAbsolutePath()+"\\DiskBlock.sfs"; + file = new File(filePath); + if(!file.exists()) { + file.createNewFile(); + }else { + try { + ObjectInputStream bi = new ObjectInputStream(new FileInputStream(file)); + StoreDiskBlock[] t = (StoreDiskBlock[]) bi.readObject(); + StoreFileToDiskBlock d = new StoreFileToDiskBlock(); + d.setStoreDiskBlocks(t); + d.convert(rootFile, fat.getDiskBlocks()); + bi.close(); + } catch (EOFException e) { + System.out.println("没有文件读取"); + } } }