From 6ee3bc8201bc6200b2777bd799eff3d37fad3b23 Mon Sep 17 00:00:00 2001 From: Radek Davidek Date: Wed, 21 Jan 2026 10:24:30 +0100 Subject: [PATCH] change indicator --- .../cz/kamma/kfmanager/model/FileItem.java | 9 ++++ .../cz/kamma/kfmanager/ui/FilePanelTab.java | 43 ++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/main/java/cz/kamma/kfmanager/model/FileItem.java b/src/main/java/cz/kamma/kfmanager/model/FileItem.java index a51025d..1de5794 100644 --- a/src/main/java/cz/kamma/kfmanager/model/FileItem.java +++ b/src/main/java/cz/kamma/kfmanager/model/FileItem.java @@ -18,6 +18,7 @@ public class FileItem { private final boolean isDirectory; private final Icon icon; private boolean marked; + private boolean recentlyChanged; private String displayPath; public FileItem(File file) { @@ -101,6 +102,14 @@ public class FileItem { public void toggleMarked() { this.marked = !this.marked; } + + public boolean isRecentlyChanged() { + return recentlyChanged; + } + + public void setRecentlyChanged(boolean recentlyChanged) { + this.recentlyChanged = recentlyChanged; + } /** * Format file size into a human-readable string diff --git a/src/main/java/cz/kamma/kfmanager/ui/FilePanelTab.java b/src/main/java/cz/kamma/kfmanager/ui/FilePanelTab.java index 0a5cad0..8ba63b9 100644 --- a/src/main/java/cz/kamma/kfmanager/ui/FilePanelTab.java +++ b/src/main/java/cz/kamma/kfmanager/ui/FilePanelTab.java @@ -19,7 +19,9 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import java.io.InputStream; @@ -967,6 +969,20 @@ public class FilePanelTab extends JPanel { return; } + // Identify which items are new or have changed metadata (size/date) + final List changedNames = new ArrayList<>(); + Map oldItemsMap = new HashMap<>(); + for (FileItem item : tableModel.items) { + oldItemsMap.put(item.getName(), item); + } + + for (FileItem newItem : newItems) { + FileItem oldItem = oldItemsMap.get(newItem.getName()); + if (oldItem == null || !newItem.isSameAs(oldItem)) { + changedNames.add(newItem.getName()); + } + } + FileItem focused = getFocusedItem(); final String focusedName = (focused != null) ? focused.getName() : null; @@ -978,11 +994,14 @@ public class FilePanelTab extends JPanel { } loadDirectory(currentDirectory, false, requestFocus, () -> { - // Restore marks + // Restore marks and set recentlyChanged flag for (FileItem item : tableModel.items) { if (markedNames.contains(item.getName())) { item.setMarked(true); } + if (changedNames.contains(item.getName())) { + item.setRecentlyChanged(true); + } } // Restore focus @@ -1006,6 +1025,24 @@ public class FilePanelTab extends JPanel { } } fileTable.repaint(); + + if (!changedNames.isEmpty()) { + // Clear the recentlyChanged flag after 2 seconds + javax.swing.Timer timer = new javax.swing.Timer(2000, e -> { + boolean found = false; + for (FileItem item : tableModel.items) { + if (item.isRecentlyChanged()) { + item.setRecentlyChanged(false); + found = true; + } + } + if (found) { + fileTable.repaint(); + } + }); + timer.setRepeats(false); + timer.start(); + } }); } @@ -2177,6 +2214,10 @@ public class FilePanelTab extends JPanel { int newStyle = baseStyle | Font.BOLD; setFont(baseFont.deriveFont(newStyle)); setForeground(markedColor); + } else if (item.isRecentlyChanged()) { + // Highlight recently changed items with bold and a different color + setFont(baseFont.deriveFont(baseStyle | Font.BOLD)); + setForeground(new Color(0, 128, 255)); // Bright blue } else { // Preserve whatever style the base font has (do not force plain) setFont(baseFont.deriveFont(baseStyle));