From 1ddb5b1d44c4edaf93fa2dfa3efdb35fbeac73a5 Mon Sep 17 00:00:00 2001
From: blastho <2904411786@qq.com>
Date: Fri, 17 Nov 2023 16:51:35 +0800
Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E6=96=B0?=
=?UTF-8?q?=E5=BB=BA=E6=96=87=E4=BB=B6=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.gitignore | 7 +
main/resources/Main-view.fxml | 9 +-
.../\346\226\207\344\273\266\345\244\271.png" | Bin 0 -> 957 bytes
...7\346\234\254\346\226\207\344\273\266.png" | Bin 0 -> 738 bytes
main/src/Data/DiskBlock.java | 23 +++
main/src/Data/FAT.java | 32 ++++
main/src/Data/File.java | 127 +++++++++++++
main/src/Data/Path.java | 30 ++++
main/src/controller/MainController.java | 167 +++++++++++++++++-
main/src/util/RandomStr.java | 16 ++
10 files changed, 398 insertions(+), 13 deletions(-)
create mode 100644 "main/resources/icon/\346\226\207\344\273\266\345\244\271.png"
create mode 100644 "main/resources/icon/\346\226\207\346\234\254\346\226\207\344\273\266.png"
create mode 100644 main/src/util/RandomStr.java
diff --git a/.gitignore b/.gitignore
index 76b719e..7fdbb4e 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 3711b66..de76537 100644
--- a/main/resources/Main-view.fxml
+++ b/main/resources/Main-view.fxml
@@ -34,14 +34,7 @@
-
-
-
-
-
-
-
-
+
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
GIT binary patch
literal 957
zcmV;u148_XP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D15!yuK~#8N?V8U|
z6HySyXSSuZYOsolG2Vz8Lreq;Qll6D2R--)_y@>Q59rB66EAx3;sHv8nlWq
zhlmZ2d<{fD?I_+@8pf=&1QJWE?l5xjkDC&_1~D16Y3deH!&%f$${BEFTJ;qpu*Mxf
zAx)ggv?I5^L4r8{jPlP#q}%f;>$SLnqukN48P%^WM}TA6*TKgM(4Wh5NIp5!OIV1(
zD+IhLO**qa?j&$%`4SeSB~W+@u#m!|dI+62_+)6B>qrE$oCG~i1Cf6IPG-z{>G%Po
zQUjVqHf=4ltd*2!C3t0+yu3(BX$cff&j8KnEDb26_f-Xz;Gw1HnRso*Yj4sL0W>4?
zYLaWg19A0KQ2c$*b=r>2S@=fTaL>umeY8vf-cTLqpjY|%@~U#!a7-I4#K>aG`YcV&
zuK^`E<$m#E_(RY*PZHe2Fn4RE%
zFan4TEuI3bTsv3+>?BMEhz%`90I{LP2p~4J7y-nF79)Vz(BdJ0{-Z|sQ|TzPcYX
z1;mCHBY@b@VgwKyT8sc$M;!)uRO2=nNf63t(K?2Y}(r7Xs5+>(GPaRwGSkiD+RBqssa4o2_E!yak~$q
z@3xH-;yF~QqZ!VqbEx16-;VRE&b;XY^oY+yZMe&szUnr))Cf>w@B``KyF!3MjP^=J
f&tNbZDggWe6f89`goWzm00000NkvXXu0mjfQJuRa
literal 0
HcmV?d00001
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
GIT binary patch
literal 738
zcmV<80v-K{P)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D0(VJ7K~#8N?bOu+gMo&BJRw}u)98LWeN)y`~CJ>0TP&*ldJw^S@qv7Q~CQ0EegF(_!gZnl%6fJSm56K)BTTNiWXtMMtD(Db@g7
z#5d*gEP$71r*urZN^4{Q3B(JB{?JZ;H##9br8GBy7~;n76&P;4qtdfevjbrKIBfp-
zMZ+_1%7xJQ0Ah%^wbG&I-H?t-S8lBcAi-k-uOEg*XNUF#5G%1xXjcHSg6o9#1;C1|
z6YP6|kheeu5z#K6_@k6__=FogaIH!?Z}DEB&wGK}Qs%}FVN}H<8AV@@G
zKJzCjD}jWoe9o?vx#?0^XMt=QfVAGy0HpPn1|Y4sGyrM6WetFUQorrxJfbghl*;}W
zK=6c56iL+_ydmM&%&*ABtb2j$M8StCZF2+zB%K<@UQfH`snkj-rRD+r1q-&)
U_}0TcDgXcg07*qoM6N<$f}o2_VgLXD
literal 0
HcmV?d00001
diff --git a/main/src/Data/DiskBlock.java b/main/src/Data/DiskBlock.java
index 4f37462..e7bdfa5 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 3981d57..8f1685a 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 70ade5e..5e1ec8a 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 fefa651..490724b 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 d639c1c..fba868f 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 0000000..a3653c0
--- /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
Date: Fri, 17 Nov 2023 17:45:56 +0800
Subject: [PATCH 2/2] =?UTF-8?q?Main-view=E4=BF=AE=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
main/resources/Main-view.fxml | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/main/resources/Main-view.fxml b/main/resources/Main-view.fxml
index de76537..5c51e3e 100644
--- a/main/resources/Main-view.fxml
+++ b/main/resources/Main-view.fxml
@@ -34,7 +34,16 @@
-
+
+
+
+
+
+
+
+
+
+
--
Gitee