Package fmg.fmg8.sonstiges

Source Code of fmg.fmg8.sonstiges.Zwischenablage

/**
*
*/
package fmg.fmg8.sonstiges;

import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;

import fmg.fmg8.statistik.Parametersatz;


/**
* @author Admin
*
*/
public class Zwischenablage implements ClipboardOwner {

    /**
     * In die Zwischenablage kopieren.
     *
     * @param s  Der zu kopierende Text.
     */
    public void copyToClipboard(final String s) {
        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
                new StringSelection(s), null);
    }

    /**
     * Aus der Zwischenablage holen.
     *
     * @return  Der Text aus der Zwischenablage.
     */
    public String getClipbB() {
        Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
        Transferable cont = clip.getContents(this);

        if (cont == null) {
             return null;
        } else {
            try {
                String s = (String) cont.getTransferData(
                    DataFlavor.stringFlavor);
                return s;
            } catch (Exception e) {
                return null;
            }
        }
    }

    /**
     * Wird aufgerufen, wenn die Zwischenablage ver�ndert wird.
     *
     * @param clipboard  Die Zwischenablage.
     * @param contents   Der Inhalt.
     */
    public void lostOwnership(final Clipboard clipboard,
                              final Transferable contents) {
        String[] args = {"log", "1"};
        Parametersatz pars = new Parametersatz(args);
        SonstMeth.log(1, "Zwischenablage veraendert.", pars);
    }
}
TOP

Related Classes of fmg.fmg8.sonstiges.Zwischenablage

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.