diff --git a/TODO.txt b/TODO.txt index 7862dcf..83241ab 100644 --- a/TODO.txt +++ b/TODO.txt @@ -210,5 +210,6 @@ test.auth.xxx=ucd 【待实现】完善移动“m”权限的安全性:当仅有“m”权限时,用户可执行“复制”操作;若同时具备删除“d”权限,才可以进行“剪切”操作。 注:这是为了防止使用者先将某个文件从一个原本不具备删除权限的文件夹内移动的一个具备删除权限的文件夹内再将其删除的恶意操作。 【已完成】新增文件夹体积计算功能:当访问者打开文件夹的“详细信息...”模态框时,系统将实时统计该文件夹的内容总体积,之后将结果显示在该界面上供用户查看。 +【已完成】进一步优化了“文件”功能:在图形界面下,可以通过点击表头对文件列表进行排序;此外还修复了几处执行文件导入导出操作时可能导致死锁的问题。 【待实现】新增导入账户设置:当执行“导入”操作时,可以使用指定账户来为它们设置“创建者”。 【待实现】优化剪切复制操作:如果执行粘贴时已剪切或复制的文件不再存在,那么在提示后自动清除剪切或复制的文件记录,将剪切或复制显示恢复到初始状态。 \ No newline at end of file diff --git a/src/main/java/kohgylw/kiftd/ui/util/FilesTable.java b/src/main/java/kohgylw/kiftd/ui/util/FilesTable.java index a3cc548..1e0d235 100644 --- a/src/main/java/kohgylw/kiftd/ui/util/FilesTable.java +++ b/src/main/java/kohgylw/kiftd/ui/util/FilesTable.java @@ -2,11 +2,15 @@ package kohgylw.kiftd.ui.util; import java.awt.Color; import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.List; import javax.swing.JTable; import javax.swing.SwingUtilities; import javax.swing.event.TableModelListener; import javax.swing.table.DefaultTableCellRenderer; +import javax.swing.table.JTableHeader; import javax.swing.table.TableModel; import kohgylw.kiftd.printer.Printer; @@ -28,13 +32,118 @@ public class FilesTable extends JTable { private static final String[] columns = new String[] { "名称", "创建日期", "大小", "创建者" }; private static List folders;// 当前显示的文件夹列表 + private static List files;// 当前显示的文件列表 public static final int MAX_LIST_LIMIT = Integer.MAX_VALUE; + private int sortByName = 1;// 名称排序顺序,默认从小到大 + private int sortByDate = 1;// 创建日期排序顺序,默认从小到大 + private static SimpleDateFormat cdf = new SimpleDateFormat("yyyy年MM月dd日");// 创建日期辅助转换对象 + private int sortBySize = 1;// 按大小排序,默认从小到大 + private int sortByCreator = 1;// 按创建者排序,默认从小到大 + /** */ private static final long serialVersionUID = -3436472714356711024L; public FilesTable() { super(new Object[][] {}, columns); + // 设置点击某一列标题时自动根据此列进行排序 + JTableHeader filesTableHeader = getTableHeader(); + filesTableHeader.addMouseListener(new MouseListener() { + + @Override + public void mouseReleased(MouseEvent e) { + + } + + @Override + public void mousePressed(MouseEvent e) { + + } + + @Override + public void mouseExited(MouseEvent e) { + + } + + @Override + public void mouseEntered(MouseEvent e) { + + } + + @Override + public void mouseClicked(MouseEvent e) { + int col = filesTableHeader.columnAtPoint(e.getPoint()); + switch (col) { + case 0: + // 按名称排序 + files.sort((e1, e2) -> { + return sortByName * e1.getFileName().compareTo(e2.getFileName()); + }); + folders.sort((e1, e2) -> { + return sortByName * e1.getFolderName().compareTo(e2.getFolderName()); + }); + sortByName = sortByName * -1; + sortByDate = 1; + sortBySize = 1; + sortByCreator = 1; + break; + case 1: + // 按创建日期排序 + files.sort((e1, e2) -> { + try { + return sortByDate * cdf.parse(e1.getFileCreationDate()) + .compareTo(cdf.parse(e2.getFileCreationDate())); + } catch (ParseException e3) { + Printer.instance.print(e3.toString()); + return 0; + } + }); + folders.sort((e1, e2) -> { + try { + return sortByDate * cdf.parse(e1.getFolderCreationDate()) + .compareTo(cdf.parse(e2.getFolderCreationDate())); + } catch (ParseException e3) { + Printer.instance.print(e3.toString()); + return 0; + } + }); + sortByDate = sortByDate * -1; + sortByName = 1; + sortBySize = 1; + sortByCreator = 1; + break; + case 2: + // 按大小排序 + files.sort((e1, e2) -> { + return sortBySize + * Long.compare(Long.parseLong(e1.getFileSize()), Long.parseLong(e2.getFileSize())); + }); + sortBySize = sortBySize * -1; + sortByName = 1; + sortByDate = 1; + sortByCreator = 1; + break; + case 3: + // 按创建者排序 + files.sort((e1, e2) -> { + return sortByCreator * e1.getFileCreator().compareTo(e2.getFileCreator()); + }); + folders.sort((e1, e2) -> { + return sortByCreator * e1.getFolderCreator().compareTo(e2.getFolderCreator()); + }); + sortByCreator = sortByCreator * -1; + sortByName = 1; + sortByDate = 1; + sortBySize = 1; + break; + + default: + break; + } + // 排序完毕后更新列表显示 + updateValues(folders, files); + } + }); } @Override @@ -109,6 +218,7 @@ public class FilesTable extends JTable { setRowFontColor(); validate(); FilesTable.folders = folders; + FilesTable.files = files; } catch (Exception e) { Printer.instance.print(e.toString()); } diff --git a/src/main/java/kohgylw/kiftd/util/file_system_manager/pojo/Folder.java b/src/main/java/kohgylw/kiftd/util/file_system_manager/pojo/Folder.java index 90d006a..545e051 100644 --- a/src/main/java/kohgylw/kiftd/util/file_system_manager/pojo/Folder.java +++ b/src/main/java/kohgylw/kiftd/util/file_system_manager/pojo/Folder.java @@ -4,7 +4,6 @@ public class Folder extends kohgylw.kiftd.server.model.Folder{ @Override public String toString() { - // TODO 自动生成的方法存根 return getFolderName(); } diff --git a/target/classes/META-INF/maven/kohgylw/kiftd/pom.properties b/target/classes/META-INF/maven/kohgylw/kiftd/pom.properties index 8337368..4433fe8 100644 --- a/target/classes/META-INF/maven/kohgylw/kiftd/pom.properties +++ b/target/classes/META-INF/maven/kohgylw/kiftd/pom.properties @@ -1,5 +1,5 @@ #Generated by Maven Integration for Eclipse -#Tue Dec 26 13:31:45 CST 2023 +#Tue Dec 26 15:14:32 CST 2023 m2e.projectLocation=/Users/kohgylw/Programs/java_workspace/kiftd m2e.projectName=kiftd groupId=kohgylw diff --git a/target/classes/kohgylw/kiftd/ui/util/FilesTable$1.class b/target/classes/kohgylw/kiftd/ui/util/FilesTable$1.class index 339bbb8..789db45 100644 Binary files a/target/classes/kohgylw/kiftd/ui/util/FilesTable$1.class and b/target/classes/kohgylw/kiftd/ui/util/FilesTable$1.class differ diff --git a/target/classes/kohgylw/kiftd/ui/util/FilesTable$1$1.class b/target/classes/kohgylw/kiftd/ui/util/FilesTable$2$1.class similarity index 59% rename from target/classes/kohgylw/kiftd/ui/util/FilesTable$1$1.class rename to target/classes/kohgylw/kiftd/ui/util/FilesTable$2$1.class index 14fe7e0..bad6238 100644 Binary files a/target/classes/kohgylw/kiftd/ui/util/FilesTable$1$1.class and b/target/classes/kohgylw/kiftd/ui/util/FilesTable$2$1.class differ diff --git a/target/classes/kohgylw/kiftd/ui/util/FilesTable$2.class b/target/classes/kohgylw/kiftd/ui/util/FilesTable$2.class index fd16e29..db03e88 100644 Binary files a/target/classes/kohgylw/kiftd/ui/util/FilesTable$2.class and b/target/classes/kohgylw/kiftd/ui/util/FilesTable$2.class differ diff --git a/target/classes/kohgylw/kiftd/ui/util/FilesTable$3.class b/target/classes/kohgylw/kiftd/ui/util/FilesTable$3.class index 15eee12..a8ffea0 100644 Binary files a/target/classes/kohgylw/kiftd/ui/util/FilesTable$3.class and b/target/classes/kohgylw/kiftd/ui/util/FilesTable$3.class differ diff --git a/target/classes/kohgylw/kiftd/ui/util/FilesTable$4.class b/target/classes/kohgylw/kiftd/ui/util/FilesTable$4.class new file mode 100644 index 0000000..6529c8b Binary files /dev/null and b/target/classes/kohgylw/kiftd/ui/util/FilesTable$4.class differ diff --git a/target/classes/kohgylw/kiftd/ui/util/FilesTable.class b/target/classes/kohgylw/kiftd/ui/util/FilesTable.class index bfd0760..aab5683 100644 Binary files a/target/classes/kohgylw/kiftd/ui/util/FilesTable.class and b/target/classes/kohgylw/kiftd/ui/util/FilesTable.class differ diff --git a/target/classes/kohgylw/kiftd/util/file_system_manager/pojo/Folder.class b/target/classes/kohgylw/kiftd/util/file_system_manager/pojo/Folder.class index 0946cee..c884ab1 100644 Binary files a/target/classes/kohgylw/kiftd/util/file_system_manager/pojo/Folder.class and b/target/classes/kohgylw/kiftd/util/file_system_manager/pojo/Folder.class differ