better memory
This commit is contained in:
parent
4e1b4feac7
commit
24798ae9eb
@ -27,6 +27,7 @@ import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Locale;
|
||||
@ -41,6 +42,8 @@ import java.nio.file.attribute.DosFileAttributes;
|
||||
* Single tab in a panel - displays the contents of one directory
|
||||
*/
|
||||
public class FilePanelTab extends JPanel {
|
||||
private static final int MAX_ICON_CACHE_ENTRIES =
|
||||
Integer.getInteger("kfmanager.iconCache.maxEntries", 128);
|
||||
|
||||
private File currentDirectory;
|
||||
private JTable fileTable;
|
||||
@ -1348,6 +1351,7 @@ public class FilePanelTab extends JPanel {
|
||||
briefCurrentColumn = 0;
|
||||
lastValidRow = 0;
|
||||
lastValidBriefColumn = 0;
|
||||
iconCache.clear();
|
||||
}
|
||||
|
||||
List<FileItem> items = (preloadedItems != null) ? preloadedItems : createFileItemList(directory);
|
||||
@ -3141,7 +3145,12 @@ public class FilePanelTab extends JPanel {
|
||||
fileTable.getColumnModel().getColumn(i).setCellRenderer(renderer);
|
||||
}
|
||||
}
|
||||
private final java.util.Map<String, Icon> iconCache = new java.util.HashMap<>();
|
||||
private final Map<String, Icon> iconCache = new LinkedHashMap<>(128, 0.75f, true) {
|
||||
@Override
|
||||
protected boolean removeEldestEntry(Map.Entry<String, Icon> eldest) {
|
||||
return size() > MAX_ICON_CACHE_ENTRIES;
|
||||
}
|
||||
};
|
||||
private final FileSystemView fileSystemView = FileSystemView.getFileSystemView();
|
||||
|
||||
private Icon getItemIcon(FileItem item) {
|
||||
@ -3159,7 +3168,7 @@ public class FilePanelTab extends JPanel {
|
||||
FileSpecificIcon.Type fileType = FileSpecificIcon.getFileType(name);
|
||||
if (isExecutableWithEmbeddedIcon(item, fileType)) {
|
||||
File file = item.getFile();
|
||||
key = "FILE_EMBEDDED_" + file.getAbsolutePath() + "_" + file.lastModified();
|
||||
key = "FILE_EMBEDDED_" + file.getAbsolutePath();
|
||||
} else {
|
||||
key = "FILE_" + fileType;
|
||||
}
|
||||
@ -3217,16 +3226,20 @@ public class FilePanelTab extends JPanel {
|
||||
return icon;
|
||||
}
|
||||
|
||||
BufferedImage image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
|
||||
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D g2 = image.createGraphics();
|
||||
try {
|
||||
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
||||
g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
||||
g2.scale(
|
||||
(double) width / Math.max(1, icon.getIconWidth()),
|
||||
(double) height / Math.max(1, icon.getIconHeight())
|
||||
);
|
||||
icon.paintIcon(null, g2, 0, 0);
|
||||
} finally {
|
||||
g2.dispose();
|
||||
}
|
||||
Image scaled = image.getScaledInstance(width, height, Image.SCALE_SMOOTH);
|
||||
return new ImageIcon(scaled);
|
||||
return new ImageIcon(image);
|
||||
}
|
||||
|
||||
private int calculateCurrentColumnWidth() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user