All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alee.extended.tab.DocumentPaneEventMethodsImpl Maven / Gradle / Ivy

/*
 * This file is part of WebLookAndFeel library.
 *
 * WebLookAndFeel library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * WebLookAndFeel library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with WebLookAndFeel library.  If not, see .
 */

package com.alee.extended.tab;

/**
 * Common implementations for {@link com.alee.extended.tab.DocumentPaneEventMethods} interface methods.
 *
 * @author Mikle Garin
 * @see How to use WebDocumentPane
 * @see DocumentPaneEventMethods
 * @see WebDocumentPane
 */
public final class DocumentPaneEventMethodsImpl
{
    /**
     * Shortcut method for {@link DocumentListener#opened(DocumentData, PaneData, int)} event.
     *
     * @param documentPane {@link WebDocumentPane}
     * @param runnable     {@link DocumentDataRunnable}
     * @param           {@link DocumentData} type
     * @return created {@link DocumentListener}
     */
    public static  DocumentListener onDocumentOpen ( final WebDocumentPane documentPane,
                                                                                final DocumentDataRunnable runnable )
    {
        final DocumentAdapter documentAdapter = new DocumentAdapter ()
        {
            @Override
            public void opened ( final T document, final PaneData pane, final int index )
            {
                runnable.run ( document, pane, index );
            }
        };
        documentPane.addDocumentListener ( documentAdapter );
        return documentAdapter;
    }

    /**
     * Shortcut method for {@link DocumentListener#selected(DocumentData, PaneData, int)} event.
     *
     * @param documentPane {@link WebDocumentPane}
     * @param runnable     {@link DocumentDataRunnable}
     * @param           {@link DocumentData} type
     * @return created {@link DocumentListener}
     */
    public static  DocumentListener onDocumentSelection ( final WebDocumentPane documentPane,
                                                                                     final DocumentDataRunnable runnable )
    {
        final DocumentAdapter documentAdapter = new DocumentAdapter ()
        {
            @Override
            public void selected ( final T document, final PaneData pane, final int index )
            {
                runnable.run ( document, pane, index );
            }
        };
        documentPane.addDocumentListener ( documentAdapter );
        return documentAdapter;
    }

    /**
     * Shortcut method for {@link DocumentListener#closing(DocumentData, PaneData, int)} event.
     *
     * @param documentPane {@link WebDocumentPane}
     * @param runnable     {@link DocumentDataCancellableRunnable}
     * @param           {@link DocumentData} type
     * @return created {@link DocumentListener}
     */
    public static  DocumentListener onDocumentClosing ( final WebDocumentPane documentPane,
                                                                                   final DocumentDataCancellableRunnable runnable )
    {
        final DocumentAdapter documentAdapter = new DocumentAdapter ()
        {
            @Override
            public boolean closing ( final T document, final PaneData pane, final int index )
            {
                return runnable.run ( document, pane, index );
            }
        };
        documentPane.addDocumentListener ( documentAdapter );
        return documentAdapter;
    }

    /**
     * Shortcut method for {@link DocumentListener#closed(DocumentData, PaneData, int)} event.
     *
     * @param documentPane {@link WebDocumentPane}
     * @param runnable     {@link DocumentDataRunnable}
     * @param           {@link DocumentData} type
     * @return created {@link DocumentListener}
     */
    public static  DocumentListener onDocumentClose ( final WebDocumentPane documentPane,
                                                                                 final DocumentDataRunnable runnable )
    {
        final DocumentAdapter documentAdapter = new DocumentAdapter ()
        {
            @Override
            public void closed ( final T document, final PaneData pane, final int index )
            {
                runnable.run ( document, pane, index );
            }
        };
        documentPane.addDocumentListener ( documentAdapter );
        return documentAdapter;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy