summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Juuxel2020-12-15 23:28:05 +0200
committerGravatar Juuxel2021-01-23 16:27:09 +0200
commit68aaf143193201ecf71ced2ae6cd9eca7a0225a1 (patch)
tree933f16082dee32d3bc3fbd4ba02d83d8b8d2cbac
parentAttempt fixing rare CME when loading a jar while tabs are open (diff)
downloadenigma-68aaf143193201ecf71ced2ae6cd9eca7a0225a1.tar.gz
enigma-68aaf143193201ecf71ced2ae6cd9eca7a0225a1.tar.xz
enigma-68aaf143193201ecf71ced2ae6cd9eca7a0225a1.zip
Add interface/enum/annotation icons and modifier displays
- Adds icons in the sidebar and structure panel for interfaces, enums and annotations. - Adds some modifiers (final, default, abstract, static) to the structure panel.
-rw-r--r--enigma-swing/src/main/java/cuchaz/enigma/gui/ClassSelector.java19
-rw-r--r--enigma-swing/src/main/java/cuchaz/enigma/gui/panels/StructurePanel.java11
-rw-r--r--enigma-swing/src/main/java/cuchaz/enigma/gui/util/GuiUtil.java24
-rw-r--r--enigma-swing/src/main/resources/icons/annotation.pngbin0 -> 877 bytes
-rw-r--r--enigma-swing/src/main/resources/icons/enum.pngbin0 -> 506 bytes
-rw-r--r--enigma-swing/src/main/resources/icons/interface.pngbin0 -> 538 bytes
-rw-r--r--enigma/src/main/java/cuchaz/enigma/analysis/StructureTreeNode.java33
-rw-r--r--enigma/src/main/java/cuchaz/enigma/translation/representation/AccessFlags.java8
8 files changed, 90 insertions, 5 deletions
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/ClassSelector.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/ClassSelector.java
index b27832be..91c9705b 100644
--- a/enigma-swing/src/main/java/cuchaz/enigma/gui/ClassSelector.java
+++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/ClassSelector.java
@@ -11,6 +11,7 @@
11 11
12package cuchaz.enigma.gui; 12package cuchaz.enigma.gui;
13 13
14import java.awt.Component;
14import java.awt.event.MouseAdapter; 15import java.awt.event.MouseAdapter;
15import java.awt.event.MouseEvent; 16import java.awt.event.MouseEvent;
16import java.util.*; 17import java.util.*;
@@ -70,8 +71,22 @@ public class ClassSelector extends JTree {
70 } 71 }
71 }); 72 });
72 73
73 final DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer(); 74 final DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer() {
74 renderer.setLeafIcon(GuiUtil.CLASS_ICON); 75 {
76 setLeafIcon(GuiUtil.CLASS_ICON);
77 }
78
79 @Override
80 public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
81 super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
82
83 if (leaf && value instanceof ClassSelectorClassNode) {
84 setIcon(GuiUtil.getClassIcon(gui, ((ClassSelectorClassNode) value).getObfEntry()));
85 }
86
87 return this;
88 }
89 };
75 setCellRenderer(renderer); 90 setCellRenderer(renderer);
76 91
77 final JTree tree = this; 92 final JTree tree = this;
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/panels/StructurePanel.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/panels/StructurePanel.java
index 139923c5..12f1d758 100644
--- a/enigma-swing/src/main/java/cuchaz/enigma/gui/panels/StructurePanel.java
+++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/panels/StructurePanel.java
@@ -31,7 +31,7 @@ public class StructurePanel extends JPanel {
31 31
32 this.structureTree = new JTree(); 32 this.structureTree = new JTree();
33 this.structureTree.setModel(null); 33 this.structureTree.setModel(null);
34 this.structureTree.setCellRenderer(new StructureTreeCellRenderer()); 34 this.structureTree.setCellRenderer(new StructureTreeCellRenderer(gui));
35 this.structureTree.setShowsRootHandles(true); 35 this.structureTree.setShowsRootHandles(true);
36 this.structureTree.addMouseListener(new MouseAdapter() { 36 this.structureTree.addMouseListener(new MouseAdapter() {
37 @Override 37 @Override
@@ -76,6 +76,11 @@ public class StructurePanel extends JPanel {
76 } 76 }
77 77
78 class StructureTreeCellRenderer extends DefaultTreeCellRenderer { 78 class StructureTreeCellRenderer extends DefaultTreeCellRenderer {
79 private final Gui gui;
80
81 StructureTreeCellRenderer(Gui gui) {
82 this.gui = gui;
83 }
79 84
80 @Override 85 @Override
81 public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { 86 public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
@@ -83,14 +88,14 @@ public class StructurePanel extends JPanel {
83 ParentedEntry entry = ((StructureTreeNode) value).getEntry(); 88 ParentedEntry entry = ((StructureTreeNode) value).getEntry();
84 89
85 if (entry instanceof ClassEntry) { 90 if (entry instanceof ClassEntry) {
86 this.setIcon(GuiUtil.CLASS_ICON); 91 this.setIcon(GuiUtil.getClassIcon(gui, (ClassEntry) entry));
87 } else if (entry instanceof MethodEntry) { 92 } else if (entry instanceof MethodEntry) {
88 this.setIcon(((MethodEntry) entry).isConstructor() ? GuiUtil.CONSTRUCTOR_ICON : GuiUtil.METHOD_ICON); 93 this.setIcon(((MethodEntry) entry).isConstructor() ? GuiUtil.CONSTRUCTOR_ICON : GuiUtil.METHOD_ICON);
89 } else if (entry instanceof FieldEntry) { 94 } else if (entry instanceof FieldEntry) {
90 this.setIcon(GuiUtil.FIELD_ICON); 95 this.setIcon(GuiUtil.FIELD_ICON);
91 } 96 }
92 97
93 this.setText(value.toString()); 98 this.setText("<html>" + ((StructureTreeNode) value).toHtml());
94 99
95 return c; 100 return c;
96 } 101 }
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/util/GuiUtil.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/util/GuiUtil.java
index 6393913d..95f08539 100644
--- a/enigma-swing/src/main/java/cuchaz/enigma/gui/util/GuiUtil.java
+++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/util/GuiUtil.java
@@ -1,5 +1,8 @@
1package cuchaz.enigma.gui.util; 1package cuchaz.enigma.gui.util;
2 2
3import cuchaz.enigma.gui.Gui;
4import cuchaz.enigma.translation.representation.AccessFlags;
5import cuchaz.enigma.translation.representation.entry.ClassEntry;
3import cuchaz.enigma.utils.Os; 6import cuchaz.enigma.utils.Os;
4 7
5import javax.imageio.ImageIO; 8import javax.imageio.ImageIO;
@@ -16,6 +19,9 @@ import java.util.Map;
16 19
17public class GuiUtil { 20public class GuiUtil {
18 public static final Icon CLASS_ICON = loadIcon("class"); 21 public static final Icon CLASS_ICON = loadIcon("class");
22 public static final Icon INTERFACE_ICON = loadIcon("interface");
23 public static final Icon ENUM_ICON = loadIcon("enum");
24 public static final Icon ANNOTATION_ICON = loadIcon("annotation");
19 public static final Icon METHOD_ICON = loadIcon("method"); 25 public static final Icon METHOD_ICON = loadIcon("method");
20 public static final Icon FIELD_ICON = loadIcon("field"); 26 public static final Icon FIELD_ICON = loadIcon("field");
21 public static final Icon CONSTRUCTOR_ICON = loadIcon("constructor"); 27 public static final Icon CONSTRUCTOR_ICON = loadIcon("constructor");
@@ -82,4 +88,22 @@ public class GuiUtil {
82 88
83 return null; 89 return null;
84 } 90 }
91
92 public static Icon getClassIcon(Gui gui, ClassEntry entry) {
93 AccessFlags access = gui.getController().project.getJarIndex().getEntryIndex().getClassAccess(entry);
94
95 if (access != null) {
96 if (access.isAnnotation()) {
97 return ANNOTATION_ICON;
98 } else if (access.isInterface()) {
99 return INTERFACE_ICON;
100 } else if (access.isEnum()) {
101 return ENUM_ICON;
102 }
103
104 // TODO: Record icon?
105 }
106
107 return CLASS_ICON;
108 }
85} 109}
diff --git a/enigma-swing/src/main/resources/icons/annotation.png b/enigma-swing/src/main/resources/icons/annotation.png
new file mode 100644
index 00000000..9589a67e
--- /dev/null
+++ b/enigma-swing/src/main/resources/icons/annotation.png
Binary files differ
diff --git a/enigma-swing/src/main/resources/icons/enum.png b/enigma-swing/src/main/resources/icons/enum.png
new file mode 100644
index 00000000..b64dc829
--- /dev/null
+++ b/enigma-swing/src/main/resources/icons/enum.png
Binary files differ
diff --git a/enigma-swing/src/main/resources/icons/interface.png b/enigma-swing/src/main/resources/icons/interface.png
new file mode 100644
index 00000000..fc2bfe56
--- /dev/null
+++ b/enigma-swing/src/main/resources/icons/interface.png
Binary files differ
diff --git a/enigma/src/main/java/cuchaz/enigma/analysis/StructureTreeNode.java b/enigma/src/main/java/cuchaz/enigma/analysis/StructureTreeNode.java
index f310aa75..ac3a3815 100644
--- a/enigma/src/main/java/cuchaz/enigma/analysis/StructureTreeNode.java
+++ b/enigma/src/main/java/cuchaz/enigma/analysis/StructureTreeNode.java
@@ -4,10 +4,12 @@ import cuchaz.enigma.EnigmaProject;
4import cuchaz.enigma.api.service.NameProposalService; 4import cuchaz.enigma.api.service.NameProposalService;
5import cuchaz.enigma.translation.TranslateResult; 5import cuchaz.enigma.translation.TranslateResult;
6import cuchaz.enigma.translation.mapping.EntryRemapper; 6import cuchaz.enigma.translation.mapping.EntryRemapper;
7import cuchaz.enigma.translation.representation.AccessFlags;
7import cuchaz.enigma.translation.representation.TypeDescriptor; 8import cuchaz.enigma.translation.representation.TypeDescriptor;
8import cuchaz.enigma.translation.representation.entry.*; 9import cuchaz.enigma.translation.representation.entry.*;
9 10
10import javax.swing.tree.DefaultMutableTreeNode; 11import javax.swing.tree.DefaultMutableTreeNode;
12import java.util.ArrayList;
11import java.util.List; 13import java.util.List;
12 14
13public class StructureTreeNode extends DefaultMutableTreeNode { 15public class StructureTreeNode extends DefaultMutableTreeNode {
@@ -90,6 +92,37 @@ public class StructureTreeNode extends DefaultMutableTreeNode {
90 return result; 92 return result;
91 } 93 }
92 94
95 public String toHtml() {
96 List<String> modifiers = new ArrayList<>();
97
98 if (this.entry instanceof DefEntry<?>) {
99 AccessFlags access = ((DefEntry<?>) this.entry).getAccess();
100 boolean isInterfaceMethod = false;
101
102 if (this.entry instanceof MethodEntry && this.entry.getParent() instanceof ClassDefEntry) {
103 isInterfaceMethod = ((ClassDefEntry) this.entry.getParent()).getAccess().isInterface();
104 }
105
106 if (access.isStatic() && !access.isEnum()) {
107 // Static member, but not an enum constant
108 modifiers.add("static");
109 } else if (isInterfaceMethod && !access.isAbstract()) {
110 // Non-static default interface method
111 modifiers.add("default");
112 }
113
114 if (access.isAbstract() && !access.isInterface() && !isInterfaceMethod) {
115 // Abstract, but not an interface or an interface method (they're always abstract)
116 modifiers.add("abstract");
117 } else if (access.isFinal() && !access.isEnum()) {
118 // Final, but not an enum or an enum constant (they're always final)
119 modifiers.add("final");
120 }
121 }
122
123 return "<i>" + String.join(" ", modifiers) + "</i> " + toString();
124 }
125
93 private String parseArgs(List<TypeDescriptor> args) { 126 private String parseArgs(List<TypeDescriptor> args) {
94 if (args.size() > 0) { 127 if (args.size() > 0) {
95 String result = "("; 128 String result = "(";
diff --git a/enigma/src/main/java/cuchaz/enigma/translation/representation/AccessFlags.java b/enigma/src/main/java/cuchaz/enigma/translation/representation/AccessFlags.java
index b280eef2..e8480a26 100644
--- a/enigma/src/main/java/cuchaz/enigma/translation/representation/AccessFlags.java
+++ b/enigma/src/main/java/cuchaz/enigma/translation/representation/AccessFlags.java
@@ -51,6 +51,14 @@ public class AccessFlags {
51 return (flags & Opcodes.ACC_INTERFACE) != 0; 51 return (flags & Opcodes.ACC_INTERFACE) != 0;
52 } 52 }
53 53
54 public boolean isAbstract() {
55 return (flags & Opcodes.ACC_ABSTRACT) != 0;
56 }
57
58 public boolean isAnnotation() {
59 return (flags & Opcodes.ACC_ANNOTATION) != 0;
60 }
61
54 public AccessFlags setPrivate() { 62 public AccessFlags setPrivate() {
55 this.setVisibility(Opcodes.ACC_PRIVATE); 63 this.setVisibility(Opcodes.ACC_PRIVATE);
56 return this; 64 return this;