<commit_before>package net.argius.stew.ui.window;

import static java.awt.event.InputEvent.SHIFT_DOWN_MASK;
import static java.awt.event.KeyEvent.*;
import static java.awt.event.MouseEvent.MOUSE_DRAGGED;
import static java.awt.event.MouseEvent.MOUSE_PRESSED;
import static javax.swing.KeyStroke.getKeyStroke;
import static net.argius.stew.ui.window.AnyActionKey.*;
import static net.argius.stew.ui.window.ResultSetTable.ActionKey.*;

import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import java.io.*;
import java.sql.*;
import java.util.*;
import java.util.List;

import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
import javax.swing.text.*;

import net.argius.stew.*;
import net.argius.stew.io.*;
import net.argius.stew.text.*;

/**
 * Table for Result Set.
 */
final class ResultSetTable extends JTable implements AnyActionListener, TextSearch {

    enum ActionKey {
        copyWithEscape,
        clearSelectedCellValue,
        setCurrentTimeValue,
        copyColumnName,
        findColumnName,
        addEmptyRow,
        insertFromClipboard,
        duplicateRows,
        linkRowsToDatabase,
        deleteRows,
        sort,
        jumpToColumn,
        doNothing,
    }

    static final String TAB = "\t";

    private static final Logger log = Logger.getLogger(ResultSetTable.class);
    private static final TableCellRenderer nullRenderer = new NullValueRenderer();

    private final AnyActionListener anyActionListener;
    private final ColumnHeaderCellRenderer columnHeaderRenderer;
    private final RowHeader rowHeader;
    private final Point mousePositionForColumnHeader = new Point();

    private int lastSortedIndex;
    private boolean lastSortedIsReverse;
    private String autoAdjustMode;

    // It is used by the process that has no key-event.
    private volatile KeyEvent lastKeyEvent;

    /**
     * Constructor.
     */
    ResultSetTable(AnyActionListener anyActionListener) {
        this.anyActionListener = anyActionListener;
        JTableHeader columnHeader = getTableHeader();
        TableCellRenderer columnHeaderDefaultRenderer = columnHeader.getDefaultRenderer();
        final RowHeader rowHeader = new RowHeader(this);
        this.columnHeaderRenderer = new ColumnHeaderCellRenderer(columnHeaderDefaultRenderer);
        this.rowHeader = rowHeader;
        setColumnSelectionAllowed(true);
        setAutoResizeMode(AUTO_RESIZE_OFF);
        columnHeader.setDefaultRenderer(columnHeaderRenderer);
        columnHeader.setReorderingAllowed(false);
        // [Events]
        // column header
        MouseInputListener colHeaderMouseListener = new ColumnHeaderMouseInputListener();
        columnHeader.addMouseListener(colHeaderMouseListener);
        columnHeader.addMouseMotionListener(colHeaderMouseListener);
        // row header
        MouseInputListener rowHeaderMouseListener = new RowHeaderMouseInputListener(rowHeader);
        rowHeader.addMouseListener(rowHeaderMouseListener);
        rowHeader.addMouseMotionListener(rowHeaderMouseListener);
        // cursor
        for (int i = 0; i < 2; i++) {
            final boolean withSelect = (i == 1);
            bindJumpAction("home", VK_HOME, withSelect);
            bindJumpAction("end", VK_END, withSelect);
            bindJumpAction("top", VK_UP, withSelect);
            bindJumpAction("bottom", VK_DOWN, withSelect);
            bindJumpAction("leftmost", VK_LEFT, withSelect);
            bindJumpAction("rightmost", VK_RIGHT, withSelect);
        }
        // key binds
        final int shortcutKey = Utilities.getMenuShortcutKeyMask();
        AnyAction aa = new AnyAction(this);
        aa.bindSelf(paste, getKeyStroke(VK_V, shortcutKey));
        aa.bindKeyStroke(true, adjustColumnWidth, getKeyStroke(VK_SLASH, shortcutKey));
        aa.bindKeyStroke(false, doNothing, getKeyStroke(VK_ESCAPE, 0));
    }

    private final class RowHeaderMouseInputListener extends MouseInputAdapter {
    
