performance improvements
This commit is contained in:
parent
07a315ee1b
commit
d00d5222c5
@ -16,7 +16,6 @@ public class FileItem {
|
||||
private final long size;
|
||||
private final Date modified;
|
||||
private final boolean isDirectory;
|
||||
private final Icon icon;
|
||||
private boolean marked;
|
||||
private boolean recentlyChanged;
|
||||
private String displayPath;
|
||||
@ -33,9 +32,6 @@ public class FileItem {
|
||||
this.isDirectory = file.isDirectory();
|
||||
this.marked = false;
|
||||
this.displayPath = displayPath;
|
||||
|
||||
// Load icon from system
|
||||
this.icon = FileSystemView.getFileSystemView().getSystemIcon(file);
|
||||
}
|
||||
|
||||
public File getFile() {
|
||||
@ -83,10 +79,6 @@ public class FileItem {
|
||||
(modified != null ? modified.getTime() == other.modified.getTime() : other.modified == null);
|
||||
}
|
||||
|
||||
public Icon getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return displayPath != null ? displayPath : file.getAbsolutePath();
|
||||
}
|
||||
|
||||
@ -1045,10 +1045,14 @@ public class FilePanelTab extends JPanel {
|
||||
}
|
||||
|
||||
public void loadDirectory(File directory, boolean autoSelectFirst, boolean requestFocus) {
|
||||
loadDirectory(directory, autoSelectFirst, requestFocus, null);
|
||||
loadDirectory(directory, null, autoSelectFirst, requestFocus, null);
|
||||
}
|
||||
|
||||
public void loadDirectory(File directory, boolean autoSelectFirst, boolean requestFocus, final Runnable postLoadAction) {
|
||||
loadDirectory(directory, null, autoSelectFirst, requestFocus, postLoadAction);
|
||||
}
|
||||
|
||||
public void loadDirectory(File directory, List<FileItem> preloadedItems, boolean autoSelectFirst, boolean requestFocus, final Runnable postLoadAction) {
|
||||
// Ensure we load an existing directory - try parents if necessary
|
||||
File dirToLoad = directory;
|
||||
while (dirToLoad != null && !dirToLoad.isDirectory()) {
|
||||
@ -1079,7 +1083,7 @@ public class FilePanelTab extends JPanel {
|
||||
lastValidBriefColumn = 0;
|
||||
}
|
||||
|
||||
List<FileItem> items = createFileItemList(directory);
|
||||
List<FileItem> items = (preloadedItems != null) ? preloadedItems : createFileItemList(directory);
|
||||
tableModel.setItems(items);
|
||||
|
||||
if (viewMode == ViewMode.BRIEF) {
|
||||
@ -1191,7 +1195,8 @@ public class FilePanelTab extends JPanel {
|
||||
}
|
||||
}
|
||||
|
||||
loadDirectory(currentDirectory, false, requestFocus, () -> {
|
||||
final List<FileItem> itemsToLoad = newItems;
|
||||
loadDirectory(currentDirectory, itemsToLoad, false, requestFocus, () -> {
|
||||
// Restore marks and set recentlyChanged flag based on active timestamps
|
||||
for (FileItem item : tableModel.items) {
|
||||
if (markedNames.contains(item.getName())) {
|
||||
@ -2642,17 +2647,7 @@ public class FilePanelTab extends JPanel {
|
||||
}
|
||||
|
||||
// Show icon for file names
|
||||
Icon icon = item.getIcon();
|
||||
if (item.getName().equals("..")) {
|
||||
icon = new UpArrowIcon(getForeground());
|
||||
} else if (item.isDirectory()) {
|
||||
if (persistedConfig != null) {
|
||||
icon = new ColoredFolderIcon(persistedConfig.getFolderColor());
|
||||
}
|
||||
} else {
|
||||
// Use type-specific icon for files
|
||||
icon = new FileSpecificIcon(FileSpecificIcon.getFileType(item.getName()));
|
||||
}
|
||||
Icon icon = getItemIcon(item);
|
||||
|
||||
if (viewMode == ViewMode.BRIEF) {
|
||||
// In BRIEF mode all columns are names
|
||||
@ -2676,7 +2671,38 @@ public class FilePanelTab extends JPanel {
|
||||
fileTable.getColumnModel().getColumn(i).setCellRenderer(renderer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private final java.util.Map<String, Icon> iconCache = new java.util.HashMap<>();
|
||||
|
||||
private Icon getItemIcon(FileItem item) {
|
||||
if (item == null) return null;
|
||||
String name = item.getName();
|
||||
if (name.equals("..")) {
|
||||
return new UpArrowIcon(getForeground());
|
||||
}
|
||||
|
||||
String key;
|
||||
if (item.isDirectory()) {
|
||||
Color folderColor = (persistedConfig != null) ? persistedConfig.getFolderColor() : new Color(255, 203, 111);
|
||||
key = "DIR_" + folderColor.getRGB();
|
||||
} else {
|
||||
key = "FILE_" + FileSpecificIcon.getFileType(name);
|
||||
}
|
||||
|
||||
Icon cached = iconCache.get(key);
|
||||
if (cached != null) return cached;
|
||||
|
||||
Icon icon;
|
||||
if (item.isDirectory()) {
|
||||
Color folderColor = (persistedConfig != null) ? persistedConfig.getFolderColor() : new Color(255, 203, 111);
|
||||
icon = new ColoredFolderIcon(folderColor);
|
||||
} else {
|
||||
icon = new FileSpecificIcon(FileSpecificIcon.getFileType(name));
|
||||
}
|
||||
iconCache.put(key, icon);
|
||||
return icon;
|
||||
}
|
||||
|
||||
private void updateColumnWidths() {
|
||||
if (viewMode == ViewMode.FULL) {
|
||||
if (fileTable.getColumnModel().getColumnCount() == 3) {
|
||||
@ -2728,7 +2754,7 @@ public class FilePanelTab extends JPanel {
|
||||
int w = fm.stringWidth(display);
|
||||
if (w > maxTextWidth) maxTextWidth = w;
|
||||
|
||||
Icon icon = item.getIcon();
|
||||
Icon icon = getItemIcon(item);
|
||||
if (icon != null) {
|
||||
int iw = icon.getIconWidth();
|
||||
if (iw > maxIconWidth) maxIconWidth = iw;
|
||||
@ -3058,6 +3084,7 @@ public class FilePanelTab extends JPanel {
|
||||
*/
|
||||
public void setAppConfig(cz.kamma.kfmanager.config.AppConfig cfg) {
|
||||
this.persistedConfig = cfg;
|
||||
iconCache.clear();
|
||||
// Apply persisted sort if present
|
||||
if (cfg != null) {
|
||||
java.util.List<String> multi = cfg.getMultipleSortCriteria();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user