diff options
| author | 2021-01-24 13:17:40 +0100 | |
|---|---|---|
| committer | 2021-01-24 13:17:40 +0100 | |
| commit | 3d18c175d7bbd1c3b7b7f24ae2bb4b9bc6cae17f (patch) | |
| tree | a9ebb8ac0bfc143f112af9f4205ced28fa1622e5 /enigma-swing/src | |
| parent | Fixed Javadoc not updating in certain cases (close/open mappings) (diff) | |
| parent | Exclude abstract modifier from enum classes (diff) | |
| download | enigma-3d18c175d7bbd1c3b7b7f24ae2bb4b9bc6cae17f.tar.gz enigma-3d18c175d7bbd1c3b7b7f24ae2bb4b9bc6cae17f.tar.xz enigma-3d18c175d7bbd1c3b7b7f24ae2bb4b9bc6cae17f.zip | |
Merge pull request #340 from Juuxel/better-icons
Add interface/enum/annotation icons and modifier displays
Diffstat (limited to 'enigma-swing/src')
| -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 |
6 files changed, 49 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 | ||
| 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 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 @@ | |||
| 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 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 | |||