        @SuppressWarnings("hiding")
        private final RowHeader rowHeader;
        private int dragStartRow;
    <commit_msg>fixed bug: Action copyWithEscape and clearSelectedCellValue were not bound in ResultSetTable<commit_after>package net.argius.stew.ui.window;

import static java.awt.event.InputEvent.SHIFT_DOWN_MASK;
import static java.awt.event.KeyEvent.*;
import static java.awt.event.MouseEvent.MOUSE_DRAGGED;
import static java.awt.event.MouseEvent.MOUSE_PRESSED;
import static javax.swing.KeyStroke.getKeyStroke;
import static net.argius.stew.ui.window.AnyActionKey.*;
import static net.argius.stew.ui.window.ResultSetTable.ActionKey.*;

import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import java.io.*;
import java.sql.*;
import java.util.*;
import java.util.List;

import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
import javax.swing.text.*;

import net.argius.stew.*;
import net.argius.stew.io.*;
import net.argius.stew.text.*;

/**
 * Table for Result Set.
 */
final class ResultSetTable extends JTable implements AnyActionListener, TextSearch {

    enum ActionKey {
        copyWithEscape,
        clearSelectedCellValue,
        setCurrentTimeValue,
        copyColumnName,
        findColumnName,
        addEmptyRow,
        insertFromClipboard,
        duplicateRows,
        linkRowsToDatabase,
        deleteRows,
        sort,
        jumpToColumn,
        doNothing,
    }

    static final String TAB = "\t";

    private static final Logger log = Logger.getLogger(ResultSetTable.class);
    private static final TableCellRenderer nullRenderer = new NullValueRenderer();

    private final AnyActionListener anyActionListener;
    private final ColumnHeaderCellRenderer columnHeaderRenderer;
    private final RowHeader rowHeader;
    private final Point mousePositionForColumnHeader = new Point();

    private int lastSortedIndex;
    private boolean lastSortedIsReverse;
    private String autoAdjustMode;

    // It is used by the process that has no key-event.
    private volatile KeyEvent lastKeyEvent;

    /**
     * Constructor.
     */
    ResultSetTable(AnyActionListener anyActionListener) {
        this.anyActionListener = anyActionListener;
        JTableHeader columnHeader = getTableHeader();
        TableCellRenderer columnHeaderDefaultRenderer = columnHeader.getDefaultRenderer();
        final RowHeader rowHeader = new RowHeader(this);
        this.columnHeaderRenderer = new ColumnHeaderCellRenderer(columnHeaderDefaultRenderer);
        this.rowHeader = rowHeader;
        setColumnSelectionAllowed(true);
        setAutoResizeMode(AUTO_RESIZE_OFF);
        columnHeader.setDefaultRenderer(columnHeaderRenderer);
        columnHeader.setReorderingAllowed(false);
        // [Events]
        // column header
        MouseInputListener colHeaderMouseListener = new ColumnHeaderMouseInputListener();
        columnHeader.addMouseListener(colHeaderMouseListener);
        columnHeader.addMouseMotionListener(colHeaderMouseListener);
        // row header
        MouseInputListener rowHeaderMouseListener = new RowHeaderMouseInputListener(rowHeader);
        rowHeader.addMouseListener(rowHeaderMouseListener);
        rowHeader.addMouseMotionListener(rowHeaderMouseListener);
        // cursor
        for (int i = 0; i < 2; i++) {
            final boolean withSelect = (i == 1);
            bindJumpAction("home", VK_HOME, withSelect);
            bindJumpAction("end", VK_END, withSelect);
            bindJumpAction("top", VK_UP, withSelect);
            bindJumpAction("bottom", VK_DOWN, withSelect);
            bindJumpAction("leftmost", VK_LEFT, withSelect);
            bindJumpAction("rightmost", VK_RIGHT, withSelect);
        }
        // key binds
        final int shortcutKey = Utilities.getMenuShortcutKeyMask();
        AnyAction aa = new AnyAction(this);
        aa.bindSelf(copyWithEscape, getKeyStroke(VK_C, shortcutKey | InputEvent.SHIFT_DOWN_MASK));
        aa.bindSelf(paste, getKeyStroke(VK_V, shortcutKey));
        aa.bindSelf(clearSelectedCellValue, getKeyStroke(VK_DELETE, 0));
        aa.bindKeyStroke(true, adjustColumnWidth, getKeyStroke(VK_SLASH, shortcutKey));
        aa.bindKeyStroke(false, doNothing, getKeyStroke(VK_ESCAPE, 0));
    }

    private final class RowHeaderMouseInputListener extends MouseInputAdapter {
    
        @SuppressWarnings("hiding")
        private final RowHeader rowHeader;
        private int dragStartRow;
    
{'fraction_non_alphanumeric': 0.08614764782557174, 'fraction_numerical': 0.001066477070742979, 'mean_word_length': 3.4234800838574424, 'pattern_counts': {'":': 0, '<': 5, '<?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': '7314274', 'n_tokens_mistral': 2312, 'n_tokens_neox': 2275, 'n_words': 507}