<commit_before>package edu.wustl.cab2b.client.ui.pagination;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Vector;

import javax.swing.event.EventListenerList;

import org.jdesktop.swingx.JXHyperlink;
import org.jdesktop.swingx.JXPanel;

import edu.wustl.cab2b.client.ui.RiverLayout;
import edu.wustl.cab2b.client.ui.controls.Cab2bHyperlink;
import edu.wustl.cab2b.client.ui.controls.Cab2bPanel;

/**
 * A Swing component to perform pagination of long list of user data.
 * This component is designed to simulate the Browser kind of pagination
 * of search results.
 * 
 * This component can be an alternative the ScrollPane component, with different
 * technique to display a long list of user data.
 * 
 * List of Property Change Listeners implemented and working.
 * 1) isSelectable
 * 2) isGroupActionEnabled // TODO this should automatically get disabled if isSelectable is disabled.
 * 3) elementsPerPage
 * 
 * @author chetan_bh
 */
public class JPagination extends Cab2bPanel implements PropertyChangeListener, MouseWheelListener {

    private static final long serialVersionUID = 1L;

    /**
     * A boolean to set selection feature enabled or disabled.
     */
    private boolean isSelectable = true;

    /**
     * A boolean to set group actions set displayed or not displayed.
     */
    private boolean isGroupActionEnabled = true;

    /**
     * A model to hold user data.
     */
    private PaginationModel paginationModel;

    /**
     * A Panel to display some common action elements like "Select All", "Clear All", etc.
     */
    private JGroupActionPanel groupActionPanel;

    /**
     * A Panel to display the page indexes, for user to navigate through the data using
     * these indices.
     */
    private JPageBar pageBar;

    /**
     * A Panel to display the page elements. 
     */
    private JXPanel pagePanel;

    /**
     * S actionListenerList, so that many listener can register
     * to listen for page element actions.
     */
    private Vector<ActionListener> pageElementActionListenerList = new Vector<ActionListener>();

    /**
     * A selection model for the entire <code>JPagination</code> component.
     */
    private PageSelectionModel pageSelectionModel;

    /**
     * A selection listener for the page element selections.
     */
    private Vector<PageSelectionListener> pageSelectionListenerList = new Vector<PageSelectionListener>();

    @Deprecated
    protected EventListenerList listenerList = new EventListenerList();

    private Component parentComponent;

    /**
     * Auto-Resize will not work for Alphabetic Pager.
     */
    boolean automaticPageResize = true;

    boolean mouseWheelEnabled = true;

    private JPageElement selectedJPageElement;

    private Cab2bHyperlink selectAllHyperlink;

    private Cab2bHyperlink clearAllHyperlink;

    private Cab2bHyperlink invertSelectionHyperlink;

    public JPagination() {
        this(null);
    }

    public JPagination(Vector<PageElement> data) {
        this(data, new NumericPager(data));
    }

    public JPagination(Vector<PageElement> data, Pager pager) {
        this(data, pager, null, false);
    }

    public JPagination(Vector<PageElement> data, Pager pager, Component parentComponent, boolean autoPageResize) {
        paginationModel = new PaginationModel(data, pager);
        pageSelectionModel = new DefaultPageSelectionModel(this);
        this.addPropertyChangeListener(this);

        if (parentComponent == null) {
            automaticPageResize = false;
        } else {
            this.automaticPageResize = autoPageResize;
            this.parentComponent = parentComponent;
            parentComponent.addComponentListener(new PaginationComponentListener());
        }

        initGUI();
        addNewMouseWheelListener();
    }
    
    public JPagination(Vector<PageElement> data, Pager pager, Component parentComponent, boolean autoPageResize, boolean selectable) {
    	this(data, pager, parentComponent, autoPageResize);
        this.isSelectable=selectable;
    }

