提交 c4cdd851 编写于 作者: S Skylot

gui: add fields and methods to tree

上级 25b2c8fe
......@@ -2,7 +2,7 @@ The majority of jadx is written and copyrighted by me (Skylot)
and released under the Apache 2.0 license:
*******************************************************************************
Copyright 2013 Skylot
Copyright 2013, Skylot
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
......@@ -105,7 +105,41 @@ as published by the Free Software Foundation.
*******************************************************************************
GUI icons copied from several places:
Jadx-gui components
===================
RSyntaxTextArea library licensed under modified BSD liense:
*******************************************************************************
Copyright (c) 2012, Robert Futrell
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the author nor the names of its contributors may
be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************
Icons copied from several places:
- Eclipse Project (JDT UI) - licensed under EPL v1.0 (http://www.eclipse.org/legal/epl-v10.html)
- famfamfam silk icon set (http://www.famfamfam.com/lab/icons/silk/) - licensed under Creative Commons Attribution 2.5 License (http://creativecommons.org/licenses/by/2.5/)
package jadx.gui;
import jadx.api.JavaClass;
import jadx.cli.JadxArgs;
import jadx.gui.treemodel.JClass;
import jadx.gui.treemodel.JNode;
import jadx.gui.treemodel.JRoot;
......@@ -23,10 +21,10 @@ import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.text.BadLocationException;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeSelectionModel;
import java.awt.BorderLayout;
import java.awt.Color;
......@@ -76,7 +74,6 @@ public class MainWindow extends JFrame {
treeModel.setRoot(treeRoot);
treeModel.reload();
tree.expandRow(0);
// expandTree();
}
private void toggleFlattenPackage() {
......@@ -89,15 +86,26 @@ public class MainWindow extends JFrame {
}
}
private void expandTree() {
DefaultMutableTreeNode currentNode = ((DefaultMutableTreeNode) tree.getModel().getRoot()).getNextNode();
do {
if (currentNode.getLevel() == 1) {
tree.expandPath(new TreePath(currentNode.getPath()));
private void treeClickAction() {
Object obj = tree.getLastSelectedPathComponent();
if (obj instanceof JNode) {
JNode node = (JNode) obj;
if (node.getJParent() != null) {
textArea.setText(node.getJParent().getCode());
scrollToLine(node.getLine());
}
currentNode = currentNode.getNextNode();
}
while (currentNode != null);
}
private void scrollToLine(int line) {
if (line < 2) {
return;
}
try {
textArea.setCaretPosition(textArea.getLineStartOffset(line - 1));
} catch (BadLocationException e) {
LOG.error("Can't scroll to " + line, e);
}
}
private void initMenuAndToolbar() {
......@@ -165,14 +173,8 @@ public class MainWindow extends JFrame {
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
tree.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
Object obj = tree.getLastSelectedPathComponent();
if (obj instanceof JClass) {
JavaClass jc = ((JClass) obj).getCls();
String code = jc.getCode();
textArea.setText(code);
textArea.setCaretPosition(0);
}
public void valueChanged(TreeSelectionEvent event) {
treeClickAction();
}
});
......
package jadx.gui.treemodel;
import jadx.api.JavaClass;
import jadx.api.JavaField;
import jadx.api.JavaMethod;
import jadx.core.dex.info.AccessInfo;
import jadx.gui.Utils;
......@@ -19,10 +21,10 @@ public class JClass extends DefaultMutableTreeNode implements JNode {
private static final ImageIcon ICON_ANNOTATION = Utils.openIcon("annotation_obj");
private final JavaClass cls;
private JClass jParrent;
public JClass(JavaClass cls) {
this.cls = cls;
updateChilds();
}
public JavaClass getCls() {
......@@ -31,9 +33,23 @@ public class JClass extends DefaultMutableTreeNode implements JNode {
@Override
public void updateChilds() {
// for (JavaClass javaClass : cls.getInnerClasses()) {
// add(new JClass(javaClass));
// }
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));
}
}
public String getCode(){
return cls.getCode();
}
@Override
......@@ -57,6 +73,20 @@ public class JClass extends DefaultMutableTreeNode implements JNode {
}
}
public void setJParent(JClass parent) {
this.jParrent = parent;
}
@Override
public JClass getJParent() {
return jParrent;
}
@Override
public int getLine() {
return cls.getDecompiledLine();
}
@Override
public String toString() {
return cls.getShortName();
......
package jadx.gui.treemodel;
import jadx.api.JavaField;
import jadx.core.dex.info.AccessInfo;
import jadx.gui.Utils;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.tree.DefaultMutableTreeNode;
public class JField extends DefaultMutableTreeNode implements JNode {
private static final ImageIcon ICON_FLD_DEF = Utils.openIcon("field_default_obj");
private static final ImageIcon ICON_FLD_PRI = Utils.openIcon("field_private_obj");
private static final ImageIcon ICON_FLD_PRO = Utils.openIcon("field_protected_obj");
private static final ImageIcon ICON_FLD_PUB = Utils.openIcon("field_public_obj");
private final JavaField field;
private final JClass jParent;
public JField(JavaField javaField, JClass jClass) {
this.field = javaField;
this.jParent = jClass;
}
@Override
public void updateChilds() {
}
@Override
public JClass getJParent() {
return jParent;
}
@Override
public int getLine() {
return field.getDecompiledLine();
}
@Override
public Icon getIcon() {
AccessInfo af = field.getAccessFlags();
if(af.isPublic()){
return ICON_FLD_PUB;
} else if(af.isPrivate()) {
return ICON_FLD_PRI;
} else if(af.isProtected()) {
return ICON_FLD_PRO;
} else {
return ICON_FLD_DEF;
}
}
@Override
public String toString() {
return field.getName();
}
}
package jadx.gui.treemodel;
import jadx.api.JavaMethod;
import jadx.core.dex.info.AccessInfo;
import jadx.gui.Utils;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.tree.DefaultMutableTreeNode;
public class JMethod extends DefaultMutableTreeNode implements JNode {
private static final ImageIcon ICON_MTH_DEF = Utils.openIcon("methdef_obj");
private static final ImageIcon ICON_MTH_PRI = Utils.openIcon("methpri_obj");
private static final ImageIcon ICON_MTH_PRO = Utils.openIcon("methpro_obj");
private static final ImageIcon ICON_MTH_PUB = Utils.openIcon("methpub_obj");
private final JavaMethod mth;
private final JClass jparent;
public JMethod(JavaMethod javaMethod, JClass jClass) {
this.mth = javaMethod;
this.jparent = jClass;
}
@Override
public void updateChilds() {
}
@Override
public JClass getJParent() {
return jparent;
}
@Override
public int getLine() {
return mth.getDecompiledLine();
}
@Override
public Icon getIcon() {
AccessInfo af = mth.getAccessFlags();
if (af.isPublic()) {
return ICON_MTH_PUB;
} else if (af.isPrivate()) {
return ICON_MTH_PRI;
} else if (af.isProtected()) {
return ICON_MTH_PRO;
} else {
return ICON_MTH_DEF;
}
}
@Override
public String toString() {
return mth.getName();
}
}
......@@ -4,6 +4,10 @@ import javax.swing.Icon;
public interface JNode {
JClass getJParent();
int getLine();
void updateChilds();
Icon getIcon();
......
......@@ -40,6 +40,7 @@ public class JPackage extends DefaultMutableTreeNode implements JNode, Comparabl
add(pkg);
}
for (JClass cls : classes) {
cls.updateChilds();
add(cls);
}
}
......@@ -65,6 +66,16 @@ public class JPackage extends DefaultMutableTreeNode implements JNode, Comparabl
return PACKAGE_ICON;
}
@Override
public JClass getJParent() {
return null;
}
@Override
public int getLine() {
return 0;
}
@Override
public int compareTo(JPackage o) {
return name.compareTo(o.name);
......
......@@ -118,6 +118,16 @@ public class JRoot extends DefaultMutableTreeNode implements JNode {
return ROOT_ICON;
}
@Override
public JClass getJParent() {
return null;
}
@Override
public int getLine() {
return 0;
}
@Override
public String toString() {
File file = wrapper.getOpenFile();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册