<commit_before>package com.jetbrains.crucible.ui.toolWindow.details;

import com.intellij.ide.util.treeView.AbstractTreeBuilder;
import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.PopupHandler;
import com.intellij.ui.treeStructure.SimpleTree;
import com.intellij.ui.treeStructure.SimpleTreeStructure;
import com.jetbrains.crucible.actions.AddCommentAction;
import com.jetbrains.crucible.model.Comment;
import com.jetbrains.crucible.model.Review;
import com.jetbrains.crucible.ui.toolWindow.CrucibleTreeStructure;
import com.jetbrains.crucible.utils.CrucibleBundle;
import org.jetbrains.annotations.NotNull;

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

/**
 * User: ktisha
 */
public class CommentsTree extends SimpleTree {

  private static final int ourBalloonWidth = 450;
  private static final int ourBalloonHeight = 400;

  public CommentsTree(@NotNull final Review review, @NotNull final Comment comment,
                      @NotNull final Editor editor, @NotNull final VirtualFile vFile) {
    final CommentNode root = new CommentNode(comment);
    setExpandableItemsEnabled(false);
    setCellRenderer(new DefaultTreeCellRenderer() {
      @Override
      public Component getTreeCellRendererComponent(JTree tree,
                                                    Object value,
                                                    boolean sel,
                                                    boolean expanded,
                                                    boolean leaf,
                                                    int row,
                                                    boolean hasFocus) {
        final JLabel label = (JLabel)super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
        label.setToolTipText(label.getText());
        setIcon(null);
        return label;
      }
    });
    final SimpleTreeStructure structure = new CrucibleTreeStructure(root);

    new AbstractTreeBuilder(this, getBuilderModel(), structure, null);
    invalidate();
    setPreferredSize(new Dimension(ourBalloonWidth, ourBalloonHeight));

    final DefaultActionGroup group = new DefaultActionGroup();
    final AddCommentAction replyToComment =
      new AddCommentAction(review, editor, vFile, CrucibleBundle.message("crucible.add.reply"),true);
    replyToComment.setContextComponent(this);
    group.add(replyToComment);
    PopupHandler.installUnknownPopupHandler(this, group, ActionManager.getInstance());
  }
}<commit_msg>improved comments tree UI a bit<commit_after>package com.jetbrains.crucible.ui.toolWindow.details;

import com.intellij.ide.util.treeView.AbstractTreeBuilder;
import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.JBDefaultTreeCellRenderer;
import com.intellij.ui.PopupHandler;
import com.intellij.ui.treeStructure.SimpleTree;
import com.intellij.ui.treeStructure.SimpleTreeStructure;
import com.intellij.util.ui.UIUtil;
import com.intellij.util.ui.tree.TreeUtil;
import com.jetbrains.crucible.actions.AddCommentAction;
import com.jetbrains.crucible.model.Comment;
import com.jetbrains.crucible.model.Review;
import com.jetbrains.crucible.ui.toolWindow.CrucibleTreeStructure;
import com.jetbrains.crucible.utils.CrucibleBundle;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;

/**
 * User: ktisha
 */
public class CommentsTree extends SimpleTree {

  private static int ourBalloonWidth = 550;
  private static int ourBalloonHeight = 200;

  public CommentsTree(@NotNull final Review review, @NotNull final Comment comment,
                      @NotNull final Editor editor, @NotNull final VirtualFile vFile) {
    final CommentNode root = new CommentNode(comment);
    setExpandableItemsEnabled(false);

    setCellRenderer(new JBDefaultTreeCellRenderer(this) {
      @Override
      public Component getTreeCellRendererComponent(JTree tree,
                                                    Object value,
                                                    boolean sel,
                                                    boolean expanded,
                                                    boolean leaf,
                                                    int row,
                                                    boolean hasFocus) {
        final JLabel label = (JLabel)super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
        label.setToolTipText(label.getText());
        label.setText("<html>" + label.getText() + "</html>");
        setIcon(null);
        String[] lines = UIUtil.splitText(label.getText(), getFontMetrics(UIUtil.getLabelFont()), ourBalloonWidth, ',');
        Font f = label.getFont();
        FontMetrics metrics = label.getFontMetrics(f);
        int hgt = (metrics.getHeight() + 10) * lines.length;
        Dimension size = new Dimension(ourBalloonWidth - 50, hgt);
        label.setPreferredSize(size);
        label.setBorder(BorderFactory.createEtchedBorder());
        label.setVerticalAlignment(TOP);
        return label;
      }
    });
    addComponentListener(new ComponentListener() {
      @Override
      public void componentResized(ComponentEvent e) {
        ourBalloonHeight = e.getComponent().getHeight();
        ourBalloonWidth = e.getComponent().getWidth();
        TreeUtil.collapseAll(CommentsTree.this, -1);
        TreeUtil.expandAll(CommentsTree.this);
      }

      @Override
      public void componentMoved(ComponentEvent e) {
      }

      @Override
      public void componentShown(ComponentEvent e) {
      }

      @Override
      public void componentHidden(ComponentEvent e) {
      }
    });
    final SimpleTreeStructure structure = new CrucibleTreeStructure(root);

    new AbstractTreeBuilder(this, getBuilderModel(), structure, null);
    invalidate();
    setPreferredSize(new Dimension(ourBalloonWidth, ourBalloonHeight));

    final DefaultActionGroup group = new DefaultActionGroup();
    final AddCommentAction replyToComment =
      new AddCommentAction(review, editor, vFile, CrucibleBundle.message("crucible.add.reply"),true);
    replyToComment.setContextComponent(this);
    group.add(replyToComment);
    PopupHandler.installUnknownPopupHandler(this, group, ActionManager.getInstance());
    TreeUtil.expandAll(this);
  }
}
{'fraction_non_alphanumeric': 0.08904719501335707, 'fraction_numerical': 0.0025230038587117838, 'mean_word_length': 2.9112013929193266, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4154093', 'n_tokens_mistral': 1799, 'n_tokens_neox': 1701, 'n_words': 355}