feat(plugins): add method to get jadx-gui icons by name
This commit is contained in:
@@ -3,6 +3,7 @@ package jadx.api.plugins.gui;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
@@ -57,6 +58,16 @@ public interface JadxGuiContext {
|
||||
*/
|
||||
JFrame getMainFrame();
|
||||
|
||||
/**
|
||||
* Load SVG icon from jadx resources.
|
||||
* All available icons can be found in "jadx-gui/src/main/resources/icons".
|
||||
* Method is thread-safe.
|
||||
*
|
||||
* @param name short name in form: "category/iconName", example: "nodes/publicClass"
|
||||
* @return loaded and cached icon, if icon not found returns default icon: "ui/error"
|
||||
*/
|
||||
ImageIcon getSVGIcon(String name);
|
||||
|
||||
ICodeNodeRef getNodeUnderCaret();
|
||||
|
||||
ICodeNodeRef getNodeUnderMouse();
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.awt.Container;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.KeyStroke;
|
||||
@@ -31,6 +32,7 @@ import jadx.gui.ui.codearea.AbstractCodeArea;
|
||||
import jadx.gui.ui.codearea.AbstractCodeContentPanel;
|
||||
import jadx.gui.ui.codearea.CodeArea;
|
||||
import jadx.gui.ui.panel.ContentPanel;
|
||||
import jadx.gui.utils.IconsCache;
|
||||
import jadx.gui.utils.JNodeCache;
|
||||
import jadx.gui.utils.UiUtils;
|
||||
|
||||
@@ -121,6 +123,16 @@ public class GuiPluginContext implements JadxGuiContext {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImageIcon getSVGIcon(String name) {
|
||||
try {
|
||||
return IconsCache.getSVGIcon(name);
|
||||
} catch (Exception e) {
|
||||
LOG.error("Failed to load icon: {}", name, e);
|
||||
return IconsCache.getSVGIcon("ui/error");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICodeNodeRef getNodeUnderCaret() {
|
||||
CodeArea codeArea = getCodeArea();
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package jadx.gui.utils;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.formdev.flatlaf.extras.FlatSVGIcon;
|
||||
|
||||
public class IconsCache {
|
||||
|
||||
private static final Map<String, FlatSVGIcon> SVG_ICONS = new ConcurrentHashMap<>();
|
||||
|
||||
public static FlatSVGIcon getSVGIcon(String name) {
|
||||
return SVG_ICONS.computeIfAbsent(name, UiUtils::openSvgIcon);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user