/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cz.vutbr.feec.utko.fojtoval.krypto.funkce;

import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import javax.swing.JTextPane;
import javax.swing.TransferHandler;

/**
 * Uprava textu v hlavnich textovych oknech.
 * @author fojtoval
 */
public class UpravaTextu {

    /**
     * Kopirovani textu do clipboardu z textove oblasti, ve ktere se nachazi kurzor.
     * @param mytextpane textova oblast, kde se nachazi kurzor
     */
    public static void Copy(JTextPane mytextpane) {
        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        TransferHandler transferHandler = mytextpane.getTransferHandler();
        transferHandler.exportToClipboard(mytextpane, clipboard, TransferHandler.COPY);
    }

    /**
     * Vkladani textu z clipboardu do textove oblasti, ve ktere se nachazi kurzor.
     * @param mytextpane textova oblast, kde se nachazi kurzor
     */
    public static void Paste(JTextPane mytextpane) {
        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        TransferHandler transferHandler = mytextpane.getTransferHandler();
        transferHandler.importData(mytextpane, clipboard.getContents(null));
    }

    /**
     * Pomocna testovaci metoda, zda je vstupni String prazdny.
     * @param str
     * @return
     */
    public static boolean isEmptyOrBlank(String str) {
     return str == null || str.trim().isEmpty();
   }

}
