mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-07 16:49:10 +00:00
[FEATURE] Added search function to Reflection Explorer
This commit is contained in:
@@ -13,7 +13,10 @@ import javax.swing.tree.DefaultMutableTreeNode;
|
|||||||
import javax.swing.tree.DefaultTreeModel;
|
import javax.swing.tree.DefaultTreeModel;
|
||||||
import javax.swing.tree.TreePath;
|
import javax.swing.tree.TreePath;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Reflection explorer
|
* A Reflection explorer
|
||||||
@@ -32,6 +35,10 @@ public class ReflectUI extends JFrame {
|
|||||||
private HashMap<DefaultMutableTreeNode, RefClass> classes;
|
private HashMap<DefaultMutableTreeNode, RefClass> classes;
|
||||||
private HashMap<DefaultMutableTreeNode, RefField> fields;
|
private HashMap<DefaultMutableTreeNode, RefField> fields;
|
||||||
|
|
||||||
|
public static void main(String args[]) {
|
||||||
|
new ReflectUI();
|
||||||
|
}
|
||||||
|
|
||||||
public ReflectUI() {
|
public ReflectUI() {
|
||||||
this.root = new DefaultMutableTreeNode("Classes");
|
this.root = new DefaultMutableTreeNode("Classes");
|
||||||
this.model = new DefaultTreeModel(root);
|
this.model = new DefaultTreeModel(root);
|
||||||
@@ -55,6 +62,33 @@ public class ReflectUI extends JFrame {
|
|||||||
JPanel infoContent = new JPanel();
|
JPanel infoContent = new JPanel();
|
||||||
infoContent.setLayout(new BoxLayout(infoContent, BoxLayout.Y_AXIS));
|
infoContent.setLayout(new BoxLayout(infoContent, BoxLayout.Y_AXIS));
|
||||||
|
|
||||||
|
final JTextField searchFunction = new JTextField();
|
||||||
|
searchFunction.setHorizontalAlignment(JTextField.CENTER);
|
||||||
|
searchFunction.setText("Search");
|
||||||
|
searchFunction.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
Context context = Context.getInstance();
|
||||||
|
ClassPath classPath = context.getClassPath();
|
||||||
|
ASMClassLoader classLoader = context.getASMClassLoader();
|
||||||
|
for (String className : classPath.classNames) {
|
||||||
|
Class<?> clazz;
|
||||||
|
try {
|
||||||
|
clazz = classLoader.loadClass(className);
|
||||||
|
RefClass refClass = new RefClass(clazz);
|
||||||
|
|
||||||
|
for (RefField field : refClass.getFields()) {
|
||||||
|
if (Objects.equals(field.asObject(), searchFunction.getText().toLowerCase())) {
|
||||||
|
setFieldInfo(field);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (ClassNotFoundException e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
JTree tree = new JTree();
|
JTree tree = new JTree();
|
||||||
tree.setRootVisible(true);
|
tree.setRootVisible(true);
|
||||||
tree.setShowsRootHandles(true);
|
tree.setShowsRootHandles(true);
|
||||||
@@ -106,6 +140,7 @@ public class ReflectUI extends JFrame {
|
|||||||
exploreContent.add(infoContent);
|
exploreContent.add(infoContent);
|
||||||
|
|
||||||
content.add(exploreContent);
|
content.add(exploreContent);
|
||||||
|
content.add(searchFunction);
|
||||||
|
|
||||||
JScrollPane contentPane = new JScrollPane(content);
|
JScrollPane contentPane = new JScrollPane(content);
|
||||||
Dimension prefSize = content.getPreferredSize();
|
Dimension prefSize = content.getPreferredSize();
|
||||||
|
|||||||
Reference in New Issue
Block a user