blob: 32f803f85b9a27f35bccdff51784338c6a905705 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
package cuchaz.enigma.gui.panels;
import cuchaz.enigma.analysis.StructureTreeNode;
import cuchaz.enigma.gui.Gui;
import cuchaz.enigma.gui.util.GuiUtil;
import cuchaz.enigma.translation.representation.entry.ClassEntry;
import cuchaz.enigma.translation.representation.entry.FieldEntry;
import cuchaz.enigma.translation.representation.entry.MethodEntry;
import cuchaz.enigma.translation.representation.entry.ParentedEntry;
import cuchaz.enigma.utils.I18n;
import javax.swing.*;
import javax.swing.tree.TreeCellRenderer;
import javax.swing.tree.TreePath;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class StructurePanel extends JPanel {
private final Gui gui;
private JPanel sortingPanel;
private JCheckBox hideDeobfuscated;
private JTree structureTree;
public StructurePanel(Gui gui) {
this.gui = gui;
this.sortingPanel = new JPanel();
this.hideDeobfuscated = new JCheckBox(I18n.translate("info_panel.tree.structure.hide_deobfuscated"));
this.hideDeobfuscated.addActionListener(event -> gui.showStructure(gui.getActiveEditor()));
this.sortingPanel.add(this.hideDeobfuscated);
this.sortingPanel.setVisible(false);
this.structureTree = new JTree();
this.structureTree.setModel(null);
this.structureTree.setCellRenderer(new StructureTreeCellRenderer());
this.structureTree.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent event) {
if (event.getClickCount() >= 2) {
// get the selected node
TreePath path = structureTree.getSelectionPath();
if (path == null) {
return;
}
Object node = path.getLastPathComponent();
if (node instanceof StructureTreeNode) {
gui.getController().navigateTo(((StructureTreeNode) node).getEntry());
}
}
}
});
this.setLayout(new BorderLayout());
this.add(this.sortingPanel, BorderLayout.NORTH);
this.add(new JScrollPane(this.structureTree));
}
public JPanel getSortingPanel() {
return this.sortingPanel;
}
public boolean shouldHideDeobfuscated() {
return this.hideDeobfuscated.isSelected();
}
public JTree getStructureTree() {
return this.structureTree;
}
public void retranslateUi() {
this.hideDeobfuscated.setText(I18n.translate("info_panel.tree.structure.hide_deobfuscated"));
}
class StructureTreeCellRenderer implements TreeCellRenderer {
private JLabel label;
public StructureTreeCellRenderer() {
this.label = new JLabel();
}
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
ParentedEntry entry = ((StructureTreeNode) value).getEntry();
if (entry instanceof ClassEntry) {
this.label.setIcon(GuiUtil.CLASS_ICON);
} else if (entry instanceof MethodEntry) {
this.label.setIcon(GuiUtil.METHOD_ICON);
} else if (entry instanceof FieldEntry) {
this.label.setIcon(GuiUtil.FIELD_ICON);
}
this.label.setText(value.toString());
return this.label;
}
}
}
|