gui: add icons to classes tree
This commit is contained in:
@@ -2,7 +2,8 @@ package jadx.gui;
|
||||
|
||||
import jadx.cli.JadxArgs;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.UIManager;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -25,7 +26,7 @@ public class JadxGUI {
|
||||
MainWindow mainWindow = new MainWindow(jadxArgs);
|
||||
mainWindow.setVisible(true);
|
||||
|
||||
if(!jadxArgs.getInput().isEmpty()) {
|
||||
if (!jadxArgs.getInput().isEmpty()) {
|
||||
mainWindow.openFile(jadxArgs.getInput().get(0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package jadx.gui;
|
||||
|
||||
import jadx.api.IJadxArgs;
|
||||
import jadx.api.Decompiler;
|
||||
import jadx.api.IJadxArgs;
|
||||
import jadx.api.JavaClass;
|
||||
import jadx.api.JavaPackage;
|
||||
import jadx.core.utils.exceptions.DecodeException;
|
||||
@@ -12,12 +12,14 @@ import java.util.List;
|
||||
|
||||
public class JadxWrapper {
|
||||
private final Decompiler decompiler;
|
||||
private File openFile;
|
||||
|
||||
public JadxWrapper(IJadxArgs jadxArgs) {
|
||||
this.decompiler = new Decompiler(jadxArgs);
|
||||
}
|
||||
|
||||
public void openFile(File file) {
|
||||
this.openFile = file;
|
||||
try {
|
||||
this.decompiler.loadFile(file);
|
||||
} catch (IOException e) {
|
||||
@@ -35,4 +37,7 @@ public class JadxWrapper {
|
||||
return decompiler.getPackages();
|
||||
}
|
||||
|
||||
public File getOpenFile() {
|
||||
return openFile;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,35 @@
|
||||
package jadx.gui;
|
||||
|
||||
import jadx.api.JavaClass;
|
||||
import jadx.api.JavaPackage;
|
||||
import jadx.cli.JadxArgs;
|
||||
import jadx.gui.model.JClass;
|
||||
import jadx.core.utils.exceptions.JadxRuntimeException;
|
||||
import jadx.gui.treemodel.JClass;
|
||||
import jadx.gui.treemodel.JNode;
|
||||
import jadx.gui.treemodel.JRoot;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JSplitPane;
|
||||
import javax.swing.JTree;
|
||||
import javax.swing.event.TreeSelectionEvent;
|
||||
import javax.swing.event.TreeSelectionListener;
|
||||
import javax.swing.filechooser.FileFilter;
|
||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.MutableTreeNode;
|
||||
import javax.swing.tree.DefaultTreeCellRenderer;
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
import javax.swing.tree.TreeSelectionModel;
|
||||
import java.awt.*;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
|
||||
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
|
||||
import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
|
||||
@@ -35,8 +45,8 @@ public class MainWindow extends JFrame {
|
||||
|
||||
private final JadxWrapper wrapper;
|
||||
private JPanel mainPanel;
|
||||
private DefaultMutableTreeNode treeRoot;
|
||||
private JTree tree;
|
||||
private DefaultTreeModel treeModel;
|
||||
private RSyntaxTextArea textArea;
|
||||
|
||||
public MainWindow(JadxArgs jadxArgs) {
|
||||
@@ -52,7 +62,7 @@ public class MainWindow extends JFrame {
|
||||
JMenu file = new JMenu("File");
|
||||
file.setMnemonic(KeyEvent.VK_F);
|
||||
|
||||
JMenuItem exit = new JMenuItem("Exit", openIcon("application-exit"));
|
||||
JMenuItem exit = new JMenuItem("Exit", Utils.openIcon("cross"));
|
||||
exit.setMnemonic(KeyEvent.VK_E);
|
||||
exit.setToolTipText("Exit application");
|
||||
exit.addActionListener(new ActionListener() {
|
||||
@@ -61,7 +71,7 @@ public class MainWindow extends JFrame {
|
||||
}
|
||||
});
|
||||
|
||||
JMenuItem open = new JMenuItem("Open", openIcon("document-open-5"));
|
||||
JMenuItem open = new JMenuItem("Open", Utils.openIcon("folder"));
|
||||
open.setMnemonic(KeyEvent.VK_E);
|
||||
open.setToolTipText("Open file");
|
||||
open.addActionListener(new ActionListener() {
|
||||
@@ -92,54 +102,49 @@ public class MainWindow extends JFrame {
|
||||
}
|
||||
|
||||
private void initTree() {
|
||||
treeRoot.removeAllChildren();
|
||||
for (JavaPackage pkg : wrapper.getPackages()) {
|
||||
MutableTreeNode child = new DefaultMutableTreeNode(pkg);
|
||||
int i = 0;
|
||||
for (JavaClass javaClass : pkg.getClasses()) {
|
||||
MutableTreeNode cls = new DefaultMutableTreeNode(new JClass(javaClass));
|
||||
child.insert(cls, i++);
|
||||
}
|
||||
treeRoot.add(child);
|
||||
}
|
||||
JRoot treeRoot = new JRoot(wrapper);
|
||||
treeModel.setRoot(treeRoot);
|
||||
treeModel.reload();
|
||||
tree.expandRow(0);
|
||||
}
|
||||
|
||||
private ImageIcon openIcon(String name) {
|
||||
String iconPath = "/icons-16/" + name + ".png";
|
||||
URL resource = getClass().getResource(iconPath);
|
||||
if (resource == null) {
|
||||
throw new JadxRuntimeException("Icon not found: " + iconPath);
|
||||
}
|
||||
return new ImageIcon(resource);
|
||||
}
|
||||
|
||||
private void initUI() {
|
||||
mainPanel = new JPanel(new BorderLayout());
|
||||
JSplitPane splitPane = new JSplitPane();
|
||||
mainPanel.add(splitPane);
|
||||
|
||||
treeRoot = new DefaultMutableTreeNode("Please open file");
|
||||
tree = new JTree(treeRoot);
|
||||
DefaultMutableTreeNode treeRoot = new DefaultMutableTreeNode("Please open file");
|
||||
treeModel = new DefaultTreeModel(treeRoot);
|
||||
tree = new JTree(treeModel);
|
||||
// tree.setRootVisible(false);
|
||||
// tree.setBackground(BACKGROUND);
|
||||
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
|
||||
tree.addTreeSelectionListener(new TreeSelectionListener() {
|
||||
@Override
|
||||
public void valueChanged(TreeSelectionEvent e) {
|
||||
Object node = tree.getLastSelectedPathComponent();
|
||||
if (node instanceof DefaultMutableTreeNode) {
|
||||
Object obj = ((DefaultMutableTreeNode) node).getUserObject();
|
||||
if (obj instanceof JClass) {
|
||||
JavaClass jc = ((JClass) obj).getCls();
|
||||
String code = jc.getCode();
|
||||
textArea.setText(code);
|
||||
textArea.setCaretPosition(0);
|
||||
}
|
||||
Object obj = tree.getLastSelectedPathComponent();
|
||||
if (obj instanceof JClass) {
|
||||
JavaClass jc = ((JClass) obj).getCls();
|
||||
String code = jc.getCode();
|
||||
textArea.setText(code);
|
||||
textArea.setCaretPosition(0);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
tree.setCellRenderer(new DefaultTreeCellRenderer() {
|
||||
@Override
|
||||
public Component getTreeCellRendererComponent(JTree tree,
|
||||
Object value, boolean selected, boolean expanded,
|
||||
boolean isLeaf, int row, boolean focused) {
|
||||
Component c = super.getTreeCellRendererComponent(tree, value, selected, expanded, isLeaf, row, focused);
|
||||
if (value instanceof JNode) {
|
||||
setIcon(((JNode) value).getIcon());
|
||||
}
|
||||
return c;
|
||||
}
|
||||
});
|
||||
|
||||
JScrollPane treeScrollPane = new JScrollPane(tree);
|
||||
splitPane.setLeftComponent(treeScrollPane);
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package jadx.gui;
|
||||
|
||||
import jadx.core.utils.exceptions.JadxRuntimeException;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import java.net.URL;
|
||||
|
||||
public class Utils {
|
||||
|
||||
public static ImageIcon openIcon(String name) {
|
||||
String iconPath = "/icons-16/" + name + ".png";
|
||||
URL resource = Utils.class.getResource(iconPath);
|
||||
if (resource == null) {
|
||||
throw new JadxRuntimeException("Icon not found: " + iconPath);
|
||||
}
|
||||
return new ImageIcon(resource);
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package jadx.gui.model;
|
||||
|
||||
import jadx.api.JavaClass;
|
||||
|
||||
public class JClass {
|
||||
|
||||
private final JavaClass cls;
|
||||
|
||||
public JClass(JavaClass cls) {
|
||||
this.cls = cls;
|
||||
}
|
||||
|
||||
public JavaClass getCls() {
|
||||
return cls;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return cls.getShortName();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package jadx.gui.treemodel;
|
||||
|
||||
import jadx.api.JavaClass;
|
||||
import jadx.gui.Utils;
|
||||
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
|
||||
public class JClass extends DefaultMutableTreeNode implements JNode {
|
||||
|
||||
private final JavaClass cls;
|
||||
|
||||
public JClass(JavaClass cls) {
|
||||
this.cls = cls;
|
||||
}
|
||||
|
||||
public JavaClass getCls() {
|
||||
return cls;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return Utils.openIcon("class_obj");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return cls.getShortName();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package jadx.gui.treemodel;
|
||||
|
||||
import javax.swing.Icon;
|
||||
|
||||
public interface JNode {
|
||||
Icon getIcon();
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package jadx.gui.treemodel;
|
||||
|
||||
import jadx.api.JavaClass;
|
||||
import jadx.api.JavaPackage;
|
||||
import jadx.gui.Utils;
|
||||
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
|
||||
public class JPackage extends DefaultMutableTreeNode implements JNode {
|
||||
private static final ImageIcon PACKAGE_ICON = Utils.openIcon("package_obj");
|
||||
|
||||
private final JavaPackage pkg;
|
||||
|
||||
public JPackage(JavaPackage pkg) {
|
||||
this.pkg = pkg;
|
||||
|
||||
for (JavaClass javaClass : pkg.getClasses()) {
|
||||
add(new JClass(javaClass));
|
||||
}
|
||||
}
|
||||
|
||||
public JavaPackage getPkg() {
|
||||
return pkg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return PACKAGE_ICON;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return pkg.getName();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package jadx.gui.treemodel;
|
||||
|
||||
import jadx.api.JavaPackage;
|
||||
import jadx.gui.JadxWrapper;
|
||||
import jadx.gui.Utils;
|
||||
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import java.io.File;
|
||||
|
||||
public class JRoot extends DefaultMutableTreeNode implements JNode {
|
||||
|
||||
private static final ImageIcon ROOT_ICON = Utils.openIcon("java_model_obj");
|
||||
|
||||
private final JadxWrapper wrapper;
|
||||
|
||||
public JRoot(JadxWrapper wrapper) {
|
||||
this.wrapper = wrapper;
|
||||
|
||||
for (JavaPackage pkg : wrapper.getPackages()) {
|
||||
add(new JPackage(pkg));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return ROOT_ICON;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
File file = wrapper.getOpenFile();
|
||||
return file != null ? file.getName() : "File not open";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user