summaryrefslogtreecommitdiff
path: root/enigma-swing/src/main/java/cuchaz/enigma/gui/renderer/ImplementationsTreeCellRenderer.java
blob: b4126c025991a8f23727a458fee9cae0ef1ea02b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package cuchaz.enigma.gui.renderer;

import java.awt.Component;

import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer;

import cuchaz.enigma.analysis.ClassImplementationsTreeNode;
import cuchaz.enigma.analysis.MethodImplementationsTreeNode;
import cuchaz.enigma.gui.Gui;
import cuchaz.enigma.gui.config.UiConfig;
import cuchaz.enigma.gui.util.GuiUtil;

public class ImplementationsTreeCellRenderer extends DefaultTreeCellRenderer {
	private final Gui gui;

	public ImplementationsTreeCellRenderer(Gui gui) {
		this.gui = gui;
	}

	@Override
	public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
		Component c = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);

		this.setForeground(UiConfig.getTextColor());

		if (value instanceof ClassImplementationsTreeNode node) {
			this.setIcon(GuiUtil.getClassIcon(this.gui, node.getClassEntry()));
		} else if (value instanceof MethodImplementationsTreeNode node) {
			this.setIcon(GuiUtil.getMethodIcon(node.getMethodEntry()));
		}

		return c;
	}
}