gui: remove not generated elements from class node tree
This commit is contained in:
@@ -26,14 +26,18 @@ import javax.swing.JToolBar;
|
||||
import javax.swing.JTree;
|
||||
import javax.swing.KeyStroke;
|
||||
import javax.swing.ProgressMonitor;
|
||||
import javax.swing.event.TreeExpansionEvent;
|
||||
import javax.swing.event.TreeSelectionEvent;
|
||||
import javax.swing.event.TreeSelectionListener;
|
||||
import javax.swing.event.TreeWillExpandListener;
|
||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||
import javax.swing.plaf.basic.BasicButtonUI;
|
||||
import javax.swing.text.BadLocationException;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.DefaultTreeCellRenderer;
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
import javax.swing.tree.ExpandVetoException;
|
||||
import javax.swing.tree.TreePath;
|
||||
import javax.swing.tree.TreeSelectionModel;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
@@ -192,6 +196,7 @@ public class MainWindow extends JFrame {
|
||||
}
|
||||
|
||||
private void showCode(JClass cls, int line) {
|
||||
cls.load();
|
||||
JPanel panel = (JPanel) openTabs.get(cls);
|
||||
if (panel != null) {
|
||||
panel = (JPanel) openTabs.get(cls);
|
||||
@@ -379,6 +384,22 @@ public class MainWindow extends JFrame {
|
||||
return c;
|
||||
}
|
||||
});
|
||||
tree.addTreeWillExpandListener(new TreeWillExpandListener() {
|
||||
|
||||
@Override
|
||||
public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
|
||||
TreePath path = event.getPath();
|
||||
Object node = path.getLastPathComponent();
|
||||
if (node instanceof JClass) {
|
||||
JClass cls = (JClass) node;
|
||||
cls.load();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException {
|
||||
}
|
||||
});
|
||||
|
||||
JScrollPane treeScrollPane = new JScrollPane(tree);
|
||||
splitPane.setLeftComponent(treeScrollPane);
|
||||
|
||||
@@ -4,6 +4,7 @@ import jadx.api.JavaClass;
|
||||
import jadx.api.JavaField;
|
||||
import jadx.api.JavaMethod;
|
||||
import jadx.core.dex.info.AccessInfo;
|
||||
import jadx.gui.utils.NLS;
|
||||
import jadx.gui.utils.Utils;
|
||||
|
||||
import javax.swing.Icon;
|
||||
@@ -22,6 +23,7 @@ public class JClass extends JNode {
|
||||
|
||||
private final JavaClass cls;
|
||||
private JClass jParrent;
|
||||
private boolean loaded;
|
||||
|
||||
public JClass(JavaClass cls) {
|
||||
this.cls = cls;
|
||||
@@ -31,21 +33,33 @@ public class JClass extends JNode {
|
||||
return cls;
|
||||
}
|
||||
|
||||
public synchronized void load() {
|
||||
if (!loaded) {
|
||||
cls.decompile();
|
||||
loaded = true;
|
||||
updateChilds();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateChilds() {
|
||||
removeAllChildren();
|
||||
JClass currentParent = jParrent == null ? this : jParrent;
|
||||
for (JavaClass javaClass : cls.getInnerClasses()) {
|
||||
JClass child = new JClass(javaClass);
|
||||
child.setJParent(currentParent);
|
||||
child.updateChilds();
|
||||
add(child);
|
||||
}
|
||||
for (JavaField f : cls.getFields()) {
|
||||
add(new JField(f, currentParent));
|
||||
}
|
||||
for (JavaMethod m : cls.getMethods()) {
|
||||
add(new JMethod(m, currentParent));
|
||||
if (!loaded) {
|
||||
add(new TextNode(NLS.str("tree.loading")));
|
||||
} else {
|
||||
JClass currentParent = jParrent == null ? this : jParrent;
|
||||
for (JavaClass javaClass : cls.getInnerClasses()) {
|
||||
JClass child = new JClass(javaClass);
|
||||
child.setJParent(currentParent);
|
||||
child.updateChilds();
|
||||
add(child);
|
||||
}
|
||||
for (JavaField f : cls.getFields()) {
|
||||
add(new JField(f, currentParent));
|
||||
}
|
||||
for (JavaMethod m : cls.getMethods()) {
|
||||
add(new JMethod(m, currentParent));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,8 +47,12 @@ public class JMethod extends JNode {
|
||||
public Icon getIcon() {
|
||||
AccessInfo accessFlags = mth.getAccessFlags();
|
||||
OverlayIcon icon = Utils.makeIcon(accessFlags, ICON_MTH_PUB, ICON_MTH_PRI, ICON_MTH_PRO, ICON_MTH_DEF);
|
||||
if (accessFlags.isConstructor()) icon.add(ICON_CONSTRUCTOR);
|
||||
if (accessFlags.isSynchronized()) icon.add(ICON_SYNC);
|
||||
if (accessFlags.isConstructor()) {
|
||||
icon.add(ICON_CONSTRUCTOR);
|
||||
}
|
||||
if (accessFlags.isSynchronized()) {
|
||||
icon.add(ICON_SYNC);
|
||||
}
|
||||
return icon;
|
||||
}
|
||||
|
||||
@@ -57,14 +61,18 @@ public class JMethod extends JNode {
|
||||
if (mth.isClassInit()) {
|
||||
return "{...}";
|
||||
}
|
||||
|
||||
StringBuilder base = new StringBuilder();
|
||||
base.append(mth.getName());
|
||||
if (mth.isConstructor()) {
|
||||
base.append(mth.getDeclaringClass().getShortName());
|
||||
} else {
|
||||
base.append(mth.getName());
|
||||
}
|
||||
base.append('(');
|
||||
for (Iterator<ArgType> it = mth.getArguments().iterator(); it.hasNext(); ) {
|
||||
base.append(Utils.typeStr(it.next()));
|
||||
if (it.hasNext())
|
||||
if (it.hasNext()) {
|
||||
base.append(", ");
|
||||
}
|
||||
}
|
||||
base.append(')');
|
||||
return Utils.typeFormat(base.toString(), mth.getReturnType());
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package jadx.gui.treemodel;
|
||||
|
||||
import javax.swing.Icon;
|
||||
|
||||
public class TextNode extends JNode {
|
||||
private final String label;
|
||||
|
||||
public TextNode(String str) {
|
||||
this.label = str;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JClass getJParent() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLine() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateChilds() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return label;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user