From 614e82bc595b63b4ef546bc2ccf6524b255a158c Mon Sep 17 00:00:00 2001 From: Vance Date: Fri, 5 Dec 2025 00:47:33 -0800 Subject: [PATCH 1/3] added a columon for date modified and Size of the file --- src/FileManagementUI.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/FileManagementUI.java b/src/FileManagementUI.java index f1700a0..9d7eaed 100644 --- a/src/FileManagementUI.java +++ b/src/FileManagementUI.java @@ -122,7 +122,6 @@ private void writeFile() { File file = fileSystem.searchFile(selected); if (file == null) return; - String content = JOptionPane.showInputDialog(this, "Content:", file.getContent()); if (content != null) { fileSystem.writeToFile(selected, content); From cbc79214e64a8cf8297bc20e31a38b2793d3bc60 Mon Sep 17 00:00:00 2001 From: Vance Date: Fri, 5 Dec 2025 00:47:40 -0800 Subject: [PATCH 2/3] Added 2 columns for date and size --- src/File.java | 12 +++++++-- src/FileManagementUI.java | 51 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 57 insertions(+), 6 deletions(-) diff --git a/src/File.java b/src/File.java index d128c11..0807d7b 100644 --- a/src/File.java +++ b/src/File.java @@ -1,11 +1,13 @@ import java.util.ArrayList; import java.util.Date; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; public class File { private String name; private String content; private double size; - private Date creationDate; + private LocalDateTime creationDate; private Date modificationDate; private ArrayList storedBlocks; @@ -13,11 +15,17 @@ public File(String name) { this.name = name; this.content = ""; this.size = 0; - this.creationDate = new Date(); + this.creationDate = LocalDateTime.now(); this.modificationDate = new Date(); this.storedBlocks = new ArrayList<>(); } + public String getcreateDate() { + return creationDate.format(DateTimeFormatter.ofPattern("MM-dd-yyyy HH:mm:ss")); + } + public String getmodDate() { + return modificationDate.toString(); + } public String getName() { return name; } diff --git a/src/FileManagementUI.java b/src/FileManagementUI.java index 9d7eaed..5cf559a 100644 --- a/src/FileManagementUI.java +++ b/src/FileManagementUI.java @@ -6,6 +6,10 @@ public class FileManagementUI extends JFrame { private FileSystem fileSystem; private DefaultListModel fileListModel; private JList fileList; + private DefaultListModel fileDateModel; + private JList fileDateList; + private DefaultListModel fileSizeModel; + private JList fileSizeList; private DefaultListModel openFilesModel; private JList openFilesList; @@ -13,7 +17,7 @@ public FileManagementUI() { fileSystem = new FileSystem(); setTitle("File Management System"); - setSize(700, 500); + setSize(1000, 500); setDefaultCloseOperation(EXIT_ON_CLOSE); setLayout(new BorderLayout(10, 10)); @@ -31,11 +35,31 @@ public FileManagementUI() { JPanel leftPanel = new JPanel(new BorderLayout(5, 5)); leftPanel.setBorder(BorderFactory.createTitledBorder("All Files")); + //JPanel midPanel = new JPanel(new BorderLayout(5, 5)); + JPanel midPanel = new JPanel(new GridLayout(1,2)); + // midPanel.setBorder(BorderFactory.createTitledBorder("Creation Date")); + fileDateModel = new DefaultListModel<>(); + fileDateList = new JList<>(fileDateModel); + fileDateList.setFont(new Font("Monospaced", Font.PLAIN, 14)); + JScrollPane dateScroll = new JScrollPane(fileDateList); + fileSizeModel = new DefaultListModel<>(); + fileSizeList = new JList<>(fileSizeModel); + fileSizeList.setFont(new Font("Monospaced", Font.PLAIN, 14)); + JScrollPane sizeScroll = new JScrollPane(fileSizeList); + dateScroll.setBorder(BorderFactory.createTitledBorder("Date Modified")); + sizeScroll.setBorder(BorderFactory.createTitledBorder("Size")); + midPanel.add(dateScroll); + midPanel.add(sizeScroll); + //JPanel fakepanel = new JPanel(new GridLayout(2, 2, 5, 60)); + //midPanel.add(fakepanel,BorderLayout.SOUTH); + + fileListModel = new DefaultListModel<>(); fileList = new JList<>(fileListModel); fileList.setFont(new Font("Monospaced", Font.PLAIN, 14)); JScrollPane fileScroll = new JScrollPane(fileList); leftPanel.add(fileScroll, BorderLayout.CENTER); + JPanel leftButtonPanel = new JPanel(new GridLayout(2, 2, 5, 5)); @@ -78,6 +102,7 @@ public FileManagementUI() { rightPanel.add(rightButtonPanel, BorderLayout.SOUTH); centerPanel.add(leftPanel); + centerPanel.add(midPanel); centerPanel.add(rightPanel); add(centerPanel, BorderLayout.CENTER); @@ -113,15 +138,23 @@ private void openFile() { if (file != null) { fileSystem.openFile(file); refreshOpenFilesList(); + refreshFileList(); } } private void writeFile() { String selected = openFilesList.getSelectedValue(); - if (selected == null) return; - + if (selected == null){ + JOptionPane.showMessageDialog(this, + "Please select a file to write", + "No Selection", + JOptionPane.WARNING_MESSAGE); + return; + } File file = fileSystem.searchFile(selected); + if (file == null) return; + String content = JOptionPane.showInputDialog(this, "Content:", file.getContent()); if (content != null) { fileSystem.writeToFile(selected, content); @@ -140,8 +173,10 @@ private void closeFile() { File file = fileSystem.searchFile(selected); if (file != null) { - fileSystem.closeFile(file); + refreshOpenFilesList(); + refreshFileList(); + fileSystem.closeFile(file); } } @@ -191,17 +226,25 @@ private void searchFile() { private void refreshFileList() { fileListModel.clear(); + fileDateModel.clear(); + fileSizeModel.clear(); ArrayList files = fileSystem.getFiles(); for (File file : files) { fileListModel.addElement(file.getName()); + fileDateModel.addElement(file.getcreateDate()); + fileSizeModel.addElement(String.valueOf(file.getSize())); } } private void refreshOpenFilesList() { openFilesModel.clear(); + fileDateModel.clear(); + fileSizeModel.clear(); ArrayList openFiles = fileSystem.getOpenFiles(); for (File file : openFiles) { openFilesModel.addElement(file.getName()); + fileDateModel.addElement(file.getcreateDate()); + fileSizeModel.addElement(String.valueOf(file.getSize())); } } From 0c807c2e9a254bad738629018e0e655762e55111 Mon Sep 17 00:00:00 2001 From: Vance Date: Sun, 7 Dec 2025 22:32:27 -0800 Subject: [PATCH 3/3] added some more comments --- src/File.java | 2 +- src/FileManagementUI.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/File.java b/src/File.java index 0807d7b..2b82af0 100644 --- a/src/File.java +++ b/src/File.java @@ -20,7 +20,7 @@ public File(String name) { this.storedBlocks = new ArrayList<>(); } - public String getcreateDate() { + public String getcreateDate() {//changed the data to datetimeformatter to sim dates on windows return creationDate.format(DateTimeFormatter.ofPattern("MM-dd-yyyy HH:mm:ss")); } public String getmodDate() { diff --git a/src/FileManagementUI.java b/src/FileManagementUI.java index 5cf559a..fe63910 100644 --- a/src/FileManagementUI.java +++ b/src/FileManagementUI.java @@ -36,7 +36,7 @@ public FileManagementUI() { leftPanel.setBorder(BorderFactory.createTitledBorder("All Files")); //JPanel midPanel = new JPanel(new BorderLayout(5, 5)); - JPanel midPanel = new JPanel(new GridLayout(1,2)); + JPanel midPanel = new JPanel(new GridLayout(1,2));//used a gird for put two scroll panes // midPanel.setBorder(BorderFactory.createTitledBorder("Creation Date")); fileDateModel = new DefaultListModel<>(); fileDateList = new JList<>(fileDateModel);