<commit_before>package example;
//-*- mode:java; encoding:utf-8 -*-
// vim:set fileencoding=utf-8:
//@homepage@
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;

public final class MainPanel extends JPanel {
    private final String[] columnNames = {"user", "rwx"};
    private final Object[][] data = {
        {"owner", 7}, {"group", 6}, {"other", 5}
    };
    private final DefaultTableModel model = new DefaultTableModel(data, columnNames) {
        @Override public Class<?> getColumnClass(int column) {
            return getValueAt(0, column).getClass();
        }
    };
    private final JTable table = new JTable(model);

    public MainPanel() {
        super(new BorderLayout());
        table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
        if (System.getProperty("java.version").startsWith("1.6.0")) {
            //1.6.0_xx bug? column header click -> edit cancel?
            table.getTableHeader().addMouseListener(new MouseAdapter() {
                @Override public void mousePressed(MouseEvent e) {
                    if (table.isEditing()) {
                        table.getCellEditor().stopCellEditing();
                    }
                }
            });
        }

        //http://ateraimemo.com/Swing/TerminateEdit.html
        //table.getTableHeader().setReorderingAllowed(false);
        //frame.setResizeable(false);
        //or
//         table.addMouseListener(new MouseAdapter() {
//             @Override public void mouseReleased(MouseEvent e) {
//                 JTable t = (JTable) e.getComponent();
//                 Point p  = e.getPoint();
//                 int row  = t.rowAtPoint(p);
//                 int col  = t.columnAtPoint(p);
//                 if (t.convertColumnIndexToModel(col) == 1) {
//                     t.getCellEditor(row, col).stopCellEditing();
//                 }
//             }
//         });

        table.getColumnModel().getColumn(1).setCellRenderer(new CheckBoxesRenderer());
        table.getColumnModel().getColumn(1).setCellEditor(new CheckBoxesEditor());

        add(new JScrollPane(table));
        setPreferredSize(new Dimension(320, 240));
    }
    public static void main(String... args) {
        EventQueue.invokeLater(new Runnable() {
            @Override public void run() {
                createAndShowGUI();
            }
        });
    }
    public static void createAndShowGUI() {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException | InstantiationException
               | IllegalAccessException | UnsupportedLookAndFeelException ex) {
            ex.printStackTrace();
        }
        JFrame frame = new JFrame("@title@");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.getContentPane().add(new MainPanel());
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}

class CheckBoxesPanel extends JPanel {
    protected final String[] title = {"r", "w", "x"};
    public JCheckBox[] buttons;
    protected CheckBoxesPanel() {
        super();
        setOpaque(false);
        setBackground(new Color(0x0, true));
        setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
        initButtons();
    }
    private void initButtons() {
        buttons = new JCheckBox[title.length];
        for (int i = 0; i < buttons.length; i++) {
            JCheckBox b = new JCheckBox(title[i]);
            b.setOpaque(false);
            b.setFocusable(false);
            b.setRolloverEnabled(false);
            b.setBackground(new Color(0x0, true));
            buttons[i] = b;
            add(b);
            add(Box.createHorizontalStrut(5));
        }
    }
    protected void updateButtons(Object v) {
        removeAll();
        initButtons();
        Integer i = (Integer) (Objects.nonNull(v) ? v : 0);
        buttons[0].setSelected((i & (1 << 2)) != 0);
        buttons[1].setSelected((i & (1 << 1)) != 0);
        buttons[2].setSelected((i & (1 << 0)) != 0);
    }
}
<commit_msg>refactor: use an instanceof operator instead of Objects.nonNull(...)<commit_after>package example;
//-*- mode:java; encoding:utf-8 -*-
// vim:set fileencoding=utf-8:
//@homepage@
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;

public final class MainPanel extends JPanel {
    private final String[] columnNames = {"user", "rwx"};
    private final Object[][] data = {
        {"owner", 7}, {"group", 6}, {"other", 5}
    };
    private final DefaultTableModel model = new DefaultTableModel(data, columnNames) {
        @Override public Class<?> getColumnClass(int column) {
            return getValueAt(0, column).getClass();
        }
    };
    private final JTable table = new JTable(model);

    public MainPanel() {
        super(new BorderLayout());
        table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
        if (System.getProperty("java.version").startsWith("1.6.0")) {
            //1.6.0_xx bug? column header click -> edit cancel?
            table.getTableHeader().addMouseListener(new MouseAdapter() {
                @Override public void mousePressed(MouseEvent e) {
                    if (table.isEditing()) {
                        table.getCellEditor().stopCellEditing();
                    }
                }
            });
        }

        //http://ateraimemo.com/Swing/TerminateEdit.html
        //table.getTableHeader().setReorderingAllowed(false);
        //frame.setResizeable(false);
        //or
//         table.addMouseListener(new MouseAdapter() {
//             @Override public void mouseReleased(MouseEvent e) {
//                 JTable t = (JTable) e.getComponent();
//                 Point p  = e.getPoint();
//                 int row  = t.rowAtPoint(p);
//                 int col  = t.columnAtPoint(p);
//                 if (t.convertColumnIndexToModel(col) == 1) {
//                     t.getCellEditor(row, col).stopCellEditing();
//                 }
//             }
//         });

        table.getColumnModel().getColumn(1).setCellRenderer(new CheckBoxesRenderer());
        table.getColumnModel().getColumn(1).setCellEditor(new CheckBoxesEditor());

        add(new JScrollPane(table));
        setPreferredSize(new Dimension(320, 240));
    }
    public static void main(String... args) {
        EventQueue.invokeLater(new Runnable() {
            @Override public void run() {
                createAndShowGUI();
            }
        });
    }
    public static void createAndShowGUI() {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException | InstantiationException
               | IllegalAccessException | UnsupportedLookAndFeelException ex) {
            ex.printStackTrace();
        }
        JFrame frame = new JFrame("@title@");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.getContentPane().add(new MainPanel());
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}

class CheckBoxesPanel extends JPanel {
    protected final String[] title = {"r", "w", "x"};
    public JCheckBox[] buttons;
    protected CheckBoxesPanel() {
        super();
        setOpaque(false);
        setBackground(new Color(0x0, true));
        setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
        initButtons();
    }
    private void initButtons() {
        buttons = new JCheckBox[title.length];
        for (int i = 0; i < buttons.length; i++) {
            JCheckBox b = new JCheckBox(title[i]);
            b.setOpaque(false);
            b.setFocusable(false);
            b.setRolloverEnabled(false);
            b.setBackground(new Color(0x0, true));
            buttons[i] = b;
            add(b);
            add(Box.createHorizontalStrut(5));
        }
    }
    protected void updateButtons(Object v) {
        removeAll();
        initButtons();
        Integer i = v instanceof Integer ? (Integer) v : 0;
        buttons[0].setSelected((i & (1 << 2)) != 0);
        buttons[1].setSelected((i & (1 << 1)) != 0);
        buttons[2].setSelected((i & (1 << 0)) != 0);
    }
}

{'fraction_non_alphanumeric': 0.13682331945270673, 'fraction_numerical': 0.009518143961927425, 'mean_word_length': 2.13072625698324, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 7, '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': '131403', 'n_tokens_mistral': 2411, 'n_tokens_neox': 2361, 'n_words': 481}