diff options
| -rw-r--r-- | enigma-swing/src/main/java/cuchaz/enigma/gui/ClassSelector.java | 19 | ||||
| -rw-r--r-- | enigma-swing/src/main/java/cuchaz/enigma/gui/panels/StructurePanel.java | 11 | ||||
| -rw-r--r-- | enigma-swing/src/main/java/cuchaz/enigma/gui/util/GuiUtil.java | 24 | ||||
| -rw-r--r-- | enigma-swing/src/main/resources/icons/annotation.png | bin | 0 -> 877 bytes | |||
| -rw-r--r-- | enigma-swing/src/main/resources/icons/enum.png | bin | 0 -> 506 bytes | |||
| -rw-r--r-- | enigma-swing/src/main/resources/icons/interface.png | bin | 0 -> 538 bytes | |||
| -rw-r--r-- | enigma/src/main/java/cuchaz/enigma/analysis/StructureTreeNode.java | 33 | ||||
| -rw-r--r-- | enigma/src/main/java/cuchaz/enigma/translation/representation/AccessFlags.java | 8 |
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 b27832b..91c9705 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 | ||
| 12 | package cuchaz.enigma.gui; | 12 | package cuchaz.enigma.gui; |
| 13 | 13 | ||
| 14 | import java.awt.Component; | ||
| 14 | import java.awt.event.MouseAdapter; | 15 | import java.awt.event.MouseAdapter; |
| 15 | import java.awt.event.MouseEvent; | 16 | import java.awt.event.MouseEvent; |
| 16 | import java.util.*; | 17 | import 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 139923c..12f1d75 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 6393913..95f0853 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 @@ | |||
| 1 | package cuchaz.enigma.gui.util; | 1 | package cuchaz.enigma.gui.util; |
| 2 | 2 | ||
| 3 | import cuchaz.enigma.gui.Gui; | ||
| 4 | import cuchaz.enigma.translation.representation.AccessFlags; | ||
| 5 | import cuchaz.enigma.translation.representation.entry.ClassEntry; | ||
| 3 | import cuchaz.enigma.utils.Os; | 6 | import cuchaz.enigma.utils.Os; |
| 4 | 7 | ||
| 5 | import javax.imageio.ImageIO; | 8 | import javax.imageio.ImageIO; |
| @@ -16,6 +19,9 @@ import java.util.Map; | |||
| 16 | 19 | ||
| 17 | public class GuiUtil { | 20 | public 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 0000000..9589a67 --- /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 0000000..b64dc82 --- /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 0000000..fc2bfe5 --- /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 f310aa7..8782b8f 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; | |||
| 4 | import cuchaz.enigma.api.service.NameProposalService; | 4 | import cuchaz.enigma.api.service.NameProposalService; |
| 5 | import cuchaz.enigma.translation.TranslateResult; | 5 | import cuchaz.enigma.translation.TranslateResult; |
| 6 | import cuchaz.enigma.translation.mapping.EntryRemapper; | 6 | import cuchaz.enigma.translation.mapping.EntryRemapper; |
| 7 | import cuchaz.enigma.translation.representation.AccessFlags; | ||
| 7 | import cuchaz.enigma.translation.representation.TypeDescriptor; | 8 | import cuchaz.enigma.translation.representation.TypeDescriptor; |
| 8 | import cuchaz.enigma.translation.representation.entry.*; | 9 | import cuchaz.enigma.translation.representation.entry.*; |
| 9 | 10 | ||
| 10 | import javax.swing.tree.DefaultMutableTreeNode; | 11 | import javax.swing.tree.DefaultMutableTreeNode; |
| 12 | import java.util.ArrayList; | ||
| 11 | import java.util.List; | 13 | import java.util.List; |
| 12 | 14 | ||
| 13 | public class StructureTreeNode extends DefaultMutableTreeNode { | 15 | public 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 && !access.isEnum()) { | ||
| 115 | // Abstract, but not an interface, an interface method or an enum class (abstract is the default or meaningless) | ||
| 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 b280eef..e8480a2 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; |