From 68aaf143193201ecf71ced2ae6cd9eca7a0225a1 Mon Sep 17 00:00:00 2001 From: Juuxel Date: Tue, 15 Dec 2020 23:28:05 +0200 Subject: 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. --- .../main/java/cuchaz/enigma/gui/ClassSelector.java | 19 ++++++++++++++-- .../cuchaz/enigma/gui/panels/StructurePanel.java | 11 +++++++--- .../main/java/cuchaz/enigma/gui/util/GuiUtil.java | 24 +++++++++++++++++++++ .../src/main/resources/icons/annotation.png | Bin 0 -> 877 bytes enigma-swing/src/main/resources/icons/enum.png | Bin 0 -> 506 bytes .../src/main/resources/icons/interface.png | Bin 0 -> 538 bytes 6 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 enigma-swing/src/main/resources/icons/annotation.png create mode 100644 enigma-swing/src/main/resources/icons/enum.png create mode 100644 enigma-swing/src/main/resources/icons/interface.png (limited to 'enigma-swing/src') 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 @@ package cuchaz.enigma.gui; +import java.awt.Component; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.*; @@ -70,8 +71,22 @@ public class ClassSelector extends JTree { } }); - final DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer(); - renderer.setLeafIcon(GuiUtil.CLASS_ICON); + final DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer() { + { + setLeafIcon(GuiUtil.CLASS_ICON); + } + + @Override + public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { + super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); + + if (leaf && value instanceof ClassSelectorClassNode) { + setIcon(GuiUtil.getClassIcon(gui, ((ClassSelectorClassNode) value).getObfEntry())); + } + + return this; + } + }; setCellRenderer(renderer); 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 { this.structureTree = new JTree(); this.structureTree.setModel(null); - this.structureTree.setCellRenderer(new StructureTreeCellRenderer()); + this.structureTree.setCellRenderer(new StructureTreeCellRenderer(gui)); this.structureTree.setShowsRootHandles(true); this.structureTree.addMouseListener(new MouseAdapter() { @Override @@ -76,6 +76,11 @@ public class StructurePanel extends JPanel { } class StructureTreeCellRenderer extends DefaultTreeCellRenderer { + private final Gui gui; + + StructureTreeCellRenderer(Gui gui) { + this.gui = gui; + } @Override 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 { ParentedEntry entry = ((StructureTreeNode) value).getEntry(); if (entry instanceof ClassEntry) { - this.setIcon(GuiUtil.CLASS_ICON); + this.setIcon(GuiUtil.getClassIcon(gui, (ClassEntry) entry)); } else if (entry instanceof MethodEntry) { this.setIcon(((MethodEntry) entry).isConstructor() ? GuiUtil.CONSTRUCTOR_ICON : GuiUtil.METHOD_ICON); } else if (entry instanceof FieldEntry) { this.setIcon(GuiUtil.FIELD_ICON); } - this.setText(value.toString()); + this.setText("" + ((StructureTreeNode) value).toHtml()); return c; } 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 @@ package cuchaz.enigma.gui.util; +import cuchaz.enigma.gui.Gui; +import cuchaz.enigma.translation.representation.AccessFlags; +import cuchaz.enigma.translation.representation.entry.ClassEntry; import cuchaz.enigma.utils.Os; import javax.imageio.ImageIO; @@ -16,6 +19,9 @@ import java.util.Map; public class GuiUtil { public static final Icon CLASS_ICON = loadIcon("class"); + public static final Icon INTERFACE_ICON = loadIcon("interface"); + public static final Icon ENUM_ICON = loadIcon("enum"); + public static final Icon ANNOTATION_ICON = loadIcon("annotation"); public static final Icon METHOD_ICON = loadIcon("method"); public static final Icon FIELD_ICON = loadIcon("field"); public static final Icon CONSTRUCTOR_ICON = loadIcon("constructor"); @@ -82,4 +88,22 @@ public class GuiUtil { return null; } + + public static Icon getClassIcon(Gui gui, ClassEntry entry) { + AccessFlags access = gui.getController().project.getJarIndex().getEntryIndex().getClassAccess(entry); + + if (access != null) { + if (access.isAnnotation()) { + return ANNOTATION_ICON; + } else if (access.isInterface()) { + return INTERFACE_ICON; + } else if (access.isEnum()) { + return ENUM_ICON; + } + + // TODO: Record icon? + } + + return CLASS_ICON; + } } 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 Binary files /dev/null and b/enigma-swing/src/main/resources/icons/annotation.png 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 Binary files /dev/null and b/enigma-swing/src/main/resources/icons/enum.png 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 Binary files /dev/null and b/enigma-swing/src/main/resources/icons/interface.png differ -- cgit v1.2.3