<commit_before>package com.example.filelist;

import com.example.Dialogs;
import com.example.preview.FilePreview;
import com.example.preview.FilePreviewFactory;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import static java.awt.event.KeyEvent.VK_ENTER;
import static javax.swing.KeyStroke.getKeyStroke;

/**
 * @author innokenty
 */
public abstract class FileList<T extends FileListEntry>
        extends JList<T> {

    public FileList(FileListModel<T> dataModel) {
        super(dataModel);
        setCellRenderer(new FileListEntryRenderer());
        initOpeningSelectedOnEnter();
        initOpeningSelectedOnDoubleClick();
    }


    /* MODEL METHODS OVERRIDING */

    /**
     * @param model only model of type com.example.filelist.FileListModel is supported
     * @throws java.lang.IllegalArgumentException if the passed model is not
     * instance of com.example.filelist.FileListModel
     */
    @Override
    public void setModel(ListModel<T> model) {
        if (model instanceof FileListModel) {
            super.setModel(model);
        } else {
            throw new IllegalArgumentException("Only model of type " +
                    "com.example.filelist.FileListModel is supported");
        }
    }

    public FileListModel<T> getModel() {
        return (FileListModel<T>) super.getModel();
    }

    public void openSelected() {
        T selectedFile = super.getSelectedValue();
        if (selectedFile.isDirectory()) {
            try {
                getModel().openFolder(selectedFile);
            } catch (Exception e) {
                Dialogs.unexpectedError(e, this);
            }
        } else {
            try {
                showFilePreview();
            } catch (Exception e) {
                Dialogs.unexpectedError(e, this);
            }
        }
    }

    /* GUI INITIALIZATION METHODS */

    protected void initOpeningSelectedOnEnter() {
        final String openFolderKey = "openFolder";
        KeyStroke enterKeyStroke = getKeyStroke(VK_ENTER, 0);
        super.getInputMap().put(enterKeyStroke, openFolderKey);
        super.getActionMap().put(openFolderKey, openSelectedAction());
    }

    private AbstractAction openSelectedAction() {
        return new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                openSelected();
            }<commit_msg>ref - code style fix in FileList<commit_after>package com.example.filelist;

import com.example.Dialogs;
import com.example.preview.FilePreview;
import com.example.preview.FilePreviewFactory;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import static java.awt.event.KeyEvent.VK_ENTER;
import static javax.swing.KeyStroke.getKeyStroke;

/**
 * @author innokenty
 */
public abstract class FileList<T extends FileListEntry>
        extends JList<T> {

    public FileList(FileListModel<T> dataModel) {
        super(dataModel);
        setCellRenderer(new FileListEntryRenderer());
        initOpeningSelectedOnEnter();
        initOpeningSelectedOnDoubleClick();
    }


    /* MODEL METHODS OVERRIDING */

    /**
     * @param model only model of type com.example.filelist.FileListModel is supported
     * @throws java.lang.IllegalArgumentException if the passed model is not
     * instance of com.example.filelist.FileListModel
     */
    @Override
    public void setModel(ListModel<T> model) {
        if (model instanceof FileListModel) {
            super.setModel(model);
        } else {
            throw new IllegalArgumentException("Only model of type " +
                    "com.example.filelist.FileListModel is supported");
        }
    }

    public FileListModel<T> getModel() {
        return (FileListModel<T>) super.getModel();
    }

    public void openSelected() {
        T selectedFile = super.getSelectedValue();
        try {
            if (selectedFile.isDirectory()) {
                getModel().openFolder(selectedFile);
            } else {
                showFilePreview();
            }
        } catch (Exception e) {
            Dialogs.unexpectedError(e, this);
        }
    }

    /* GUI INITIALIZATION METHODS */

    protected void initOpeningSelectedOnEnter() {
        final String openFolderKey = "openFolder";
        KeyStroke enterKeyStroke = getKeyStroke(VK_ENTER, 0);
        super.getInputMap().put(enterKeyStroke, openFolderKey);
        super.getActionMap().put(openFolderKey, openSelectedAction());
    }

    private AbstractAction openSelectedAction() {
        return new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent e) {
                openSelected();
            }
{'fraction_non_alphanumeric': 0.09583074051026758, 'fraction_numerical': 0.00041485169052063887, 'mean_word_length': 2.5018155410312275, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '3394119', 'n_tokens_mistral': 1333, 'n_tokens_neox': 1285, 'n_words': 283}