From ad49f6d08133253b5e2e54cc13fe3a54d85bf8d6 Mon Sep 17 00:00:00 2001 From: liach Date: Sun, 24 Feb 2019 12:43:41 -0800 Subject: 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 * Make the text green and italic instead Signed-off-by: liach * Update again for the new tree gen Also tweaked new tree gen to show only useful branch nodes Signed-off-by: liach --- src/main/java/cuchaz/enigma/gui/Gui.java | 14 ++++---- .../cuchaz/enigma/gui/MethodTreeCellRenderer.java | 40 ++++++++++++++++++++++ 2 files changed, 47 insertions(+), 7 deletions(-) create mode 100644 src/main/java/cuchaz/enigma/gui/MethodTreeCellRenderer.java (limited to 'src/main/java/cuchaz/enigma/gui') diff --git a/src/main/java/cuchaz/enigma/gui/Gui.java b/src/main/java/cuchaz/enigma/gui/Gui.java index c419aae..a604323 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; import javax.swing.*; import javax.swing.text.BadLocationException; import javax.swing.text.Highlighter; -import javax.swing.tree.DefaultMutableTreeNode; -import javax.swing.tree.DefaultTreeModel; -import javax.swing.tree.TreeNode; -import javax.swing.tree.TreePath; +import javax.swing.tree.*; import java.awt.*; import java.awt.event.*; import java.nio.file.Path; @@ -153,7 +150,7 @@ public class Gui { inheritanceTree.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent event) { - if (event.getClickCount() == 2) { + if (event.getClickCount() >= 2) { // get the selected node TreePath path = inheritanceTree.getSelectionPath(); if (path == null) { @@ -173,6 +170,9 @@ public class Gui { } } }); + TreeCellRenderer cellRenderer = inheritanceTree.getCellRenderer(); + inheritanceTree.setCellRenderer(new MethodTreeCellRenderer((DefaultTreeCellRenderer) cellRenderer)); + JPanel inheritancePanel = new JPanel(); inheritancePanel.setLayout(new BorderLayout()); inheritancePanel.add(new JScrollPane(inheritanceTree)); @@ -183,7 +183,7 @@ public class Gui { implementationsTree.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent event) { - if (event.getClickCount() == 2) { + if (event.getClickCount() >= 2) { // get the selected node TreePath path = implementationsTree.getSelectionPath(); if (path == null) { @@ -212,7 +212,7 @@ public class Gui { @SuppressWarnings("unchecked") @Override public void mouseClicked(MouseEvent event) { - if (event.getClickCount() == 2) { + if (event.getClickCount() >= 2) { // get the selected node TreePath path = callsTree.getSelectionPath(); 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 0000000..c78ead2 --- /dev/null +++ b/src/main/java/cuchaz/enigma/gui/MethodTreeCellRenderer.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2015 Jeff Martin. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html + *

+ * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ + +package cuchaz.enigma.gui; + +import cuchaz.enigma.analysis.MethodInheritanceTreeNode; + +import javax.swing.*; +import javax.swing.tree.TreeCellRenderer; +import java.awt.*; + +class MethodTreeCellRenderer implements TreeCellRenderer { + + private final TreeCellRenderer parent; + + MethodTreeCellRenderer(TreeCellRenderer parent) { + this.parent = parent; + } + + @Override + public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { + Component ret = parent.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); + if (value instanceof MethodInheritanceTreeNode && ((MethodInheritanceTreeNode) value).isImplemented()) { + ret.setForeground(Color.BLACK); + ret.setFont(ret.getFont().deriveFont(Font.PLAIN)); + } else { + ret.setForeground(Color.GRAY); + ret.setFont(ret.getFont().deriveFont(Font.ITALIC)); + } + return ret; + } +} -- cgit v1.2.3