diff --git a/.gitignore b/.gitignore index 76b719eb14718632a893eb627d00606531e0853b..7fdbb4ec8bfc5aca2db558ee0c5f62c1e2691bf0 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,13 @@ bin-release/ *.air *.ipa *.apk +target/ +.idea/ +.gitee/ +*.iml +*.xml +*.md +LICENSE # Project files, i.e. `.project`, `.actionScriptProperties` and `.flexProperties` # should NOT be excluded as they contain compiler settings and other important diff --git a/main/resources/Main-view.fxml b/main/resources/Main-view.fxml index 3711b664dbe2b521e8fc4c5141b2b6be0ccf02c8..5c51e3e6da31ce0c5e01c564caed89f1a0c50112 100644 --- a/main/resources/Main-view.fxml +++ b/main/resources/Main-view.fxml @@ -34,14 +34,16 @@ + diff --git "a/main/resources/icon/\346\226\207\344\273\266\345\244\271.png" "b/main/resources/icon/\346\226\207\344\273\266\345\244\271.png" new file mode 100644 index 0000000000000000000000000000000000000000..19baa91fb9acc0b0d4443472b1bdc0428e5e4d71 Binary files /dev/null and "b/main/resources/icon/\346\226\207\344\273\266\345\244\271.png" differ diff --git "a/main/resources/icon/\346\226\207\346\234\254\346\226\207\344\273\266.png" "b/main/resources/icon/\346\226\207\346\234\254\346\226\207\344\273\266.png" new file mode 100644 index 0000000000000000000000000000000000000000..9fde0c1a32d7ce61fb03cc1aee9ab74ddecc4297 Binary files /dev/null and "b/main/resources/icon/\346\226\207\346\234\254\346\226\207\344\273\266.png" differ diff --git a/main/src/Data/DiskBlock.java b/main/src/Data/DiskBlock.java index 4f374624fa80704f156d3d585942aa7548a5688d..e7bdfa55b848ff9f47f0bc55fe74b6bbb181e8e7 100644 --- a/main/src/Data/DiskBlock.java +++ b/main/src/Data/DiskBlock.java @@ -7,4 +7,27 @@ public class DiskBlock implements Serializable { private int nextDiskNum; //用于记录文件的下一个磁盘块 (若为0,表示该磁盘块空闲,-1表示文件内容结束,254表示磁盘损坏,不能使用) private String type; //存储的类型(文件,文件夹,系统文件,空); + public int getNumber() { + return number; + } + + public void setNumber(int number) { + this.number = number; + } + + public int getNextDiskNum() { + return nextDiskNum; + } + + public void setNextDiskNum(int nextDiskNum) { + this.nextDiskNum = nextDiskNum; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } } diff --git a/main/src/Data/FAT.java b/main/src/Data/FAT.java index 3981d5793f90740baf8f3a13c0e023509db30ae6..8f1685a69d146cb2398246b9c1078d6c3e23d1b0 100644 --- a/main/src/Data/FAT.java +++ b/main/src/Data/FAT.java @@ -8,4 +8,36 @@ public class FAT { private File root; private Path rootPath; private List paths;//存储所有的path + + public DiskBlock[] getDiskBlocks() { + return diskBlocks; + } + + public void setDiskBlocks(DiskBlock[] diskBlocks) { + this.diskBlocks = diskBlocks; + } + + public File getRoot() { + return root; + } + + public void setRoot(File root) { + this.root = root; + } + + public Path getRootPath() { + return rootPath; + } + + public void setRootPath(Path rootPath) { + this.rootPath = rootPath; + } + + public List getPaths() { + return paths; + } + + public void setPaths(List paths) { + this.paths = paths; + } } diff --git a/main/src/Data/File.java b/main/src/Data/File.java index 70ade5e0af6b8e347d02a5ebe060c60e053ee7c2..5e1ec8acf4c0cacc49a21e782ca13c54075b75b0 100644 --- a/main/src/Data/File.java +++ b/main/src/Data/File.java @@ -1,6 +1,7 @@ package Data; import java.io.Serializable; +import java.util.ArrayList; import java.util.List; public class File implements Serializable { @@ -21,4 +22,130 @@ public class File implements Serializable { private String content;//文件内容; List childrenFile;//子文件或子目录 + public File(boolean isReadOnly, boolean isSystemFile, boolean isNormalFile, boolean isFolder, String absolutePath, String fileName, File parent,Path path) { + this.isReadOnly = isReadOnly; + this.isSystemFile = isSystemFile; + this.isNormalFile = isNormalFile; + this.isFolder = isFolder; + this.absolutePath = absolutePath; + this.fileName = fileName; + this.parent = parent; + isOpen = false; + this.path = path; + if(isFolder == true){ + childrenFile = new ArrayList<>(); + } + } + + public boolean isReadOnly() { + return isReadOnly; + } + + public void setReadOnly(boolean readOnly) { + isReadOnly = readOnly; + } + + public boolean isSystemFile() { + return isSystemFile; + } + + public void setSystemFile(boolean systemFile) { + isSystemFile = systemFile; + } + + public boolean isNormalFile() { + return isNormalFile; + } + + public void setNormalFile(boolean normalFile) { + isNormalFile = normalFile; + } + + public boolean isFolder() { + return isFolder; + } + + public void setFolder(boolean folder) { + isFolder = folder; + } + + public String getAbsolutePath() { + return absolutePath; + } + + public void setAbsolutePath(String absolutePath) { + this.absolutePath = absolutePath; + } + + public String getFileName() { + return fileName; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + public int getDiskStartNum() { + return diskStartNum; + } + + public void setDiskStartNum(int diskStartNum) { + this.diskStartNum = diskStartNum; + } + + public File getParent() { + return parent; + } + + public void setParent(File parent) { + this.parent = parent; + } + + public int getLength() { + return length; + } + + public void setLength(int length) { + this.length = length; + } + + public boolean isOpen() { + return isOpen; + } + + public void setOpen(boolean open) { + isOpen = open; + } + + public int getSize() { + return size; + } + + public void setSize(int size) { + this.size = size; + } + + public Path getPath() { + return path; + } + + public void setPath(Path path) { + this.path = path; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public List getChildrenFile() { + return childrenFile; + } + + public void setChildrenFile(List childrenFile) { + this.childrenFile = childrenFile; + } } diff --git a/main/src/Data/Path.java b/main/src/Data/Path.java index fefa651fac112bcaa0fa49cade5b615b5d23f3c2..490724b161f65eb36085ca0fc6bb578699053c74 100644 --- a/main/src/Data/Path.java +++ b/main/src/Data/Path.java @@ -1,5 +1,6 @@ package Data; +import java.util.ArrayList; import java.util.List; public class Path { @@ -8,4 +9,33 @@ public class Path { 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/MainController.java b/main/src/controller/MainController.java index d639c1c93b47fac3eab99b6de623c26648122812..fba868f093daf5385188b51f29e151f442af21d1 100644 --- a/main/src/controller/MainController.java +++ b/main/src/controller/MainController.java @@ -1,21 +1,32 @@ package controller; +import Data.File; +import Data.Path; import javafx.animation.KeyFrame; import javafx.animation.Timeline; import javafx.fxml.FXML; +import javafx.geometry.*; import javafx.scene.chart.PieChart; -import javafx.scene.control.Label; -import javafx.scene.control.TableColumn; -import javafx.scene.control.TableView; -import javafx.scene.control.TextField; -import javafx.scene.control.TreeView; +import javafx.scene.control.*; +import javafx.scene.image.Image; import javafx.scene.image.ImageView; + +import javafx.scene.input.MouseButton; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.FlowPane; +import javafx.scene.text.Font; import javafx.util.Duration; +import javafx.event.ActionEvent; +import javafx.event.EventHandler; +import javafx.scene.input.MouseEvent; + import java.io.IOException; import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.Vector; +import util.*; public class MainController { @@ -79,10 +90,59 @@ public class MainController { @FXML private ImageView upBtn; + // 创建文件 + private MenuItem createFileItem; + // 创建文件夹 + private MenuItem createFolderItem; + // 打开文件 + private MenuItem openItem; + // 重命名文件 + private MenuItem renameItem; + // 删除文件 + private MenuItem deleteItem; + // 显示文件属性 + // private MenuItem propItem; + // 更改文件属性 + private MenuItem changItem; + private File rootFile; + private File currentFile; + Path rootPath; + Path currentPath; + + Map icons = new HashMap<>(); + + + private ContextMenu createContextMenu; + private ContextMenu actionContextMenu; + @FXML void initialize() throws IOException { //项目初始化 timeInit(); + + rootPath = new Path("c:",null); + currentPath = rootPath; + contextMenuInit(); + menuItemAction(); + rootFile = new File(false,true,false,true,"c:","c:",null,rootPath); + currentFile = rootFile; + fileExplorer.setAlignment(Pos.TOP_LEFT); + fileExplorer.setHgap(15); + fileExplorer.setVgap(20); + fileExplorer.setPadding(new Insets(0,10,0,10)); + } + + private void contextMenuInit() { + createFileItem = new MenuItem("新建文件"); + createFolderItem = new MenuItem("新建文件夹"); + + openItem = new MenuItem("打开"); + deleteItem = new MenuItem("删除"); + renameItem = new MenuItem("重命名"); + changItem = new MenuItem("切换文件读写属性"); + + createContextMenu = new ContextMenu(createFileItem, createFolderItem); + actionContextMenu = new ContextMenu(openItem, deleteItem, renameItem, changItem); } public void timeInit() { @@ -105,4 +165,101 @@ public class MainController { this.data.setText("20" + year + "/" + month + "/" + day); } + + @FXML + public void clickFileExplorer(MouseEvent mouseEvent) { + fileExplorer.addEventHandler(MouseEvent.MOUSE_CLICKED,(MouseEvent click) -> { + if(click.getButton() == MouseButton.SECONDARY){ + createContextMenu.show(fileExplorer,click.getScreenX(),click.getScreenY()); + }else { + createContextMenu.hide(); + } + }); + } + + public void menuItemAction(){ + createFileItem.setOnAction(ActionEvent -> { + createFile(); + }); + + createFolderItem.setOnAction(ActionEvent -> { + createFolder(); + }); + } + + + + public void createFile(){ + String rdStr = RandomStr.getRandomString(5); + Path newPath = new Path(currentPath.getPathName()+"新建文件"+rdStr,currentPath); + File file = new File(true,false,true,false,currentPath.getPathName()+"\\新建文件"+rdStr,"新建文件"+rdStr,rootFile,newPath); + System.out.println("创建文件"); + Label icon = new Label(file.getFileName(),new ImageView("icon/文本文件.png")); + icon.setContentDisplay(ContentDisplay.TOP); + icon.setWrapText(false); + icon.setPrefWidth(100); + icon.setAlignment(Pos.CENTER); + icons.put(file.getAbsolutePath(),icon); + Vector folders = new Vector<>(); + Vector files = new Vector<>(); + + for(File file1 : currentFile.getChildrenFile()){ + if(file1.isFolder()){ + folders.add(file1.getAbsolutePath()); + fileExplorer.getChildren().remove(icons.get(file1.getAbsolutePath())); + }else { + files.add(file1.getAbsolutePath()); + fileExplorer.getChildren().remove(icons.get(file1.getAbsolutePath())); + } + } + + for(String folder1 : folders){ + fileExplorer.getChildren().add(icons.get(folder1)); + } + for(String file1 : files){ + fileExplorer.getChildren().add(icons.get(file1)); + } + fileExplorer.getChildren().add(icon); + + currentFile.getChildrenFile().add(file); + currentFile.getPath().getChildren().add(newPath); + } + + public void createFolder(){ + String rdStr = RandomStr.getRandomString(5); + Path newPath = new Path(currentPath.getPathName()+"新建文件夹" + rdStr,currentPath); + File file = new File(false,false,true,true,currentPath.getPathName()+"\\新建文件夹"+rdStr,"新建文件夹"+rdStr,rootFile,newPath); + System.out.println("创建文件夹"); + Label icon = new Label(file.getFileName(),new ImageView("icon/文件夹.png")); + icon.setContentDisplay(ContentDisplay.TOP); + icon.setWrapText(false); + icon.setPrefWidth(100); + icon.setAlignment(Pos.CENTER); + icons.put(file.getAbsolutePath(), icon); + Vector folders = new Vector<>(); + Vector files = new Vector<>(); + for(File file1 : currentFile.getChildrenFile()){ + if(file1.isFolder()){ + folders.add(file1.getAbsolutePath()); + fileExplorer.getChildren().remove(icons.get(file1.getAbsolutePath())); + }else { + files.add(file1.getAbsolutePath()); + fileExplorer.getChildren().remove(icons.get(file1.getAbsolutePath())); + } + } + + for(String folder1 : folders){ + if(folder1 != null) { + fileExplorer.getChildren().add(icons.get(folder1)); + } + } + fileExplorer.getChildren().add(icon); + for(String file1 : files){ + if(file1 !=null) { + fileExplorer.getChildren().add(icons.get(file1)); + } + } + currentFile.getChildrenFile().add(file); + currentFile.getPath().getChildren().add(newPath); + } } diff --git a/main/src/util/RandomStr.java b/main/src/util/RandomStr.java new file mode 100644 index 0000000000000000000000000000000000000000..a3653c0fbdcf8e4e945b4cde4f94d5d8a6161516 --- /dev/null +++ b/main/src/util/RandomStr.java @@ -0,0 +1,16 @@ +package util; + +import java.util.Random; + +public class RandomStr { + public static String getRandomString(int length){ + String str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + Random random=new Random(); + StringBuffer sb=new StringBuffer(); + for(int i=0;i