summaryrefslogtreecommitdiff
path: root/enigma-swing/src/main/java/cuchaz/enigma/gui/renderer/CallsTreeCellRenderer.java
blob: 0aa6510c03de28e3d1ebcf4e75d5c192ed78dada (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
36
37
38
39
40
41
42
43
44
45
package cuchaz.enigma.gui.renderer;

import cuchaz.enigma.analysis.*;
import cuchaz.enigma.gui.Gui;
import cuchaz.enigma.gui.config.UiConfig;
import cuchaz.enigma.gui.util.GuiUtil;
import cuchaz.enigma.translation.representation.entry.MethodEntry;

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

public class CallsTreeCellRenderer extends DefaultTreeCellRenderer {
    private final Gui gui;

    public CallsTreeCellRenderer(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);
        EntryReference<?, ?> reference = ((ReferenceTreeNode<?, ?>) value).getReference();

        this.setForeground(UiConfig.getTextColor());

        // if the node represents the method calling the entry
        if (reference != null) {
            if (reference.context instanceof MethodEntry) {
                this.setIcon(GuiUtil.getMethodIcon((MethodEntry) reference.context));
            }
        // if the node represents the called entry
        } else {
            if (value instanceof ClassReferenceTreeNode node) {
                this.setIcon(GuiUtil.getClassIcon(this.gui, node.getEntry()));
            } else if (value instanceof MethodReferenceTreeNode node) {
                this.setIcon(GuiUtil.getMethodIcon(node.getEntry()));
            } else if (value instanceof FieldReferenceTreeNode) {
                this.setIcon(GuiUtil.FIELD_ICON);
            }
        }

        return c;
    }
}