<commit_before>// -*- mode:java; encoding:utf-8 -*-
// vim:set fileencoding=utf-8:
// @homepage@

package example;

import java.awt.*;
import javax.swing.*;
import javax.swing.text.JTextComponent;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;

public final class MainPanel extends JPanel {
  private static final String DUMMY_TEXT = "Quartz glyph job vex'd cwm finks.";

  private MainPanel() {
    super(new GridLayout(3, 1));

    JTextPane label1 = new JTextPane();
    // MutableAttributeSet attr = new SimpleAttributeSet();
    Style attr = label1.getStyle(StyleContext.DEFAULT_STYLE);
    StyleConstants.setLineSpacing(attr, -.2f);
    label1.setParagraphAttributes(attr, true);
    label1.setText("JTextPane\n" + DUMMY_TEXT);
    // [XP Style Icons - Download](https://xp-style-icons.en.softonic.com/)
    ImageIcon icon = new ImageIcon(getClass().getResource("wi0124-32.png"));
    add(makeLeftIcon(label1, icon));

    JTextArea label2 = new JTextArea("JTextArea\n" + DUMMY_TEXT);
    add(makeLeftIcon(label2, icon));

    JLabel label3 = new JLabel("<html>JLabel+html<br>" + DUMMY_TEXT);
    label3.setIcon(icon);
    add(label3);

    setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
    setPreferredSize(new Dimension(320, 240));
  }

  private static Box makeLeftIcon(JTextComponent label, ImageIcon icon) {
    label.setForeground(UIManager.getColor("Label.foreground"));
    // label.setBackground(UIManager.getColor("Label.background"));
    label.setOpaque(false);
    label.setEditable(false);
    label.setFocusable(false);
    label.setMaximumSize(label.getPreferredSize());
    label.setMinimumSize(label.getPreferredSize());
<commit_msg>refactor: argument 'getClass().getResource(...)' might be null<commit_after>// -*- mode:java; encoding:utf-8 -*-
// vim:set fileencoding=utf-8:
// @homepage@

package example;

import java.awt.*;
import java.io.IOException;
import java.io.InputStream;
import java.util.Optional;
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.text.JTextComponent;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;

public final class MainPanel extends JPanel {
  private static final String TEXT = "Quartz glyph job vex'd cwm finks.";

  private MainPanel() {
    super(new GridLayout(3, 1));
    JTextPane label1 = new JTextPane();
    // MutableAttributeSet attr = new SimpleAttributeSet();
    Style attr = label1.getStyle(StyleContext.DEFAULT_STYLE);
    StyleConstants.setLineSpacing(attr, -.2f);
    label1.setParagraphAttributes(attr, true);
    label1.setText("JTextPane\n" + TEXT);
    // [XP Style Icons - Download](https://xp-style-icons.en.softonic.com/)
    String path = "example/wi0124-32.png";
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    Icon icon = Optional.ofNullable(cl.getResource(path)).map(url -> {
      try (InputStream s = url.openStream()) {
        return new ImageIcon(ImageIO.read(s));
      } catch (IOException ex) {
        return UIManager.getIcon("OptionPane.errorIcon");
      }
    }).orElseGet(() -> UIManager.getIcon("OptionPane.errorIcon"));
    add(makeLeftIcon(label1, icon));

    JTextArea label2 = new JTextArea("JTextArea\n" + TEXT);
    add(makeLeftIcon(label2, icon));

    JLabel label3 = new JLabel("<html>JLabel+html<br>" + TEXT);
    label3.setIcon(icon);
    add(label3);

    setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
    setPreferredSize(new Dimension(320, 240));
  }

  private static Box makeLeftIcon(JTextComponent label, Icon icon) {
    label.setForeground(UIManager.getColor("Label.foreground"));
    // label.setBackground(UIManager.getColor("Label.background"));
    label.setOpaque(false);
    label.setEditable(false);
    label.setFocusable(false);
    label.setMaximumSize(label.getPreferredSize());
    label.setMinimumSize(label.getPreferredSize());

{'fraction_non_alphanumeric': 0.14004044489383216, 'fraction_numerical': 0.015672396359959553, 'mean_word_length': 4.391008174386921, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2393329', 'n_tokens_mistral': 1294, 'n_tokens_neox': 1256, 'n_words': 240}