From 4218ef7c954f7a02b120c5da978041e7b92c7ca2 Mon Sep 17 00:00:00 2001 From: AckerMen <835340812@qq.com> Date: Fri, 17 Nov 2023 17:19:58 +0800 Subject: [PATCH 1/2] =?UTF-8?q?flowPane=E5=89=8D=E7=AB=AF=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/resources/Main-view.fxml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/main/resources/Main-view.fxml b/main/resources/Main-view.fxml index 3711b66..c80068a 100644 --- a/main/resources/Main-view.fxml +++ b/main/resources/Main-view.fxml @@ -31,12 +31,13 @@
- + @@ -93,7 +93,18 @@ diff --git a/main/src/Data/File.java b/main/src/Data/File.java index 131e713..c723ce0 100644 --- a/main/src/Data/File.java +++ b/main/src/Data/File.java @@ -28,6 +28,7 @@ public class File implements Serializable { this.isFolder = isFolder; this.fileName = fileName; this.parent = parent; + this.content = ""; isOpen = false; if(isFolder == true){ childrenFile = new ArrayList<>(); @@ -107,7 +108,7 @@ public class File implements Serializable { } public int getSize() { - return size; + return content.length(); } public void setSize(int size) { @@ -137,4 +138,14 @@ public class File implements Serializable { public void setChildrenFile(List childrenFile) { this.childrenFile = childrenFile; } + + public String getTypeName() { + if(this.isFolder) { + if (this.isSystemFile) return "系统文件夹"; + else return "普通文件夹"; + }else{ + if (this.isSystemFile) return "系统文件"; + else return "普通文件"; + } + } } diff --git a/main/src/controller/MainController.java b/main/src/controller/MainController.java index 5cc6c22..77e1aa3 100644 --- a/main/src/controller/MainController.java +++ b/main/src/controller/MainController.java @@ -2,6 +2,7 @@ package controller; import Data.File; import Data.Path; +import com.sun.org.apache.xml.internal.resolver.CatalogEntry; import javafx.animation.KeyFrame; import javafx.animation.Timeline; import javafx.fxml.FXML; @@ -22,10 +23,7 @@ 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 java.util.*; import operations.createFileOperations; import operations.openOperations; @@ -33,6 +31,7 @@ import util.*; public class MainController { + @FXML private ImageView backBtn; @@ -75,9 +74,18 @@ public class MainController { @FXML private Label hours; + @FXML + private ImageView iconMes; + + @FXML + private Label memoryMes; + @FXML private Label nameLabel; + @FXML + private Label nameMes; + @FXML private TextField path; @@ -90,6 +98,12 @@ public class MainController { @FXML private Label sizeLabel; + @FXML + private Label timeMes; + + @FXML + private Label typeMes; + @FXML private ImageView upBtn; @@ -168,6 +182,32 @@ public class MainController { this.data.setText("20" + year + "/" + month + "/" + day); } + public void setFilePreview(File newFile,Label label){ + label.setOnMouseEntered(event1 -> { + iconMes.setVisible(true); + Image icon; + ((Label) event1.getSource()).setStyle("-fx-background-color: rgba(29,29,31,0.15);"); + nameMes.setText("文件名称:" + newFile.getFileName()); + if (newFile.getTypeName().equals("普通文件")||newFile.getTypeName().equals("系统文件")) { + typeMes.setText("文件类型:" + newFile.getTypeName()); + icon = new Image("icon/文本文件.png"); + } else { + typeMes.setText("文件类型:" + newFile.getTypeName()); + icon = new Image("icon/文件夹.png"); + } + iconMes.setImage(icon); + memoryMes.setText("占用空间:" + newFile.getSize()); +// timeMes.setText("建立时间:" + newFile.getTime()); + }); + label.setOnMouseExited(event12 -> { + ((Label) event12.getSource()).setStyle(null); + nameMes.setText(""); + typeMes.setText(""); + iconMes.setVisible(false); + memoryMes.setText(""); + timeMes.setText(""); + }); + } //FlowPane的鼠标点击事件 @FXML @@ -175,6 +215,7 @@ public class MainController { fileExplorer.addEventHandler(MouseEvent.MOUSE_CLICKED,(MouseEvent click) -> { if(click.getButton() == MouseButton.SECONDARY && !actionContextMenu.isShowing()){ //右键点击事件 createContextMenu.show(fileExplorer,click.getScreenX(),click.getScreenY()); + }else { createContextMenu.hide(); } @@ -183,12 +224,14 @@ public class MainController { public void menuItemAction(){ createFileItem.setOnAction(ActionEvent -> { - createFileOperations.createFile(fileExplorer,icons,actionContextMenu); + File file = createFileOperations.createFile(fileExplorer,icons,actionContextMenu); + setFilePreview(file,icons.get(file)); //createFile(); }); createFolderItem.setOnAction(ActionEvent -> { - createFileOperations.createFolder(fileExplorer,icons,actionContextMenu); + File folder = createFileOperations.createFolder(fileExplorer,icons,actionContextMenu); + setFilePreview(folder,icons.get(folder)); //createFolder(); }); } @@ -204,169 +247,4 @@ public class MainController { - //创建文件 -/* 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,currentFile,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,icon); - Vector folders = new Vector<>(); - Vector files = new Vector<>(); - - for(File file1 : currentFile.getChildrenFile()){ - if(file1.isFolder()){ - folders.add(file1); - fileExplorer.getChildren().remove(icons.get(file1)); - }else { - files.add(file1); - fileExplorer.getChildren().remove(icons.get(file1)); - } - } - - for(File folder1 : folders){ - fileExplorer.getChildren().add(icons.get(folder1)); - } - for(File file1 : files){ - fileExplorer.getChildren().add(icons.get(file1)); - } - fileExplorer.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(); - selectIcon = src; - if (event.getButton() == MouseButton.SECONDARY && event.getClickCount() == 1) { - 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("选择"); - } else { - actionContextMenu.hide(); - } - } - }); - - - } - - //创建文件夹 - 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,currentFile,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, icon); - Vector folders = new Vector<>(); - Vector files = new Vector<>(); - for(File file1 : currentFile.getChildrenFile()){ - if(file1.isFolder()){ - folders.add(file1); - fileExplorer.getChildren().remove(icons.get(file1)); - }else { - files.add(file1); - fileExplorer.getChildren().remove(icons.get(file1)); - } - } - - for(File folder1 : folders){ - if(folder1 != null) { - fileExplorer.getChildren().add(icons.get(folder1)); - } - } - fileExplorer.getChildren().add(icon); - for(File file1 : files){ - if(file1 !=null) { - fileExplorer.getChildren().add(icons.get(file1)); - } - } - 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(); - selectIcon = icon; - System.out.println(src); - if (event.getButton() == MouseButton.SECONDARY && event.getClickCount() == 1) { - openItem.setOnAction(ActionEvent -> { - currentFile = FindLabelToFile.findFile(icons, src); - if(currentFile != null) { - if (currentFile.isFolder()) { - System.out.println(1); - System.out.println(src); - openOperations.openFolder(fileExplorer, currentFile, icons); - } else { - openOperations.openFile(); - } - } - }); - actionContextMenu.show(src, event.getScreenX(), event.getScreenY()); - } else if (event.getButton() == MouseButton.PRIMARY && event.getClickCount() == 2) { - System.out.println("打开文件"); - currentFile = FindLabelToFile.findFile(icons, icon); - System.out.println(currentFile.getFileName()); - if (currentFile.isFolder()) { - openOperations.openFolder(fileExplorer, currentFile, icons); - } else { - openOperations.openFile(); - } - - } else if (event.getButton() == MouseButton.PRIMARY && event.getClickCount() == 1) { - System.out.println("选择"); - } else { - actionContextMenu.hide(); - } - } - }); - }*/ - } diff --git a/main/src/operations/createFileOperations.java b/main/src/operations/createFileOperations.java index 39fb350..c01087e 100644 --- a/main/src/operations/createFileOperations.java +++ b/main/src/operations/createFileOperations.java @@ -2,6 +2,7 @@ package operations; import Data.File; import Data.Path; +import controller.MainController; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Pos; @@ -24,7 +25,7 @@ import static controller.MainController.currentFile; import static controller.MainController.rootFile; public class createFileOperations { - public static void createFile(FlowPane flowPane, Map icons, ContextMenu actionContextMenu){ + 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); @@ -116,10 +117,10 @@ public class createFileOperations { } } }); - + return file; } - public static void createFolder(FlowPane flowPane, /*File currentFile,*/ Map icons, ContextMenu actionContextMenu){ + 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); @@ -215,6 +216,6 @@ public class createFileOperations { } } }); + return file; } - } -- Gitee