change indicator

This commit is contained in:
Radek Davidek 2026-01-21 10:24:30 +01:00
parent 4d9774471c
commit 6ee3bc8201
2 changed files with 51 additions and 1 deletions

View File

@ -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) {
@ -102,6 +103,14 @@ public class FileItem {
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
*/

View File

@ -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<String> changedNames = new ArrayList<>();
Map<String, FileItem> 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));