package SapforTestingSystem.SapforTasksPackage.UI;
import Common.UI.Trees.StyledTreeCellRenderer;
import SapforTestingSystem.Json.SapforVersion_json;

import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import java.util.Objects;
public class SapforVersionsTreeCellRenderer extends StyledTreeCellRenderer {
    public java.awt.Component getTreeCellRendererComponent(
            JTree tree, Object value,
            boolean selected, boolean expanded,
            boolean leaf, int row, boolean hasFocus) {
        super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
        Object o = ((DefaultMutableTreeNode) value).getUserObject();
        if (o instanceof TreeSummary) {
            TreeSummary summary = (TreeSummary) o;
            setForeground(tree.getForeground());
            setFont(getFont().deriveFont((float) 14.0));
            setIcon(summary.getIcon());
        }
        else {
            if (o instanceof SapforVersion_json){
                SapforVersion_json version_json = (SapforVersion_json) o;
                setForeground(tree.getForeground());
                setFont(getFont().deriveFont((float) 14.0));
                setIcon(new ImageIcon(Objects.requireNonNull(getClass().getResource("/icons/versions/TestVersion.png"))));
                setText(version_json.toString());
            }
        }
        return this;
    }
}
