<commit_before>package org.hanuna.gitalk.swing_ui.render;

import org.hanuna.gitalk.ui.tables.GraphCommitCell;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;
import java.awt.*;

/**
 * @author erokhins
 */
public abstract class AbstractPaddingCellRender implements TableCellRenderer {
  public static final Color MARKED_BACKGROUND = new Color(0xB6, 0xE4, 0xFF);

  private ExtDefaultCellRender cellRender = new ExtDefaultCellRender();

  protected abstract int getLeftPadding(JTable table, @Nullable Object value);

  protected abstract String getCellText(JTable table, @Nullable Object value);

  protected abstract void additionPaint(Graphics g, JTable table, @Nullable Object value);

  protected abstract boolean isMarked(JTable table, @Nullable Object value);

  protected abstract GraphCommitCell.Kind getKind(JTable table, @Nullable Object value);

  @Override
  public Component getTableCellRendererComponent(JTable table, @Nullable Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    return cellRender.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
  }

  public class ExtDefaultCellRender extends DefaultTableCellRenderer {
    private JTable table;
    private Object value;

    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
      this.table = table;
      this.value = value;
      super.getTableCellRendererComponent(table, getCellText(table, value), isSelected, hasFocus, row, column);
      if (isMarked(table, value) && !isSelected) {
        setBackground(MARKED_BACKGROUND);
      }
      else {
        setBackground(isSelected ? table.getSelectionBackground() : Color.WHITE);
      }
      Border paddingBorder = BorderFactory.createEmptyBorder(0, getLeftPadding(table, value), 0, 0);
      this.setBorder(BorderFactory.createCompoundBorder(this.getBorder(), paddingBorder));

      GraphCommitCell.Kind kind = getKind(table, value);
      switch (kind) {
        case APPLIED:
          setForeground(Color.GREEN);
          break;
        case NORMAL:
          setForeground(Color.BLACK);
          break;<commit_msg>(Hackathon over) better appearance of APPLY commits<commit_after>package org.hanuna.gitalk.swing_ui.render;

import org.hanuna.gitalk.ui.tables.GraphCommitCell;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;
import java.awt.*;

/**
 * @author erokhins
 */
public abstract class AbstractPaddingCellRender implements TableCellRenderer {
  public static final Color MARKED_BACKGROUND = new Color(0xB6, 0xE4, 0xFF);
  public static final Color APPLIED_BACKGROUND = new Color(0x92, 0xF5, 0x8F);

  private ExtDefaultCellRender cellRender = new ExtDefaultCellRender();

  protected abstract int getLeftPadding(JTable table, @Nullable Object value);

  protected abstract String getCellText(JTable table, @Nullable Object value);

  protected abstract void additionPaint(Graphics g, JTable table, @Nullable Object value);

  protected abstract boolean isMarked(JTable table, @Nullable Object value);

  protected abstract GraphCommitCell.Kind getKind(JTable table, @Nullable Object value);

  @Override
  public Component getTableCellRendererComponent(JTable table, @Nullable Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    return cellRender.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
  }

  public class ExtDefaultCellRender extends DefaultTableCellRenderer {
    private JTable table;
    private Object value;

    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
      this.table = table;
      this.value = value;
      super.getTableCellRendererComponent(table, getCellText(table, value), isSelected, hasFocus, row, column);
      if (isMarked(table, value) && !isSelected) {
        setBackground(MARKED_BACKGROUND);
      }
      else {
        setBackground(isSelected ? table.getSelectionBackground() : Color.WHITE);
      }
      Border paddingBorder = BorderFactory.createEmptyBorder(0, getLeftPadding(table, value), 0, 0);
      this.setBorder(BorderFactory.createCompoundBorder(this.getBorder(), paddingBorder));

      GraphCommitCell.Kind kind = getKind(table, value);
      switch (kind) {
        case APPLIED:
          setBackground(APPLIED_BACKGROUND);
          break;
        case NORMAL:
          setForeground(Color.BLACK);
          break;
{'fraction_non_alphanumeric': 0.08435742553634659, 'fraction_numerical': 0.0047906686107061025, 'mean_word_length': 4.545034642032332, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '382201', 'n_tokens_mistral': 1313, 'n_tokens_neox': 1266, 'n_words': 356}