diff --git a/src/main/java/org/parabot/core/ui/ReflectUI.java b/src/main/java/org/parabot/core/ui/ReflectUI.java index 8bc0391..f4d1aa3 100644 --- a/src/main/java/org/parabot/core/ui/ReflectUI.java +++ b/src/main/java/org/parabot/core/ui/ReflectUI.java @@ -13,7 +13,10 @@ import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreePath; import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.util.HashMap; +import java.util.Objects; /** * A Reflection explorer @@ -32,6 +35,10 @@ public class ReflectUI extends JFrame { private HashMap classes; private HashMap fields; + public static void main(String args[]) { + new ReflectUI(); + } + public ReflectUI() { this.root = new DefaultMutableTreeNode("Classes"); this.model = new DefaultTreeModel(root); @@ -55,6 +62,33 @@ public class ReflectUI extends JFrame { JPanel infoContent = new JPanel(); 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(); tree.setRootVisible(true); tree.setShowsRootHandles(true); @@ -106,6 +140,7 @@ public class ReflectUI extends JFrame { exploreContent.add(infoContent); content.add(exploreContent); + content.add(searchFunction); JScrollPane contentPane = new JScrollPane(content); Dimension prefSize = content.getPreferredSize();