Java JComponent Container isPasteEnabled(JComponent targetComponent)

Here you can find the source of isPasteEnabled(JComponent targetComponent)

Description

Testeaza daca o componenta este buna pentru copy

License

Open Source License

Parameter

Parameter Description
targetComponent a parameter

Declaration

public static boolean isPasteEnabled(JComponent targetComponent) 

Method Source Code


//package com.java2s;
/*//w  ww  . ja va2s. c o m
 *
 * This file is part of Genome Artist.
 *
 * Genome Artist 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.
 *
 * Genome Artist 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 Genome Artist.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.Transferable;
import javax.swing.JComponent;
import javax.swing.TransferHandler;

public class Main {
    /**
     * Testeaza daca o componenta este buna pentru copy
     * @param targetComponent
     * @return
     */
    public static boolean isPasteEnabled(JComponent targetComponent) {
        Clipboard clipboard = getClipboard(targetComponent);
        Transferable trans = null;
        if (clipboard != null)
            trans = clipboard.getContents(null);

        //Creez suport pentru paste
        TransferHandler.TransferSupport transferSupport = new TransferHandler.TransferSupport(targetComponent,
                trans);
        TransferHandler transferHandler = targetComponent.getTransferHandler();

        //Verific pachetul cu componenta
        if (transferHandler != null && trans != null)
            return targetComponent.getTransferHandler().canImport(transferSupport);
        else
            return false;
    }

    /**
     * Returns the clipboard to use for cut/copy/paste.
     */
    private static Clipboard getClipboard(JComponent c) {
        return Toolkit.getDefaultToolkit().getSystemClipboard();
    }
}

Related

  1. getWindow(final JComponent comp)
  2. getWindow(JComponent c)
  3. getWindowLocation(JComponent start)
  4. invokeRepaintOnLayeredRoot(Component leaf, boolean everything)
  5. isCopyEnabled(JComponent targetComponent)
  6. rootPaneForComponent(Component comp)
  7. widgetsEnable(boolean flag, JComponent... comps)