summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar liach2019-02-24 12:43:41 -0800
committerGravatar Gegy2019-02-24 22:43:41 +0200
commitad49f6d08133253b5e2e54cc13fe3a54d85bf8d6 (patch)
tree81feffbf613a13d386eddb98a8df901e8b19e303 /src
parentFix name duplication checking not occurring on root classes (diff)
downloadenigma-ad49f6d08133253b5e2e54cc13fe3a54d85bf8d6.tar.gz
enigma-ad49f6d08133253b5e2e54cc13fe3a54d85bf8d6.tar.xz
enigma-ad49f6d08133253b5e2e54cc13fe3a54d85bf8d6.zip
Adds a red highlight for overridden methods in method inheritance tree gui (#112)
* Make implemented method nodes in inheritance ui more obvious Signed-off-by: liach <liach@users.noreply.github.com> * Make the text green and italic instead Signed-off-by: liach <liach@users.noreply.github.com> * Update again for the new tree gen Also tweaked new tree gen to show only useful branch nodes Signed-off-by: liach <liach@users.noreply.github.com>
Diffstat (limited to 'src')
-rw-r--r--src/main/java/cuchaz/enigma/analysis/MethodInheritanceTreeNode.java27
-rw-r--r--src/main/java/cuchaz/enigma/gui/Gui.java14
-rw-r--r--src/main/java/cuchaz/enigma/gui/MethodTreeCellRenderer.java40
3 files changed, 62 insertions, 19 deletions
diff --git a/src/main/java/cuchaz/enigma/analysis/MethodInheritanceTreeNode.java b/src/main/java/cuchaz/enigma/analysis/MethodInheritanceTreeNode.java
index 862bb92a..e77b5cce 100644
--- a/src/main/java/cuchaz/enigma/analysis/MethodInheritanceTreeNode.java
+++ b/src/main/java/cuchaz/enigma/analysis/MethodInheritanceTreeNode.java
@@ -24,12 +24,12 @@ public class MethodInheritanceTreeNode extends DefaultMutableTreeNode {
24 24
25 private final Translator translator; 25 private final Translator translator;
26 private MethodEntry entry; 26 private MethodEntry entry;
27 private boolean isImplemented; 27 private boolean implemented;
28 28
29 public MethodInheritanceTreeNode(Translator translator, MethodEntry entry, boolean isImplemented) { 29 public MethodInheritanceTreeNode(Translator translator, MethodEntry entry, boolean implemented) {
30 this.translator = translator; 30 this.translator = translator;
31 this.entry = entry; 31 this.entry = entry;
32 this.isImplemented = isImplemented; 32 this.implemented = implemented;
33 } 33 }
34 34
35 public static MethodInheritanceTreeNode findNode(MethodInheritanceTreeNode node, MethodEntry entry) { 35 public static MethodInheritanceTreeNode findNode(MethodInheritanceTreeNode node, MethodEntry entry) {
@@ -53,11 +53,7 @@ public class MethodInheritanceTreeNode extends DefaultMutableTreeNode {
53 } 53 }
54 54
55 public boolean isImplemented() { 55 public boolean isImplemented() {
56 return this.isImplemented; 56 return this.implemented;
57 }
58
59 public boolean shouldExpand() {
60 return this.isImplemented || !this.isLeaf();
61 } 57 }
62 58
63 @Override 59 @Override
@@ -65,7 +61,7 @@ public class MethodInheritanceTreeNode extends DefaultMutableTreeNode {
65 MethodEntry translatedEntry = translator.translate(entry); 61 MethodEntry translatedEntry = translator.translate(entry);
66 String className = translatedEntry.getContainingClass().getFullName(); 62 String className = translatedEntry.getContainingClass().getFullName();
67 63
68 if (!this.isImplemented) { 64 if (!this.implemented) {
69 return className; 65 return className;
70 } else { 66 } else {
71 String methodName = translatedEntry.getName(); 67 String methodName = translatedEntry.getName();
@@ -73,20 +69,27 @@ public class MethodInheritanceTreeNode extends DefaultMutableTreeNode {
73 } 69 }
74 } 70 }
75 71
76 public void load(JarIndex index) { 72 /**
73 * Returns true if there is sub-node worthy to display.
74 */
75 public boolean load(JarIndex index) {
77 // get all the child nodes 76 // get all the child nodes
78 EntryIndex entryIndex = index.getEntryIndex(); 77 EntryIndex entryIndex = index.getEntryIndex();
79 InheritanceIndex inheritanceIndex = index.getInheritanceIndex(); 78 InheritanceIndex inheritanceIndex = index.getInheritanceIndex();
80 79
80 boolean ret = false;
81 for (ClassEntry inheritorEntry : inheritanceIndex.getChildren(this.entry.getParent())) { 81 for (ClassEntry inheritorEntry : inheritanceIndex.getChildren(this.entry.getParent())) {
82 MethodEntry methodEntry = new MethodEntry(inheritorEntry, this.entry.getName(), this.entry.getDesc()); 82 MethodEntry methodEntry = new MethodEntry(inheritorEntry, this.entry.getName(), this.entry.getDesc());
83 83
84 MethodInheritanceTreeNode node = new MethodInheritanceTreeNode(translator, methodEntry, entryIndex.hasMethod(methodEntry)); 84 MethodInheritanceTreeNode node = new MethodInheritanceTreeNode(translator, methodEntry, entryIndex.hasMethod(methodEntry));
85 node.load(index); 85 boolean childOverride = node.load(index);
86 86
87 if (node.shouldExpand()) { 87 if (childOverride || node.implemented) {
88 this.add(node); 88 this.add(node);
89 ret = true;
89 } 90 }
90 } 91 }
92
93 return ret;
91 } 94 }
92} 95}
diff --git a/src/main/java/cuchaz/enigma/gui/Gui.java b/src/main/java/cuchaz/enigma/gui/Gui.java
index c419aae8..a6043234 100644
--- a/src/main/java/cuchaz/enigma/gui/Gui.java
+++ b/src/main/java/cuchaz/enigma/gui/Gui.java
@@ -38,10 +38,7 @@ import de.sciss.syntaxpane.DefaultSyntaxKit;
38import javax.swing.*; 38import javax.swing.*;
39import javax.swing.text.BadLocationException; 39import javax.swing.text.BadLocationException;
40import javax.swing.text.Highlighter; 40import javax.swing.text.Highlighter;
41import javax.swing.tree.DefaultMutableTreeNode; 41import javax.swing.tree.*;
42import javax.swing.tree.DefaultTreeModel;
43import javax.swing.tree.TreeNode;
44import javax.swing.tree.TreePath;
45import java.awt.*; 42import java.awt.*;
46import java.awt.event.*; 43import java.awt.event.*;
47import java.nio.file.Path; 44import java.nio.file.Path;
@@ -153,7 +150,7 @@ public class Gui {
153 inheritanceTree.addMouseListener(new MouseAdapter() { 150 inheritanceTree.addMouseListener(new MouseAdapter() {
154 @Override 151 @Override
155 public void mouseClicked(MouseEvent event) { 152 public void mouseClicked(MouseEvent event) {
156 if (event.getClickCount() == 2) { 153 if (event.getClickCount() >= 2) {
157 // get the selected node 154 // get the selected node
158 TreePath path = inheritanceTree.getSelectionPath(); 155 TreePath path = inheritanceTree.getSelectionPath();
159 if (path == null) { 156 if (path == null) {
@@ -173,6 +170,9 @@ public class Gui {
173 } 170 }
174 } 171 }
175 }); 172 });
173 TreeCellRenderer cellRenderer = inheritanceTree.getCellRenderer();
174 inheritanceTree.setCellRenderer(new MethodTreeCellRenderer((DefaultTreeCellRenderer) cellRenderer));
175
176 JPanel inheritancePanel = new JPanel(); 176 JPanel inheritancePanel = new JPanel();
177 inheritancePanel.setLayout(new BorderLayout()); 177 inheritancePanel.setLayout(new BorderLayout());
178 inheritancePanel.add(new JScrollPane(inheritanceTree)); 178 inheritancePanel.add(new JScrollPane(inheritanceTree));
@@ -183,7 +183,7 @@ public class Gui {
183 implementationsTree.addMouseListener(new MouseAdapter() { 183 implementationsTree.addMouseListener(new MouseAdapter() {
184 @Override 184 @Override
185 public void mouseClicked(MouseEvent event) { 185 public void mouseClicked(MouseEvent event) {
186 if (event.getClickCount() == 2) { 186 if (event.getClickCount() >= 2) {
187 // get the selected node 187 // get the selected node
188 TreePath path = implementationsTree.getSelectionPath(); 188 TreePath path = implementationsTree.getSelectionPath();
189 if (path == null) { 189 if (path == null) {
@@ -212,7 +212,7 @@ public class Gui {
212 @SuppressWarnings("unchecked") 212 @SuppressWarnings("unchecked")
213 @Override 213 @Override
214 public void mouseClicked(MouseEvent event) { 214 public void mouseClicked(MouseEvent event) {
215 if (event.getClickCount() == 2) { 215 if (event.getClickCount() >= 2) {
216 // get the selected node 216 // get the selected node
217 TreePath path = callsTree.getSelectionPath(); 217 TreePath path = callsTree.getSelectionPath();
218 if (path == null) { 218 if (path == null) {
diff --git a/src/main/java/cuchaz/enigma/gui/MethodTreeCellRenderer.java b/src/main/java/cuchaz/enigma/gui/MethodTreeCellRenderer.java
new file mode 100644
index 00000000..c78ead23
--- /dev/null
+++ b/src/main/java/cuchaz/enigma/gui/MethodTreeCellRenderer.java
@@ -0,0 +1,40 @@
1/*******************************************************************************
2 * Copyright (c) 2015 Jeff Martin.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the GNU Lesser General Public
5 * License v3.0 which accompanies this distribution, and is available at
6 * http://www.gnu.org/licenses/lgpl.html
7 * <p>
8 * Contributors:
9 * Jeff Martin - initial API and implementation
10 ******************************************************************************/
11
12package cuchaz.enigma.gui;
13
14import cuchaz.enigma.analysis.MethodInheritanceTreeNode;
15
16import javax.swing.*;
17import javax.swing.tree.TreeCellRenderer;
18import java.awt.*;
19
20class MethodTreeCellRenderer implements TreeCellRenderer {
21
22 private final TreeCellRenderer parent;
23
24 MethodTreeCellRenderer(TreeCellRenderer parent) {
25 this.parent = parent;
26 }
27
28 @Override
29 public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
30 Component ret = parent.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
31 if (value instanceof MethodInheritanceTreeNode && ((MethodInheritanceTreeNode) value).isImplemented()) {
32 ret.setForeground(Color.BLACK);
33 ret.setFont(ret.getFont().deriveFont(Font.PLAIN));
34 } else {
35 ret.setForeground(Color.GRAY);
36 ret.setFont(ret.getFont().deriveFont(Font.ITALIC));
37 }
38 return ret;
39 }
40}