package org.hanuna.gitalk.swing_ui.render;

import org.hanuna.gitalk.common.OneElementList;
import org.hanuna.gitalk.swing_ui.render.painters.RefPainter;
import org.hanuna.gitalk.ui.tables.refs.refs.RefTreeTableNode;

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

/**
* @author erokhins
*/
public class RefTreeCellRender implements TreeCellRenderer {
    private final RefPainter refPainter = new RefPainter();
    private RefTreeTableNode node;
    private final JLabel label = new JLabel() {
        @Override
        public void paint(Graphics g) {
            if (node.isRefNode()) {
                refPainter.draw((Graphics2D) g, OneElementList.buildList(node.getRef()), 0);
            } else {
                super.paint(g);
            }
        }
    };

    @Override
    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
        this.node = (RefTreeTableNode) value;
        label.setFont(new Font("Arial", Font.BOLD, 14));

        if (node.isRefNode()) {
            label.setText(node.getRef().getName() + "   ");
        } else {
            label.setText(node.getText());
        }
        return label;
    }
}

@@ -293,16 +293,132 @@
 a.awt.*;
+%0Aimport java.awt.image.BufferedImage;%0A%0Aimport static org.hanuna.gitalk.swing_ui.render.Print_Parameters.HEIGHT_CELL;
 %0A%0A/**%0A* 
@@ -755,82 +755,332 @@
     
-refPainter.draw((Graphics2D) g, OneElementList.buildList(node.getRef()), 0
+BufferedImage image = new BufferedImage(1000, HEIGHT_CELL, BufferedImage.TYPE_INT_ARGB);%0A                Graphics2D g2 = image.createGraphics();%0A                g2.setBackground(new Color(0,0,0,0));%0A                refPainter.draw(g2, OneElementList.buildList(node.getRef()), 0);%0A                g.drawImage(image,0, 0, null
 );%0A 

fix draw refs