    private void initGUI() {
        this.removeAll();
        pageBar = new JPageBar(paginationModel.pager.getAllPageIndices(), new Vector(), this);
        setLayout(new BorderLayout());

        if (isGroupActionEnabled) {
            groupActionPanel = new JGroupActionPanel();
            add(groupActionPanel, BorderLayout.NORTH);
        }

        pagePanel = getPagePanel(paginationModel.firstPage());
        if (automaticPageResize)
            pagePanel.addComponentListener(new PaginationComponentListener());
        add(pagePanel, BorderLayout.CENTER);
        add(pageBar, BorderLayout.SOUTH);<commit_msg>Restored the two line that were removed by mistake<commit_after>package edu.wustl.cab2b.client.ui.pagination;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Vector;

import javax.swing.event.EventListenerList;

import org.jdesktop.swingx.JXHyperlink;
import org.jdesktop.swingx.JXPanel;

import edu.wustl.cab2b.client.ui.RiverLayout;
import edu.wustl.cab2b.client.ui.controls.Cab2bHyperlink;
import edu.wustl.cab2b.client.ui.controls.Cab2bPanel;

/**
 * A Swing component to perform pagination of long list of user data.
 * This component is designed to simulate the Browser kind of pagination
 * of search results.
 * 
 * This component can be an alternative the ScrollPane component, with different
 * technique to display a long list of user data.
 * 
 * List of Property Change Listeners implemented and working.
 * 1) isSelectable
 * 2) isGroupActionEnabled // TODO this should automatically get disabled if isSelectable is disabled.
 * 3) elementsPerPage
 * 
 * @author chetan_bh
 */
public class JPagination extends Cab2bPanel implements PropertyChangeListener, MouseWheelListener {

    private static final long serialVersionUID = 1L;

    /**
     * A boolean to set selection feature enabled or disabled.
     */
    private boolean isSelectable = true;

    /**
     * A boolean to set group actions set displayed or not displayed.
     */
    private boolean isGroupActionEnabled = true;

    /**
     * A model to hold user data.
     */
    private PaginationModel paginationModel;

    /**
     * A Panel to display some common action elements like "Select All", "Clear All", etc.
     */
    private JGroupActionPanel groupActionPanel;

    /**
     * A Panel to display the page indexes, for user to navigate through the data using
     * these indices.
     */
    private JPageBar pageBar;

    /**
     * A Panel to display the page elements. 
     */
    private JXPanel pagePanel;

    /**
     * S actionListenerList, so that many listener can register
     * to listen for page element actions.
     */
    private Vector<ActionListener> pageElementActionListenerList = new Vector<ActionListener>();

    /**
     * A selection model for the entire <code>JPagination</code> component.
     */
    private PageSelectionModel pageSelectionModel;

    /**
     * A selection listener for the page element selections.
     */
    private Vector<PageSelectionListener> pageSelectionListenerList = new Vector<PageSelectionListener>();

    @Deprecated
    protected EventListenerList listenerList = new EventListenerList();

    private Component parentComponent;

    /**
     * Auto-Resize will not work for Alphabetic Pager.
     */
    boolean automaticPageResize = true;

    boolean mouseWheelEnabled = true;

    private JPageElement selectedJPageElement;

    private Cab2bHyperlink selectAllHyperlink;

    private Cab2bHyperlink clearAllHyperlink;

    private Cab2bHyperlink invertSelectionHyperlink;

    public JPagination() {
        this(null);
    }

    public JPagination(Vector<PageElement> data) {
        this(data, new NumericPager(data));
    }

    public JPagination(Vector<PageElement> data, Pager pager) {
        this(data, pager, null, false);
    }

    public JPagination(Vector<PageElement> data, Pager pager, Component parentComponent, boolean autoPageResize) {
        paginationModel = new PaginationModel(data, pager);
        pageSelectionModel = new DefaultPageSelectionModel(this);
        this.addPropertyChangeListener(this);

        if (parentComponent == null) {
            automaticPageResize = false;
        } else {
            this.automaticPageResize = autoPageResize;
            this.parentComponent = parentComponent;
            parentComponent.addComponentListener(new PaginationComponentListener());
        }

        initGUI();
        addNewMouseWheelListener();
    }
    
    public JPagination(Vector<PageElement> data, Pager pager, Component parentComponent, boolean autoPageResize, boolean selectable) {
    	this(data, pager, parentComponent, autoPageResize);
        this.isSelectable=selectable;
        initGUI();
        addNewMouseWheelListener();
    }

    private void initGUI() {
        this.removeAll();
        pageBar = new JPageBar(paginationModel.pager.getAllPageIndices(), new Vector(), this);
        setLayout(new BorderLayout());

        if (isGroupActionEnabled) {
            groupActionPanel = new JGroupActionPanel();
            add(groupActionPanel, BorderLayout.NORTH);
        }

        pagePanel = getPagePanel(paginationModel.firstPage());
        if (automaticPageResize)
            pagePanel.addComponentListener(new PaginationComponentListener());
        add(pagePanel, BorderLayout.CENTER);
        add(pageBar, BorderLayout.SOUTH);
{'fraction_non_alphanumeric': 0.08037825059101655, 'fraction_numerical': 0.0027580772261623326, 'mean_word_length': 3.3333333333333335, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '2655217', 'n_tokens_mistral': 2802, 'n_tokens_neox': 2695, 'n_words': 767}