Resource List Icon Cache
This is still a work in progress and may cause bugs, specifically when you remove an imported resource without resetting the workspace
This commit is contained in:
parent
4d87d2ee99
commit
0bc6d4a01b
2 changed files with 25 additions and 7 deletions
|
@ -20,6 +20,7 @@ import the.bytecode.club.bytecodeviewer.bootloader.InstallFatJar;
|
||||||
import the.bytecode.club.bytecodeviewer.bootloader.UpdateCheck;
|
import the.bytecode.club.bytecodeviewer.bootloader.UpdateCheck;
|
||||||
import the.bytecode.club.bytecodeviewer.gui.MainViewerGUI;
|
import the.bytecode.club.bytecodeviewer.gui.MainViewerGUI;
|
||||||
import the.bytecode.club.bytecodeviewer.gui.components.*;
|
import the.bytecode.club.bytecodeviewer.gui.components.*;
|
||||||
|
import the.bytecode.club.bytecodeviewer.gui.resourcelist.ResourceListIconRenderer;
|
||||||
import the.bytecode.club.bytecodeviewer.gui.resourceviewer.TabbedPane;
|
import the.bytecode.club.bytecodeviewer.gui.resourceviewer.TabbedPane;
|
||||||
import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.ClassViewer;
|
import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.ClassViewer;
|
||||||
import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.ResourceViewer;
|
import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.ResourceViewer;
|
||||||
|
@ -83,7 +84,6 @@ import static the.bytecode.club.bytecodeviewer.Constants.*;
|
||||||
* + BCV's classLoader should be destroyed each time a resource is added or removed
|
* + BCV's classLoader should be destroyed each time a resource is added or removed
|
||||||
*
|
*
|
||||||
* TODO DarkLAF Specific Bugs:
|
* TODO DarkLAF Specific Bugs:
|
||||||
* + Resource List creates swing lag with large project
|
|
||||||
* + JMenuBar can only be displayed on a JFrame, a work around is needed for this (Partially solved)
|
* + JMenuBar can only be displayed on a JFrame, a work around is needed for this (Partially solved)
|
||||||
*
|
*
|
||||||
* TODO IN-PROGRESS:
|
* TODO IN-PROGRESS:
|
||||||
|
@ -709,6 +709,7 @@ public class BytecodeViewer
|
||||||
BytecodeViewer.viewer.workPane.resetWorkspace();
|
BytecodeViewer.viewer.workPane.resetWorkspace();
|
||||||
BytecodeViewer.viewer.searchBoxPane.resetWorkspace();
|
BytecodeViewer.viewer.searchBoxPane.resetWorkspace();
|
||||||
BCV.getClassNodeLoader().clear();
|
BCV.getClassNodeLoader().clear();
|
||||||
|
ResourceListIconRenderer.iconCache.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -9,6 +9,7 @@ import javax.swing.tree.DefaultTreeCellRenderer;
|
||||||
import javax.swing.tree.TreeNode;
|
import javax.swing.tree.TreeNode;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author http://stackoverflow.com/questions/14968005
|
* @author http://stackoverflow.com/questions/14968005
|
||||||
|
@ -17,6 +18,9 @@ import java.util.ArrayList;
|
||||||
|
|
||||||
public class ResourceListIconRenderer extends DefaultTreeCellRenderer
|
public class ResourceListIconRenderer extends DefaultTreeCellRenderer
|
||||||
{
|
{
|
||||||
|
//TODO the icon cache needs to be cleared on treenode removal
|
||||||
|
public static HashMap<ResourceTreeNode, ImageIcon> iconCache = new HashMap<>();
|
||||||
|
|
||||||
//called every time there is a pane update
|
//called every time there is a pane update
|
||||||
@Override
|
@Override
|
||||||
public Component getTreeCellRendererComponent(
|
public Component getTreeCellRendererComponent(
|
||||||
|
@ -28,7 +32,14 @@ public class ResourceListIconRenderer extends DefaultTreeCellRenderer
|
||||||
|
|
||||||
if (value instanceof ResourceTreeNode)
|
if (value instanceof ResourceTreeNode)
|
||||||
{
|
{
|
||||||
|
if (iconCache.containsKey(value))
|
||||||
|
{
|
||||||
|
setIcon(iconCache.get(value));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
ResourceTreeNode node = (ResourceTreeNode) value;
|
ResourceTreeNode node = (ResourceTreeNode) value;
|
||||||
|
|
||||||
String nameOG = node.toString();
|
String nameOG = node.toString();
|
||||||
String name = nameOG.toLowerCase();
|
String name = nameOG.toLowerCase();
|
||||||
String onlyName = FilenameUtils.getName(name);
|
String onlyName = FilenameUtils.getName(name);
|
||||||
|
@ -44,13 +55,13 @@ public class ResourceListIconRenderer extends DefaultTreeCellRenderer
|
||||||
&& (node.getParent() == node.getRoot()
|
&& (node.getParent() == node.getRoot()
|
||||||
|| node.getChildCount() == 0))
|
|| node.getChildCount() == 0))
|
||||||
{
|
{
|
||||||
setIcon(knownResourceType.getIcon());
|
cacheNodeIcon(node, knownResourceType.getIcon());
|
||||||
iconSet = true;
|
iconSet = true;
|
||||||
}
|
}
|
||||||
//hardcoded resource icons go here
|
//hardcoded resource icons go here
|
||||||
else if (nameOG.equals("Decoded Resources") && node.getChildCount() > 0)
|
else if (nameOG.equals("Decoded Resources") && node.getChildCount() > 0)
|
||||||
{
|
{
|
||||||
setIcon(IconResources.decodedIcon);
|
cacheNodeIcon(node, IconResources.decodedIcon);
|
||||||
iconSet = true;
|
iconSet = true;
|
||||||
}
|
}
|
||||||
else if (node.getChildCount() == 0
|
else if (node.getChildCount() == 0
|
||||||
|
@ -58,7 +69,7 @@ public class ResourceListIconRenderer extends DefaultTreeCellRenderer
|
||||||
|| nameOG.equals("LICENSE")
|
|| nameOG.equals("LICENSE")
|
||||||
|| nameOG.equals("NOTICE")))
|
|| nameOG.equals("NOTICE")))
|
||||||
{
|
{
|
||||||
setIcon(IconResources.textIcon);
|
cacheNodeIcon(node, IconResources.textIcon);
|
||||||
iconSet = true;
|
iconSet = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,17 +118,23 @@ public class ResourceListIconRenderer extends DefaultTreeCellRenderer
|
||||||
{
|
{
|
||||||
//java packages
|
//java packages
|
||||||
if (isJava)
|
if (isJava)
|
||||||
setIcon(IconResources.packagesIcon);
|
cacheNodeIcon(node, IconResources.packagesIcon);
|
||||||
else //regular folders
|
else //regular folders
|
||||||
setIcon(IconResources.folderIcon);
|
cacheNodeIcon(node, IconResources.folderIcon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//unknown files
|
//unknown files
|
||||||
else if (knownResourceType == null && !iconSet)
|
else if (knownResourceType == null && !iconSet)
|
||||||
setIcon(IconResources.unknownFileIcon);
|
cacheNodeIcon(node, IconResources.unknownFileIcon);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void cacheNodeIcon(ResourceTreeNode node, ImageIcon icon)
|
||||||
|
{
|
||||||
|
iconCache.put(node, icon);
|
||||||
|
setIcon(icon);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue