summaryrefslogtreecommitdiff
path: root/enigma-swing/src/main/java/cuchaz/enigma/gui/renderer/ImplementationsTreeCellRenderer.java
blob: 7bf390053a355b620480b41456ae7a30213d8fe7 (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
package cuchaz.enigma.gui.renderer;

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;

import javax.swing.*;
import javax.swing.tree.DefaultTreeCellRenderer;
import java.awt.*;

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;
    }
}